Search in sources :

Example 1 with TransactionSynchronizationManager

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

the class TransactionSynchronizationManagerTest method shouldUnderstandIfTransactionBodyExecuting.

@Test
public void shouldUnderstandIfTransactionBodyExecuting() {
    final boolean[] inBody = new boolean[] { false };
    final TransactionSynchronizationManager synchronizationManager = new TransactionSynchronizationManager();
    transactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            inBody[0] = synchronizationManager.isTransactionBodyExecuting();
            return null;
        }
    });
    assertThat(inBody[0], is(true));
    assertThat(synchronizationManager.isTransactionBodyExecuting(), is(false));
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) TransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TransactionSynchronizationManager) TransactionStatus(org.springframework.transaction.TransactionStatus) Test(org.junit.Test)

Example 2 with TransactionSynchronizationManager

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

the class TransactionSynchronizationManagerTest method shouldUnderstandIfTransactionIsActive.

@Test
public void shouldUnderstandIfTransactionIsActive() {
    final TransactionSynchronizationManager synchronizationManager = new TransactionSynchronizationManager();
    final ArrayList<Boolean> transactionActivity = new ArrayList<>();
    transactionTemplate.execute(new org.springframework.transaction.support.TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            transactionActivity.add(synchronizationManager.isActualTransactionActive());
        }
    });
    assertThat(transactionActivity, is(Arrays.asList(true)));
    assertThat(synchronizationManager.isActualTransactionActive(), is(false));
}
Also used : TransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TransactionSynchronizationManager) ArrayList(java.util.ArrayList) TransactionStatus(org.springframework.transaction.TransactionStatus) Test(org.junit.Test)

Example 3 with TransactionSynchronizationManager

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

the class StageServiceTest method findStageSummaryByIdentifierShouldRespondWith401WhenUserDoesNotHavePermissionToViewThePipeline.

@Test
public void findStageSummaryByIdentifierShouldRespondWith401WhenUserDoesNotHavePermissionToViewThePipeline() throws Exception {
    SecurityService securityService = mock(SecurityService.class);
    when(securityService.hasViewPermissionForPipeline(ALWAYS_ALLOW_USER, "pipeline_name")).thenReturn(false);
    TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
    StageService service = new StageService(stageDao, null, null, null, securityService, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    StageSummaryModel model = service.findStageSummaryByIdentifier(new StageIdentifier("pipeline_name/10/stage_name/1"), ALWAYS_ALLOW_USER, result);
    assertThat(result.httpCode(), is(401));
    assertThat(model, is(nullValue()));
}
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 4 with TransactionSynchronizationManager

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

the class StageServiceTest method shouldNotReturnAnythingWhenCurrentStageHasNotFailed.

@Test
public void shouldNotReturnAnythingWhenCurrentStageHasNotFailed() {
    TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
    StageRunFinder runFinder = new StageService(stageDao, jobInstanceService, mock(StageStatusTopic.class), mock(StageStatusCache.class), securityService, pipelineDao, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
    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(2, "2"), identifier(1, "1")));
    assertThat(runFinder.findRunForStage(new StageIdentifier(PIPELINE_NAME, 3, STAGE_NAME, "1")).isEmpty(), is(true));
}
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 5 with TransactionSynchronizationManager

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

the class StageServiceTest method shouldFindStageSummaryModelForGivenStageIdentifier.

@Test
public void shouldFindStageSummaryModelForGivenStageIdentifier() throws Exception {
    SecurityService securityService = alwaysAllow();
    TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
    StageService service = new StageService(stageDao, null, null, null, securityService, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
    Stage stageRun1 = StageMother.completedStageInstanceWithTwoPlans("stage_name");
    stageRun1.setIdentifier(new StageIdentifier("pipeline_name/10/stage_name/1"));
    stageRun1.setCounter(1);
    Stage stageRun2 = StageMother.completedStageInstanceWithTwoPlans("stage_name");
    stageRun2.setIdentifier(new StageIdentifier("pipeline_name/10/stage_name/2"));
    stageRun2.setCounter(2);
    Stages stages = new Stages(stageRun1, stageRun2);
    StageIdentifier stageId = new StageIdentifier("pipeline_name/10/stage_name/2");
    when(stageDao.getAllRunsOfStageForPipelineInstance(stageId.getPipelineName(), stageId.getPipelineCounter(), stageId.getStageName())).thenReturn(stages);
    StageSummaryModel stageForView = service.findStageSummaryByIdentifier(stageId, ALWAYS_ALLOW_USER, new HttpLocalizedOperationResult());
    assertThat(stageForView.getName(), is(stageRun2.getName()));
    assertThat(stageForView.getState(), is(stageRun2.stageState()));
    assertThat(stageForView.getStageCounter(), is(String.valueOf(stageRun2.getCounter())));
    assertThat(stageForView.getTotalRuns(), is(2));
}
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)

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