use of org.springframework.transaction.support.SimpleTransactionStatus in project opennms by OpenNMS.
the class CollectdTest method setupTransactionManager.
/**
* Add a dummy transaction manager that has mock calls to commit() and rollback()
*/
private void setupTransactionManager() {
PlatformTransactionManager m_transactionManager = m_easyMockUtils.createMock(PlatformTransactionManager.class);
TransactionTemplate transactionTemplate = new TransactionTemplate(m_transactionManager);
m_collectd.setTransactionTemplate(transactionTemplate);
expect(m_transactionManager.getTransaction(isA(TransactionDefinition.class))).andReturn(new SimpleTransactionStatus()).anyTimes();
m_transactionManager.rollback(isA(TransactionStatus.class));
expectLastCall().anyTimes();
m_transactionManager.commit(isA(TransactionStatus.class));
expectLastCall().anyTimes();
}
use of org.springframework.transaction.support.SimpleTransactionStatus in project spring-framework by spring-projects.
the class MockCallbackPreferringTransactionManager method execute.
@Override
public <T> T execute(TransactionDefinition definition, TransactionCallback<T> callback) throws TransactionException {
this.definition = definition;
this.status = new SimpleTransactionStatus();
return callback.doInTransaction(this.status);
}
use of org.springframework.transaction.support.SimpleTransactionStatus in project gocd by gocd.
the class PipelineSqlMapDaoCachingTest method shouldInvalidateCacheOfPipelineInstancesTriggeredWithMaterialRevision.
@Test
void shouldInvalidateCacheOfPipelineInstancesTriggeredWithMaterialRevision() {
GitMaterialInstance materialInstance = new GitMaterialInstance("url", null, "branch", "submodule", "flyweight");
String cacheKey = pipelineDao.cacheKeyForPipelineInstancesTriggeredWithDependencyMaterial("p1", materialInstance.getFingerprint(), "r1");
List<PipelineIdentifier> result = Arrays.asList(new PipelineIdentifier("p1", 1, "1"));
when(mockTemplate.queryForList(eq("pipelineInstancesTriggeredOffOfMaterialRevision"), any())).thenReturn((List) result);
List<PipelineIdentifier> actual = pipelineDao.getPipelineInstancesTriggeredWithDependencyMaterial("p1", materialInstance, "r1");
assertThat(actual).hasSize(1);
assertThat((List<PipelineIdentifier>) goCache.get(cacheKey)).hasSize(1);
MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(new GitMaterial("url", "branch"), new Modification("user", "comment", "email", new Date(), "r1")));
Pipeline pipeline = new Pipeline("p1", BuildCause.createWithModifications(materialRevisions, ""));
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
((TransactionSynchronizationAdapter) invocation.getArguments()[0]).afterCommit();
return null;
}
}).when(transactionSynchronizationManager).registerSynchronization(any(TransactionSynchronization.class));
when(transactionTemplate.execute(any(TransactionCallback.class))).then(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
((TransactionCallback) invocation.getArguments()[0]).doInTransaction(new SimpleTransactionStatus());
return null;
}
});
pipelineDao.save(pipeline);
assertThat(goCache.get(cacheKey)).isNull();
}
use of org.springframework.transaction.support.SimpleTransactionStatus in project gocd by gocd.
the class PipelineStateDaoTest method shouldNotCorruptCacheIfSaveFailsWhileLocking.
@Test
void shouldNotCorruptCacheIfSaveFailsWhileLocking() {
String pipelineName = UUID.randomUUID().toString();
Pipeline pipeline = PipelineMother.pipeline(pipelineName, new Stage());
PipelineState pipelineState = new PipelineState(pipelineName);
goCache.put(pipelineStateDao.pipelineLockStateCacheKey(pipelineName), pipelineState);
when(transactionTemplate.execute(any(org.springframework.transaction.support.TransactionCallbackWithoutResult.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
org.springframework.transaction.support.TransactionCallbackWithoutResult callback = (org.springframework.transaction.support.TransactionCallbackWithoutResult) invocation.getArguments()[0];
callback.doInTransaction(new SimpleTransactionStatus());
return null;
}
});
doThrow(new RuntimeException("could not save!")).when(session).saveOrUpdate(any(PipelineState.class));
try {
pipelineStateDao.lockPipeline(pipeline);
fail("save should have thrown an exception!");
} catch (Exception e) {
PipelineState stateFromCache = (PipelineState) goCache.get(pipelineStateDao.pipelineLockStateCacheKey(pipelineName));
assertThat(stateFromCache.isLocked(), is(false));
assertThat(stateFromCache.getLockedByPipelineId(), is(0L));
assertThat(stateFromCache.getLockedBy(), is(nullValue()));
}
}
Aggregations