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));
}
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));
}
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));
}
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);
}
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()));
}
Aggregations