Search in sources :

Example 6 with TransactionSynchronizationManager

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

the class StageServiceTest method shouldNotReturnAnythingWhenNothingIsFailing.

@Test
public void shouldNotReturnAnythingWhenNothingIsFailing() {
    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(new ArrayList<>());
    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 7 with TransactionSynchronizationManager

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

the class StageServiceTest method findStageSummaryByIdentifierShouldRespondWith404WhenNoStagesFound.

@Test
public void findStageSummaryByIdentifierShouldRespondWith404WhenNoStagesFound() throws Exception {
    SecurityService securityService = mock(SecurityService.class);
    when(securityService.hasViewPermissionForPipeline(ALWAYS_ALLOW_USER, "pipeline_does_not_exist")).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();
    StageIdentifier stageId = new StageIdentifier("pipeline_does_not_exist/10/stage_name/1");
    when(stageDao.getAllRunsOfStageForPipelineInstance(stageId.getPipelineName(), stageId.getPipelineCounter(), stageId.getStageName())).thenReturn(new Stages());
    StageSummaryModel model = service.findStageSummaryByIdentifier(stageId, ALWAYS_ALLOW_USER, result);
    assertThat(result.httpCode(), is(404));
    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 8 with TransactionSynchronizationManager

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

the class StageServiceTest method shouldFindLatestStageFromCache.

@Test
public void shouldFindLatestStageFromCache() throws SQLException {
    Stage expectedStage = StageMother.custom("pipeline", "stage", null);
    StageStatusCache cache = new StageStatusCache(stageDao);
    cache.stageStatusChanged(expectedStage);
    TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
    StageService service = new StageService(stageDao, jobInstanceService, null, cache, null, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
    Stage actualStage = service.findLatestStage("pipeline", "stage");
    assertThat(actualStage, is(expectedStage));
}
Also used : StageStatusCache(com.thoughtworks.go.domain.activity.StageStatusCache) TestTransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager) TransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TransactionSynchronizationManager) Test(org.junit.Test)

Example 9 with TransactionSynchronizationManager

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

the class PipelineTimelineTest method setUp.

@Before
public void setUp() throws Exception {
    now = new DateTime();
    pipelineRepository = mock(PipelineRepository.class);
    materials = Arrays.asList("first", "second", "third", "fourth");
    first = PipelineMaterialModificationMother.modification(1, materials, Arrays.asList(now, now.plusMinutes(1), now.plusMinutes(2), now.plusMinutes(3)), 1, "111", "pipeline");
    second = PipelineMaterialModificationMother.modification(2, materials, Arrays.asList(now, now.plusMinutes(2), now.plusMinutes(1), now.plusMinutes(2)), 2, "222", "pipeline");
    third = PipelineMaterialModificationMother.modification(3, materials, Arrays.asList(now, now.plusMinutes(2), now.plusMinutes(1), now.plusMinutes(3)), 3, "333", "pipeline");
    fourth = PipelineMaterialModificationMother.modification(4, materials, Arrays.asList(now, now.plusMinutes(2), now.plusMinutes(3), now.plusMinutes(2)), 4, "444", "pipeline");
    pipelineName = "pipeline";
    transactionTemplate = mock(TransactionTemplate.class);
    transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
}
Also used : TransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TransactionSynchronizationManager) PipelineRepository(com.thoughtworks.go.server.persistence.PipelineRepository) TransactionTemplate(com.thoughtworks.go.server.transaction.TransactionTemplate) DateTime(org.joda.time.DateTime) Before(org.junit.Before)

Example 10 with TransactionSynchronizationManager

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

the class GitMaterial method git.

private GitCommand git(ProcessOutputStreamConsumer outputStreamConsumer, final File workingFolder, int preferredCloneDepth, SubprocessExecutionContext executionContext) throws Exception {
    if (isSubmoduleFolder()) {
        return new GitCommand(getFingerprint(), new File(workingFolder.getPath()), GitMaterialConfig.DEFAULT_BRANCH, true, executionContext.getDefaultEnvironmentVariables(), secrets());
    }
    GitCommand gitCommand = new GitCommand(getFingerprint(), workingFolder, getBranch(), false, executionContext.getDefaultEnvironmentVariables(), secrets());
    if (!isGitRepository(workingFolder) || isRepositoryChanged(gitCommand, workingFolder)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Invalid git working copy or repository changed. Delete folder: " + workingFolder);
        }
        deleteDirectoryNoisily(workingFolder);
    }
    createParentFolderIfNotExist(workingFolder);
    if (!workingFolder.exists()) {
        TransactionSynchronizationManager txManager = new TransactionSynchronizationManager();
        if (txManager.isActualTransactionActive()) {
            txManager.registerSynchronization(new TransactionSynchronizationAdapter() {

                @Override
                public void afterCompletion(int status) {
                    if (status != TransactionSynchronization.STATUS_COMMITTED) {
                        FileUtils.deleteQuietly(workingFolder);
                    }
                }
            });
        }
        int cloneDepth = shallowClone ? preferredCloneDepth : Integer.MAX_VALUE;
        int returnValue;
        if (executionContext.isServer()) {
            returnValue = gitCommand.cloneWithNoCheckout(outputStreamConsumer, url.forCommandline());
        } else {
            returnValue = gitCommand.clone(outputStreamConsumer, url.forCommandline(), cloneDepth);
        }
        bombIfFailedToRunCommandLine(returnValue, "Failed to run git clone command");
    }
    return gitCommand;
}
Also used : TransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TransactionSynchronizationManager) File(java.io.File) TransactionSynchronizationAdapter(org.springframework.transaction.support.TransactionSynchronizationAdapter) GitCommand(com.thoughtworks.go.domain.materials.git.GitCommand)

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