Skip to content

Commit

Permalink
Store healthCheck as field
Browse files Browse the repository at this point in the history
  • Loading branch information
kokosing committed Sep 11, 2019
1 parent 6b95975 commit b1e12fa
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public final class DockerContainer
private final String image;
private final Map<String, String> environment;
private final List<String> capabilities;
private final CheckedConsumer<HostPortProvider> healthCheck;
private DockerClient dockerClient;
private String containerId;

Expand All @@ -69,16 +70,17 @@ public DockerContainer(String image, List<Integer> ports, Map<String, String> en
this.image = requireNonNull(image, "image is null");
this.environment = ImmutableMap.copyOf(requireNonNull(environment, "environment is null"));
this.capabilities = ImmutableList.copyOf(requireNonNull(capabilities, "capabilities is null"));
this.healthCheck = requireNonNull(healthCheck, "healthCheck is null");
try {
startContainer(ports, healthCheck);
startContainer(ports);
}
catch (Exception e) {
closeAllSuppress(e, this);
throw new RuntimeException(e);
}
}

private void startContainer(List<Integer> ports, CheckedConsumer<HostPortProvider> healthCheck)
private void startContainer(List<Integer> ports)
throws Exception
{
dockerClient = DefaultDockerClient.fromEnv().build();
Expand Down Expand Up @@ -108,7 +110,7 @@ private void startContainer(List<Integer> ports, CheckedConsumer<HostPortProvide

LOG.info("Auto-assigned host ports are %s", hostPorts);

waitForContainer(healthCheck);
waitForContainer();
}

private boolean isContainerUp()
Expand Down Expand Up @@ -157,7 +159,7 @@ private void createContainer(List<Integer> ports)
waitForContainerPorts(ports);
}

private void waitForContainer(CheckedConsumer<HostPortProvider> healthCheck)
private void waitForContainer()
{
RetryPolicy<Object> retryPolicy = new RetryPolicy<>()
.withMaxDuration(Duration.of(10, MINUTES))
Expand Down

0 comments on commit b1e12fa

Please sign in to comment.