Search in sources :

Example 1 with TopResults

use of com.spotify.docker.client.messages.TopResults in project docker-client by spotify.

the class DefaultDockerClientTest method testTopProcessesOfContainer.

@Test
public void testTopProcessesOfContainer() throws Exception {
    sut.pull(BUSYBOX_LATEST);
    final ContainerConfig containerConfig = ContainerConfig.builder().image(BUSYBOX_LATEST).cmd("sh", "-c", "while :; do sleep 1; done").build();
    final String containerName = randomName();
    final ContainerCreation containerCreation = sut.createContainer(containerConfig, containerName);
    final String containerId = containerCreation.id();
    sut.startContainer(containerId);
    // Ensure that it's running so we can check the active processes
    {
        final ContainerInfo containerInfo = sut.inspectContainer(containerId);
        assertThat(containerInfo.state().running(), equalTo(true));
    }
    final TopResults topResults = sut.topContainer(containerId, null);
    assertThat(topResults.titles(), not(Matchers.empty()));
    // there could be one or two processes running, depending on if we happen to catch it in
    // between sleeps
    assertThat(topResults.processes(), hasSize(greaterThanOrEqualTo(1)));
    assertThat(topResults.titles(), either(hasItem("CMD")).or(hasItem("COMMAND")));
    final List<String> firstProcessStatus = topResults.processes().get(0);
    assertThat("All processes will run as 'root'", firstProcessStatus, hasItem("root"));
}
Also used : ContainerConfig(com.spotify.docker.client.messages.ContainerConfig) ContainerCreation(com.spotify.docker.client.messages.ContainerCreation) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo) Long.toHexString(java.lang.Long.toHexString) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) TopResults(com.spotify.docker.client.messages.TopResults) Test(org.junit.Test)

Aggregations

ContainerConfig (com.spotify.docker.client.messages.ContainerConfig)1 ContainerCreation (com.spotify.docker.client.messages.ContainerCreation)1 ContainerInfo (com.spotify.docker.client.messages.ContainerInfo)1 TopResults (com.spotify.docker.client.messages.TopResults)1 Long.toHexString (java.lang.Long.toHexString)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)1 Test (org.junit.Test)1