use of com.thoughtworks.go.domain.JobIdentifier in project gocd by gocd.
the class ConsoleActivityMonitorTest method shouldConsiderAllBuildingJobsActiveOnInitialization.
@Test
public void shouldConsiderAllBuildingJobsActiveOnInitialization() {
long now = System.currentTimeMillis();
when(timeProvider.currentTimeMillis()).thenReturn(now);
JobIdentifier firstJob = new JobIdentifier("pipeline-foo", 10, "foo-10", "stage-bar", "12", "build");
JobIdentifier secondJob = new JobIdentifier("pipeline-bar", 12, "bar-12", "stage-baz", "15", "quux");
JobInstanceService jobInstanceService = mock(JobInstanceService.class);
when(jobInstanceService.allBuildingJobs()).thenReturn(Arrays.asList(firstJob, secondJob));
consoleActivityMonitor = new ConsoleActivityMonitor(timeProvider, systemEnvironment, jobInstanceService, serverHealthService, goConfigService, consoleService);
consoleActivityMonitor.populateActivityMap();
stubInitializerCallsForActivityMonitor(jobInstanceService);
consoleActivityMonitor.cancelUnresponsiveJobs(scheduleService);
verifyZeroInteractions(jobInstanceService);
// just below threshold
when(timeProvider.currentTimeMillis()).thenReturn(now + UNRESPONSIVE_JOB_KILL_THRESHOLD - 1);
consoleActivityMonitor.cancelUnresponsiveJobs(scheduleService);
verifyZeroInteractions(jobInstanceService);
// just above threshold
when(timeProvider.currentTimeMillis()).thenReturn(now + UNRESPONSIVE_JOB_KILL_THRESHOLD + 1);
consoleActivityMonitor.cancelUnresponsiveJobs(scheduleService);
verify(scheduleService).cancelJob(firstJob);
verify(scheduleService).cancelJob(secondJob);
}
use of com.thoughtworks.go.domain.JobIdentifier in project gocd by gocd.
the class ConsoleActivityMonitorTest method shouldAppendToConsoleLog_JobKilledDueToInactivityMessage.
@Test
public void shouldAppendToConsoleLog_JobKilledDueToInactivityMessage() throws IOException, IllegalArtifactLocationException {
JobIdentifier unresponsiveJob = new JobIdentifier("pipelines", 10, "label-10", "stage", "3", "job", 25l);
listener.jobStatusChanged(buildingInstance(unresponsiveJob));
when(timeProvider.currentTimeMillis()).thenReturn(new DateTime(1971, 1, 1, 0, 55, 59, 0).getMillis());
consoleActivityMonitor.consoleUpdatedFor(unresponsiveJob);
when(timeProvider.currentTimeMillis()).thenReturn(new DateTime(1972, 1, 1, 1, 1, 0, 0).getMillis());
consoleActivityMonitor.cancelUnresponsiveJobs(scheduleService);
verify(consoleService).appendToConsoleLog(unresponsiveJob, "Go cancelled this job as it has not generated any console output for more than 5 minute(s)");
}
use of com.thoughtworks.go.domain.JobIdentifier in project gocd by gocd.
the class ConsoleActivityMonitorTest method shouldNotCancelCompletedJob_becauseOfActivityAfterCompletion.
@Test
public void shouldNotCancelCompletedJob_becauseOfActivityAfterCompletion() {
DateTime now = new DateTime();
when(timeProvider.currentTimeMillis()).thenReturn(now.getMillis());
JobIdentifier jobId = new JobIdentifier("foo-pipeline", 10, "foo-10", "bar-stage", "20", "baz-build");
JobInstance job = buildingInstance(jobId);
listener.jobStatusChanged(job);
job.completing(JobResult.Passed);
job.completed(new Date());
listener.jobStatusChanged(job);
// Once a job is completed we should not track the console updates.
consoleActivityMonitor.consoleUpdatedFor(jobId);
when(timeProvider.currentTimeMillis()).thenReturn(now.plusDays(10).getMillis());
consoleActivityMonitor.cancelUnresponsiveJobs(scheduleService);
verifyNoMoreInteractions(jobInstanceService);
}
use of com.thoughtworks.go.domain.JobIdentifier in project gocd by gocd.
the class ConsoleActivityMonitorTest method shouldClearServerHealthMessageWhenUnresponsiveJobShowsActivity.
@Test
public void shouldClearServerHealthMessageWhenUnresponsiveJobShowsActivity() {
DateTime now = new DateTime();
when(timeProvider.currentTimeMillis()).thenReturn(now.getMillis());
JobIdentifier responsiveJob = new JobIdentifier("foo", 12, "foo-10", "stage", "2", "job", 20l);
listener.jobStatusChanged(buildingInstance(responsiveJob));
when(timeProvider.currentTimeMillis()).thenReturn(now.plusMinutes(2).plus(1).getMillis());
consoleActivityMonitor.consoleUpdatedFor(responsiveJob);
verify(serverHealthService).removeByScope(HealthStateScope.forJob("foo", "stage", "job"));
}
use of com.thoughtworks.go.domain.JobIdentifier in project gocd by gocd.
the class ConsoleActivityMonitorTest method shouldClearServerHealthMessageWhenUnresponsiveJobIsCancelled.
@Test
public void shouldClearServerHealthMessageWhenUnresponsiveJobIsCancelled() {
DateTime now = new DateTime();
when(timeProvider.currentTimeMillis()).thenReturn(now.getMillis());
JobIdentifier unresponsiveJob = new JobIdentifier("foo", 12, "foo-10", "stage", "2", "job", 20l);
listener.jobStatusChanged(buildingInstance(unresponsiveJob));
when(timeProvider.currentTimeMillis()).thenReturn(now.plus(UNRESPONSIVE_JOB_KILL_THRESHOLD).plus(1).getMillis());
consoleActivityMonitor.cancelUnresponsiveJobs(scheduleService);
verify(scheduleService).cancelJob(unresponsiveJob);
verify(serverHealthService).removeByScope(HealthStateScope.forJob("foo", "stage", "job"));
}
Aggregations