From aedec58e91016094f8ca7994ef4480abf74175bf Mon Sep 17 00:00:00 2001 From: Peter Daum Date: Mon, 17 Oct 2016 22:43:44 +0200 Subject: [PATCH 1/3] Added waitBeforeProceed parameter --- src/main/java/com/github/geowarin/junit/DockerRuleParams.java | 2 ++ 1 file changed, 2 insertions(+) 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; } From 7f6617c0caa426591f5d31b777c59856d0acb6b0 Mon Sep 17 00:00:00 2001 From: Peter Daum Date: Mon, 17 Oct 2016 22:43:59 +0200 Subject: [PATCH 2/3] Added method to set waitBeforeProceed --- .../com/github/geowarin/junit/DockerRuleBuilder.java | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 * From 70817f34c1060b6b5420a3b75198fe361853ac55 Mon Sep 17 00:00:00 2001 From: Peter Daum Date: Mon, 17 Oct 2016 22:44:48 +0200 Subject: [PATCH 3/3] Added waiting before proceeding with further checks to junit rule --- .../com/github/geowarin/junit/DockerRule.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) 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); }