Search in sources :

Example 1 with JobConfigIdentifier

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

Example 2 with JobConfigIdentifier

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");
}
Also used : StageDao(com.thoughtworks.go.server.dao.StageDao) JobInstance(com.thoughtworks.go.domain.JobInstance) JobConfigIdentifier(com.thoughtworks.go.domain.JobConfigIdentifier) Test(org.junit.Test)

Example 3 with JobConfigIdentifier

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()));
}
Also used : StageDao(com.thoughtworks.go.server.dao.StageDao) Expectations(org.jmock.Expectations) JobInstance(com.thoughtworks.go.domain.JobInstance) ArrayList(java.util.ArrayList) JobConfigIdentifier(com.thoughtworks.go.domain.JobConfigIdentifier) Mockery(org.jmock.Mockery) Test(org.junit.Test)

Example 4 with JobConfigIdentifier

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;
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) JobNotFoundException(com.thoughtworks.go.config.JobNotFoundException) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) JobConfigIdentifier(com.thoughtworks.go.domain.JobConfigIdentifier) Pipeline(com.thoughtworks.go.domain.Pipeline)

Example 5 with JobConfigIdentifier

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

Aggregations

JobConfigIdentifier (com.thoughtworks.go.domain.JobConfigIdentifier)13 Test (org.junit.Test)11 JobInstance (com.thoughtworks.go.domain.JobInstance)10 StageDao (com.thoughtworks.go.server.dao.StageDao)4 Pipeline (com.thoughtworks.go.domain.Pipeline)2 JobNotFoundException (com.thoughtworks.go.config.JobNotFoundException)1 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)1 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)1 ArrayList (java.util.ArrayList)1 Expectations (org.jmock.Expectations)1 Mockery (org.jmock.Mockery)1