Search in sources :

Example 6 with TransactionImple

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

the class AsyncCommit method test.

@Test
public void test() throws Exception {
    UserTransactionImple ut = new UserTransactionImple();
    ut.begin();
    TransactionImple current = TransactionImple.getTransaction();
    TestResource res1, res2;
    current.enlistResource(res1 = new TestResource());
    current.enlistResource(res2 = new TestResource());
    current.delistResource(res2, XAResource.TMSUCCESS);
    current.delistResource(res1, XAResource.TMSUCCESS);
    Future<Void> commitAsync = ut.commitAsync();
    commitAsync.get();
}
Also used : UserTransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) UserTransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple) TestResource(com.hp.mwtests.ts.jta.common.TestResource) Test(org.junit.Test)

Example 7 with TransactionImple

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

the class WorkUnitTest method testWorkManager.

@Test
public void testWorkManager() throws Exception {
    DummyWork work = new DummyWork();
    Transaction tx = new TransactionImple(0);
    TxWorkManager.addWork(work, tx);
    try {
        TxWorkManager.addWork(new DummyWork(), tx);
        fail();
    } catch (final Throwable ex) {
    }
    assertTrue(TxWorkManager.hasWork(tx));
    assertEquals(work, TxWorkManager.getWork(tx));
    TxWorkManager.removeWork(work, tx);
    assertEquals(TxWorkManager.getWork(tx), null);
}
Also used : Transaction(javax.transaction.Transaction) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) Test(org.junit.Test)

Example 8 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple 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 9 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple 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 10 with TransactionImple

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

Aggregations

TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple)32 Test (org.junit.Test)30 FailureXAResource (com.hp.mwtests.ts.jta.common.FailureXAResource)12 XAException (javax.transaction.xa.XAException)11 RollbackException (javax.transaction.RollbackException)10 DummyXA (com.hp.mwtests.ts.jta.common.DummyXA)9 Uid (com.arjuna.ats.arjuna.common.Uid)7 XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)7 HeuristicMixedException (javax.transaction.HeuristicMixedException)6 TestResource (com.hp.mwtests.ts.jta.common.TestResource)5 XAResource (javax.transaction.xa.XAResource)5 Xid (javax.transaction.xa.Xid)5 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)4 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)4 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)4 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)4 SystemException (javax.transaction.SystemException)4 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)3 CommitMarkableResourceRecordRecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule)3 XidImple (com.arjuna.ats.jta.xa.XidImple)3