diff --git a/src/main/java/com/github/geowarin/junit/DockerRule.java b/src/main/java/com/github/geowarin/junit/DockerRule.java index 0ba7127..1617def 100644 --- a/src/main/java/com/github/geowarin/junit/DockerRule.java +++ b/src/main/java/com/github/geowarin/junit/DockerRule.java @@ -1,7 +1,19 @@ package com.github.geowarin.junit; -import com.spotify.docker.client.*; -import com.spotify.docker.client.messages.*; +import com.spotify.docker.client.DefaultDockerClient; +import com.spotify.docker.client.DockerCertificateException; +import com.spotify.docker.client.DockerCertificates; +import com.spotify.docker.client.DockerClient; +import static com.spotify.docker.client.DockerClient.LogsParam.follow; +import static com.spotify.docker.client.DockerClient.LogsParam.stdout; +import com.spotify.docker.client.DockerException; +import com.spotify.docker.client.LogMessage; +import com.spotify.docker.client.LogStream; +import com.spotify.docker.client.messages.ContainerConfig; +import com.spotify.docker.client.messages.ContainerCreation; +import com.spotify.docker.client.messages.ContainerInfo; +import com.spotify.docker.client.messages.HostConfig; +import com.spotify.docker.client.messages.PortBinding; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.rules.ExternalResource; @@ -19,8 +31,6 @@ import java.util.List; import java.util.Map; -import static com.spotify.docker.client.DockerClient.LogsParam.*; - /** *

* JUnit rule starting a docker container before the test and killing it @@ -65,6 +75,10 @@ protected void before() throws Throwable { ContainerInfo info = dockerClient.inspectContainer(container.id()); ports = info.networkSettings().ports(); + if(params.waitBeforeProceed != null) { + Thread.sleep(params.waitBeforeProceed); + } + if (params.portToWaitOn != null) { waitForPort(getHostPort(params.portToWaitOn), params.waitTimeout); } diff --git a/src/main/java/com/github/geowarin/junit/DockerRuleBuilder.java b/src/main/java/com/github/geowarin/junit/DockerRuleBuilder.java index 50524f2..e73bb4a 100644 --- a/src/main/java/com/github/geowarin/junit/DockerRuleBuilder.java +++ b/src/main/java/com/github/geowarin/junit/DockerRuleBuilder.java @@ -51,6 +51,17 @@ public DockerRuleBuilder waitForPort(String portToWaitOn) { return waitForPort(portToWaitOn, 10000); } + /** + * Utility method to wait before proceed with further checks + * + * @param waitBeforeProceed waiting time in milliseconds + * @return The builder + */ + public DockerRuleBuilder waitBeforeProceed(Integer waitBeforeProceed) { + params.waitBeforeProceed = waitBeforeProceed; + return this; + } + /** * Utility method to ensure a container is started * diff --git a/src/main/java/com/github/geowarin/junit/DockerRuleParams.java b/src/main/java/com/github/geowarin/junit/DockerRuleParams.java index b722960..b25e0a7 100644 --- a/src/main/java/com/github/geowarin/junit/DockerRuleParams.java +++ b/src/main/java/com/github/geowarin/junit/DockerRuleParams.java @@ -10,4 +10,6 @@ public class DockerRuleParams { String portToWaitOn; public int waitTimeout; String logToWait; + + Integer waitBeforeProceed; }