Search in sources :

Example 41 with SubordinateTransaction

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

the class XARecoveryModuleUnitTest method testEmptyResourceEnlistmentParams.

/**
 * Test which uses method {@link TransactionImple#enlistResource(XAResource, Object[])} could be used
 * with empty object array and still works.
 */
@Test
public void testEmptyResourceEnlistmentParams() throws Exception {
    final Uid uid = new Uid();
    final Xid xid = XidUtils.getXid(uid, true);
    SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().importTransaction(xid);
    TransactionImple subordinateTransactionImple = (TransactionImple) subordinateTransaction;
    TestXAResourceWrapper xar = new TestXAResourceWrapper("narayana", "narayana", "java:/test1");
    subordinateTransactionImple.enlistResource(xar, new Object[] {});
    int statusPrepare = subordinateTransaction.doPrepare();
    subordinateTransaction.doCommit();
    assertEquals("transaction should be prepared", TwoPhaseOutcome.PREPARE_OK, statusPrepare);
    assertEquals("XAResource can't be rolled-back", 0, xar.rollbackCount());
    assertEquals("XAResource has to be committed", 1, xar.commitCount());
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) Xid(javax.transaction.xa.Xid) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) TestXAResourceWrapper(com.hp.mwtests.ts.jta.recovery.TestXAResourceWrapper) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Example 42 with SubordinateTransaction

use of com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction 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

SubordinateTransaction (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)42 Test (org.junit.Test)35 XAException (javax.transaction.xa.XAException)18 Uid (com.arjuna.ats.arjuna.common.Uid)16 Xid (javax.transaction.xa.Xid)13 XidImple (com.arjuna.ats.jta.xa.XidImple)12 TransactionImporter (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter)7 XATerminatorImple (com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple)6 RollbackException (javax.transaction.RollbackException)6 SystemException (javax.transaction.SystemException)6 XAResource (javax.transaction.xa.XAResource)6 XATerminatorImple (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.XATerminatorImple)4 ArrayList (java.util.ArrayList)4 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)3 SubordinateXidImple (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateXidImple)3 UnexpectedConditionException (com.arjuna.ats.jta.exceptions.UnexpectedConditionException)3 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)3 TestXAResource (com.hp.mwtests.ts.jta.jts.TestXAResource)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 HeuristicMixedException (javax.transaction.HeuristicMixedException)3