final ContainerExit exit; try { exit = docker.waitContainer(containerId); } finally { unregister();
@Before public void setup() throws Exception { try (final DockerClient docker = getNewDockerClient()) { // Build an image with an ENTRYPOINT and CMD prespecified final String dockerDirectory = Resources.getResource("syslog-test-image").getPath(); docker.build(Paths.get(dockerDirectory), testImage); // Figure out the host IP from the container's point of view (needed for syslog) final ContainerConfig config = ContainerConfig.builder() .image(BUSYBOX) .cmd(asList("ip", "route", "show")) .build(); final ContainerCreation creation = docker.createContainer(config); final String containerId = creation.id(); docker.startContainer(containerId); // Wait for the container to exit. // If we don't wait, docker.logs() might return an epmty string because the container // cmd hasn't run yet. docker.waitContainer(containerId); final String log; try (LogStream logs = docker.logs(containerId, stdout(), stderr())) { log = logs.readFully(); } final Matcher m = DEFAULT_GATEWAY_PATTERN.matcher(log); if (m.find()) { syslogHost = m.group("gateway"); } else { fail("couldn't determine the host address from '" + log + "'"); } } }
@Test public void test() throws Exception { startDefaultMaster(); final String id = "test-" + toHexString(new SecureRandom().nextInt()); final String namespace = "helios-" + id; final String intruder1 = intruder(namespace); final String intruder2 = intruder(namespace); // Start a container in the agent namespace startContainer(intruder1); // Start agent final HeliosClient client = defaultClient(); startDefaultAgent(testHost(), "--id=" + id); awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS); awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS); // With LXC, killing a container results in exit code 0. // In docker 1.5 killing a container results in exit code 137, in previous versions it's -1. final String executionDriver = docker.info().executionDriver(); final List<Long> expectedExitCodes = (executionDriver != null && executionDriver.startsWith("lxc-")) ? Collections.singletonList(0L) : asList(-1L, 137L); // Wait for the agent to kill the container final ContainerExit exit1 = docker.waitContainer(intruder1); assertThat(exit1.statusCode(), isIn(expectedExitCodes)); // Start another container in the agent namespace startContainer(intruder2); // Wait for the agent to kill the second container as well final ContainerExit exit2 = docker.waitContainer(intruder2); assertThat(exit2.statusCode(), isIn(expectedExitCodes)); }
final ContainerExit exit = docker.waitContainer(taskStatus.getContainerId()); assertThat(exit.statusCode(), is(0L));
/** * Block until container exit. */ public void waitForExit() throws InterruptedException { try { dockerClient.waitContainer(container.id()); } catch (DockerException e) { throw new IllegalStateException(e); } }
docker.startContainer(container.id()); ContainerExit exitStatus = docker.waitContainer(containerId);
final ContainerExit exit; try { exit = docker.waitContainer(containerId); } finally { unregister();
ContainerExit exitStatus = docker.waitContainer(this.containerId);