Search in sources :

Example 11 with FailureXAResource

use of com.hp.mwtests.ts.jta.common.FailureXAResource in project narayana by jbosstm.

the class ExceptionDeferrerTest method testCheckDeferredRollbackException.

@Test
public void testCheckDeferredRollbackException() throws Exception {
    ThreadActionData.purgeActions();
    TransactionImple tx = new TransactionImple(0);
    try {
        tx.enlistResource(new FailureXAResource(FailLocation.commit, FailType.rollback));
    } catch (final RollbackException ex) {
        fail();
    }
    try {
        tx.commit();
        fail();
    } catch (final RollbackException ex) {
        assertEquals(XAException.XA_HEURRB, ((XAException) ex.getSuppressed()[0]).errorCode);
    }
}
Also used : XAException(javax.transaction.xa.XAException) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) FailureXAResource(com.hp.mwtests.ts.jta.common.FailureXAResource) RollbackException(javax.transaction.RollbackException) Test(org.junit.Test)

Example 12 with FailureXAResource

use of com.hp.mwtests.ts.jta.common.FailureXAResource in project narayana by jbosstm.

the class ExceptionDeferrerTest method testCheckDeferredHeuristicRollbackSecondOfThreeFails.

@Test
public void testCheckDeferredHeuristicRollbackSecondOfThreeFails() throws Exception {
    ThreadActionData.purgeActions();
    TxControl.setXANodeName("test");
    TransactionImple tx = new TransactionImple(500);
    try {
        tx.enlistResource(new TestResource());
        tx.enlistResource(new FailureXAResource(FailLocation.commit, FailType.nota));
        tx.enlistResource(new TestResource());
    } catch (final RollbackException ex) {
        fail();
    }
    try {
        tx.commit();
        fail();
    } catch (final HeuristicMixedException ex) {
        assertEquals(XAException.XAER_NOTA, ((XAException) ex.getSuppressed()[0]).errorCode);
    }
}
Also used : XAException(javax.transaction.xa.XAException) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) FailureXAResource(com.hp.mwtests.ts.jta.common.FailureXAResource) HeuristicMixedException(javax.transaction.HeuristicMixedException) TestResource(com.hp.mwtests.ts.jta.common.TestResource) RollbackException(javax.transaction.RollbackException) Test(org.junit.Test)

Example 13 with FailureXAResource

use of com.hp.mwtests.ts.jta.common.FailureXAResource in project narayana by jbosstm.

the class XATerminatorUnitTest method testFail.

