Skip to content

Commit 64d3451

Browse files
committed
Add custom Redis wait strategy as an example and to mitigate #160
1 parent 9c57f9f commit 64d3451

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

shade-test/clashing-deps-jackson/src/test/java/RedisJacksonBackedCacheTest.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import org.junit.Before;
44
import org.junit.Rule;
55
import org.junit.Test;
6+
import org.rnorth.ducttape.unreliables.Unreliables;
67
import org.testcontainers.containers.GenericContainer;
78
import redis.clients.jedis.Jedis;
89

910
import java.util.Optional;
11+
import java.util.concurrent.TimeUnit;
1012

1113
import static org.rnorth.visibleassertions.VisibleAssertions.*;
1214

@@ -17,7 +19,8 @@ public class RedisJacksonBackedCacheTest {
1719

1820
@Rule
1921
public GenericContainer redis = new GenericContainer("redis:3.0.6")
20-
.withExposedPorts(6379);
22+
.withExposedPorts(6379)
23+
.waitingFor(new RedisWaitStrategy());
2124
private Cache cache;
2225

2326
@Before
@@ -33,10 +36,10 @@ public void testFindingAnInsertedValue() {
3336
Optional<String> foundObject = cache.get("foo", String.class);
3437

3538
assertTrue("When an object in the cache is retrieved, it can be found",
36-
foundObject.isPresent());
39+
foundObject.isPresent());
3740
assertEquals("When we put a String in to the cache and retrieve it, the value is the same",
38-
"FOO",
39-
foundObject.get());
41+
"FOO",
42+
foundObject.get());
4043
}
4144

4245
@Test
@@ -46,4 +49,16 @@ public void testNotFindingAValueThatWasNotInserted() {
4649
assertFalse("When an object that's not in the cache is retrieved, nothing is found",
4750
foundObject.isPresent());
4851
}
52+
53+
private class RedisWaitStrategy extends GenericContainer.AbstractWaitStrategy {
54+
@Override
55+
protected void waitUntilReady() {
56+
//noinspection LoopStatementThatDoesntLoop
57+
Unreliables.retryUntilSuccess(10, TimeUnit.SECONDS, () ->
58+
{
59+
Jedis jedis = new Jedis(redis.getContainerIpAddress(), redis.getMappedPort(6379));
60+
return jedis.ping();
61+
});
62+
}
63+
}
4964
}

0 commit comments

Comments
 (0)