Search in sources :

Example 6 with StageStatusListener

use of com.thoughtworks.go.server.domain.StageStatusListener 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 7 with StageStatusListener

use of com.thoughtworks.go.server.domain.StageStatusListener in project gocd by gocd.

the class ScheduleServiceStageTriggerTest method shouldNotNotifyListenersForWhenCancelStageTransactionRollsback.

@Test
public void shouldNotNotifyListenersForWhenCancelStageTransactionRollsback() throws Exception {
    Pipeline oldest = preCondition.createPipelineWithFirstStagePassedAndSecondStageRunning();
    preCondition.createPipelineWithFirstStagePassedAndSecondStageHasNotStarted();
    preCondition.createPipelineWithFirstStagePassedAndSecondStageHasNotStarted();
    final Stage stage = oldest.getStages().byName(preCondition.ftStage);
    final StageIdentifier identifier = stage.getIdentifier();
    StageStatusTopic stageStatusTopic = mock(StageStatusTopic.class);
    JobResultTopic jobResultTopic = mock(JobResultTopic.class);
    StageStatusListener stageStatusListener = mock(StageStatusListener.class);
    JobInstanceService jobInstanceService = jobInstanceService(jobResultTopic);
    StageService stageService = new StageService(stageDao, jobInstanceService, stageStatusTopic, stageStatusCache, securityService, pipelineDao, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache, stageStatusListener);
    SchedulingPerformanceLogger schedulingPerformanceLogger = mock(SchedulingPerformanceLogger.class);
    scheduleService = new ScheduleService(goConfigService, pipelineService, stageService, schedulingCheckerService, pipelineDao, stageDao, stageOrderService, securityService, pipelineScheduleQueue, this.jobInstanceService, jobInstanceDao, agentAssignment, environmentConfigService, pipelineLockService, serverHealthService, transactionTemplate, null, transactionSynchronizationManager, null, null, null, null, schedulingPerformanceLogger, null);
    try {
        transactionTemplate.executeWithExceptionHandling(new TransactionCallback() {

            @Override
            public Object doInTransaction(TransactionStatus status) throws Exception {
                scheduleService.cancelAndTriggerRelevantStages(stage.getId(), null, null);
                throw new GoUnauthorizedException();
            }
        });
    } catch (Exception e) {
    // ignore
    }
    verify(stageStatusTopic, never()).post(any(StageStatusMessage.class));
    verify(jobResultTopic, never()).post(any(JobResultMessage.class));
    verify(stageStatusListener, never()).stageStatusChanged(any(Stage.class));
}
Also used : StageStatusTopic(com.thoughtworks.go.server.messaging.StageStatusTopic) JobResultTopic(com.thoughtworks.go.server.messaging.JobResultTopic) TransactionStatus(org.springframework.transaction.TransactionStatus) SchedulingPerformanceLogger(com.thoughtworks.go.server.perf.SchedulingPerformanceLogger) GoUnauthorizedException(com.thoughtworks.go.server.GoUnauthorizedException) StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) TransactionCallback(com.thoughtworks.go.server.transaction.TransactionCallback) GoUnauthorizedException(com.thoughtworks.go.server.GoUnauthorizedException) JobResultMessage(com.thoughtworks.go.server.messaging.JobResultMessage) StageStatusMessage(com.thoughtworks.go.server.messaging.StageStatusMessage) Test(org.junit.Test)

Example 8 with StageStatusListener

use of com.thoughtworks.go.server.domain.StageStatusListener in project gocd by gocd.

the class PipelineServiceTest method shouldNotifyStageStatusListenersOnlyWhenTransactionCommits.

@Test
public void shouldNotifyStageStatusListenersOnlyWhenTransactionCommits() throws Exception {
    StageStatusListener stageStatusListener = mock(StageStatusListener.class);
    JobStatusListener jobStatusListener = mock(JobStatusListener.class);
    Pipeline pipeline = stubPipelineSaveForStatusListener(stageStatusListener, jobStatusListener);
    service.save(pipeline);
    verify(stageStatusListener).stageStatusChanged(any(Stage.class));
    verify(jobStatusListener).jobStatusChanged(any(JobInstance.class));
}
Also used : StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) JobInstance(com.thoughtworks.go.domain.JobInstance) JobStatusListener(com.thoughtworks.go.server.domain.JobStatusListener) Stage(com.thoughtworks.go.domain.Stage) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Example 9 with StageStatusListener

