Search in sources :

Example 1 with DummyXA

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

the class ObjStoreBrowserTest method generateHeuristic.

private TransactionImple generateHeuristic(TransactionImple tx, FailureXAResource failureXAResource) throws Exception {
    ThreadActionData.purgeActions();
    XAResource[] resources = { new DummyXA(false), failureXAResource };
    // enlist the XA resources into the transaction
    for (XAResource resource : resources) tx.enlistResource(resource);
    try {
        tx.commit();
        fail("Expected a mixed heuristic");
    } catch (final HeuristicMixedException expected) {
    }
    return tx;
}
Also used : XAResource(javax.transaction.xa.XAResource) DummyXA(com.hp.mwtests.ts.jta.common.DummyXA) HeuristicMixedException(javax.transaction.HeuristicMixedException)

Example 2 with DummyXA

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

the class TransactionImpleUnitTest method test.

@Test
public void test() throws Exception {
    ThreadActionData.purgeActions();
    TransactionImple tx = new TransactionImple(0);
    TxImpleOverride.put(tx);
    assertEquals(tx, TransactionImple.getTransaction(tx.get_uid()));
    DummyXA res = new DummyXA(false);
    tx.enlistResource(res);
    tx.delistResource(res, XAResource.TMSUSPEND);
    assertTrue(tx.isAlive());
    tx.commit();
    assertTrue(tx.getRemainingTimeoutMills() != -1);
    assertTrue(tx.getTimeout() != -1);
    assertEquals(tx.getSynchronizations().size(), 0);
    assertEquals(tx.getResources().size(), 1);
    TxImpleOverride.remove(tx);
    assertTrue(TransactionImple.getTransactions() != null);
    assertEquals(TransactionImple.getTransaction(tx.get_uid()), null);
    try {
        tx = (TransactionImple) TransactionManager.transactionManager(new InitialContext());
        fail();
    } catch (final Throwable ex) {
    }
    assertNull(TransactionImple.getTransaction(null));
}
Also used : DummyXA(com.hp.mwtests.ts.jta.common.DummyXA) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 3 with DummyXA

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

the class TransactionImpleUnitTest method testDelist.

@Test
public void testDelist() throws Exception {
    ThreadActionData.purgeActions();
    TransactionImple tx = new TransactionImple(0);
    try {
        tx.delistResource(null, XAResource.TMSUCCESS);
        fail();
    } catch (final SystemException ex) {
    }
    DummyXA xares = new DummyXA(false);
    try {
        assertFalse(tx.delistResource(xares, XAResource.TMSUCCESS));
    } catch (final Throwable ex) {
        fail();
    }
    tx.enlistResource(xares);
    assertTrue(tx.delistResource(xares, XAResource.TMSUCCESS));
    tx.commit();
    try {
        tx.delistResource(xares, XAResource.TMSUCCESS);
        fail();
    } catch (final IllegalStateException ex) {
    }
}
Also used : DummyXA(com.hp.mwtests.ts.jta.common.DummyXA) SystemException(javax.transaction.SystemException) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) Test(org.junit.Test)

Example 4 with DummyXA

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

the class XAResourceRecordUnitTest method testPackUnpack.

@Test
public void testPackUnpack() throws Exception {
    XAResourceRecord xares;
    DummyRecoverableXAConnection rc = new DummyRecoverableXAConnection();
    Object[] params = new Object[1];
    params[XAResourceRecord.XACONNECTION] = rc;
    xares = new XAResourceRecord(new TransactionImple(0), new DummyXA(false), new XidImple(new Uid()), params);
    OutputObjectState os = new OutputObjectState();
    assertTrue(xares.save_state(os, ObjectType.ANDPERSISTENT));
    InputObjectState is = new InputObjectState(os);
    assertTrue(xares.restore_state(is, ObjectType.ANDPERSISTENT));
    xares = new XAResourceRecord(new TransactionImple(0), new DummyXA(false), new XidImple(new Uid()), null);
    os = new OutputObjectState();
    assertTrue(xares.save_state(os, ObjectType.ANDPERSISTENT));
    is = new InputObjectState(os);
    assertTrue(xares.restore_state(is, ObjectType.ANDPERSISTENT));
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) DummyRecoverableXAConnection(com.hp.mwtests.ts.jta.common.DummyRecoverableXAConnection) Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) 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) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) Test(org.junit.Test)

Example 5 with DummyXA

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

Aggregations

DummyXA (com.hp.mwtests.ts.jta.common.DummyXA)15 Test (org.junit.Test)13 TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple)9 Uid (com.arjuna.ats.arjuna.common.Uid)6 XidImple (com.arjuna.ats.jta.xa.XidImple)5 XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)4 Xid (javax.transaction.xa.Xid)3 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)2 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)2 DummyRecoverableXAConnection (com.hp.mwtests.ts.jta.common.DummyRecoverableXAConnection)2 HeuristicMixedException (javax.transaction.HeuristicMixedException)2 SystemException (javax.transaction.SystemException)2 XAResource (javax.transaction.xa.XAResource)2 RecoveryXids (com.arjuna.ats.internal.jta.recovery.arjunacore.RecoveryXids)1 XARecoveryResourceImple (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryResourceImple)1 XAOnePhaseResource (com.arjuna.ats.internal.jta.resources.arjunacore.XAOnePhaseResource)1 FailureXAResource (com.hp.mwtests.ts.jta.common.FailureXAResource)1 TestResource (com.hp.mwtests.ts.jta.common.TestResource)1 FailureXAResource (com.hp.mwtests.ts.jta.tools.FailureXAResource)1 Method (java.lang.reflect.Method)1