Search in sources :

Example 11 with StageStatusListener

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));
}
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.Test)

Example 12 with StageStatusListener

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));
}
Also used : StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) JobResultMessage(com.thoughtworks.go.server.messaging.JobResultMessage) TransactionStatus(org.springframework.transaction.TransactionStatus) Assertions(com.thoughtworks.go.utils.Assertions) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 13 with StageStatusListener

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));
}
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.Test)

Example 14 with StageStatusListener

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));
}
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.Test)

Example 15 with StageStatusListener

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));
}
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.Test)

Aggregations

StageStatusListener (com.thoughtworks.go.server.domain.StageStatusListener)15 Test (org.junit.Test)14 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 JobResultMessage (com.thoughtworks.go.server.messaging.JobResultMessage)3 TimeProvider (com.thoughtworks.go.util.TimeProvider)3 TransactionStatus (org.springframework.transaction.TransactionStatus)3 StageDao (com.thoughtworks.go.server.dao.StageDao)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 SQLException (java.sql.SQLException)2 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)2 GoUnauthorizedException (com.thoughtworks.go.server.GoUnauthorizedException)1 TransactionCallback (com.thoughtworks.go.server.transaction.TransactionCallback)1 Assertions (com.thoughtworks.go.utils.Assertions)1 ArrayList (java.util.ArrayList)1