Search in sources :

Example 1 with NopServiceRegistrationHandle

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);
        }
    });
}
Also used : ThrottleState(com.spotify.helios.common.descriptors.ThrottleState) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) ContainerState(com.spotify.docker.client.messages.ContainerState) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NoopSupervisorMetrics(com.spotify.helios.servicescommon.statistics.NoopSupervisorMetrics) JobId(com.spotify.helios.common.descriptors.JobId) ServiceRegistration(com.spotify.helios.serviceregistration.ServiceRegistration) NopServiceRegistrationHandle(com.spotify.helios.serviceregistration.NopServiceRegistrationHandle) Before(org.junit.Before)

Aggregations

ContainerState (com.spotify.docker.client.messages.ContainerState)1 JobId (com.spotify.helios.common.descriptors.JobId)1 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)1 ThrottleState (com.spotify.helios.common.descriptors.ThrottleState)1 NopServiceRegistrationHandle (com.spotify.helios.serviceregistration.NopServiceRegistrationHandle)1 ServiceRegistration (com.spotify.helios.serviceregistration.ServiceRegistration)1 NoopSupervisorMetrics (com.spotify.helios.servicescommon.statistics.NoopSupervisorMetrics)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1