use of com.thoughtworks.go.domain.JobConfigIdentifier in project gocd by gocd.
the class JobStatusCacheTest method shouldReturnNullWhenNoCurrentJob.
@Test
public void shouldReturnNullWhenNoCurrentJob() throws Exception {
pipelineFixture.createdPipelineWithAllStagesPassed();
JobConfigIdentifier jobConfigIdentifier = new JobConfigIdentifier(pipelineFixture.pipelineName, pipelineFixture.devStage, "wrong-job");
JobInstance currentJob = jobStatusCache.currentJob(jobConfigIdentifier);
assertThat(currentJob, is(nullValue()));
}
use of com.thoughtworks.go.domain.JobConfigIdentifier in project gocd by gocd.
the class JobStatusCacheTest method shouldSkipNeverRunJobsWhenTryingToDealWithOtherJobs.
@Test
public void shouldSkipNeverRunJobsWhenTryingToDealWithOtherJobs() {
StageDao dao = mock(StageDao.class);
JobInstance random = jobInstance("random");
when(dao.mostRecentJobsForStage("cruise", "dev")).thenReturn(Arrays.asList(random));
JobStatusCache cache = new JobStatusCache(dao);
assertThat(cache.currentJobs(new JobConfigIdentifier("cruise", "dev", "linux-firefox")).isEmpty(), is(true));
assertThat(cache.currentJobs(new JobConfigIdentifier("cruise", "dev", "random")).get(0), is(random));
Mockito.verify(dao, times(2)).mostRecentJobsForStage("cruise", "dev");
}
use of com.thoughtworks.go.domain.JobConfigIdentifier in project gocd by gocd.
the class JobStatusCacheTest method shouldLoadMostRecentInstanceFromDBOnlyOnce.
@Test
public void shouldLoadMostRecentInstanceFromDBOnlyOnce() throws SQLException {
Mockery mockery = new Mockery();
final StageDao mock = mockery.mock(StageDao.class);
final JobInstance instance = JobInstanceMother.passed("linux-firefox");
final List<JobInstance> found = new ArrayList<>();
found.add(instance);
mockery.checking(new Expectations() {
{
one(mock).mostRecentJobsForStage("pipeline", "stage");
will(returnValue(found));
}
});
JobConfigIdentifier identifier = new JobConfigIdentifier(instance.getPipelineName(), instance.getStageName(), instance.getName());
JobStatusCache cache = new JobStatusCache(mock);
assertThat(cache.currentJob(identifier).getState(), is(instance.getState()));
//call currentJob for the second time, should not call jobInstanceDao now
assertThat(cache.currentJob(identifier).getState(), is(instance.getState()));
}
use of com.thoughtworks.go.domain.JobConfigIdentifier in project gocd by gocd.
the class RestfulService method findJob.
/**
* buildId should only be given when caller is absolutely sure about the job instance
* (makes sense in agent-uploading artifacts/properties scenario because agent won't run a job if its copied over(it only executes real jobs)) -JJ
*/
public JobIdentifier findJob(String pipelineName, String counterOrLabel, String stageName, String stageCounter, String buildName, Long buildId) {
JobConfigIdentifier jobConfig = goConfigService.translateToActualCase(new JobConfigIdentifier(pipelineName, stageName, buildName));
Pipeline pipeline = pipelineService.findPipelineByCounterOrLabel(jobConfig.getPipelineName(), counterOrLabel);
stageCounter = StringUtils.isEmpty(stageCounter) ? JobIdentifier.LATEST : stageCounter;
StageIdentifier stageIdentifier = translateStageCounter(pipeline.getIdentifier(), jobConfig.getStageName(), stageCounter);
JobIdentifier jobId;
if (buildId == null) {
jobId = jobResolverService.actualJobIdentifier(new JobIdentifier(stageIdentifier, jobConfig.getJobName()));
} else {
jobId = new JobIdentifier(stageIdentifier, jobConfig.getJobName(), buildId);
}
if (jobId == null) {
//fix for #5739
throw new JobNotFoundException(pipelineName, stageName, buildName);
}
return jobId;
}
use of com.thoughtworks.go.domain.JobConfigIdentifier in project gocd by gocd.
the class JobStatusCache method cache.
private synchronized void cache(JobInstance newJob) {
JobConfigIdentifier identifier = newJob.getIdentifier().jobConfigIdentifier();
jobs.put(identifier, newJob);
clearOldJobs(newJob);
}
Aggregations