Search in sources :

Example 1 with StageStatusListener

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));
}
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 StageStatusListener

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);
    }
}
Also used : StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) TimeProvider(com.thoughtworks.go.util.TimeProvider) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 3 with StageStatusListener

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));
}
Also used : StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) JobInstance(com.thoughtworks.go.domain.JobInstance) JobStatusListener(com.thoughtworks.go.server.domain.JobStatusListener) Stage(com.thoughtworks.go.domain.Stage) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.jupiter.api.Test)

Example 4 with StageStatusListener

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);
}
Also used : StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) Test(org.junit.jupiter.api.Test)

Example 5 with StageStatusListener

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);
}
Also used : StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) TimeProvider(com.thoughtworks.go.util.TimeProvider) Test(org.junit.jupiter.api.Test)

Aggregations

StageStatusListener (com.thoughtworks.go.server.domain.StageStatusListener)14 Test (org.junit.jupiter.api.Test)12 Stage (com.thoughtworks.go.domain.Stage)5 JobInstance (com.thoughtworks.go.domain.JobInstance)4 Pipeline (com.thoughtworks.go.domain.Pipeline)4 JobStatusListener (com.thoughtworks.go.server.domain.JobStatusListener)4 TimeProvider (com.thoughtworks.go.util.TimeProvider)3 StageDao (com.thoughtworks.go.server.dao.StageDao)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.Test)2 TransactionStatus (org.springframework.transaction.TransactionStatus)2 NotAuthorizedException (com.thoughtworks.go.config.exceptions.NotAuthorizedException)1 TransactionCallback (com.thoughtworks.go.server.transaction.TransactionCallback)1 ArrayList (java.util.ArrayList)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1