|
15 | 15 | import com.lambdaworks.redis.RedisClient;
|
16 | 16 | import com.lambdaworks.redis.RedisCommandTimeoutException;
|
17 | 17 | import com.lambdaworks.redis.api.sync.RedisCommands;
|
| 18 | +import eu.rekawek.toxiproxy.model.ToxicDirection; |
18 | 19 |
|
19 | 20 | public class ToxiproxyTests {
|
20 | 21 |
|
| 22 | + // Use a shared network so that containers can talk with each other |
21 | 23 | private static Network network = Network.newNetwork();
|
22 | 24 |
|
23 | 25 | private static GenericContainer redis = new GenericContainer("redis:5.0.4")
|
@@ -58,16 +60,20 @@ public void canConnectToRedisViaToxiproxy() {
|
58 | 60 | }
|
59 | 61 |
|
60 | 62 | @Test
|
61 |
| - public void toxiproxyCanMessUpCallsToRedis() { |
| 63 | + public void toxiproxyCanMessUpCallsToRedis() throws Exception { |
62 | 64 | ToxiproxyContainer.ContainerProxy proxy = toxiproxy.getProxy(redis, 6379);
|
63 |
| - proxy.setConnectionCut(true); |
64 | 65 |
|
65 | 66 | RedisClient client = RedisClient.create("redis://" + proxy.getContainerIpAddress() + ":" + proxy.getProxyPort());
|
66 | 67 | client.setDefaultTimeout(500, TimeUnit.MILLISECONDS);
|
67 | 68 |
|
| 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 | + |
68 | 75 | Assertions.assertThrows(RedisCommandTimeoutException.class, () -> {
|
69 |
| - RedisCommands<String, String> connect = client.connect().sync(); |
70 |
| - connect.set("key", "value"); |
| 76 | + connect.get("key"); |
71 | 77 | });
|
72 | 78 | }
|
73 | 79 |
|
|
0 commit comments