public void testSyncBeforeEndCalledOnceOnRollback() throws Exception {
final AtomicInteger beforeEndCountA = new AtomicInteger(0);
final AtomicInteger beforeEndCountB = new AtomicInteger(0);
final AtomicInteger rollbackCountA = new AtomicInteger(0);
final AtomicInteger rollbackCountB = new AtomicInteger(0);
underTest.addSynchronization(new Synchronization() {
@Override
public void beforeEnd() throws Exception {
if (beforeEndCountA.getAndIncrement() == 0) {
throw new TransactionRolledBackException("force rollback");
}
}
@Override
public void afterCommit() throws Exception {
fail("exepcted rollback exception");
}
@Override
public void afterRollback() throws Exception {
rollbackCountA.incrementAndGet();
}
});
underTest.addSynchronization(new Synchronization() {
@Override
public void beforeEnd() throws Exception {
beforeEndCountB.getAndIncrement();
}