use of javax.transaction.Synchronization in project wildfly by wildfly.
the class InfinispanBatcherTestCase method createBatchDiscard.
@Test
public void createBatchDiscard() throws Exception {
Transaction tx = mock(Transaction.class);
ArgumentCaptor<Synchronization> capturedSync = ArgumentCaptor.forClass(Synchronization.class);
when(this.tm.getTransaction()).thenReturn(tx);
try (TransactionBatch batch = this.batcher.createBatch()) {
verify(this.tm).begin();
verify(tx).registerSynchronization(capturedSync.capture());
assertSame(tx, batch.getTransaction());
batch.discard();
} finally {
capturedSync.getValue().afterCompletion(Status.STATUS_ROLLEDBACK);
}
verify(tx, never()).commit();
verify(tx).rollback();
assertNull(InfinispanBatcher.CURRENT_BATCH.get());
}
use of javax.transaction.Synchronization in project wildfly by wildfly.
the class InfinispanBatcherTestCase method createNestedBatchDiscard.
@Test
public void createNestedBatchDiscard() throws Exception {
Transaction tx = mock(Transaction.class);
ArgumentCaptor<Synchronization> capturedSync = ArgumentCaptor.forClass(Synchronization.class);
when(this.tm.getTransaction()).thenReturn(tx);
try (TransactionBatch outerBatch = this.batcher.createBatch()) {
verify(this.tm).begin();
verify(tx).registerSynchronization(capturedSync.capture());
reset(this.tm);
assertSame(tx, outerBatch.getTransaction());
when(tx.getStatus()).thenReturn(Status.STATUS_ACTIVE);
when(this.tm.getTransaction()).thenReturn(tx);
try (TransactionBatch innerBatch = this.batcher.createBatch()) {
verify(this.tm, never()).begin();
innerBatch.discard();
}
verify(tx, never()).commit();
verify(tx, never()).rollback();
} finally {
capturedSync.getValue().afterCompletion(Status.STATUS_ROLLEDBACK);
}
verify(tx).rollback();
verify(tx, never()).commit();
assertNull(InfinispanBatcher.CURRENT_BATCH.get());
}
use of javax.transaction.Synchronization in project wildfly by wildfly.
the class InfinispanBatcherTestCase method createOverlappingBatchDiscard.
@SuppressWarnings("resource")
@Test
public void createOverlappingBatchDiscard() throws Exception {
Transaction tx = mock(Transaction.class);
ArgumentCaptor<Synchronization> capturedSync = ArgumentCaptor.forClass(Synchronization.class);
when(this.tm.getTransaction()).thenReturn(tx);
TransactionBatch batch = this.batcher.createBatch();
verify(this.tm).begin();
verify(tx).registerSynchronization(capturedSync.capture());
reset(this.tm);
try {
assertSame(tx, batch.getTransaction());
when(this.tm.getTransaction()).thenReturn(tx);
when(tx.getStatus()).thenReturn(Status.STATUS_ACTIVE);
try (TransactionBatch innerBatch = this.batcher.createBatch()) {
verify(this.tm, never()).begin();
innerBatch.discard();
batch.close();
verify(tx, never()).commit();
verify(tx, never()).rollback();
}
} finally {
capturedSync.getValue().afterCompletion(Status.STATUS_ROLLEDBACK);
}
verify(tx).rollback();
verify(tx, never()).commit();
assertNull(InfinispanBatcher.CURRENT_BATCH.get());
}
use of javax.transaction.Synchronization in project tomee by apache.
the class TransactionalTest method runtimeChecked.
@Test
public void runtimeChecked() throws Exception {
for (int i = 0; i < 2; i++) {
final AtomicInteger status = new AtomicInteger();
try {
bean.runtimeChecked(new Runnable() {
@Override
public void run() {
try {
OpenEJB.getTransactionManager().getTransaction().registerSynchronization(new Synchronization() {
@Override
public void beforeCompletion() {
// no-op
}
@Override
public void afterCompletion(int state) {
status.set(state);
}
});
} catch (final RollbackException | SystemException e) {
fail();
}
}
});
fail();
} catch (final AnException e) {
// no-op
}
assertEquals(Status.STATUS_COMMITTED, status.get());
}
}
use of javax.transaction.Synchronization in project tomee by apache.
the class TransactionalTest method runtimeException.
@Test
public void runtimeException() throws Exception {
for (int i = 0; i < 2; i++) {
final AtomicInteger status = new AtomicInteger(-1);
try {
bean.runtimeEx(new Runnable() {
@Override
public void run() {
try {
OpenEJB.getTransactionManager().getTransaction().registerSynchronization(new Synchronization() {
@Override
public void beforeCompletion() {
// no-op
}
@Override
public void afterCompletion(int state) {
status.set(state);
}
});
} catch (final RollbackException | SystemException e) {
fail();
}
}
});
fail();
} catch (final AnException e) {
// no-op
}
assertEquals(Status.STATUS_ROLLEDBACK, status.get());
}
}
Aggregations