@Test(groups = "ignoreInCircleCi") public void testStopContainer() throws DockerException { final RemoteApiVersion apiVersion = getVersion(dockerClient); CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999").exec(); LOG.info("Created container: {}", container.toString()); assertThat(container.getId(), not(isEmptyString())); dockerClient.startContainerCmd(container.getId()).exec(); LOG.info("Stopping container: {}", container.getId()); dockerClient.stopContainerCmd(container.getId()).withTimeout(2).exec(); InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec(); LOG.info("Container Inspect: {}", inspectContainerResponse.toString()); assertThat(inspectContainerResponse.getState().getRunning(), is(equalTo(false))); final Integer exitCode = inspectContainerResponse.getState().getExitCode(); if (apiVersion.equals(VERSION_1_22)) { assertThat(exitCode, is(0)); } else { assertThat(exitCode, not(0)); } }
@Test public void testWaitContainer() throws DockerException { CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("true").exec(); LOG.info("Created container: {}", container.toString()); assertThat(container.getId(), not(isEmptyString())); dockerClient.startContainerCmd(container.getId()).exec(); int exitCode = dockerClient.waitContainerCmd(container.getId()).exec(); LOG.info("Container exit code: {}", exitCode); assertThat(exitCode, equalTo(0)); InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec(); LOG.info("Container Inspect: {}", inspectContainerResponse.toString()); assertThat(inspectContainerResponse.getState().isRunning(), is(equalTo(false))); assertThat(inspectContainerResponse.getState().getExitCode(), is(equalTo(exitCode))); }