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