Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait before proceed parameter #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/main/java/com/github/geowarin/junit/DockerRule.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,8 +31,6 @@
import java.util.List;
import java.util.Map;

import static com.spotify.docker.client.DockerClient.LogsParam.*;

/**
* <p>
* JUnit rule starting a docker container before the test and killing it
Expand Down Expand Up @@ -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);
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/github/geowarin/junit/DockerRuleBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/github/geowarin/junit/DockerRuleParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public class DockerRuleParams {
String portToWaitOn;
public int waitTimeout;
String logToWait;

Integer waitBeforeProceed;
}