Search in sources :

Example 1 with Synchronization

use of com.hp.mwtests.ts.jta.common.Synchronization in project narayana by jbosstm.

the class TransactionImpleUnitTest method testInvalid.

@Test
public void testInvalid() throws Exception {
    ThreadActionData.purgeActions();
    TxImpleOverride tx = new TxImpleOverride();
    assertEquals(tx.hashCode(), -1);
    assertEquals(tx.getStatus(), Status.STATUS_NO_TRANSACTION);
    try {
        tx.commit();
        fail();
    } catch (final IllegalStateException ex) {
    }
    try {
        tx.rollback();
        fail();
    } catch (final IllegalStateException ex) {
    }
    try {
        tx.setRollbackOnly();
        fail();
    } catch (final IllegalStateException ex) {
    }
    try {
        tx.registerSynchronization(new Synchronization());
        fail();
    } catch (final IllegalStateException ex) {
    }
    tx.toString();
    assertFalse(tx.isAlive());
}
Also used : Synchronization(com.hp.mwtests.ts.jta.common.Synchronization) Test(org.junit.Test)

Example 2 with Synchronization

use of com.hp.mwtests.ts.jta.common.Synchronization in project narayana by jbosstm.

the class SynchronizationUnitTest method testValid.

@Test
public void testValid() {
    SynchronizationImple sync = new SynchronizationImple(new Synchronization());
    assertTrue(sync.get_uid().notEquals(Uid.nullUid()));
    assertTrue(sync.beforeCompletion());
    assertTrue(sync.afterCompletion(Status.STATUS_COMMITTED));
    SynchronizationImple comp = new SynchronizationImple(new Synchronization());
    assertTrue(comp.compareTo(sync) != 0);
    assertTrue(sync.toString() != null);
}
Also used : Synchronization(com.hp.mwtests.ts.jta.common.Synchronization) SynchronizationImple(com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple) Test(org.junit.Test)

Example 3 with Synchronization

use of com.hp.mwtests.ts.jta.common.Synchronization 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.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.arjunacore.TransactionSynchronizationRegistryImple) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) Synchronization(com.hp.mwtests.ts.jta.common.Synchronization) Test(org.junit.Test)

Example 4 with Synchronization

use of com.hp.mwtests.ts.jta.common.Synchronization 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.arjunacore.TransactionSynchronizationRegistryImple) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) Synchronization(com.hp.mwtests.ts.jta.common.Synchronization) Test(org.junit.Test)

Aggregations

Synchronization (com.hp.mwtests.ts.jta.common.Synchronization)4 Test (org.junit.Test)4 TransactionSynchronizationRegistryImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple)2 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)2 SynchronizationImple (com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple)1