Search in sources :

Example 41 with JobIdentifier

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);
}
Also used : JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Test(org.junit.Test)

Example 42 with JobIdentifier

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)");
}
Also used : JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 43 with JobIdentifier

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);
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) DateTime(org.joda.time.DateTime) Date(java.util.Date) Test(org.junit.Test)

Example 44 with JobIdentifier

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"));
}
Also used : JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 45 with JobIdentifier

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"));
}
Also used : JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)113 Test (org.junit.Test)85 File (java.io.File)16 JobInstance (com.thoughtworks.go.domain.JobInstance)15 Pipeline (com.thoughtworks.go.domain.Pipeline)13 DateTime (org.joda.time.DateTime)12 Before (org.junit.Before)10 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 Stage (com.thoughtworks.go.domain.Stage)6 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)5 IllegalArtifactLocationException (com.thoughtworks.go.domain.exception.IllegalArtifactLocationException)5 AgentMetadata (com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata)5 IOException (java.io.IOException)5 ModelAndView (org.springframework.web.servlet.ModelAndView)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)3 Property (com.thoughtworks.go.domain.Property)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 RunIf (com.googlecode.junit.ext.RunIf)2 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)2 HeaderConstraint (com.thoughtworks.go.server.security.HeaderConstraint)2