use of javax.transaction.Synchronization in project wildfly by wildfly.
the class InfinispanBatcherTestCase method createBatchClose.
@Test
public void createBatchClose() 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());
} finally {
capturedSync.getValue().afterCompletion(Status.STATUS_COMMITTED);
}
verify(tx).commit();
assertNull(InfinispanBatcher.CURRENT_BATCH.get());
}
use of javax.transaction.Synchronization in project geode by apache.
the class GlobalTransactionJUnitTest method testRegisterSynchronization.
@Test
public void testRegisterSynchronization() throws Exception {
try {
boolean exceptionoccurred = false;
utx.begin();
try {
Transaction txn = tm.getTransaction();
Synchronization sync = new SyncImpl();
txn.registerSynchronization(sync);
} catch (RollbackException e) {
exceptionoccurred = true;
}
if (exceptionoccurred)
fail("exception occurred while trying to register synchronization ");
utx.rollback();
} catch (Exception e) {
try {
utx.rollback();
} catch (Exception e1) {
e1.printStackTrace();
}
fail("exception in testRegisterSynchronization due to " + e);
e.printStackTrace();
}
}
use of javax.transaction.Synchronization in project geode by apache.
the class TransactionImplJUnitTest method testRegisterSynchronization.
@Test
public void testRegisterSynchronization() throws Exception {
utx.begin();
TransactionImpl txn = (TransactionImpl) tm.getTransaction();
Synchronization sync = new SyncImpl();
txn.registerSynchronization(sync);
assertTrue("Synchronization not registered succesfully", txn.getSyncList().contains(sync));
utx.commit();
}
use of javax.transaction.Synchronization in project geode by apache.
the class GlobalTransactionJUnitTest method testRegisterSynchronizationAfterRollBack.
@Test
public void testRegisterSynchronizationAfterRollBack() throws Exception {
try {
boolean exceptionoccurred = false;
utx.begin();
utx.setRollbackOnly();
Context ctx = cache.getJNDIContext();
try {
Transaction txn = tm.getTransaction();
Synchronization sync = new SyncImpl();
txn.registerSynchronization(sync);
} catch (RollbackException e) {
exceptionoccurred = true;
}
if (!exceptionoccurred)
fail("RollbackException not occurred although the transaction was marked for rollback");
utx.rollback();
} catch (Exception e) {
try {
utx.rollback();
} catch (Exception e1) {
e1.printStackTrace();
}
fail("exception in testSetRollbackonly due to " + e);
e.printStackTrace();
}
}
use of javax.transaction.Synchronization in project Payara by payara.
the class SynchronizationImpl method before_completion.
public void before_completion() {
// Regular syncs first then the interposed syncs
Enumeration e = syncs.elements();
while (e.hasMoreElements()) {
Synchronization sync = (Synchronization) e.nextElement();
try {
sync.beforeCompletion();
} catch (RuntimeException rex) {
try {
state.setRollbackOnly();
} catch (Exception ex1) {
_logger.log(Level.WARNING, "jts.unexpected_error_occurred_in_after_completion", ex1);
}
_logger.log(Level.WARNING, "jts.unexpected_error_occurred_in_after_completion", rex);
throw rex;
} catch (Exception ex) {
_logger.log(Level.WARNING, "jts.unexpected_error_occurred_in_after_completion", ex);
}
}
Enumeration e1 = interposedSyncs.elements();
while (e1.hasMoreElements()) {
Synchronization sync = (Synchronization) e1.nextElement();
try {
sync.beforeCompletion();
} catch (RuntimeException rex) {
try {
state.setRollbackOnly();
} catch (Exception ex1) {
_logger.log(Level.WARNING, "jts.unexpected_error_occurred_in_after_completion", ex1);
}
_logger.log(Level.WARNING, "jts.unexpected_error_occurred_in_after_completion", rex);
throw rex;
} catch (Exception ex) {
_logger.log(Level.WARNING, "jts.unexpected_error_occurred_in_after_completion", ex);
}
}
state.beforeCompletion();
}
Aggregations