package org.testcontainers.junit;

import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;
import org.testcontainers.containers.DockerComposeContainer;
import org.testcontainers.utility.TestEnvironment;
import redis.clients.jedis.Jedis;

import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals;

/**
 * Created by rnorth on 21/05/2016.
 */
public abstract class BaseDockerComposeTest {

    protected static final int REDIS_PORT = 6379;

    protected abstract DockerComposeContainer getEnvironment();

    @BeforeClass
    public static void checkVersion() {
        Assume.assumeTrue(TestEnvironment.dockerApiAtLeast("1.22"));
    }

    @Test
    public void simpleTest() {
        Jedis jedis = new Jedis(getEnvironment().getServiceHost("redis_1", REDIS_PORT), getEnvironment().getServicePort("redis_1", REDIS_PORT));

        jedis.incr("test");
        jedis.incr("test");
        jedis.incr("test");

        assertEquals("A redis instance defined in compose can be used in isolation", "3", jedis.get("test"));
    }

    @Test
    public void secondTest() {
        // used in manual checking for cleanup in between tests
        Jedis jedis = new Jedis(getEnvironment().getServiceHost("redis_1", REDIS_PORT), getEnvironment().getServicePort("redis_1", REDIS_PORT));

        jedis.incr("test");
        jedis.incr("test");
        jedis.incr("test");

        assertEquals("Tests use fresh container instances", "3", jedis.get("test"));
        // if these end up using the same container one of the test methods will fail.
        // However, @Rule creates a separate DockerComposeContainer instance per test, so this just shouldn't happen
    }
}

@@ -106,16 +106,68 @@
 t.Test;%0A
+import org.rnorth.ducttape.unreliables.Unreliables;%0A
 import o
@@ -219,16 +219,16 @@
 tainer;%0A
-
 import o
@@ -305,16 +305,55 @@
 Jedis;%0A%0A
+import java.util.concurrent.TimeUnit;%0A%0A
 import s
@@ -939,32 +939,188 @@
  REDIS_PORT));%0A%0A
+        // TODO: remove following resolution of #160%0A        Unreliables.retryUntilSuccess(10, TimeUnit.SECONDS, () -%3E %7B jedis.connect(); return true; %7D);%0A%0A
         jedis.in
@@ -1410,16 +1410,16 @@
 n tests%0A
-
         
@@ -1548,32 +1548,188 @@
  REDIS_PORT));%0A%0A
+        // TODO: remove following resolution of #160%0A        Unreliables.retryUntilSuccess(10, TimeUnit.SECONDS, () -%3E %7B jedis.connect(); return true; %7D);%0A%0A
         jedis.in

Add extra waits for Redis startup in docker compose tests