Search in sources :

Example 1 with StageDao

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

Example 2 with StageDao

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()));
}
Also used : StageDao(com.thoughtworks.go.server.dao.StageDao) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 3 with StageDao

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

Example 4 with StageDao

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

Example 5 with StageDao

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;
}
Also used : StageDao(com.thoughtworks.go.server.dao.StageDao) JobResultTopic(com.thoughtworks.go.server.messaging.JobResultTopic) StageStatusTopic(com.thoughtworks.go.server.messaging.StageStatusTopic) ServerHealthStates(com.thoughtworks.go.serverhealth.ServerHealthStates) JobInstanceDao(com.thoughtworks.go.server.dao.JobInstanceDao) StageStatusCache(com.thoughtworks.go.domain.activity.StageStatusCache) JobStatusCache(com.thoughtworks.go.domain.activity.JobStatusCache) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) PipelineDao(com.thoughtworks.go.server.dao.PipelineDao)

Aggregations

StageDao (com.thoughtworks.go.server.dao.StageDao)13 Test (org.junit.jupiter.api.Test)10 PipelineDao (com.thoughtworks.go.server.dao.PipelineDao)3 JobStatusCache (com.thoughtworks.go.domain.activity.JobStatusCache)2 StageStatusCache (com.thoughtworks.go.domain.activity.StageStatusCache)2 JobInstanceDao (com.thoughtworks.go.server.dao.JobInstanceDao)2 StageStatusListener (com.thoughtworks.go.server.domain.StageStatusListener)2 JobResultTopic (com.thoughtworks.go.server.messaging.JobResultTopic)2 StageStatusTopic (com.thoughtworks.go.server.messaging.StageStatusTopic)2 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)2 ServerHealthStates (com.thoughtworks.go.serverhealth.ServerHealthStates)2 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)1 Pipeline (com.thoughtworks.go.domain.Pipeline)1 Stage (com.thoughtworks.go.domain.Stage)1 GoCache (com.thoughtworks.go.server.cache.GoCache)1 SchedulingPerformanceLogger (com.thoughtworks.go.server.perf.SchedulingPerformanceLogger)1 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)1 TestTransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager)1 TestTransactionTemplate (com.thoughtworks.go.server.transaction.TestTransactionTemplate)1 ArrayList (java.util.ArrayList)1