@Override public Container container(String containerName) { return new Container(containerName, this); }
@Override public Container container(String containerName) { return new Container(containerName, this); }
public Container container(String containerName) { containers.putIfAbsent(containerName, new Container(containerName, docker, dockerCompose)); return containers.get(containerName); }
public Container withComposeExecutableReturningContainerFor(String containerName) { return new Container(containerName, mockDocker, dockerCompose); } }
@Test public void return_a_container_with_the_specified_name_when_getting_a_new_container() { Container container = containers.container(CONTAINER_NAME); assertThat(container, is(new Container(CONTAINER_NAME, docker, dockerCompose))); }
@Test public void testStateChanges_withoutHealthCheck() throws IOException, InterruptedException { DockerCompose dockerCompose = new DefaultDockerCompose( DockerComposeFiles.from("src/test/resources/no-healthcheck.yaml"), dockerMachine, ProjectName.random()); // The noHealthcheck service has no healthcheck specified; it should be immediately healthy Container container = new Container("noHealthcheck", docker, dockerCompose); assertEquals(State.DOWN, container.state()); container.up(); assertEquals(State.HEALTHY, container.state()); container.kill(); assertEquals(State.DOWN, container.state()); }
/** * This test is not currently enabled in Circle as it does not provide a sufficiently recent version of docker-compose. * * @see <a href="https://github.com/palantir/docker-compose-rule/issues/156">Issue #156</a> */ @Test public void testStateChanges_withHealthCheck() throws IOException, InterruptedException { assumeThat("docker version", Docker.version(), new GreaterOrEqual<>(Version.forIntegers(1, 12, 0))); assumeThat("docker-compose version", DockerCompose.version(), new GreaterOrEqual<>(Version.forIntegers(1, 10, 0))); DockerCompose dockerCompose = new DefaultDockerCompose( DockerComposeFiles.from("src/test/resources/native-healthcheck.yaml"), dockerMachine, ProjectName.random()); // The withHealthcheck service's healthcheck checks every 100ms whether the file "healthy" exists Container container = new Container("withHealthcheck", docker, dockerCompose); assertEquals(State.DOWN, container.state()); container.up(); assertEquals(State.UNHEALTHY, container.state()); dockerCompose.exec(noOptions(), "withHealthcheck", arguments("touch", "healthy")); wait.until(container::state, equalTo(State.HEALTHY)); dockerCompose.exec(noOptions(), "withHealthcheck", arguments("rm", "healthy")); wait.until(container::state, equalTo(State.UNHEALTHY)); container.kill(); assertEquals(State.DOWN, container.state()); } }