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, null);
try {
transactionTemplate.executeWithExceptionHandling(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) throws Exception {
scheduleService.cancelAndTriggerRelevantStages(stage.getId(), null, null);
throw new NotAuthorizedException("blah");
}
});
} 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 StageServiceIntegrationTest method shouldIgnoreErrorsWhenNotifyingListenersDuringSave.
@Test
public void shouldIgnoreErrorsWhenNotifyingListenersDuringSave() throws Exception {
List<StageStatusListener> original = new ArrayList<>(stageService.getStageStatusListeners());
try {
stageService.getStageStatusListeners().clear();
StageStatusListener failingListener = mock(StageStatusListener.class);
doThrow(new RuntimeException("Should not be rethrown by save")).when(failingListener).stageStatusChanged(any(Stage.class));
StageStatusListener passingListener = mock(StageStatusListener.class);
stageService.getStageStatusListeners().add(failingListener);
stageService.getStageStatusListeners().add(passingListener);
Stage newInstance = instanceFactory.createStageInstance(pipelineConfig.first(), new DefaultSchedulingContext("anonumous"), md5, new TimeProvider());
Stage savedStage = stageService.save(savedPipeline, newInstance);
assertThat("Got: " + savedStage.getId(), savedStage.getId() > 0L, is(true));
verify(passingListener).stageStatusChanged(any(Stage.class));
} finally {
stageService.getStageStatusListeners().clear();
stageService.getStageStatusListeners().addAll(original);
}
}
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 StageServiceIntegrationTest method shouldNotifyListenerOnStageStatusChange.
@Test
public void shouldNotifyListenerOnStageStatusChange() {
StageStatusListener listener = mock(StageStatusListener.class);
stageService.addStageStatusListener(listener);
stageService.updateResult(stage);
verify(listener).stageStatusChanged(stage);
}
use of com.thoughtworks.go.server.domain.StageStatusListener in project gocd by gocd.
the class StageServiceIntegrationTest method shouldNotifyListenersWhenStageScheduled.
@Test
public void shouldNotifyListenersWhenStageScheduled() throws Exception {
StageStatusListener listener = mock(StageStatusListener.class);
stageService.addStageStatusListener(listener);
Stage newInstance = instanceFactory.createStageInstance(pipelineConfig.first(), new DefaultSchedulingContext("anonymous"), md5, new TimeProvider());
Stage savedStage = stageService.save(savedPipeline, newInstance);
verify(listener).stageStatusChanged(savedStage);
}
Aggregations