Search in sources :

Example 1 with StageStatusTopic

use of com.thoughtworks.go.server.messaging.StageStatusTopic 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, pipelineScheduledTopic, 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) CannotScheduleException(com.thoughtworks.go.domain.CannotScheduleException) Pipeline(com.thoughtworks.go.domain.Pipeline) StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) TransactionCallback(com.thoughtworks.go.server.transaction.TransactionCallback) GoUnauthorizedException(com.thoughtworks.go.server.GoUnauthorizedException) JobResultMessage(com.thoughtworks.go.server.messaging.JobResultMessage) Stage(com.thoughtworks.go.domain.Stage) StageStatusMessage(com.thoughtworks.go.server.messaging.StageStatusMessage) Test(org.junit.Test)

Example 2 with StageStatusTopic

use of com.thoughtworks.go.server.messaging.StageStatusTopic 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, pipelineScheduledTopic, 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));
}
Also used : StageStatusTopic(com.thoughtworks.go.server.messaging.StageStatusTopic) JobResultTopic(com.thoughtworks.go.server.messaging.JobResultTopic) SchedulingPerformanceLogger(com.thoughtworks.go.server.perf.SchedulingPerformanceLogger) Pipeline(com.thoughtworks.go.domain.Pipeline) StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) JobResultMessage(com.thoughtworks.go.server.messaging.JobResultMessage) Stage(com.thoughtworks.go.domain.Stage) StageStatusMessage(com.thoughtworks.go.server.messaging.StageStatusMessage) Test(org.junit.Test)

Example 3 with StageStatusTopic

use of com.thoughtworks.go.server.messaging.StageStatusTopic in project gocd by gocd.

the class StageServiceTest method shouldSendStageStatusMessageAfterStageIsCancelled.

@Test
public void shouldSendStageStatusMessageAfterStageIsCancelled() throws SQLException {
    StageStatusTopic topic = mock(StageStatusTopic.class);
    final Stage cancelledStage = StageMother.cancelledStage("stage", "job");
    cancelledStage.setIdentifier(new StageIdentifier("pipeline/1/stage/1"));
    final StageService service = new StageService(stageDao, jobInstanceService, topic, new StageStatusCache(stageDao), null, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, mock(GoCache.class));
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        public void doInTransactionWithoutResult(TransactionStatus status) {
            service.cancelStage(cancelledStage);
        }
    });
    verify(topic).post(new StageStatusMessage(cancelledStage.getIdentifier(), StageState.Cancelled, StageResult.Cancelled, Username.ANONYMOUS));
    verifyNoMoreInteractions(topic);
}
Also used : StageStatusTopic(com.thoughtworks.go.server.messaging.StageStatusTopic) StageStatusCache(com.thoughtworks.go.domain.activity.StageStatusCache) GoCache(com.thoughtworks.go.server.cache.GoCache) TransactionStatus(org.springframework.transaction.TransactionStatus) StageStatusMessage(com.thoughtworks.go.server.messaging.StageStatusMessage) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.Test)

Aggregations

StageStatusMessage (com.thoughtworks.go.server.messaging.StageStatusMessage)3 StageStatusTopic (com.thoughtworks.go.server.messaging.StageStatusTopic)3 Test (org.junit.Test)3 Pipeline (com.thoughtworks.go.domain.Pipeline)2 Stage (com.thoughtworks.go.domain.Stage)2 StageStatusListener (com.thoughtworks.go.server.domain.StageStatusListener)2 JobResultMessage (com.thoughtworks.go.server.messaging.JobResultMessage)2 JobResultTopic (com.thoughtworks.go.server.messaging.JobResultTopic)2 SchedulingPerformanceLogger (com.thoughtworks.go.server.perf.SchedulingPerformanceLogger)2 TransactionStatus (org.springframework.transaction.TransactionStatus)2 CannotScheduleException (com.thoughtworks.go.domain.CannotScheduleException)1 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)1 StageStatusCache (com.thoughtworks.go.domain.activity.StageStatusCache)1 GoUnauthorizedException (com.thoughtworks.go.server.GoUnauthorizedException)1 GoCache (com.thoughtworks.go.server.cache.GoCache)1 TransactionCallback (com.thoughtworks.go.server.transaction.TransactionCallback)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1