Search in sources :

Example 1 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();
    TransactionImple tx = new TransactionImple(0);
    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.arjunacore.TransactionImple) FailureXAResource(com.hp.mwtests.ts.jta.common.FailureXAResource) HeuristicMixedException(javax.transaction.HeuristicMixedException) Test(org.junit.Test)

Example 2 with FailureXAResource

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

the class XAResourceRecordUnitTest method testValid1PC.

@Test
public void testValid1PC() throws Exception {
    TransactionImple tx = new TransactionImple(0);
    DummyXA res = new DummyXA(false);
    XAResourceRecord xares = new XAResourceRecord(tx, res, tx.getTxId(), null);
    assertEquals(xares.topLevelOnePhaseCommit(), TwoPhaseOutcome.FINISH_OK);
    xares = new XAResourceRecord(tx, new FailureXAResource(FailLocation.end, FailType.normal), tx.getTxId(), null);
    assertEquals(xares.topLevelOnePhaseCommit(), TwoPhaseOutcome.ONE_PHASE_ERROR);
    xares = new XAResourceRecord(tx, new FailureXAResource(FailLocation.end, FailType.timeout), tx.getTxId(), null);
    assertEquals(xares.topLevelOnePhaseCommit(), TwoPhaseOutcome.ONE_PHASE_ERROR);
    xares = new XAResourceRecord(tx, new FailureXAResource(FailLocation.end, FailType.XA_RBCOMMFAIL), tx.getTxId(), null);
    assertEquals(xares.topLevelOnePhaseCommit(), TwoPhaseOutcome.ONE_PHASE_ERROR);
    xares = new XAResourceRecord(tx, new FailureXAResource(FailLocation.commit, FailType.heurcom), tx.getTxId(), null);
    assertEquals(xares.topLevelOnePhaseCommit(), TwoPhaseOutcome.FINISH_OK);
    xares = new XAResourceRecord(tx, new FailureXAResource(FailLocation.commit, FailType.timeout), tx.getTxId(), null);
    assertEquals(xares.topLevelOnePhaseCommit(), TwoPhaseOutcome.ONE_PHASE_ERROR);
    xares = new XAResourceRecord(tx, new FailureXAResource(FailLocation.commit, FailType.nota), tx.getTxId(), null);
    assertEquals(xares.topLevelOnePhaseCommit(), TwoPhaseOutcome.HEURISTIC_HAZARD);
    xares = new XAResourceRecord(tx, new FailureXAResource(FailLocation.commit, FailType.inval), tx.getTxId(), null);
    assertEquals(xares.topLevelOnePhaseCommit(), TwoPhaseOutcome.HEURISTIC_HAZARD);
    xares = new XAResourceRecord(tx, new FailureXAResource(FailLocation.commit, FailType.proto), tx.getTxId(), null);
    assertEquals(xares.topLevelOnePhaseCommit(), TwoPhaseOutcome.ONE_PHASE_ERROR);
    xares = new XAResourceRecord(tx, new FailureXAResource(FailLocation.commit, FailType.rmfail), tx.getTxId(), null);
    assertEquals(xares.topLevelOnePhaseCommit(), TwoPhaseOutcome.HEURISTIC_HAZARD);
}
Also used : DummyXA(com.hp.mwtests.ts.jta.common.DummyXA) XAResourceRecord(com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) FailureXAResource(com.hp.mwtests.ts.jta.common.FailureXAResource) Test(org.junit.Test)

Example 3 with FailureXAResource

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

the class XAResourceRecordUnitTest method testCommitFailure.

@Test
public void testCommitFailure() throws Exception {
    FailureXAResource fxa = new FailureXAResource(FailureXAResource.FailLocation.commit);
    TransactionImple tx = new TransactionImple(0);
    XAResourceRecord xares = new XAResourceRecord(tx, fxa, tx.getTxId(), null);
    assertEquals(xares.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(xares.topLevelCommit(), 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 4 with FailureXAResource

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

the class ExceptionDeferrerTest method testCheckDeferredHeuristicException.

@Test
public void testCheckDeferredHeuristicException() throws Exception {
    ThreadActionData.purgeActions();
    TransactionImple tx = new TransactionImple(0);
    try {
        tx.enlistResource(new FailureXAResource(FailLocation.commit, FailType.normal));
    } catch (final RollbackException ex) {
        fail();
    }
    try {
        tx.commit();
        fail();
    } catch (final HeuristicMixedException ex) {
        assertEquals(XAException.XA_HEURMIX, ((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) RollbackException(javax.transaction.RollbackException) Test(org.junit.Test)

Example 5 with FailureXAResource

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

the class ExceptionDeferrerTest method testCheckDeferredHeuristicRollbackSecondResourceFails.

@Test
public void testCheckDeferredHeuristicRollbackSecondResourceFails() 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));
    } 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)

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