Search in sources :

Example 11 with JobStatusListener

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

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

Example 14 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 15 with JobStatusListener

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