Search in sources :

Example 11 with TransactionImple

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

the class JTSXARTest method injectCommitException.

void injectCommitException(String exceptionType) throws Exception {
    XAFailureSpec fault = new XAFailureSpec("JTSXARTest", XAFailureMode.XAEXCEPTION, XAFailureType.XARES_COMMIT, exceptionType, 0);
    XAException xae = XAFailureResource.getXAExceptionType(exceptionType);
    int expectedXAE = xae == null ? HeuristicStatus.UNKNOWN_XA_ERROR_CODE : xae.errorCode;
    TransactionManagerImple tm = new TransactionManagerImple();
    Uid txUid;
    TransactionImple txn;
    // clean the thread that will create the transaction
    ThreadActionData.purgeActions();
    // begin a transaction
    tm.begin();
    txn = (TransactionImple) tm.getTransaction();
    txUid = txn.get_uid();
    // enlist two XA resources
    tm.getTransaction().enlistResource(new XAFailureResource());
    tm.getTransaction().enlistResource(new XAFailureResource(fault));
    // commit the transaction and check for any expected exceptions
    try {
        tm.commit();
    } catch (HeuristicRollbackException e) {
        if (!XAFailureSpec.compatibleHeuristics(XAException.XA_HEURRB, expectedXAE))
            throw e;
    } catch (RollbackException e) {
        if (!XAFailureSpec.compatibleHeuristics(XAException.XA_RBROLLBACK, expectedXAE))
            throw e;
    } catch (HeuristicMixedException e) {
        if (!XAFailureSpec.compatibleHeuristics(XAException.XA_HEURMIX, expectedXAE))
            throw e;
    } catch (SystemException e) {
        if (!XAFailureSpec.compatibleHeuristics(XAException.XAER_RMFAIL, expectedXAE))
            throw e;
    }
    // Validate that the correct MBeans were created to instrument the transaction and participants
    // and validate they have the correct heuristic status
    ObjStoreBrowser osb = createObjStoreBrowser(true);
    UidWrapper w = osb.findUid(txUid);
    assertNotNull(w);
    Set<UidWrapper> wrappers = validateChildBeans(osb, w.getName(), 1, expectedXAE);
    assertTrue(wrappers.size() > 0);
}
Also used : XAException(javax.transaction.xa.XAException) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) ObjStoreBrowser(com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser) Uid(com.arjuna.ats.arjuna.common.Uid) TransactionManagerImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionManagerImple) UidWrapper(com.arjuna.ats.arjuna.tools.osb.mbean.UidWrapper)

Example 12 with TransactionImple

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

the class WorkUnitTest method testWorkManager.

@Test
public void testWorkManager() throws Exception {
    DummyWork work = new DummyWork();
    Transaction tx = new TransactionImple();
    TxWorkManager.addWork(work, tx);
    try {
        TxWorkManager.addWork(new DummyWork(), tx);
        fail();
    } catch (final Throwable ex) {
    }
    assertTrue(TxWorkManager.hasWork(tx));
    assertEquals(work, TxWorkManager.getWork(tx));
    TxWorkManager.removeWork(work, tx);
    assertEquals(TxWorkManager.getWork(tx), null);
}
Also used : Transaction(javax.transaction.Transaction) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) Test(org.junit.Test)

Example 13 with TransactionImple

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

the class WorkUnitTest method testWorkSynchronization.

@Test
public void testWorkSynchronization() throws Exception {
    Transaction tx = new TransactionImple();
    Synchronization ws = new WorkSynchronization(tx);
    DummyWork work = new DummyWork();
    TxWorkManager.addWork(work, tx);
    try {
        ws.beforeCompletion();
        fail();
    } catch (final IllegalStateException ex) {
    }
    ws.afterCompletion(Status.STATUS_COMMITTED);
}
Also used : Transaction(javax.transaction.Transaction) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) WorkSynchronization(com.arjuna.ats.internal.jta.transaction.jts.jca.WorkSynchronization) Synchronization(javax.transaction.Synchronization) WorkSynchronization(com.arjuna.ats.internal.jta.transaction.jts.jca.WorkSynchronization) Test(org.junit.Test)

Example 14 with TransactionImple

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

the class SynchronizationUnitTest method test.

@Test
public void test() throws Exception {
    TransactionImple tx = new TransactionImple();
    LocalCleanupSynchronization sync = new LocalCleanupSynchronization(tx);
    assertTrue(sync.beforeCompletion());
    assertTrue(sync.afterCompletion(ActionStatus.COMMITTED));
    assertTrue(sync.get_uid().notEquals(Uid.nullUid()));
    assertTrue(sync.compareTo(new LocalCleanupSynchronization(null)) != 0);
}
Also used : TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) LocalCleanupSynchronization(com.arjuna.ats.internal.jta.resources.jts.LocalCleanupSynchronization) Test(org.junit.Test)

Example 15 with TransactionImple

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

the class TransactionImpleUnitTest method testFailure.

@Test
public void testFailure() throws Exception {
    ThreadActionData.purgeActions();
    OTSImpleManager.current().contextManager().purgeActions();
    TransactionImple tx = new TransactionImple();
    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.jts.TransactionImple) FailureXAResource(com.hp.mwtests.ts.jta.common.FailureXAResource) HeuristicMixedException(javax.transaction.HeuristicMixedException) Test(org.junit.Test)

Aggregations

TransactionImple (com.arjuna.ats.internal.jta.transaction.jts.TransactionImple)28 Test (org.junit.Test)23 DummyXA (com.hp.mwtests.ts.jta.jts.common.DummyXA)9 Uid (com.arjuna.ats.arjuna.common.Uid)7 XAResourceRecord (com.arjuna.ats.internal.jta.resources.jts.orbspecific.XAResourceRecord)7 Transaction (javax.transaction.Transaction)5 XidImple (com.arjuna.ats.jta.xa.XidImple)4 DummyRecoverableXAConnection (com.hp.mwtests.ts.jta.common.DummyRecoverableXAConnection)4 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)3 FailureXAResource (com.hp.mwtests.ts.jta.common.FailureXAResource)3 Synchronization (javax.transaction.Synchronization)3 SystemException (javax.transaction.SystemException)3 WorkSynchronization (com.arjuna.ats.internal.jta.transaction.jts.jca.WorkSynchronization)2 FailureXAResource (com.hp.mwtests.ts.jta.tools.FailureXAResource)2 RollbackException (javax.transaction.RollbackException)2 XAException (javax.transaction.xa.XAException)2 Xid (javax.transaction.xa.Xid)2 Control (org.omg.CosTransactions.Control)2 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)1 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)1