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"));
}
Aggregations