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