Search in sources :

Example 11 with XATerminatorImple

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

the class XATerminatorImpleUnitTest method testPrepareAbort.

@Test
public void testPrepareAbort() throws Exception {
    XidImple xid = new XidImple(new Uid());
    TransactionImporter imp = SubordinationManager.getTransactionImporter();
    imp.importTransaction(xid);
    XATerminatorImple xa = new XATerminatorImple();
    assertEquals(xa.prepare(xid), XAResource.XA_RDONLY);
    try {
        xa.rollback(xid);
    } catch (final XAException ex) {
    }
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) XAException(javax.transaction.xa.XAException) TransactionImporter(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter) XATerminatorImple(com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple) Test(org.junit.Test)

Example 12 with XATerminatorImple

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

the class XATerminatorImpleUnitTest method testImportMultipleTx.

@Test
public void testImportMultipleTx() throws XAException, RollbackException, SystemException {
    Implementations.initialise();
    Implementationsx.initialise();
    XidImple xid = new XidImple(new Uid());
    TransactionImporter imp = SubordinationManager.getTransactionImporter();
    SubordinateTransaction subordinateTransaction = imp.importTransaction(xid);
    XATerminatorImple xa = new XATerminatorImple();
    XAResourceImple xar1 = new XAResourceImple(XAResource.XA_OK);
    XAResourceImple xar2 = new XAResourceImple(XAException.XAER_RMFAIL);
    subordinateTransaction.enlistResource(xar1);
    subordinateTransaction.enlistResource(xar2);
    xa.prepare(xid);
    try {
        xa.commit(xid, false);
        fail("Did not expect to pass");
    } catch (XAException xae) {
        assertTrue(xae.errorCode == XAException.XAER_RMFAIL);
    }
    Xid[] xids = xa.recover(XAResource.TMSTARTRSCAN);
    assertTrue(Arrays.binarySearch(xids, xid, new Comparator<Xid>() {

        @Override
        public int compare(Xid o1, Xid o2) {
            if (((XidImple) o1).equals(o2)) {
                return 0;
            } else {
                return -1;
            }
        }
    }) != -1);
    // Will throw a heuristic. The doRollback should be allowed but when we realise that the XAR1 is commited it shouldn't be allowed. Maybe we should also not shutdown the first XAR or maybe we need to rely on bottom up.
    xa.rollback(xid);
    assertTrue(xar2.rollbackCalled());
    xa.recover(XAResource.TMENDRSCAN);
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) TransactionImporter(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter) XATerminatorImple(com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Example 13 with XATerminatorImple

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

the class JCAServerTransactionRecoveryModuleTest method testReloadStateAcceptable.

@Test
public void testReloadStateAcceptable() throws XAException, RollbackException, SystemException {
    JCAServerTransactionRecoveryModule module = new JCAServerTransactionRecoveryModule();
    XATerminator terminator = new XATerminatorImple();
    Xid xid = new Xid() {

        @Override
        public int getFormatId() {
            return 0;
        }

        @Override
        public byte[] getGlobalTransactionId() {
            return new byte[0];
        }

        @Override
        public byte[] getBranchQualifier() {
            return new byte[0];
        }
    };
    SubordinationManager.getTransactionImporter().importTransaction(xid);
    SubordinateTransaction importedTransaction = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
    importedTransaction.enlistResource(new XAResource() {

        @Override
        public void commit(Xid xid, boolean b) throws XAException {
            commitCalled = true;
        }

        @Override
        public void end(Xid xid, int i) throws XAException {
        }

        @Override
        public void forget(Xid xid) throws XAException {
        }

        @Override
        public int getTransactionTimeout() throws XAException {
            return 0;
        }

        @Override
        public boolean isSameRM(XAResource xaResource) throws XAException {
            return false;
        }

        @Override
        public int prepare(Xid xid) throws XAException {
            return 0;
        }

        @Override
        public Xid[] recover(int i) throws XAException {
            return new Xid[0];
        }

        @Override
        public void rollback(Xid xid) throws XAException {
        }

        @Override
        public boolean setTransactionTimeout(int i) throws XAException {
            return false;
        }

        @Override
        public void start(Xid xid, int i) throws XAException {
        }
    });
    terminator.prepare(xid);
    module.periodicWorkFirstPass();
    module.periodicWorkSecondPass();
    module.periodicWorkFirstPass();
    module.periodicWorkSecondPass();
    assertFalse(commitCalled);
    terminator.commit(xid, false);
    assertTrue(commitCalled);
}
Also used : XATerminator(javax.resource.spi.XATerminator) Xid(javax.transaction.xa.Xid) XAResource(javax.transaction.xa.XAResource) XAException(javax.transaction.xa.XAException) XATerminatorImple(com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Aggregations

XATerminatorImple (com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple)13 Test (org.junit.Test)13 Uid (com.arjuna.ats.arjuna.common.Uid)12 TransactionImporter (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter)12 XidImple (com.arjuna.ats.jta.xa.XidImple)10 XAException (javax.transaction.xa.XAException)9 SubordinateTransaction (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)6 Xid (javax.transaction.xa.Xid)6 TestXAResource (com.hp.mwtests.ts.jta.jts.TestXAResource)3 RollbackException (javax.transaction.RollbackException)3 SystemException (javax.transaction.SystemException)3 XAResource (javax.transaction.xa.XAResource)2 ObjectStoreIterator (com.arjuna.ats.arjuna.objectstore.ObjectStoreIterator)1 ObjStoreBrowser (com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser)1 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule)1 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ObjectName (javax.management.ObjectName)1