Search in sources :

Example 1 with JobResultTopic

use of com.thoughtworks.go.server.messaging.JobResultTopic 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));
}
Also used : StageStatusTopic(com.thoughtworks.go.server.messaging.StageStatusTopic) JobResultTopic(com.thoughtworks.go.server.messaging.JobResultTopic) TransactionStatus(org.springframework.transaction.TransactionStatus) NotAuthorizedException(com.thoughtworks.go.config.exceptions.NotAuthorizedException) SchedulingPerformanceLogger(com.thoughtworks.go.server.perf.SchedulingPerformanceLogger) NotAuthorizedException(com.thoughtworks.go.config.exceptions.NotAuthorizedException) StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) TransactionCallback(com.thoughtworks.go.server.transaction.TransactionCallback) JobResultMessage(com.thoughtworks.go.server.messaging.JobResultMessage) StageStatusMessage(com.thoughtworks.go.server.messaging.StageStatusMessage) Test(org.junit.jupiter.api.Test)

Example 2 with JobResultTopic

use of com.thoughtworks.go.server.messaging.JobResultTopic 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() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            throw new RuntimeException();
        }
    }).when(stageService).cancelStage(stage, null);
    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, 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) StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) JobResultMessage(com.thoughtworks.go.server.messaging.JobResultMessage) StageStatusMessage(com.thoughtworks.go.server.messaging.StageStatusMessage) Test(org.junit.jupiter.api.Test)

Aggregations

StageStatusListener (com.thoughtworks.go.server.domain.StageStatusListener)2 JobResultMessage (com.thoughtworks.go.server.messaging.JobResultMessage)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 Test (org.junit.jupiter.api.Test)2 NotAuthorizedException (com.thoughtworks.go.config.exceptions.NotAuthorizedException)1 TransactionCallback (com.thoughtworks.go.server.transaction.TransactionCallback)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1