use of com.thoughtworks.go.server.domain.JobStatusListener 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));
}
use of com.thoughtworks.go.server.domain.JobStatusListener 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));
}
use of com.thoughtworks.go.server.domain.JobStatusListener in project gocd by gocd.
the class JobInstanceServiceIntegrationTest method shouldNotNotifyListenersWhenTransactionRollsback.
@Test
public void shouldNotNotifyListenersWhenTransactionRollsback() {
final boolean[] isListenerCalled = { false };
JobStatusListener jobStatusListener = new JobStatusListener() {
@Override
public void jobStatusChanged(JobInstance job) {
isListenerCalled[0] = true;
}
};
jobInstanceService.registerJobStateChangeListener(jobStatusListener);
StageConfig ftStage = pipelineFixture.ftStage();
Pipeline pipeline = pipelineFixture.createPipelineWithFirstStagePassedAndSecondStageRunning();
Stage stage = pipeline.getStages().byName(CaseInsensitiveString.str(ftStage.name()));
final JobInstance instance = stage.getJobInstances().get(0);
instance.changeState(JobState.Building, new Date());
try {
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
jobInstanceService.updateStateAndResult(instance);
throw new RuntimeException("to rollback txn");
}
});
fail("Should have thrown an exception and transaction rolled back. Listeners should not have be called on afterCommit");
} catch (RuntimeException e) {
}
assertThat(isListenerCalled[0], is(false));
}
use of com.thoughtworks.go.server.domain.JobStatusListener in project gocd by gocd.
the class JobInstanceServiceIntegrationTest method shouldFailRequestedJobAndNotifyStageChange.
@Test
public void shouldFailRequestedJobAndNotifyStageChange() throws SQLException {
PipelineConfig goConfig = PipelineMother.withSingleStageWithMaterials("go", "dev", withBuildPlans("unit"));
Stage goDev = dbHelper.schedulePipeline(goConfig, new TimeProvider()).getStages().get(0);
dbHelper.buildingBuildInstance(goDev);
PipelineConfig mingleConfig = PipelineMother.withSingleStageWithMaterials("mingle", "test", withBuildPlans("integration"));
Stage mingleTest = dbHelper.schedulePipeline(mingleConfig, new TimeProvider()).getStages().get(0);
dbHelper.buildingBuildInstance(mingleTest);
JobInstance jobInstance = dbHelper.newPipelineWithFirstStageScheduled(PipelineMother.withSingleStageWithMaterials("twist", "acceptance", withBuildPlans("firefox"))).getStages().get(0).getJobInstances().get(0);
final JobInstance[] changedJobPassed = new JobInstance[1];
jobInstanceService.registerJobStateChangeListener(new JobStatusListener() {
public void jobStatusChanged(JobInstance job) {
changedJobPassed[0] = job;
}
});
JobInstance jobInstance1 = jobInstanceService.buildByIdWithTransitions(jobInstance.getId());
jobInstanceService.failJob(jobInstance1);
assertThat(changedJobPassed[0].isFailed(), is(true));
}
use of com.thoughtworks.go.server.domain.JobStatusListener in project gocd by gocd.
the class JobInstanceSqlMapDaoCachingTest method shouldNotClearJobIdentifierFromCacheForAnyOtherJobStateChangeOtherThanRescheduledAsTheBuildIdDoesNotChange.
@Test
public void shouldNotClearJobIdentifierFromCacheForAnyOtherJobStateChangeOtherThanRescheduledAsTheBuildIdDoesNotChange() {
jobInstanceDao.setSqlMapClientTemplate(mockTemplate);
JobInstance job = JobInstanceMother.buildEndingWithState(JobState.Building, JobResult.Unknown, "config");
when(mockTemplate.queryForObject(eq("findJobId"), any(Map.class))).thenReturn(job.getIdentifier());
jobInstanceDao.findOriginalJobIdentifier(job.getIdentifier().getStageIdentifier(), job.getName());
List<JobState> jobStatesForWhichCacheNeedsToBeMaintained = new ArrayList<>(Arrays.asList(JobState.Assigned, JobState.Building, JobState.Completed, JobState.Discontinued, JobState.Paused, JobState.Scheduled, JobState.Preparing, JobState.Assigned.Unknown));
JobStatusListener listener = jobInstanceDao;
for (JobState jobState : jobStatesForWhichCacheNeedsToBeMaintained) {
job.changeState(jobState, new Date());
listener.jobStatusChanged(job);
}
jobInstanceDao.findOriginalJobIdentifier(job.getIdentifier().getStageIdentifier(), job.getName());
verify(mockTemplate, times(1)).queryForObject(eq("findJobId"), any(Map.class));
}
Aggregations