@Test
public void testFail() throws Exception {
    XATerminatorImple term = new XATerminatorImple();
    XidImple xid = new XidImple(new Uid());
    SubordinationManager.getTransactionImporter().importTransaction(xid);
    SubordinateTransaction tx = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
    tx.enlistResource(new FailureXAResource(FailLocation.commit, FailType.rollback));
    try {
        term.commit(xid, false);
        fail();
    } catch (final XAException ex) {
    }
    xid = new XidImple(new Uid());
    SubordinationManager.getTransactionImporter().importTransaction(xid);
    tx = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
    tx.enlistResource(new FailureXAResource(FailLocation.commit, FailType.heurcom));
    try {
        term.commit(xid, false);
        fail();
    } catch (final XAException ex) {
    }
    xid = new XidImple(new Uid());
    SubordinationManager.getTransactionImporter().importTransaction(xid);
    tx = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
    tx.enlistResource(new FailureXAResource(FailLocation.commit, FailType.heurcom));
    term.prepare(xid);
    try {
        term.commit(xid, false);
    } catch (final XAException ex) {
        fail();
    }
    xid = new XidImple(new Uid());
    SubordinationManager.getTransactionImporter().importTransaction(xid);
    tx = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
    tx.enlistResource(new FailureXAResource(FailLocation.commit, FailType.normal));
    try {
        term.commit(xid, false);
        fail();
    } catch (final XAException ex) {
    }
    xid = new XidImple(new Uid());
    SubordinationManager.getTransactionImporter().importTransaction(xid);
    tx = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
    tx.enlistResource(new FailureXAResource(FailLocation.rollback, FailType.rollback));
    try {
        term.rollback(xid);
    } catch (final XAException ex) {
        fail();
    }
    xid = new XidImple(new Uid());
    SubordinationManager.getTransactionImporter().importTransaction(xid);
    tx = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
    tx.enlistResource(new FailureXAResource(FailLocation.rollback, FailType.heurcom));
    term.prepare(xid);
    try {
        term.rollback(xid);
        fail();
    } catch (final XAException ex) {
    }
    xid = new XidImple(new Uid());
    SubordinationManager.getTransactionImporter().importTransaction(xid);
    tx = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
    tx.enlistResource(new FailureXAResource(FailLocation.rollback, FailType.normal));
    term.prepare(xid);
    try {
        term.rollback(xid);
        fail();
    } catch (final XAException ex) {
    }
    xid = new XidImple(new Uid());
    SubordinationManager.getTransactionImporter().importTransaction(xid);
    tx = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
    tx.enlistResource(new FailureXAResource(FailLocation.prepare_and_rollback, FailType.normal));
    try {
        term.prepare(xid);
        fail();
    } catch (final XAException ex) {
    }
    xid = new XidImple(new Uid());
    SubordinationManager.getTransactionImporter().importTransaction(xid);
    tx = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
    tx.enlistResource(new FailureXAResource(FailLocation.prepare_and_rollback, FailType.heurcom));
    try {
        term.prepare(xid);
        fail();
    } catch (final XAException ex) {
    }
    xid = new XidImple(new Uid());
    SubordinationManager.getTransactionImporter().importTransaction(xid);
    tx = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
    tx.enlistResource(new FailureXAResource(FailLocation.prepare_and_rollback, FailType.rollback));
    try {
        term.prepare(xid);
        fail();
    } 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) FailureXAResource(com.hp.mwtests.ts.jta.common.FailureXAResource) XATerminatorImple(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.XATerminatorImple) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Example 14 with FailureXAResource

use of com.hp.mwtests.ts.jta.common.FailureXAResource in project narayana by jbosstm.

the class XAResourceRecordUnitTest method testRollbackFailure.

@Test
public void testRollbackFailure() throws Exception {
    FailureXAResource fxa = new FailureXAResource(FailureXAResource.FailLocation.rollback);
    TransactionImple tx = new TransactionImple(0);
    XAResourceRecord xares = new XAResourceRecord(tx, fxa, tx.getTxId(), null);
    assertEquals(xares.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(xares.topLevelAbort(), TwoPhaseOutcome.HEURISTIC_MIXED);
    assertTrue(xares.forgetHeuristic());
}
Also used : XAResourceRecord(com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord) FailureXAResource(com.hp.mwtests.ts.jta.common.FailureXAResource) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) Test(org.junit.Test)

Example 15 with FailureXAResource

use of com.hp.mwtests.ts.jta.common.FailureXAResource 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

FailureXAResource (com.hp.mwtests.ts.jta.common.FailureXAResource)16 Test (org.junit.Test)16 TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple)12 XAException (javax.transaction.xa.XAException)9 RollbackException (javax.transaction.RollbackException)8 HeuristicMixedException (javax.transaction.HeuristicMixedException)7 XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)3 TransactionImple (com.arjuna.ats.internal.jta.transaction.jts.TransactionImple)3 TestResource (com.hp.mwtests.ts.jta.common.TestResource)3 XAResourceRecord (com.arjuna.ats.internal.jta.resources.jts.orbspecific.XAResourceRecord)2 SystemException (javax.transaction.SystemException)2 HeuristicMixed (org.omg.CosTransactions.HeuristicMixed)2 Uid (com.arjuna.ats.arjuna.common.Uid)1 SubordinateTransaction (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)1 XATerminatorImple (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.XATerminatorImple)1 XidImple (com.arjuna.ats.jta.xa.XidImple)1 DummyXA (com.hp.mwtests.ts.jta.common.DummyXA)1