use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class JobInstanceSqlMapDaoIntegrationTest method savedJobForAgent.
private JobInstance savedJobForAgent(final String jobName, final String uuid, final boolean runOnAllAgents, final boolean runMultipleInstance) {
return (JobInstance) transactionTemplate.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
JobInstance jobInstance = scheduled(jobName, new DateTime().plusMinutes(1).toDate());
jobInstance.setRunOnAllAgents(runOnAllAgents);
jobInstance.setRunMultipleInstance(runMultipleInstance);
jobInstanceService.save(savedStage.getIdentifier(), stageId, jobInstance);
jobInstance.changeState(JobState.Building);
jobInstance.setAgentUuid(uuid);
jobInstanceDao.updateStateAndResult(jobInstance);
return jobInstance;
}
});
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class PluggableSCMMaterialUpdaterIntegrationTest method shouldUpdateMaterialInstanceWhenAdditionalDataIsUpdatedDuringLatestModification.
@Test
public void shouldUpdateMaterialInstanceWhenAdditionalDataIsUpdatedDuringLatestModification() throws Exception {
final PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
final MaterialInstance materialInstance = material.createMaterialInstance();
materialRepository.saveOrUpdate(materialInstance);
Map<String, String> data = new HashMap<>();
data.put("k1", "v1");
when(scmExtension.getLatestRevision(any(String.class), any(SCMPropertyConfiguration.class), any(Map.class), any(String.class))).thenReturn(new MaterialPollResult(data, new SCMRevision()));
mockSCMExtensionInPoller();
scmMaterialUpdater = new ScmMaterialUpdater(materialRepository, materialChecker, subprocessExecutionContext, materialService);
pluggableSCMMaterialUpdater = new PluggableSCMMaterialUpdater(materialRepository, scmMaterialUpdater, transactionTemplate);
transactionTemplate.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus transactionStatus) {
pluggableSCMMaterialUpdater.insertLatestOrNewModifications(material, materialInstance, new File(""), new Modifications());
return null;
}
});
MaterialInstance actualInstance = materialRepository.findMaterialInstance(material);
assertThat(actualInstance.getAdditionalDataMap(), is(data));
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class MaterialRepositoryIntegrationTest method materialsShouldBeSerializable.
@Test
public void materialsShouldBeSerializable() throws Exception {
SvnMaterial svnMaterial = MaterialsMother.svnMaterial();
Modification modification = new Modification("user", "comment", "email", new Date(), "revision");
modification.createModifiedFile("file1", "folder1", ModifiedAction.added);
modification.createModifiedFile("file2", "folder2", ModifiedAction.deleted);
final MaterialRevision materialRevision = new MaterialRevision(svnMaterial, modification);
MaterialInstance materialInstance = (MaterialInstance) transactionTemplate.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
return repo.saveMaterialRevision(materialRevision);
}
});
List<Modification> mods = repo.findMaterialRevisionsForMaterial(materialInstance.getId());
List<Modification> deserialized = (List<Modification>) SerializationTester.serializeAndDeserialize(mods);
assertThat(deserialized, is(mods));
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class MaterialRepositoryIntegrationTest method shouldNotSaveAndClearCacheWhenThereAreNoNewModifications.
@Test
public void shouldNotSaveAndClearCacheWhenThereAreNoNewModifications() {
final MaterialInstance materialInstance = repo.findOrCreateFrom(new GitMaterial(UUID.randomUUID().toString(), "branch"));
String key = repo.materialModificationsWithPaginationKey(materialInstance);
String subKey = repo.materialModificationsWithPaginationSubKey(Pagination.ONE_ITEM);
goCache.put(key, subKey, new Modifications(new Modification()));
transactionTemplate.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
repo.saveModifications(materialInstance, new ArrayList<>());
return null;
}
});
assertThat(goCache.get(key, subKey), is(notNullValue()));
}
use of org.springframework.transaction.support.TransactionCallback in project gocd by gocd.
the class MaterialRepositoryIntegrationTest method saveOneScmModification.
private MaterialRevision saveOneScmModification(final String revision, final Material original, final String user, final String filename, final String comment) {
return (MaterialRevision) transactionTemplate.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
Modification modification = new Modification(user, comment, "email", new Date(), revision);
modification.createModifiedFile(filename, "folder1", ModifiedAction.added);
MaterialRevision originalRevision = new MaterialRevision(original, modification);
repo.save(new MaterialRevisions(originalRevision));
return originalRevision;
}
});
}
Aggregations