use of com.thoughtworks.go.server.domain.StageStatusListener in project gocd by gocd.

the class GoDashboardActivityListenerTest method onInitializationAndStartOfDaemons_shouldRegisterAListener_WhichCallsStageStatusChangeHandler_ForStageStatusChanges.

@Test
public void onInitializationAndStartOfDaemons_shouldRegisterAListener_WhichCallsStageStatusChangeHandler_ForStageStatusChanges() throws Exception {
    Stage aStage = StageMother.custom("stage1");
    GoDashboardStageStatusChangeHandler handler = mock(GoDashboardStageStatusChangeHandler.class);
    ArgumentCaptor<StageStatusListener> captor = ArgumentCaptor.forClass(StageStatusListener.class);
    doNothing().when(stageService).addStageStatusListener(captor.capture());
    GoDashboardActivityListener listener = new GoDashboardActivityListener(goConfigService, stageService, pipelinePauseService, pipelineLockService, handler, null, null, null, null, featureToggleService);
    listener.initialize();
    listener.startDaemon();
    StageStatusListener stageStatusListener = captor.getAllValues().get(0);
    stageStatusListener.stageStatusChanged(aStage);
    waitForProcessingToHappen();
    verify(handler).call(aStage);
    verify(stageService).addStageStatusListener(stageStatusListener);
}
Also used : StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) Stage(com.thoughtworks.go.domain.Stage) Test(org.junit.Test)

Example 10 with StageStatusListener

use of com.thoughtworks.go.server.domain.StageStatusListener in project gocd by gocd.

the class ScheduleServiceIntegrationTest method shouldTriggerNextStageOfPipelineEvenIfOneOfTheListenersFailWithAnError.

@Test
public void shouldTriggerNextStageOfPipelineEvenIfOneOfTheListenersFailWithAnError() throws Exception {
    String pipelineName = UUID.randomUUID().toString();
    String firstStage = "firstStage";
    String secondStage = "secondStage";
    PipelineConfig pipelineConfig = configHelper.addPipeline(PipelineConfigMother.createPipelineConfigWithStages(pipelineName, firstStage, secondStage));
    Pipeline pipeline = dbHelper.schedulePipeline(pipelineConfig, forceBuild(pipelineConfig), new TimeProvider());
    stageService.addStageStatusListener(new StageStatusListener() {

        @Override
        public void stageStatusChanged(Stage stage) {
            throw new LinkageError("some nasty linkage error");
        }
    });
    JobInstance job = pipeline.getFirstStage().getFirstJob();
    JobIdentifier jobIdentifier = job.getIdentifier();
    scheduleService.jobCompleting(jobIdentifier, JobResult.Passed, job.getAgentUuid());
    scheduleService.updateJobStatus(jobIdentifier, JobState.Completed);
    assertThat(stageService.findLatestStage(pipelineName, secondStage), is(notNullValue()));
}
Also used : StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) TimeProvider(com.thoughtworks.go.util.TimeProvider)

Aggregations

StageStatusListener (com.thoughtworks.go.server.domain.StageStatusListener)15 Test (org.junit.Test)14 Stage (com.thoughtworks.go.domain.Stage)5 JobInstance (com.thoughtworks.go.domain.JobInstance)4 Pipeline (com.thoughtworks.go.domain.Pipeline)4 JobStatusListener (com.thoughtworks.go.server.domain.JobStatusListener)4 JobResultMessage (com.thoughtworks.go.server.messaging.JobResultMessage)3 TimeProvider (com.thoughtworks.go.util.TimeProvider)3 TransactionStatus (org.springframework.transaction.TransactionStatus)3 StageDao (com.thoughtworks.go.server.dao.StageDao)2 JobResultTopic (com.thoughtworks.go.server.messaging.JobResultTopic)2 StageStatusMessage (com.thoughtworks.go.server.messaging.StageStatusMessage)2 StageStatusTopic (com.thoughtworks.go.server.messaging.StageStatusTopic)2 SchedulingPerformanceLogger (com.thoughtworks.go.server.perf.SchedulingPerformanceLogger)2 SQLException (java.sql.SQLException)2 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)2 GoUnauthorizedException (com.thoughtworks.go.server.GoUnauthorizedException)1 TransactionCallback (com.thoughtworks.go.server.transaction.TransactionCallback)1 Assertions (com.thoughtworks.go.utils.Assertions)1 ArrayList (java.util.ArrayList)1