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()));
}
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()));
}
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));
}
Aggregations