use of com.thoughtworks.go.server.domain.StageStatusListener in project gocd by gocd.
the class ScheduleServiceStageTriggerTest method shouldDoCancellationInTransaction.
@Test
public void shouldDoCancellationInTransaction() throws Exception {
Pipeline oldest = preCondition.createPipelineWithFirstStagePassedAndSecondStageRunning();
preCondition.createPipelineWithFirstStagePassedAndSecondStageHasNotStarted();
preCondition.createPipelineWithFirstStagePassedAndSecondStageHasNotStarted();
Stage stage = oldest.getStages().byName(preCondition.ftStage);
StageStatusTopic stageStatusTopic = mock(StageStatusTopic.class);
JobResultTopic jobResultTopic = mock(JobResultTopic.class);
StageStatusListener stageStatusListener = mock(StageStatusListener.class);
StageService stageService = mock(StageService.class);
when(stageService.stageById(stage.getId())).thenReturn(stage);
Mockito.doAnswer(new Answer() {
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
throw new RuntimeException();
}
}).when(stageService).cancelStage(stage);
StageOrderService stageOrderService = mock(StageOrderService.class);
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 {
scheduleService.cancelAndTriggerRelevantStages(stage.getId(), null, null);
} catch (RuntimeException 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 shouldPostAllMessagesAfterTheDatabaseIsUpdatedWhenCancellingAStage.
@Test
public void shouldPostAllMessagesAfterTheDatabaseIsUpdatedWhenCancellingAStage() {
jobResultTopic.addListener(new GoMessageListener<JobResultMessage>() {
public void onMessage(JobResultMessage message) {
JobIdentifier jobIdentifier = message.getJobIdentifier();
JobInstance instance = jobInstanceDao.mostRecentJobWithTransitions(jobIdentifier);
receivedState = instance.getState();
receivedResult = instance.getResult();
}
});
stageService.addStageStatusListener(new StageStatusListener() {
public void stageStatusChanged(Stage stage) {
Stage retrievedStage = stageDao.stageById(stage.getId());
receivedStageResult = retrievedStage.getResult();
}
});
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
public void doInTransactionWithoutResult(TransactionStatus status) {
stageService.cancelStage(stage);
}
});
Assertions.waitUntil(Timeout.TEN_SECONDS, new Assertions.Predicate() {
public boolean call() throws Exception {
return receivedResult != null && receivedState != null && receivedStageResult != null;
}
});
assertThat(receivedState, is(JobState.Completed));
assertThat(receivedResult, is(JobResult.Cancelled));
assertThat(receivedStageResult, is(StageResult.Cancelled));
}
use of com.thoughtworks.go.server.domain.StageStatusListener in project gocd by gocd.
the class PipelineServiceTest method shouldNotNotifyStatusListenersWhenTransactionRollsback.
@Test
public void shouldNotNotifyStatusListenersWhenTransactionRollsback() throws Exception {
StageStatusListener stageStatusListener = mock(StageStatusListener.class);
JobStatusListener jobStatusListener = mock(JobStatusListener.class);
Pipeline pipeline = stubPipelineSaveForStatusListener(stageStatusListener, jobStatusListener);
Mockito.doThrow(new RuntimeException()).when(pipelineTimeline).update();
try {
service.save(pipeline);
} catch (RuntimeException e) {
// ignore
}
verify(stageStatusListener, never()).stageStatusChanged(any(Stage.class));
verify(jobStatusListener, never()).jobStatusChanged(any(JobInstance.class));
}
use of com.thoughtworks.go.server.domain.StageStatusListener in project gocd by gocd.
the class PipelineServiceTriangleDependencyTest method shouldNotNotifyStatusListenersWhenTransactionRollsback.
@Test
public void shouldNotNotifyStatusListenersWhenTransactionRollsback() throws Exception {
StageStatusListener stageStatusListener = mock(StageStatusListener.class);
JobStatusListener jobStatusListener = mock(JobStatusListener.class);
Pipeline pipeline = stubPipelineSaveForStatusListener(stageStatusListener, jobStatusListener);
Mockito.doThrow(new RuntimeException()).when(pipelineTimeline).update();
try {
service.save(pipeline);
} catch (RuntimeException e) {
// ignore
}
verify(stageStatusListener, never()).stageStatusChanged(any(Stage.class));
verify(jobStatusListener, never()).jobStatusChanged(any(JobInstance.class));
}
use of com.thoughtworks.go.server.domain.StageStatusListener in project gocd by gocd.
the class PipelineServiceTriangleDependencyTest 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));
}
Aggregations