Search in sources :

Example 1 with TransactionSynchronizationRegistryImple

use of com.arjuna.ats.internal.jta.transaction.jts.TransactionSynchronizationRegistryImple in project narayana by jbosstm.

the class TransactionSynchronizationRegistryTest method testTSRUseAfterCompletion.

@Test
public void testTSRUseAfterCompletion() throws Exception {
    javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
    final CompletionCountLock ccl = new CompletionCountLock(2);
    tm.begin();
    final TransactionSynchronizationRegistry tsr = new TransactionSynchronizationRegistryImple();
    tsr.registerInterposedSynchronization(new Synchronization() {

        @Override
        public void afterCompletion(int status) {
            String key = "key";
            Object value = new Object();
            try {
                tsr.getResource(key);
                ccl.incrementFailedCount();
            } catch (IllegalStateException ise) {
                // Expected
                ccl.incrementCount();
            }
            try {
                tsr.putResource(key, value);
                ccl.incrementFailedCount();
            } catch (IllegalStateException ise) {
                // Expected
                ccl.incrementCount();
            }
        }

        @Override
        public void beforeCompletion() {
        // TODO Auto-generated method stub
        }
    });
    tm.commit();
    assertTrue(ccl.waitForCompletion());
}
Also used : TransactionSynchronizationRegistryImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionSynchronizationRegistryImple) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) Synchronization(javax.transaction.Synchronization) Test(org.junit.Test)

Example 2 with TransactionSynchronizationRegistryImple

use of com.arjuna.ats.internal.jta.transaction.jts.TransactionSynchronizationRegistryImple in project narayana by jbosstm.

the class TransactionSynchronizationRegistryTest method testTSR.

@Test
public void testTSR() throws Exception {
    javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
    TransactionSynchronizationRegistry tsr = new TransactionSynchronizationRegistryImple();
    assertNull(tsr.getTransactionKey());
    assertEquals(tm.getStatus(), tsr.getTransactionStatus());
    tm.begin();
    assertNotNull(tsr.getTransactionKey());
    assertEquals(tm.getStatus(), tsr.getTransactionStatus());
    String key = "key";
    Object value = new Object();
    assertNull(tsr.getResource(key));
    tsr.putResource(key, value);
    assertEquals(value, tsr.getResource(key));
    Synchronization synchronization = new com.hp.mwtests.ts.jta.jts.common.Synchronization();
    tsr.registerInterposedSynchronization(synchronization);
    assertFalse(tsr.getRollbackOnly());
    tsr.setRollbackOnly();
    assertTrue(tsr.getRollbackOnly());
    boolean gotExpectedException = false;
    try {
        tsr.registerInterposedSynchronization(synchronization);
    } catch (IllegalStateException e) {
        gotExpectedException = true;
    }
    assertTrue(gotExpectedException);
    tm.rollback();
    assertEquals(tm.getStatus(), tsr.getTransactionStatus());
}
Also used : TransactionSynchronizationRegistryImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionSynchronizationRegistryImple) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) Synchronization(javax.transaction.Synchronization) Test(org.junit.Test)

Aggregations

TransactionSynchronizationRegistryImple (com.arjuna.ats.internal.jta.transaction.jts.TransactionSynchronizationRegistryImple)2 Synchronization (javax.transaction.Synchronization)2 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)2 Test (org.junit.Test)2