use of com.spotify.helios.serviceregistration.NopServiceRegistrationHandle in project helios by spotify.
the class GracePeriodTest method setup.
@Before
public void setup() throws Exception {
final ContainerState runningState = Mockito.mock(ContainerState.class);
when(runningState.running()).thenReturn(true);
when(runningResponse.state()).thenReturn(runningState);
when(runningResponse.networkSettings()).thenReturn(NetworkSettings.builder().ports(Collections.emptyMap()).build());
final ContainerState stoppedState = Mockito.mock(ContainerState.class);
when(stoppedState.running()).thenReturn(false);
when(stoppedResponse.state()).thenReturn(stoppedState);
when(retryPolicy.delay(any(ThrottleState.class))).thenReturn(10L);
when(registrar.register(any(ServiceRegistration.class))).thenReturn(new NopServiceRegistrationHandle());
final TaskConfig config = TaskConfig.builder().namespace(NAMESPACE).host("AGENT_NAME").job(JOB).envVars(ENV).defaultRegistrationDomain("domain").build();
final TaskStatus.Builder taskStatus = TaskStatus.newBuilder().setJob(JOB).setEnv(ENV).setPorts(PORTS);
final StatusUpdater statusUpdater = new DefaultStatusUpdater(model, taskStatus);
final TaskMonitor monitor = new TaskMonitor(JOB.getId(), FlapController.create(), statusUpdater);
final TaskRunnerFactory runnerFactory = TaskRunnerFactory.builder().registrar(registrar).config(config).dockerClient(docker).listener(monitor).build();
sut = Supervisor.newBuilder().setJob(JOB).setStatusUpdater(statusUpdater).setDockerClient(docker).setRestartPolicy(retryPolicy).setRunnerFactory(runnerFactory).setMetrics(new NoopSupervisorMetrics()).setMonitor(monitor).setSleeper(sleeper).build();
final ConcurrentMap<JobId, TaskStatus> statusMap = Maps.newConcurrentMap();
doAnswer(new Answer<Object>() {
@Override
public Object answer(final InvocationOnMock invocationOnMock) {
final Object[] arguments = invocationOnMock.getArguments();
final JobId jobId = (JobId) arguments[0];
final TaskStatus status = (TaskStatus) arguments[1];
statusMap.put(jobId, status);
return null;
}
}).when(model).setTaskStatus(eq(JOB.getId()), taskStatusCaptor.capture());
when(model.getTaskStatus(eq(JOB.getId()))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(final InvocationOnMock invocationOnMock) throws Throwable {
final JobId jobId = (JobId) invocationOnMock.getArguments()[0];
return statusMap.get(jobId);
}
});
}
Aggregations