Skip to content

Commit af678a3

Browse files
authored
Expose Toxiproxy control port and proxy name (#3454)
* 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.
1 parent 1b2d228 commit af678a3

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

modules/toxiproxy/src/main/java/org/testcontainers/containers/ToxiproxyContainer.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ protected void containerIsStarted(InspectContainerResponse containerInfo) {
6363
client = new ToxiproxyClient(getHost(), getMappedPort(TOXIPROXY_CONTROL_PORT));
6464
}
6565

66+
/**
67+
* @return Publicly exposed Toxiproxy HTTP API control port.
68+
*/
69+
public int getControlPort() {
70+
return getMappedPort(TOXIPROXY_CONTROL_PORT);
71+
}
72+
6673
/**
6774
* Obtain a {@link ContainerProxy} instance for target container that is managed by Testcontainers. The target
6875
* container should be routable from this <b>from this {@link ToxiproxyContainer} instance</b> (e.g. on the same
@@ -130,6 +137,10 @@ public static class ContainerProxy {
130137
@Getter private final int originalProxyPort;
131138
private boolean isCurrentlyCut;
132139

140+
public String getName() {
141+
return toxi.getName();
142+
}
143+
133144
public ToxicList toxics() {
134145
return toxi.toxics();
135146
}

modules/toxiproxy/src/test/java/org/testcontainers/containers/ToxiproxyTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,20 @@ public void testOriginalAndMappedPorts() {
149149
assertEquals("mapped port is correct", toxiproxy.getMappedPort(proxy2.getOriginalProxyPort()), proxy2.getProxyPort());
150150
}
151151

152+
@Test
153+
public void testProxyName() {
154+
final ToxiproxyContainer.ContainerProxy proxy = toxiproxy.getProxy("hostname", 7070);
155+
156+
assertEquals("proxy name is hostname and port", "hostname:7070", proxy.getName());
157+
}
158+
159+
@Test
160+
public void testControlPort() {
161+
final int controlPort = toxiproxy.getControlPort();
162+
163+
assertEquals("control port is mapped from port 8474", toxiproxy.getMappedPort(8474), controlPort);
164+
}
165+
152166
private void checkCallWithLatency(Jedis jedis, final String description, int expectedMinLatency, long expectedMaxLatency) {
153167
final long start = System.currentTimeMillis();
154168
String s = jedis.get("somekey");

0 commit comments

Comments
 (0)