Search in sources :

Example 1 with JobStatusListener

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

Example 2 with JobStatusListener

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);
}
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 3 with JobStatusListener

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));
}
Also used : JobStatusListener(com.thoughtworks.go.server.domain.JobStatusListener) Test(org.junit.Test)

Example 4 with JobStatusListener

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));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) JobStatusListener(com.thoughtworks.go.server.domain.JobStatusListener) Test(org.junit.Test)

Example 5 with JobStatusListener

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));
}
Also used : JobStatusListener(com.thoughtworks.go.server.domain.JobStatusListener) TransactionStatus(org.springframework.transaction.TransactionStatus) Date(java.util.Date) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.Test)

Aggregations

JobStatusListener (com.thoughtworks.go.server.domain.JobStatusListener)14 Test (org.junit.Test)14 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