Search in sources :

Example 1 with JobResultMessage

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

the class JobInstanceServiceTest method shouldNotifyListenersWhenAssignedJobIsCancelled.

@Test
public void shouldNotifyListenersWhenAssignedJobIsCancelled() {
    final JobInstanceService jobService = new JobInstanceService(jobInstanceDao, buildPropertiesService, topic, jobStatusCache, transactionTemplate, transactionSynchronizationManager, null, null, goConfigService, null, pluginManager, serverHealthService);
    job.setAgentUuid("dummy agent");
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            jobService.cancelJob(job);
        }
    });
    verify(jobInstanceDao).updateStateAndResult(job);
    verify(buildPropertiesService).saveCruiseProperties(job);
    verify(topic).post(new JobResultMessage(job.getIdentifier(), JobResult.Cancelled, job.getAgentUuid()));
}
Also used : JobResultMessage(com.thoughtworks.go.server.messaging.JobResultMessage) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.Test)

Example 2 with JobResultMessage

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

the class StageServiceIntegrationTest method shouldNotCancelAlreadyCompletedBuild.

@Test
public void shouldNotCancelAlreadyCompletedBuild() throws SQLException {
    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();
        }
    });
    JobInstanceMother.completed(job, Passed, new Date());
    jobInstanceDao.updateStateAndResult(job);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        public void doInTransactionWithoutResult(TransactionStatus status) {
            stageService.cancelStage(stage);
        }
    });
    JobInstance instanceFromDB = jobInstanceDao.buildByIdWithTransitions(job.getId());
    assertThat(instanceFromDB.getState(), is(JobState.Completed));
    assertThat(instanceFromDB.getResult(), is(Passed));
    assertThat(agentService.findAgentAndRefreshStatus(UUID).isCancelled(), is(false));
    assertThat(receivedState, is(nullValue()));
    assertThat(receivedResult, is(nullValue()));
}
Also used : JobResultMessage(com.thoughtworks.go.server.messaging.JobResultMessage) TransactionStatus(org.springframework.transaction.TransactionStatus) Date(java.util.Date) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.Test)

Example 3 with JobResultMessage

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

Aggregations

JobResultMessage (com.thoughtworks.go.server.messaging.JobResultMessage)3 Test (org.junit.Test)3 TransactionStatus (org.springframework.transaction.TransactionStatus)3 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)3 StageStatusListener (com.thoughtworks.go.server.domain.StageStatusListener)1 Assertions (com.thoughtworks.go.utils.Assertions)1 SQLException (java.sql.SQLException)1 Date (java.util.Date)1