use of org.springframework.transaction.support.TransactionSynchronization in project gocd by gocd.
the class TransactionContext method transactionPushed.
public void transactionPushed() {
if (!isTransactionBodyExecuting()) {
if (isInTransactionSurrounding() && txnFinished) {
throw new RuntimeException(TOO_MANY_TXNS_IN_SURROUNDING);
}
txnFinished = false;
}
ensureCanPush(txnActive);
txnActive--;
if (!futureSynchronizations.isEmpty()) {
for (TransactionSynchronization futureSynchronization : futureSynchronizations) {
doRegisterSynchronization(futureSynchronization);
}
clearFutureSynchronizations();
}
}
use of org.springframework.transaction.support.TransactionSynchronization in project gocd by gocd.
the class TransactionSynchronizationManagerTest method shouldRegisterSynchronization.
@Test
public void shouldRegisterSynchronization() {
final TransactionSynchronizationManager synchronizationManager = new TransactionSynchronizationManager();
final TransactionSynchronization synchronization = mock(TransactionSynchronization.class);
transactionTemplate.execute(new org.springframework.transaction.support.TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
synchronizationManager.registerSynchronization(synchronization);
}
});
verify(synchronization).afterCommit();
}
use of org.springframework.transaction.support.TransactionSynchronization in project gocd by gocd.
the class TransactionSynchronizationManagerTest method shouldRegisterSynchronization_andNotCallItOnTransactionFailure.
@Test
public void shouldRegisterSynchronization_andNotCallItOnTransactionFailure() {
final TransactionSynchronizationManager synchronizationManager = new TransactionSynchronizationManager();
final TransactionSynchronization synchronization = mock(TransactionSynchronization.class);
try {
transactionTemplate.execute(new org.springframework.transaction.support.TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
synchronizationManager.registerSynchronization(synchronization);
throw new RuntimeException();
}
});
} catch (Exception e) {
//ignore
}
verify(synchronization, never()).afterCommit();
}
use of org.springframework.transaction.support.TransactionSynchronization in project spring-framework by spring-projects.
the class JtaTransactionManagerTests method jtaTransactionManagerWithExistingTransactionAndRollbackOnlyAndNoGlobalRollback.
@Test
public void jtaTransactionManagerWithExistingTransactionAndRollbackOnlyAndNoGlobalRollback() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
final TransactionSynchronization synch = mock(TransactionSynchronization.class);
JtaTransactionManager ptm = newJtaTransactionManager(ut);
ptm.setGlobalRollbackOnParticipationFailure(false);
TransactionTemplate tt = new TransactionTemplate(ptm);
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
TransactionSynchronizationManager.registerSynchronization(synch);
status.setRollbackOnly();
}
});
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
verify(ut).setRollbackOnly();
verify(synch).beforeCompletion();
verify(synch).afterCompletion(TransactionSynchronization.STATUS_UNKNOWN);
}
use of org.springframework.transaction.support.TransactionSynchronization in project spring-framework by spring-projects.
the class JtaTransactionManagerTests method jtaTransactionManagerWithPropagationSupports.
@Test
public void jtaTransactionManagerWithPropagationSupports() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION);
final TransactionSynchronization synch = mock(TransactionSynchronization.class);
JtaTransactionManager ptm = newJtaTransactionManager(ut);
TransactionTemplate tt = new TransactionTemplate(ptm);
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
TransactionSynchronizationManager.registerSynchronization(synch);
status.setRollbackOnly();
}
});
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
verify(synch).beforeCompletion();
verify(synch).afterCompletion(TransactionSynchronization.STATUS_ROLLED_BACK);
}
Aggregations