Search in sources :

Example 1 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.

the class ObjStoreBrowserTest method testMBeanHeuristic.

/**
 * Test that resources that generate heuristics are instrumented correctly
 * @throws Exception
 */
@Test
public void testMBeanHeuristic() throws Exception {
    // generates a heuristic on commit
    FailureXAResource failureXAResource = new FailureXAResource(FailureXAResource.FailLocation.commit);
    getHeuristicMBean(osb, new TransactionImple(1000000000), failureXAResource);
}
Also used : TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) Test(org.junit.Test)

Example 2 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.

the class TransactionImpleUnitTest method testThreadIsActive.

@Test
public void testThreadIsActive() throws Exception {
    ThreadActionData.purgeActions();
    Class[] parameterTypes = new Class[1];
    TransactionImple tx = new TransactionImple(0);
    tx.enlistResource(new RecoveryXAResource());
    parameterTypes[0] = XAResource.class;
    Method m = tx.getClass().getDeclaredMethod("threadIsActive", parameterTypes);
    m.setAccessible(true);
    Object[] parameters = new Object[1];
    parameters[0] = new RecoveryXAResource();
    Boolean res = (Boolean) m.invoke(tx, parameters);
    assertFalse(res.booleanValue());
    tx.rollback();
    ThreadActionData.purgeActions();
}
Also used : TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) Method(java.lang.reflect.Method) RecoveryXAResource(com.hp.mwtests.ts.jta.common.RecoveryXAResource) Test(org.junit.Test)

Example 3 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.

the class TransactionImpleUnitTest method test.

@Test
public void test() throws Exception {
    ThreadActionData.purgeActions();
    TransactionImple tx = new TransactionImple(0);
    TxImpleOverride.put(tx);
    assertEquals(tx, TransactionImple.getTransaction(tx.get_uid()));
    DummyXA res = new DummyXA(false);
    tx.enlistResource(res);
    tx.delistResource(res, XAResource.TMSUSPEND);
    assertTrue(tx.isAlive());
    tx.commit();
    assertTrue(tx.getRemainingTimeoutMills() != -1);
    assertTrue(tx.getTimeout() != -1);
    assertEquals(tx.getSynchronizations().size(), 0);
    assertEquals(tx.getResources().size(), 1);
    TxImpleOverride.remove(tx);
    assertTrue(TransactionImple.getTransactions() != null);
    assertEquals(TransactionImple.getTransaction(tx.get_uid()), null);
    try {
        tx = (TransactionImple) TransactionManager.transactionManager(new InitialContext());
        fail();
    } catch (final Throwable ex) {
    }
    assertNull(TransactionImple.getTransaction(null));
}
Also used : DummyXA(com.hp.mwtests.ts.jta.common.DummyXA) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 4 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.

the class TransactionImpleUnitTest method testFailure.

@Test
public void testFailure() throws Exception {
    ThreadActionData.purgeActions();
    TransactionImple tx = new TransactionImple(0);
    assertFalse(tx.equals(null));
    assertTrue(tx.equals(tx));
    tx.enlistResource(new FailureXAResource(FailLocation.commit));
    try {
        tx.commit();
        fail();
    } catch (final HeuristicMixedException ex) {
    }
    assertEquals(tx.getStatus(), Status.STATUS_COMMITTED);
    try {
        tx.registerSynchronization(null);
        fail();
    } catch (final SystemException ex) {
    }
    try {
        tx.commit();
        fail();
    } catch (final IllegalStateException ex) {
    }
}
Also used : SystemException(javax.transaction.SystemException) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) FailureXAResource(com.hp.mwtests.ts.jta.common.FailureXAResource) HeuristicMixedException(javax.transaction.HeuristicMixedException) Test(org.junit.Test)

Example 5 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.

the class TransactionImpleUnitTest method testDelist.

@Test
public void testDelist() throws Exception {
    ThreadActionData.purgeActions();
    TransactionImple tx = new TransactionImple(0);
    try {
        tx.delistResource(null, XAResource.TMSUCCESS);
        fail();
    } catch (final SystemException ex) {
    }
    DummyXA xares = new DummyXA(false);
    try {
        assertFalse(tx.delistResource(xares, XAResource.TMSUCCESS));
    } catch (final Throwable ex) {
        fail();
    }
    tx.enlistResource(xares);
    assertTrue(tx.delistResource(xares, XAResource.TMSUCCESS));
    tx.commit();
    try {
        tx.delistResource(xares, XAResource.TMSUCCESS);
        fail();
    } catch (final IllegalStateException ex) {
    }
}
Also used : DummyXA(com.hp.mwtests.ts.jta.common.DummyXA) SystemException(javax.transaction.SystemException) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) Test(org.junit.Test)

Aggregations

TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple)32 Test (org.junit.Test)30 FailureXAResource (com.hp.mwtests.ts.jta.common.FailureXAResource)12 XAException (javax.transaction.xa.XAException)11 RollbackException (javax.transaction.RollbackException)10 DummyXA (com.hp.mwtests.ts.jta.common.DummyXA)9 Uid (com.arjuna.ats.arjuna.common.Uid)7 XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)7 HeuristicMixedException (javax.transaction.HeuristicMixedException)6 TestResource (com.hp.mwtests.ts.jta.common.TestResource)5 XAResource (javax.transaction.xa.XAResource)5 Xid (javax.transaction.xa.Xid)5 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)4 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)4 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)4 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)4 SystemException (javax.transaction.SystemException)4 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)3 CommitMarkableResourceRecordRecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule)3 XidImple (com.arjuna.ats.jta.xa.XidImple)3