Skip to content

Commit

Permalink
Expose Toxiproxy control port and proxy name (#3454)
Browse files Browse the repository at this point in the history
* Expose Toxiproxy control port and proxy name

In order to work with and external Toxiproxy client we need the control
port to get the mapped port and the proxy names to interact with.

* Accessor for Toxiproxy mapped control port

Hidden the port constant again and created accessor for Toxiproxy
mapped control port.
  • Loading branch information
aartigao committed Dec 10, 2020
1 parent 1b2d228 commit af678a3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ protected void containerIsStarted(InspectContainerResponse containerInfo) {
client = new ToxiproxyClient(getHost(), getMappedPort(TOXIPROXY_CONTROL_PORT));
}

/**
* @return Publicly exposed Toxiproxy HTTP API control port.
*/
public int getControlPort() {
return getMappedPort(TOXIPROXY_CONTROL_PORT);
}

/**
* Obtain a {@link ContainerProxy} instance for target container that is managed by Testcontainers. The target
* container should be routable from this <b>from this {@link ToxiproxyContainer} instance</b> (e.g. on the same
Expand Down Expand Up @@ -130,6 +137,10 @@ public static class ContainerProxy {
@Getter private final int originalProxyPort;
private boolean isCurrentlyCut;

public String getName() {
return toxi.getName();
}

public ToxicList toxics() {
return toxi.toxics();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,20 @@ public void testOriginalAndMappedPorts() {
assertEquals("mapped port is correct", toxiproxy.getMappedPort(proxy2.getOriginalProxyPort()), proxy2.getProxyPort());
}

@Test
public void testProxyName() {
final ToxiproxyContainer.ContainerProxy proxy = toxiproxy.getProxy("hostname", 7070);

assertEquals("proxy name is hostname and port", "hostname:7070", proxy.getName());
}

@Test
public void testControlPort() {
final int controlPort = toxiproxy.getControlPort();

assertEquals("control port is mapped from port 8474", toxiproxy.getMappedPort(8474), controlPort);
}

private void checkCallWithLatency(Jedis jedis, final String description, int expectedMinLatency, long expectedMaxLatency) {
final long start = System.currentTimeMillis();
String s = jedis.get("somekey");
Expand Down

0 comments on commit af678a3

Please sign in to comment.