Search in sources :

Example 1 with TestResource

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

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

the class XAResourceRecordUnitTest method testReadonly.

@Test
public void testReadonly() throws Exception {
    XAResourceRecord xares;
    DummyRecoverableXAConnection rc = new DummyRecoverableXAConnection();
    Object[] params = new Object[1];
    params[XAResourceRecord.XACONNECTION] = rc;
    xares = new XAResourceRecord(new TransactionImple(0), new TestResource(true), new XidImple(new Uid()), params);
    assertEquals(xares.topLevelCommit(), TwoPhaseOutcome.NOT_PREPARED);
    assertEquals(xares.topLevelPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) DummyRecoverableXAConnection(com.hp.mwtests.ts.jta.common.DummyRecoverableXAConnection) Uid(com.arjuna.ats.arjuna.common.Uid) XAResourceRecord(com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) TestResource(com.hp.mwtests.ts.jta.common.TestResource) Test(org.junit.Test)

Example 3 with TestResource

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

Example 4 with TestResource

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

the class ExceptionDeferrerTest method testCheckDeferredHeuristicRollbackFirstResourceFails.

@Test
public void testCheckDeferredHeuristicRollbackFirstResourceFails() throws Exception {
    ThreadActionData.purgeActions();
    TxControl.setXANodeName("test");
    TransactionImple tx = new TransactionImple(500);
    try {
        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 5 with TestResource

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

Aggregations

TestResource (com.hp.mwtests.ts.jta.common.TestResource)10 Test (org.junit.Test)10 TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple)5 Uid (com.arjuna.ats.arjuna.common.Uid)3 XidImple (com.arjuna.ats.jta.xa.XidImple)3 FailureXAResource (com.hp.mwtests.ts.jta.common.FailureXAResource)3 HeuristicMixedException (javax.transaction.HeuristicMixedException)3 RollbackException (javax.transaction.RollbackException)3 XAException (javax.transaction.xa.XAException)3 DummyRecoverableXAConnection (com.hp.mwtests.ts.jta.common.DummyRecoverableXAConnection)2 Transaction (javax.transaction.Transaction)2 RecoveryXids (com.arjuna.ats.internal.jta.recovery.arjunacore.RecoveryXids)1 XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)1 XAResourceRecord (com.arjuna.ats.internal.jta.resources.jts.orbspecific.XAResourceRecord)1 UserTransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple)1 TransactionImple (com.arjuna.ats.internal.jta.transaction.jts.TransactionImple)1 DummyXA (com.hp.mwtests.ts.jta.common.DummyXA)1 FirstXAResource (com.hp.mwtests.ts.jta.common.FirstXAResource)1 LastXAResource (com.hp.mwtests.ts.jta.common.LastXAResource)1 XAResource (javax.transaction.xa.XAResource)1