use of com.thoughtworks.go.server.transaction.TransactionCallback in project gocd by gocd.
the class ScheduleServiceStageTriggerTest method shouldNotNotifyListenersForWhenCancelStageTransactionRollsback.
@Test
public void shouldNotNotifyListenersForWhenCancelStageTransactionRollsback() throws Exception {
Pipeline oldest = preCondition.createPipelineWithFirstStagePassedAndSecondStageRunning();
preCondition.createPipelineWithFirstStagePassedAndSecondStageHasNotStarted();
preCondition.createPipelineWithFirstStagePassedAndSecondStageHasNotStarted();
final Stage stage = oldest.getStages().byName(preCondition.ftStage);
final StageIdentifier identifier = stage.getIdentifier();
StageStatusTopic stageStatusTopic = mock(StageStatusTopic.class);
JobResultTopic jobResultTopic = mock(JobResultTopic.class);
StageStatusListener stageStatusListener = mock(StageStatusListener.class);
JobInstanceService jobInstanceService = jobInstanceService(jobResultTopic);
StageService stageService = new StageService(stageDao, jobInstanceService, stageStatusTopic, stageStatusCache, securityService, pipelineDao, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache, stageStatusListener);
SchedulingPerformanceLogger schedulingPerformanceLogger = mock(SchedulingPerformanceLogger.class);
scheduleService = new ScheduleService(goConfigService, pipelineService, stageService, schedulingCheckerService, pipelineScheduledTopic, pipelineDao, stageDao, stageOrderService, securityService, pipelineScheduleQueue, this.jobInstanceService, jobInstanceDao, agentAssignment, environmentConfigService, pipelineLockService, serverHealthService, transactionTemplate, null, transactionSynchronizationManager, null, null, null, null, schedulingPerformanceLogger, null);
try {
transactionTemplate.executeWithExceptionHandling(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) throws Exception {
scheduleService.cancelAndTriggerRelevantStages(stage.getId(), null, null);
throw new GoUnauthorizedException();
}
});
} catch (Exception e) {
//ignore
}
verify(stageStatusTopic, never()).post(any(StageStatusMessage.class));
verify(jobResultTopic, never()).post(any(JobResultMessage.class));
verify(stageStatusListener, never()).stageStatusChanged(any(Stage.class));
}
use of com.thoughtworks.go.server.transaction.TransactionCallback in project gocd by gocd.
the class MaterialDatabaseUpdater method updateMaterial.
public void updateMaterial(final Material material) throws Exception {
String materialMutex = mutexForMaterial(material);
HealthStateScope scope = HealthStateScope.forMaterial(material);
try {
MaterialInstance materialInstance = materialRepository.findMaterialInstance(material);
if (materialInstance == null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("[Material Update] Material repository not found, creating with latest revision from %s", material));
}
synchronized (materialMutex) {
if (materialRepository.findMaterialInstance(material) == null) {
transactionTemplate.executeWithExceptionHandling(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) throws Exception {
initializeMaterialWithLatestRevision(material);
return null;
}
});
}
}
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("[Material Update] Existing material repository, fetching new revisions from %s in flyweight %s", material, materialInstance.getFlyweightName()));
}
synchronized (materialMutex) {
transactionTemplate.executeWithExceptionHandling(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) throws Exception {
updateMaterialWithNewRevisions(material);
return null;
}
});
}
}
healthService.removeByScope(scope);
} catch (Exception e) {
String message = "Modification check failed for material: " + material.getLongDescription();
String errorDescription = e.getMessage() == null ? "Unknown error" : e.getMessage();
healthService.update(ServerHealthState.error(message, errorDescription, HealthStateType.general(scope)));
LOGGER.warn(String.format("[Material Update] %s", message), e);
throw e;
}
}
use of com.thoughtworks.go.server.transaction.TransactionCallback in project gocd by gocd.
the class ModificationIntegrationTest method shouldPersistAdditionalDataIntoModificationsTable.
@Test
public void shouldPersistAdditionalDataIntoModificationsTable() throws Exception {
String revision = "revision";
HashMap<String, String> additionalDataMap = new HashMap<>();
additionalDataMap.put("key", "value");
String additionalData = JsonHelper.toJsonString(additionalDataMap);
final Modification modification = new Modification("user", "comment", "foo@bar.fooadsf", new Date(), revision, additionalData);
final GitMaterial git = new GitMaterial("url", "branch");
transactionTemplate.executeWithExceptionHandling(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) throws Exception {
MaterialInstance gitInstance = materialRepository.findOrCreateFrom(git);
materialRepository.saveModification(gitInstance, modification);
return null;
}
});
Modification actual = materialRepository.findModificationWithRevision(git, revision);
/*
Checking if time are the same, because actual has SQLTime whereas we send in java.util.Date. No idea how we were testing this ever
because Modification#equals fails instance check (ShilpaG & Sachin)
*/
assertThat(actual.getModifiedTime().getTime(), is(modification.getModifiedTime().getTime()));
assertThat(actual.getAdditionalData(), is(additionalData));
assertThat(actual.getAdditionalDataMap(), is(additionalDataMap));
}
Aggregations