Search in sources :

Example 6 with ImageInfo

use of com.spotify.docker.client.messages.ImageInfo in project helios by spotify.

the class SupervisorTest method verifySupervisorStopsDockerContainerWithConfiguredKillTime.

@Test
public void verifySupervisorStopsDockerContainerWithConfiguredKillTime() throws Exception {
    final String containerId = "deadbeef";
    final Job longKillTimeJob = Job.newBuilder().setName(NAME).setCommand(COMMAND).setImage(IMAGE).setVersion(VERSION).setSecondsToWaitBeforeKill(30).build();
    mockTaskStatus(longKillTimeJob.getId());
    final Supervisor longKillTimeSupervisor = createSupervisor(longKillTimeJob);
    when(docker.createContainer(any(ContainerConfig.class), any(String.class))).thenReturn(ContainerCreation.builder().id(containerId).build());
    final ImageInfo imageInfo = mock(ImageInfo.class);
    when(docker.inspectImage(IMAGE)).thenReturn(imageInfo);
    // Have waitContainer wait forever.
    final SettableFuture<ContainerExit> waitFuture = SettableFuture.create();
    when(docker.waitContainer(containerId)).thenAnswer(futureAnswer(waitFuture));
    // Start the job (so that a runner exists)
    longKillTimeSupervisor.setGoal(START);
    when(docker.inspectContainer(eq(containerId))).thenReturn(runningResponse);
    // This is already verified above, but it works as a hack to wait for the model/docker state
    // to converge in such a way that a setGoal(STOP) will work. :|
    verify(docker, timeout(30000)).waitContainer(containerId);
    // Stop the job
    longKillTimeSupervisor.setGoal(STOP);
    verify(docker, timeout(30000)).stopContainer(eq(containerId), eq(longKillTimeJob.getSecondsToWaitBeforeKill()));
    // Change docker container state to stopped now that it was killed
    when(docker.inspectContainer(eq(containerId))).thenReturn(stoppedResponse);
}
Also used : ContainerConfig(com.spotify.docker.client.messages.ContainerConfig) ContainerExit(com.spotify.docker.client.messages.ContainerExit) Job(com.spotify.helios.common.descriptors.Job) ImageInfo(com.spotify.docker.client.messages.ImageInfo) Test(org.junit.Test)

Aggregations

ContainerConfig (com.spotify.docker.client.messages.ContainerConfig)6 ImageInfo (com.spotify.docker.client.messages.ImageInfo)6 Test (org.junit.Test)5 ContainerCreation (com.spotify.docker.client.messages.ContainerCreation)4 ContainerExit (com.spotify.docker.client.messages.ContainerExit)4 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)2 DockerException (com.spotify.docker.client.exceptions.DockerException)1 DockerTimeoutException (com.spotify.docker.client.exceptions.DockerTimeoutException)1 ImageNotFoundException (com.spotify.docker.client.exceptions.ImageNotFoundException)1 ImagePullFailedException (com.spotify.docker.client.exceptions.ImagePullFailedException)1 ContainerInfo (com.spotify.docker.client.messages.ContainerInfo)1 ContainerState (com.spotify.docker.client.messages.ContainerState)1 HostConfig (com.spotify.docker.client.messages.HostConfig)1 Job (com.spotify.helios.common.descriptors.Job)1 ExecutionException (java.util.concurrent.ExecutionException)1