Search in sources :

Example 16 with TransactionSynchronizationManager

use of com.thoughtworks.go.server.transaction.TransactionSynchronizationManager in project gocd by gocd.

the class StageServiceTest method canGetFailureRunForThreeStages.

@Test
public void canGetFailureRunForThreeStages() {
    TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
    StageRunFinder runFinder = new StageService(stageDao, jobInstanceService, mock(StageStatusTopic.class), mock(StageStatusCache.class), securityService, pipelineDao, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
    List<StageIdentifier> expectedStages = new ArrayList<>();
    expectedStages.add(new StageIdentifier(PIPELINE_NAME, 3, STAGE_NAME, "1"));
    expectedStages.add(new StageIdentifier(PIPELINE_NAME, 2, STAGE_NAME, "2"));
    expectedStages.add(new StageIdentifier(PIPELINE_NAME, 1, STAGE_NAME, "1"));
    Pipeline pipeline = pipeline(10.0);
    Pipeline pipelineThatLastPassed = pipeline(5.0);
    when(pipelineDao.findPipelineByNameAndCounter(PIPELINE_NAME, 3)).thenReturn(pipeline);
    when(pipelineDao.findEarlierPipelineThatPassedForStage(PIPELINE_NAME, STAGE_NAME, 10.0)).thenReturn(pipelineThatLastPassed);
    when(stageDao.findFailedStagesBetween(PIPELINE_NAME, STAGE_NAME, 5.0, 10.0)).thenReturn(asList(identifier(3, "1"), identifier(2, "2"), identifier(1, "1")));
    assertEquals(expectedStages, runFinder.findRunForStage(new StageIdentifier(PIPELINE_NAME, 3, STAGE_NAME, "1")));
}
Also used : StageStatusTopic(com.thoughtworks.go.server.messaging.StageStatusTopic) TestTransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager) TransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TransactionSynchronizationManager) StageStatusCache(com.thoughtworks.go.domain.activity.StageStatusCache) StageRunFinder(com.thoughtworks.go.server.dao.sparql.StageRunFinder) Test(org.junit.Test)

Example 17 with TransactionSynchronizationManager

use of com.thoughtworks.go.server.transaction.TransactionSynchronizationManager in project gocd by gocd.

the class StageServiceTest method findStageSummaryByIdentifierShouldRespondWith404WhenStagesHavingGivenCounterIsNotFound.

@Test
public void findStageSummaryByIdentifierShouldRespondWith404WhenStagesHavingGivenCounterIsNotFound() throws Exception {
    SecurityService securityService = mock(SecurityService.class);
    when(securityService.hasViewPermissionForPipeline(ALWAYS_ALLOW_USER, "dev")).thenReturn(true);
    TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
    StageService service = new StageService(stageDao, null, null, null, securityService, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    Stages stages = new Stages();
    Stage stage1 = new Stage();
    stage1.setIdentifier(new StageIdentifier("dev/10/stage_name/1"));
    stages.add(stage1);
    StageIdentifier stageId = new StageIdentifier("dev/10/stage_name/9999999999");
    when(stageDao.getAllRunsOfStageForPipelineInstance(stageId.getPipelineName(), stageId.getPipelineCounter(), stageId.getStageName())).thenReturn(stages);
    StageSummaryModel model = service.findStageSummaryByIdentifier(stageId, ALWAYS_ALLOW_USER, result);
    assertThat(model, is(nullValue()));
    assertThat(result.httpCode(), is(404));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) TestTransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager) TransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TransactionSynchronizationManager) Test(org.junit.Test)

Example 18 with TransactionSynchronizationManager

use of com.thoughtworks.go.server.transaction.TransactionSynchronizationManager in project gocd by gocd.

the class StageServiceTest method shouldUpdateJobInstanceAndStageOnCancellingJob.

@Test
public void shouldUpdateJobInstanceAndStageOnCancellingJob() throws SQLException {
    JobInstance job = new JobInstance("job");
    job.setIdentifier(new JobIdentifier("pipeline", 10, "label", STAGE_NAME, "5", "job"));
    TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
    StageService service = new StageService(stageDao, jobInstanceService, null, null, null, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
    JobInstance foundJob = new JobInstance("job");
    foundJob.setState(JobState.Scheduled);
    foundJob.setResult(JobResult.Unknown);
    JobInstances foundJobInstances = new JobInstances(foundJob);
    Stage foundStage = new Stage(STAGE_NAME, foundJobInstances, "jez", "manual", new TimeProvider());
    foundStage.calculateResult();
    assertThat(foundStage.getState(), is(not(StageState.Cancelled)));
    assertThat(foundStage.getResult(), is(not(StageResult.Cancelled)));
    foundJob.setState(JobState.Completed);
    foundJob.setResult(JobResult.Cancelled);
    when(stageDao.findStageWithIdentifier(job.getIdentifier().getStageIdentifier())).thenReturn(foundStage);
    service.cancelJob(job);
    assertThat(foundStage.getState(), is(StageState.Cancelled));
    assertThat(foundStage.getResult(), is(StageResult.Cancelled));
    verify(jobInstanceService).cancelJob(job);
    verify(stageDao).updateResult(foundStage, StageResult.Cancelled);
}
Also used : TestTransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager) TransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TransactionSynchronizationManager) TimeProvider(com.thoughtworks.go.util.TimeProvider) Test(org.junit.Test)

Aggregations

TransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TransactionSynchronizationManager)18 Test (org.junit.Test)15 TestTransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager)11 StageStatusCache (com.thoughtworks.go.domain.activity.StageStatusCache)5 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)5 StageRunFinder (com.thoughtworks.go.server.dao.sparql.StageRunFinder)4 StageStatusTopic (com.thoughtworks.go.server.messaging.StageStatusTopic)4 TransactionStatus (org.springframework.transaction.TransactionStatus)4 Before (org.junit.Before)2 TransactionSynchronization (org.springframework.transaction.support.TransactionSynchronization)2 GitCommand (com.thoughtworks.go.domain.materials.git.GitCommand)1 GoCache (com.thoughtworks.go.server.cache.GoCache)1 DatabaseStrategy (com.thoughtworks.go.server.database.DatabaseStrategy)1 PipelineRepository (com.thoughtworks.go.server.persistence.PipelineRepository)1 MaterialConfigConverter (com.thoughtworks.go.server.service.MaterialConfigConverter)1 MaterialExpansionService (com.thoughtworks.go.server.service.MaterialExpansionService)1 TransactionTemplate (com.thoughtworks.go.server.transaction.TransactionTemplate)1 TestingClock (com.thoughtworks.go.util.TestingClock)1 TimeProvider (com.thoughtworks.go.util.TimeProvider)1 File (java.io.File)1