Search in sources :

Example 6 with JobStatusListener

use of com.thoughtworks.go.server.domain.JobStatusListener in project gocd by gocd.

the class JobInstanceServiceTest method shouldIgnoreErrorsWhenNotifyingListenersDuringSave.

@Test
public void shouldIgnoreErrorsWhenNotifyingListenersDuringSave() throws Exception {
    final JobStatusListener failingListener = Mockito.mock(JobStatusListener.class, "listener1");
    final JobStatusListener passingListener = Mockito.mock(JobStatusListener.class, "listener2");
    doThrow(new RuntimeException("Should not be rethrown by save")).when(failingListener).jobStatusChanged(job);
    final Pipeline pipeline = new NullPipeline();
    final Stage stage = new Stage();
    stage.setId(1);
    final JobInstanceService jobService = new JobInstanceService(jobInstanceDao, null, null, jobStatusCache, transactionTemplate, transactionSynchronizationManager, null, null, goConfigService, null, pluginManager, serverHealthService, failingListener, passingListener);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        public void doInTransactionWithoutResult(TransactionStatus status) {
            jobService.save(new StageIdentifier(pipeline.getName(), null, pipeline.getLabel(), stage.getName(), String.valueOf(stage.getCounter())), stage.getId(), job);
        }
    });
    verify(jobInstanceDao).save(1l, job);
    verify(passingListener).jobStatusChanged(job);
}
Also used : JobStatusListener(com.thoughtworks.go.server.domain.JobStatusListener) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.Test)

Example 7 with JobStatusListener

use of com.thoughtworks.go.server.domain.JobStatusListener in project gocd by gocd.

the class JobInstanceServiceTest method shouldRegisterANewListener.

@Test
public void shouldRegisterANewListener() throws SQLException {
    JobInstanceService jobService = new JobInstanceService(jobInstanceDao, null, null, jobStatusCache, transactionTemplate, transactionSynchronizationManager, null, null, goConfigService, null, pluginManager, serverHealthService);
    JobStatusListener listener = mock(JobStatusListener.class);
    jobService.registerJobStateChangeListener(listener);
    jobService.updateStateAndResult(job);
    verify(jobInstanceDao).updateStateAndResult(job);
    verify(listener).jobStatusChanged(job);
}
Also used : JobStatusListener(com.thoughtworks.go.server.domain.JobStatusListener) Test(org.junit.Test)

Example 8 with JobStatusListener

use of com.thoughtworks.go.server.domain.JobStatusListener in project gocd by gocd.

the class JobInstanceServiceTest method shouldNotifyAllListenersWhenSaveJob.

@Test
public void shouldNotifyAllListenersWhenSaveJob() throws Exception {
    final JobStatusListener listener1 = Mockito.mock(JobStatusListener.class, "listener1");
    final JobStatusListener listener2 = Mockito.mock(JobStatusListener.class, "listener2");
    final Pipeline pipeline = new NullPipeline();
    final Stage stage = new Stage();
    stage.setId(1);
    final JobInstanceService jobService = new JobInstanceService(jobInstanceDao, null, null, jobStatusCache, transactionTemplate, transactionSynchronizationManager, null, null, goConfigService, null, pluginManager, serverHealthService, listener1, listener2);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        public void doInTransactionWithoutResult(TransactionStatus status) {
            jobService.save(new StageIdentifier(pipeline.getName(), null, pipeline.getLabel(), stage.getName(), String.valueOf(stage.getCounter())), stage.getId(), job);
        }
    });
    verify(jobInstanceDao).save(1l, job);
    verify(listener1).jobStatusChanged(job);
    verify(listener2).jobStatusChanged(job);
}
Also used : JobStatusListener(com.thoughtworks.go.server.domain.JobStatusListener) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.Test)

Example 9 with JobStatusListener

use of com.thoughtworks.go.server.domain.JobStatusListener in project gocd by gocd.

the class JobInstanceServiceTest method shouldNotifyAllListenersWhenUpdateJobStatus.

@Test
public void shouldNotifyAllListenersWhenUpdateJobStatus() throws Exception {
    final JobStatusListener listener1 = Mockito.mock(JobStatusListener.class, "listener1");
    final JobStatusListener listener2 = Mockito.mock(JobStatusListener.class, "listener2");
    JobInstanceService jobService = new JobInstanceService(jobInstanceDao, null, null, jobStatusCache, transactionTemplate, transactionSynchronizationManager, null, null, goConfigService, null, pluginManager, serverHealthService, listener1, listener2);
    jobService.updateStateAndResult(job);
    verify(jobInstanceDao).updateStateAndResult(job);
    verify(listener1).jobStatusChanged(job);
    verify(listener2).jobStatusChanged(job);
}
Also used : JobStatusListener(com.thoughtworks.go.server.domain.JobStatusListener) Test(org.junit.Test)

Example 10 with JobStatusListener

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

Aggregations

JobStatusListener (com.thoughtworks.go.server.domain.JobStatusListener)15 Test (org.junit.Test)15 JobInstance (com.thoughtworks.go.domain.JobInstance)4 Pipeline (com.thoughtworks.go.domain.Pipeline)4 Stage (com.thoughtworks.go.domain.Stage)4 StageStatusListener (com.thoughtworks.go.server.domain.StageStatusListener)4 TransactionStatus (org.springframework.transaction.TransactionStatus)4 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)4 TimeProvider (com.thoughtworks.go.util.TimeProvider)1 Date (java.util.Date)1