Search in sources :

Example 6 with XATerminatorImple

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

the class XATerminatorUnitTest method testInvalid.

@Test
public void testInvalid() throws Exception {
    XATerminatorImple term = new XATerminatorImple();
    XidImple xid = new XidImple(new Uid());
    try {
        SubordinationManager.getTransactionImporter().importTransaction(null);
        fail();
    } catch (final IllegalArgumentException ex) {
    }
    try {
        SubordinationManager.getTransactionImporter().recoverTransaction(null);
        fail();
    } catch (final IllegalArgumentException ex) {
    }
    try {
        SubordinationManager.getTransactionImporter().getImportedTransaction(null);
        fail();
    } catch (final IllegalArgumentException ex) {
    }
    try {
        SubordinationManager.getTransactionImporter().removeImportedTransaction(null);
        fail();
    } catch (final IllegalArgumentException ex) {
    }
    Uid uid = new Uid();
    try {
        Object obj = SubordinationManager.getTransactionImporter().recoverTransaction(uid);
        fail();
    } catch (IllegalArgumentException ex) {
    }
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) XATerminatorImple(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.XATerminatorImple) Test(org.junit.Test)

Example 7 with XATerminatorImple

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

Aggregations

Uid (com.arjuna.ats.arjuna.common.Uid)7 XATerminatorImple (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.XATerminatorImple)7 XidImple (com.arjuna.ats.jta.xa.XidImple)7 Test (org.junit.Test)7 XAException (javax.transaction.xa.XAException)6 SubordinateTransaction (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)4 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)3 UnexpectedConditionException (com.arjuna.ats.jta.exceptions.UnexpectedConditionException)3 TransactionImporter (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter)2 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)2 FailureXAResource (com.hp.mwtests.ts.jta.common.FailureXAResource)2 RollbackException (javax.transaction.RollbackException)2 SystemException (javax.transaction.SystemException)2 Xid (javax.transaction.xa.Xid)2 RecordTypeMap (com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap)1 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)1 XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)1 TransactionManagerImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple)1 Transaction (javax.transaction.Transaction)1 XAResource (javax.transaction.xa.XAResource)1