Search in sources :

Example 76 with XidImple

use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.

the class XATerminatorUnitTest method testCommitMid.

@Test
public void testCommitMid() throws Exception {
    TransactionManagerImple tm = new TransactionManagerImple();
    RecordTypeManager.manager().add(new RecordTypeMap() {

        @SuppressWarnings("unchecked")
        public Class getRecordClass() {
            return XAResourceRecord.class;
        }

        public int getType() {
            return RecordType.JTA_RECORD;
        }
    });
    XATerminatorImple xaTerminator = new XATerminatorImple();
    XidImple xid = new XidImple(new Uid());
    XAResourceImple toCommit = new XAResourceImple(XAResource.XA_OK, XAResource.XA_OK);
    {
        SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().importTransaction(xid);
        tm.resume(subordinateTransaction);
        subordinateTransaction.enlistResource(new XAResourceImple(XAResource.XA_RDONLY, XAResource.XA_OK));
        subordinateTransaction.enlistResource(toCommit);
        Transaction suspend = tm.suspend();
    }
    {
        SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
        tm.resume(subordinateTransaction);
        subordinateTransaction.doPrepare();
        Transaction suspend = tm.suspend();
    }
    XARecoveryModule xaRecoveryModule = new XARecoveryModule();
    xaRecoveryModule.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {

        @Override
        public boolean initialise(String p) throws Exception {
            return false;
        }

        @Override
        public XAResource[] getXAResources() throws Exception {
            return new XAResource[] { toCommit };
        }
    });
    RecoveryManager.manager().addModule(xaRecoveryModule);
    xaTerminator.doRecover(null, null);
    {
        SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
        tm.resume(subordinateTransaction);
        subordinateTransaction.doCommit();
        tm.suspend();
    }
    RecoveryManager.manager().removeModule(xaRecoveryModule, false);
    assertTrue(toCommit.wasCommitted());
    SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) UnexpectedConditionException(com.arjuna.ats.jta.exceptions.UnexpectedConditionException) RollbackException(javax.transaction.RollbackException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException) Uid(com.arjuna.ats.arjuna.common.Uid) TransactionManagerImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple) RecordTypeMap(com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Transaction(javax.transaction.Transaction) XATerminatorImple(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.XATerminatorImple) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Example 77 with XidImple

use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.

the class ForgetTest method testCommitHeuristic.

@Test
public void testCommitHeuristic() {
    SampleOnePhaseResource res = new SampleOnePhaseResource(SampleOnePhaseResource.ErrorType.heurcom);
    XidImple xid = new XidImple(new Uid());
    XAOnePhaseResource xares = new XAOnePhaseResource(res, xid, null);
    assertEquals(xares.commit(), TwoPhaseOutcome.FINISH_OK);
    assertTrue(res.forgetCalled());
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) XAOnePhaseResource(com.arjuna.ats.internal.jta.resources.arjunacore.XAOnePhaseResource) SampleOnePhaseResource(com.hp.mwtests.ts.jta.common.SampleOnePhaseResource) Test(org.junit.Test)

Example 78 with XidImple

use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.

the class UtilsUnitTest method testXAHelper.

@Test
public void testXAHelper() throws Exception {
    assertTrue(XAHelper.printXAErrorCode(null) != null);
    XAException ex = new XAException(XAException.XA_HEURCOM);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_HEURCOM");
    ex = new XAException(XAException.XA_HEURHAZ);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_HEURHAZ");
    ex = new XAException(XAException.XA_HEURMIX);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_HEURMIX");
    ex = new XAException(XAException.XA_HEURRB);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_HEURRB");
    ex = new XAException(XAException.XA_NOMIGRATE);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_NOMIGRATE");
    ex = new XAException(XAException.XA_RBCOMMFAIL);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_RBCOMMFAIL");
    ex = new XAException(XAException.XA_RBDEADLOCK);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_RBDEADLOCK");
    ex = new XAException(XAException.XA_RBINTEGRITY);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_RBINTEGRITY");
    ex = new XAException(XAException.XA_RBOTHER);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_RBOTHER");
    ex = new XAException(XAException.XA_RBPROTO);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_RBPROTO");
    ex = new XAException(XAException.XA_RBROLLBACK);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_RBROLLBACK");
    ex = new XAException(XAException.XA_RBTIMEOUT);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_RBTIMEOUT");
    ex = new XAException(XAException.XA_RBTRANSIENT);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_RBTRANSIENT");
    ex = new XAException(XAException.XA_RDONLY);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_RDONLY");
    ex = new XAException(XAException.XA_RETRY);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_RETRY");
    ex = new XAException(XAException.XAER_RMERR);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XAER_RMERR");
    ex = new XAException(XAException.XAER_ASYNC);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XAER_ASYNC");
    ex = new XAException(XAException.XAER_DUPID);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XAER_DUPID");
    ex = new XAException(XAException.XAER_INVAL);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XAER_INVAL");
    ex = new XAException(XAException.XAER_NOTA);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XAER_NOTA");
    ex = new XAException(XAException.XAER_OUTSIDE);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XAER_OUTSIDE");
    ex = new XAException(XAException.XAER_PROTO);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XAER_PROTO");
    ex = new XAException(XAException.XAER_RMFAIL);
    assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XAER_RMFAIL");
    assertTrue(XAHelper.printXAErrorCode(new XAException(-1)) != null);
    XidImple xid1 = new XidImple(new Uid());
    XidImple xid2 = new XidImple(new Uid());
    XidImple xid3 = new XidImple(xid1);
    assertFalse(XAHelper.sameXID(xid1, xid2));
    assertTrue(XAHelper.sameXID(xid1, xid3));
    assertTrue(XAHelper.sameTransaction(xid1, xid1));
    assertTrue(XAHelper.sameTransaction(xid1, xid3));
    assertTrue(XAHelper.xidToString(xid1) != null);
    XID x = new XID();
    x.bqual_length = 1;
    x.gtrid_length = 1;
    x.data = new byte[] { '1', '2' };
    assertTrue(x.toString() != null);
    XAHelper.xidToString(new DummyXid());
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) XID(com.arjuna.ats.internal.jta.xa.XID) XAException(javax.transaction.xa.XAException) Test(org.junit.Test)

Example 79 with XidImple

use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.

the class OnePhaseUnitTest method testCommitHeuristic.

@Test
public void testCommitHeuristic() {
    SampleOnePhaseResource res = new SampleOnePhaseResource(ErrorType.heurcom);
    XidImple xid = new XidImple(new Uid());
    XAOnePhaseResource xares = new XAOnePhaseResource(res, xid, null);
    assertEquals(xares.commit(), TwoPhaseOutcome.FINISH_OK);
    assertTrue(res.forgetCalled());
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) XAOnePhaseResource(com.arjuna.ats.internal.jta.resources.arjunacore.XAOnePhaseResource) SampleOnePhaseResource(com.hp.mwtests.ts.jta.common.SampleOnePhaseResource) Test(org.junit.Test)

Example 80 with XidImple

use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.

the class OnePhaseUnitTest method testRollbackHeuristic.

@Test
public void testRollbackHeuristic() {
    SampleOnePhaseResource res = new SampleOnePhaseResource(ErrorType.heurrb);
    XidImple xid = new XidImple(new Uid());
    XAOnePhaseResource xares = new XAOnePhaseResource(res, xid, null);
    assertEquals(xares.commit(), TwoPhaseOutcome.ONE_PHASE_ERROR);
    assertTrue(res.forgetCalled());
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) XAOnePhaseResource(com.arjuna.ats.internal.jta.resources.arjunacore.XAOnePhaseResource) SampleOnePhaseResource(com.hp.mwtests.ts.jta.common.SampleOnePhaseResource) Test(org.junit.Test)

Aggregations

XidImple (com.arjuna.ats.jta.xa.XidImple)90 Uid (com.arjuna.ats.arjuna.common.Uid)71 Test (org.junit.Test)71 Xid (javax.transaction.xa.Xid)35 XAException (javax.transaction.xa.XAException)28 SubordinateTransaction (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)27 Transaction (javax.transaction.Transaction)16 XATerminator (javax.resource.spi.XATerminator)15 TransactionImporter (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter)12 XATerminatorImple (com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple)10 IOException (java.io.IOException)10 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)9 XAOnePhaseResource (com.arjuna.ats.internal.jta.resources.arjunacore.XAOnePhaseResource)9 XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)9 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)8 SampleOnePhaseResource (com.hp.mwtests.ts.jta.common.SampleOnePhaseResource)8 RollbackException (javax.transaction.RollbackException)8 SystemException (javax.transaction.SystemException)8 XAResource (javax.transaction.xa.XAResource)8 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)7