use of com.thoughtworks.go.server.dao.StageDao 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.server.dao.StageDao in project gocd by gocd.
the class JobStatusCacheTest method shouldLoadMostRecentInstanceFromDBOnlyOnce.
@Test
public void shouldLoadMostRecentInstanceFromDBOnlyOnce() {
final StageDao mock = mock(StageDao.class);
final JobInstance instance = JobInstanceMother.passed("linux-firefox");
final List<JobInstance> found = new ArrayList<>();
found.add(instance);
when(mock.mostRecentJobsForStage("pipeline", "stage")).thenReturn(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.server.dao.StageDao in project gocd by gocd.
the class StageStatusCacheTest method shouldRemoveNeverBeenBuiltWhenTheStageIsBuiltForTheFirstTime.
@Test
public void shouldRemoveNeverBeenBuiltWhenTheStageIsBuiltForTheFirstTime() {
final StageDao stageDao = Mockito.mock(StageDao.class);
final StageConfigIdentifier identifier = new StageConfigIdentifier("cruise", "dev");
final Stage instance = StageMother.failingStage("dev");
instance.setIdentifier(new StageIdentifier("cruise", 1, "dev", "1"));
when(stageDao.mostRecentStage(identifier)).thenReturn(null);
StageStatusCache cache = new StageStatusCache(stageDao);
assertThat(cache.currentStage(identifier), is(nullValue()));
cache.stageStatusChanged(instance);
assertThat(cache.currentStage(identifier), is(instance));
verify(stageDao, times(1)).mostRecentStage(identifier);
}
use of com.thoughtworks.go.server.dao.StageDao in project gocd by gocd.
the class StageStatusCacheTest method shouldLoadMostRecentInstanceFromDBOnlyOnce.
@Test
public void shouldLoadMostRecentInstanceFromDBOnlyOnce() {
final StageDao mock = mock(StageDao.class);
final StageConfigIdentifier identifier = new StageConfigIdentifier("cruise", "dev");
final Stage instance = StageMother.failingStage("dev");
when(mock.mostRecentStage(identifier)).thenReturn(instance);
StageStatusCache cache = new StageStatusCache(mock);
assertThat(cache.currentStage(identifier).getName(), is(instance.getName()));
// call currentStage for the second time, should not call stageDao now
assertThat(cache.currentStage(identifier).getName(), is(instance.getName()));
}
use of com.thoughtworks.go.server.dao.StageDao in project gocd by gocd.
the class PipelineServiceTriangleDependencyTest method stubPipelineSaveForStatusListener.
private Pipeline stubPipelineSaveForStatusListener(StageStatusListener stageStatusListener, JobStatusListener jobStatusListener) {
StageDao stageDao = mock(StageDao.class);
ServerHealthService serverHealthService = mock(ServerHealthService.class);
when(serverHealthService.logs()).thenReturn(new ServerHealthStates());
JobInstanceService jobInstanceService = new JobInstanceService(mock(JobInstanceDao.class), mock(JobResultTopic.class), mock(JobStatusCache.class), actualTransactionTemplate, transactionSynchronizationManager, null, null, goConfigService, null, serverHealthService, jobStatusListener);
StageService stageService = new StageService(stageDao, jobInstanceService, mock(StageStatusTopic.class), mock(StageStatusCache.class), mock(SecurityService.class), mock(PipelineDao.class), mock(ChangesetService.class), mock(GoConfigService.class), actualTransactionTemplate, transactionSynchronizationManager, goCache);
Stage savedStage = StageMother.passedStageInstance("stage", "job", "pipeline-name");
when(stageDao.save(any(Pipeline.class), any(Stage.class))).thenReturn(savedStage);
stageService.addStageStatusListener(stageStatusListener);
service = new PipelineService(pipelineDao, stageService, mock(PipelineLockService.class), pipelineTimeline, materialRepository, actualTransactionTemplate, systemEnvironment, null, materialConfigConverter);
Pipeline pipeline = PipelineMother.pipeline("cruise", savedStage);
when(pipelineDao.save(pipeline)).thenReturn(pipeline);
when(materialRepository.findMaterialRevisionsForPipeline(9L)).thenReturn(MaterialRevisions.EMPTY);
return pipeline;
}
Aggregations