Skip to content

Commit 99eb0ce

Browse files
committed
Toxiproxy examples (latency)
1 parent 713adb2 commit 99eb0ce

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Diff for: src/test/java/com/codfishworks/toxiproxy/ToxiproxyTests.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
import com.lambdaworks.redis.RedisClient;
1616
import com.lambdaworks.redis.RedisCommandTimeoutException;
1717
import com.lambdaworks.redis.api.sync.RedisCommands;
18+
import eu.rekawek.toxiproxy.model.ToxicDirection;
1819

1920
public class ToxiproxyTests {
2021

22+
// Use a shared network so that containers can talk with each other
2123
private static Network network = Network.newNetwork();
2224

2325
private static GenericContainer redis = new GenericContainer("redis:5.0.4")
@@ -58,16 +60,20 @@ public void canConnectToRedisViaToxiproxy() {
5860
}
5961

6062
@Test
61-
public void toxiproxyCanMessUpCallsToRedis() {
63+
public void toxiproxyCanMessUpCallsToRedis() throws Exception {
6264
ToxiproxyContainer.ContainerProxy proxy = toxiproxy.getProxy(redis, 6379);
63-
proxy.setConnectionCut(true);
6465

6566
RedisClient client = RedisClient.create("redis://" + proxy.getContainerIpAddress() + ":" + proxy.getProxyPort());
6667
client.setDefaultTimeout(500, TimeUnit.MILLISECONDS);
6768

69+
RedisCommands<String, String> connect = client.connect().sync();
70+
connect.set("key", "value");
71+
72+
// Let's add an artificial delay and see what happens...
73+
proxy.toxics().latency("extra_latency", ToxicDirection.UPSTREAM, 1000);
74+
6875
Assertions.assertThrows(RedisCommandTimeoutException.class, () -> {
69-
RedisCommands<String, String> connect = client.connect().sync();
70-
connect.set("key", "value");
76+
connect.get("key");
7177
});
7278
}
7379

0 commit comments

Comments
 (0)