Search in sources :

Example 91 with JobIdentifier

use of com.thoughtworks.go.domain.JobIdentifier in project gocd by gocd.

the class ConsoleActivityMonitorTest method shouldNotTrackConsoleActivityFor_completedJob.

@Test
public void shouldNotTrackConsoleActivityFor_completedJob() {
    JobIdentifier jobId = new JobIdentifier("foo-pipeline", 10, "foo-10", "bar-stage", "20", "baz-build");
    JobInstance job = buildingInstance(jobId);
    listener.jobStatusChanged(job);
    Date jobStartAndCompleteTime = new Date();
    when(timeProvider.currentTimeMillis()).thenReturn(jobStartAndCompleteTime.getTime());
    consoleActivityMonitor.consoleUpdatedFor(jobId);
    job.completing(JobResult.Passed);
    job.completed(new Date());
    listener.jobStatusChanged(job);
    when(timeProvider.currentTimeMillis()).thenReturn(new DateTime().plusDays(10).getMillis());
    consoleActivityMonitor.cancelUnresponsiveJobs(scheduleService);
    verifyNoMoreInteractions(jobInstanceService);
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 92 with JobIdentifier

use of com.thoughtworks.go.domain.JobIdentifier in project gocd by gocd.

the class ConsoleActivityMonitorTest method shouldClearServerHealthMessageForAnyJobCancelledExternally.

@Test
public void shouldClearServerHealthMessageForAnyJobCancelledExternally() {
    DateTime now = new DateTime();
    when(timeProvider.currentTimeMillis()).thenReturn(now.getMillis());
    JobIdentifier unresponsiveJob = new JobIdentifier("foo", 12, "foo-10", "stage", "2", "job", 20l);
    JobInstance job = buildingInstance(unresponsiveJob);
    listener.jobStatusChanged(job);
    job.cancel();
    listener.jobStatusChanged(job);
    verify(serverHealthService).removeByScope(HealthStateScope.forJob("foo", "stage", "job"));
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 93 with JobIdentifier

use of com.thoughtworks.go.domain.JobIdentifier in project gocd by gocd.

the class ConsoleActivityMonitorTest method shouldCancelUnresponsiveJobs.

@Test
public void shouldCancelUnresponsiveJobs() {
    JobIdentifier unresponsiveJob = new JobIdentifier("pipelines", 10, "label-10", "stage", "3", "job", 25l);
    listener.jobStatusChanged(buildingInstance(unresponsiveJob));
    JobIdentifier responsiveJob = new JobIdentifier("foo", 12, "foo-10", "stage", "2", "job", 20l);
    listener.jobStatusChanged(buildingInstance(responsiveJob));
    when(timeProvider.currentTimeMillis()).thenReturn(new DateTime(1971, 1, 1, 0, 55, 59, 0).getMillis());
    consoleActivityMonitor.consoleUpdatedFor(unresponsiveJob);
    consoleActivityMonitor.consoleUpdatedFor(responsiveJob);
    when(timeProvider.currentTimeMillis()).thenReturn(new DateTime(1972, 1, 1, 1, 0, 0, 0).getMillis());
    consoleActivityMonitor.consoleUpdatedFor(responsiveJob);
    when(timeProvider.currentTimeMillis()).thenReturn(new DateTime(1972, 1, 1, 1, 1, 0, 0).getMillis());
    consoleActivityMonitor.cancelUnresponsiveJobs(scheduleService);
    verify(scheduleService).cancelJob(unresponsiveJob);
    consoleActivityMonitor.cancelUnresponsiveJobs(scheduleService);
    verifyNoMoreInteractions(jobInstanceService);
}
Also used : JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 94 with JobIdentifier

use of com.thoughtworks.go.domain.JobIdentifier in project gocd by gocd.

the class ConsoleServiceTest method shouldCreateTemporaryConsoleFileAndMoveIfItDoesNotExist.

@Test
public void shouldCreateTemporaryConsoleFileAndMoveIfItDoesNotExist() throws Exception {
    JobIdentifier jobIdentifier = JobIdentifierMother.anyBuildIdentifier();
    File temporaryConsoleLog = new File(testFolder.getRoot(), "temporary_console.log");
    File finalConsoleLog = new File(testFolder.getRoot(), "final_console.log");
    when(chooser.temporaryConsoleFile(jobIdentifier)).thenReturn(temporaryConsoleLog);
    when(chooser.findArtifact(jobIdentifier, getConsoleOutputFolderAndFileName())).thenReturn(finalConsoleLog);
    service.moveConsoleArtifacts(jobIdentifier);
    assertThat(temporaryConsoleLog.exists(), is(false));
    assertThat(finalConsoleLog.exists(), is(true));
}
Also used : JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) File(java.io.File) Test(org.junit.Test)

Example 95 with JobIdentifier

use of com.thoughtworks.go.domain.JobIdentifier in project gocd by gocd.

the class ConsoleServiceTest method shouldMoveConsoleArtifacts.

@Test
public void shouldMoveConsoleArtifacts() throws Exception {
    JobIdentifier jobIdentifier = JobIdentifierMother.anyBuildIdentifier();
    File temporaryConsoleLog = testFolder.newFile("temporary_console.log");
    File finalConsoleLog = new File(testFolder.getRoot(), "final_console.log");
    when(chooser.temporaryConsoleFile(jobIdentifier)).thenReturn(temporaryConsoleLog);
    when(chooser.findArtifact(jobIdentifier, getConsoleOutputFolderAndFileName())).thenReturn(finalConsoleLog);
    service.moveConsoleArtifacts(jobIdentifier);
    assertThat(temporaryConsoleLog.exists(), is(false));
    assertThat(finalConsoleLog.exists(), is(true));
}
Also used : JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) File(java.io.File) 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