public static void killCassandraContainer(String containerName) { Container container = EteSetup.getContainer(containerName); try { container.kill(); } catch (IOException | InterruptedException e) { throw Throwables.propagate(e); } }
@Override public void after() { if (!initialized.get()) { return; } try { kvs.close(); containers.getContainer(containerInstance.getServiceName()).kill(); } catch (IOException | InterruptedException e) { throw Throwables.rewrapAndThrowUncheckedException(e); } }
private static void killCassandraContainer(String containerName) throws IOException, InterruptedException { CONTAINERS.getContainer(containerName).kill(); DockerPort containerPort = new DockerPort(containerName, CASSANDRA_THRIFT_PORT, CASSANDRA_THRIFT_PORT); Awaitility.waitAtMost(10, TimeUnit.SECONDS).pollInterval(2, TimeUnit.SECONDS).until( () -> !containerPort.isListeningNow()); } }
@Test public void kill_can_be_run_on_killed_container() { forEachContainer(containerName -> { try { Container container = docker.containers().container(containerName); container.kill(); assertThat(container.state(), is(State.DOWN)); container.kill(); } catch (IOException | InterruptedException e) { propagate(e); } }); }
@Test public void can_kill_and_start_containers() { forEachContainer(containerName -> { try { Container container = docker.containers().container(containerName); container.kill(); assertThat(container.state(), is(State.DOWN)); container.start(); assertThat(container.state(), is(State.HEALTHY)); } catch (IOException | InterruptedException e) { propagate(e); } }); }
@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()); } }