Search in sources :

Example 6 with StageDao

use of com.thoughtworks.go.server.dao.StageDao in project gocd by gocd.

the class StageServiceIntegrationTest method shouldNotifyListenersWhenJobCancelledSuccessfully.

@Test
public void shouldNotifyListenersWhenJobCancelledSuccessfully() {
    StageStatusListener listener = mock(StageStatusListener.class);
    JobInstanceService jobInstanceService = mock(JobInstanceService.class);
    JobInstance job = JobInstanceMother.building("foo");
    JobIdentifier jobId = new JobIdentifier("pipeline", 10, "label-10", "stage", "1", "foo");
    job.setIdentifier(jobId);
    StageDao stageDao = mock(StageDao.class);
    Stage stage = StageMother.custom("stage");
    when(stageDao.findStageWithIdentifier(jobId.getStageIdentifier())).thenReturn(stage);
    StageService service = new StageService(stageDao, jobInstanceService, null, null, null, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache, listener);
    service.cancelJob(job);
    verify(listener).stageStatusChanged(stage);
}
Also used : StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) StageDao(com.thoughtworks.go.server.dao.StageDao) Test(org.junit.Test)

Example 7 with StageDao

use of com.thoughtworks.go.server.dao.StageDao in project gocd by gocd.

the class StageServiceIntegrationTest method shouldNotNotifyListenersWhenJobCancellationTransactionRollsback.

@Test
public void shouldNotNotifyListenersWhenJobCancellationTransactionRollsback() {
    StageStatusListener listener = mock(StageStatusListener.class);
    JobInstanceService jobInstanceService = mock(JobInstanceService.class);
    JobInstance job = JobInstanceMother.building("foo");
    doThrow(new RuntimeException("test exception")).when(jobInstanceService).cancelJob(job);
    JobIdentifier jobId = new JobIdentifier("pipeline", 10, "label-10", "stage", "1", "foo");
    job.setIdentifier(jobId);
    StageDao stageDao = mock(StageDao.class);
    Stage stage = StageMother.custom("stage");
    when(stageDao.findStageWithIdentifier(jobId.getStageIdentifier())).thenReturn(stage);
    StageService service = new StageService(stageDao, jobInstanceService, null, null, null, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache, listener);
    try {
        service.cancelJob(job);
        fail("should have thrown up when underlying service bombed");
    } catch (Exception e) {
        assertThat(e.getMessage(), is("test exception"));
    }
    verify(listener, never()).stageStatusChanged(any(Stage.class));
}
Also used : StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) StageDao(com.thoughtworks.go.server.dao.StageDao) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 8 with StageDao

use of com.thoughtworks.go.server.dao.StageDao in project gocd by gocd.

the class StageStatusCacheTest method shouldQueryTheDbOnlyOnceForStagesThatHaveNeverBeenBuilt.

@Test
public void shouldQueryTheDbOnlyOnceForStagesThatHaveNeverBeenBuilt() throws SQLException {
    final StageDao stageDao = Mockito.mock(StageDao.class);
    final StageConfigIdentifier identifier = new StageConfigIdentifier("cruise", "dev");
    StageStatusCache cache = new StageStatusCache(stageDao);
    when(stageDao.mostRecentStage(identifier)).thenReturn(null);
    assertThat(cache.currentStage(identifier), is(nullValue()));
    assertThat(cache.currentStage(identifier), is(nullValue()));
    verify(stageDao, times(1)).mostRecentStage(identifier);
}
Also used : StageDao(com.thoughtworks.go.server.dao.StageDao) StageConfigIdentifier(com.thoughtworks.go.domain.StageConfigIdentifier) Test(org.junit.Test)

Example 9 with StageDao

use of com.thoughtworks.go.server.dao.StageDao in project gocd by gocd.

the class JobStatusCacheTest method shouldRemoveTheNeverRunInstanceWhenTheJobRunsForTheFirstTime.

@Test
public void shouldRemoveTheNeverRunInstanceWhenTheJobRunsForTheFirstTime() {
    StageDao dao = mock(StageDao.class);
    when(dao.mostRecentJobsForStage("cruise", "dev")).thenReturn(new ArrayList<>());
    JobStatusCache cache = new JobStatusCache(dao);
    assertThat(cache.currentJobs(new JobConfigIdentifier("cruise", "dev", "linux-firefox")).isEmpty(), is(true));
    JobInstance instance = jobInstance("linux-firefox");
    cache.jobStatusChanged(instance);
    assertThat(cache.currentJobs(new JobConfigIdentifier("cruise", "dev", "linux-firefox")).get(0), is(instance));
    Mockito.verify(dao, times(1)).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 10 with StageDao

use of com.thoughtworks.go.server.dao.StageDao in project gocd by gocd.

the class JobStatusCacheTest method shouldHitTheDatabaseOnlyOnceIfTheJobIsNeverScheduledEver.

@Test
public void shouldHitTheDatabaseOnlyOnceIfTheJobIsNeverScheduledEver() {
    StageDao dao = mock(StageDao.class);
    when(dao.mostRecentJobsForStage("cruise", "dev")).thenReturn(new ArrayList<>());
    JobStatusCache cache = new JobStatusCache(dao);
    assertThat(cache.currentJobs(new JobConfigIdentifier("cruise", "dev", "linux-firefox")).isEmpty(), is(true));
    assertThat(cache.currentJobs(new JobConfigIdentifier("cruise", "dev", "linux-firefox")).isEmpty(), is(true));
    Mockito.verify(dao, times(1)).mostRecentJobsForStage("cruise", "dev");
}
Also used : StageDao(com.thoughtworks.go.server.dao.StageDao) JobConfigIdentifier(com.thoughtworks.go.domain.JobConfigIdentifier) Test(org.junit.Test)

Aggregations

StageDao (com.thoughtworks.go.server.dao.StageDao)13 Test (org.junit.Test)10 Stage (com.thoughtworks.go.domain.Stage)5 JobConfigIdentifier (com.thoughtworks.go.domain.JobConfigIdentifier)4 JobInstance (com.thoughtworks.go.domain.JobInstance)3 Pipeline (com.thoughtworks.go.domain.Pipeline)3 StageConfigIdentifier (com.thoughtworks.go.domain.StageConfigIdentifier)3 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 Expectations (org.jmock.Expectations)2 Mockery (org.jmock.Mockery)2 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)1 GoCache (com.thoughtworks.go.server.cache.GoCache)1