use of com.thoughtworks.go.server.domain.JobStatusListener 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));
}
use of com.thoughtworks.go.server.domain.JobStatusListener in project gocd by gocd.
the class JobInstanceServiceTest method shouldNotifyListenerWhenUpdateAssignedInfo.
@Test
public void shouldNotifyListenerWhenUpdateAssignedInfo() throws Exception {
final JobStatusListener listener1 = Mockito.mock(JobStatusListener.class, "listener1");
final JobStatusListener listener2 = Mockito.mock(JobStatusListener.class, "listener2");
final JobInstanceService jobService = new JobInstanceService(jobInstanceDao, null, null, jobStatusCache, transactionTemplate, transactionSynchronizationManager, null, null, goConfigService, null, pluginManager, serverHealthService, listener1, listener2);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
jobService.updateAssignedInfo(job);
}
});
verify(listener1).jobStatusChanged(job);
verify(listener2).jobStatusChanged(job);
verify(jobInstanceDao).updateAssignedInfo(job);
}
use of com.thoughtworks.go.server.domain.JobStatusListener in project gocd by gocd.
the class JobInstanceSqlMapDaoCachingTest method shouldClearJobIdentifierFromCacheWhenJobIsRescheduled.
@Test
public void shouldClearJobIdentifierFromCacheWhenJobIsRescheduled() throws Exception {
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());
job.changeState(JobState.Rescheduled, new Date());
JobStatusListener listener = jobInstanceDao;
listener.jobStatusChanged(job);
jobInstanceDao.findOriginalJobIdentifier(job.getIdentifier().getStageIdentifier(), job.getName());
verify(mockTemplate, times(2)).queryForObject(eq("findJobId"), any(Map.class));
}
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 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));
}
Aggregations