use of org.springframework.transaction.support.SimpleTransactionStatus in project cucumber-jvm by cucumber.
the class SpringTransactionHooksTest method shouldObtainOrStartTransactionInBeforeHook.
@Test
public void shouldObtainOrStartTransactionInBeforeHook() {
final SimpleTransactionStatus dummyTxStatus = new SimpleTransactionStatus();
when(mockedPlatformTransactionManager.getTransaction(isA(TransactionDefinition.class))).thenReturn(dummyTxStatus);
target.startTransaction();
assertSame(target.getTransactionStatus(), dummyTxStatus);
}
use of org.springframework.transaction.support.SimpleTransactionStatus in project spring-framework by spring-projects.
the class TransactionalTestExecutionListenerTests method assertAfterTestMethodWithTransactionalTestMethod.
private void assertAfterTestMethodWithTransactionalTestMethod(Class<? extends Invocable> clazz) throws Exception {
BDDMockito.<Class<?>>given(testContext.getTestClass()).willReturn(clazz);
Invocable instance = BeanUtils.instantiateClass(clazz);
given(testContext.getTestInstance()).willReturn(instance);
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("transactionalTest"));
given(tm.getTransaction(BDDMockito.any(TransactionDefinition.class))).willReturn(new SimpleTransactionStatus());
assertThat(instance.invoked()).as("callback should not have been invoked").isFalse();
TransactionContextHolder.removeCurrentTransactionContext();
listener.beforeTestMethod(testContext);
assertThat(instance.invoked()).as("callback should not have been invoked").isFalse();
listener.afterTestMethod(testContext);
assertThat(instance.invoked()).as("callback should have been invoked").isTrue();
}
use of org.springframework.transaction.support.SimpleTransactionStatus in project gocd by gocd.
the class PipelineStateDaoTest method shouldNotCorruptCacheIfSaveFailsWhileUnLocking.
@Test
void shouldNotCorruptCacheIfSaveFailsWhileUnLocking() {
String pipelineName = UUID.randomUUID().toString();
PipelineState pipelineState = new PipelineState(pipelineName);
long lockedByPipelineId = 1;
pipelineState.lock(lockedByPipelineId);
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.unlockPipeline(pipelineName);
fail("save should have thrown an exception!");
} catch (Exception e) {
PipelineState stateFromCache = (PipelineState) goCache.get(pipelineStateDao.pipelineLockStateCacheKey(pipelineName));
assertThat(stateFromCache.isLocked(), is(true));
assertThat(stateFromCache.getLockedByPipelineId(), is(lockedByPipelineId));
}
}
use of org.springframework.transaction.support.SimpleTransactionStatus in project gocd by gocd.
the class PipelineSqlMapDaoCachingTest method shouldInvalidateCacheOfPipelineInstancesTriggeredWithDependencyMaterial.
@Test
void shouldInvalidateCacheOfPipelineInstancesTriggeredWithDependencyMaterial() {
String cacheKey = pipelineDao.cacheKeyForPipelineInstancesTriggeredWithDependencyMaterial("p1", "p", 1);
when(mockTemplate.queryForList(eq("pipelineInstancesTriggeredOutOfDependencyMaterial"), anyString())).thenReturn(new ArrayList());
List<PipelineIdentifier> actual = pipelineDao.getPipelineInstancesTriggeredWithDependencyMaterial("p1", new PipelineIdentifier("p", 1));
assertThat(actual).hasSize(0);
assertThat((List<PipelineIdentifier>) goCache.get(cacheKey)).hasSize(0);
MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(new DependencyMaterial(new CaseInsensitiveString("p"), new CaseInsensitiveString("s")), new Modification("u", "comment", "email", new Date(), "p/1/s/1")));
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 cucumber-jvm by cucumber.
the class SpringTransactionHooksTest method shouldTriggerTransactionRollbackInAfterHook.
@Test
public void shouldTriggerTransactionRollbackInAfterHook() {
final SimpleTransactionStatus dummyTxStatus = new SimpleTransactionStatus();
target.setTransactionStatus(dummyTxStatus);
target.rollBackTransaction();
verify(mockedPlatformTransactionManager).rollback(dummyTxStatus);
}
Aggregations