Search in sources :

Example 6 with TestResource

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

the class JTAOrder method test.

@Test
public void test() throws Exception {
    XAResource theResource = new TestResource();
    FirstXAResource first = new FirstXAResource();
    LastXAResource last = new LastXAResource();
    javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
    System.out.println("Starting top-level transaction.");
    tm.begin();
    javax.transaction.Transaction theTransaction = tm.getTransaction();
    theTransaction.enlistResource(theResource);
    theTransaction.enlistResource(last);
    theTransaction.enlistResource(first);
    System.out.println("Committing transaction.");
    tm.commit();
    assertEquals(Status.STATUS_COMMITTED, theTransaction.getStatus());
}
Also used : LastXAResource(com.hp.mwtests.ts.jta.common.LastXAResource) XAResource(javax.transaction.xa.XAResource) FirstXAResource(com.hp.mwtests.ts.jta.common.FirstXAResource) FirstXAResource(com.hp.mwtests.ts.jta.common.FirstXAResource) TestResource(com.hp.mwtests.ts.jta.common.TestResource) LastXAResource(com.hp.mwtests.ts.jta.common.LastXAResource) Test(org.junit.Test)

Example 7 with TestResource

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

the class SimpleNestedTest method testEnabled.

@Test
public void testEnabled() throws Exception {
    jtaPropertyManager.getJTAEnvironmentBean().setSupportSubtransactions(true);
    javax.transaction.TransactionManager transactionManager = com.arjuna.ats.jta.TransactionManager.transactionManager();
    transactionManager.begin();
    transactionManager.begin();
    Transaction currentTrans = transactionManager.getTransaction();
    TestResource res1, res2;
    currentTrans.enlistResource(res1 = new TestResource());
    currentTrans.enlistResource(res2 = new TestResource());
    currentTrans.delistResource(res2, XAResource.TMSUCCESS);
    currentTrans.delistResource(res1, XAResource.TMSUCCESS);
    transactionManager.commit();
    transactionManager.commit();
}
Also used : Transaction(javax.transaction.Transaction) TestResource(com.hp.mwtests.ts.jta.common.TestResource) Test(org.junit.Test)

Example 8 with TestResource

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

the class SimpleTest method test.

@Test
public void test() throws Exception {
    javax.transaction.TransactionManager transactionManager = com.arjuna.ats.jta.TransactionManager.transactionManager();
    transactionManager.begin();
    Transaction currentTrans = transactionManager.getTransaction();
    TestResource res1, res2;
    currentTrans.enlistResource(res1 = new TestResource());
    currentTrans.enlistResource(res2 = new TestResource());
    currentTrans.delistResource(res2, XAResource.TMSUCCESS);
    currentTrans.delistResource(res1, XAResource.TMSUCCESS);
    transactionManager.commit();
}
Also used : Transaction(javax.transaction.Transaction) TestResource(com.hp.mwtests.ts.jta.common.TestResource) Test(org.junit.Test)

Example 9 with TestResource

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

the class RecoveryXidsUnitTest method test.

@Test
public void test() {
    TestResource tr = new TestResource();
    RecoveryXids rxids = new RecoveryXids(tr);
    Xid[] xids = new XidImple[2];
    xids[0] = new XidImple(new Uid());
    xids[1] = new XidImple(new Uid());
    RecoveryXids dup1 = new RecoveryXids(new DummyXA(false));
    RecoveryXids dup2 = new RecoveryXids(tr);
    assertFalse(rxids.equals(dup1));
    assertTrue(rxids.equals(dup2));
    rxids.nextScan(xids);
    rxids.nextScan(xids);
    xids[1] = new XidImple(new Uid());
    rxids.nextScan(xids);
    Object[] trans = rxids.toRecover();
    assertEquals(0, trans.length);
    try {
        Thread.sleep(20010);
    } catch (InterruptedException e) {
    }
    // force cleanup.
    rxids.nextScan(xids);
    trans = rxids.toRecover();
    assertEquals(2, trans.length);
    assertTrue(trans[0].equals(xids[0]) || trans[1].equals(xids[0]));
    assertTrue(trans[0].equals(xids[1]) || trans[1].equals(xids[1]));
    assertTrue(rxids.contains(xids[0]));
    assertFalse(rxids.updateIfEquivalentRM(new TestResource(), null));
    assertTrue(rxids.updateIfEquivalentRM(new TestResource(), xids));
    assertFalse(rxids.isSameRM(new TestResource()));
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) Xid(javax.transaction.xa.Xid) DummyXA(com.hp.mwtests.ts.jta.common.DummyXA) RecoveryXids(com.arjuna.ats.internal.jta.recovery.arjunacore.RecoveryXids) TestResource(com.hp.mwtests.ts.jta.common.TestResource) Test(org.junit.Test)

Example 10 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 {
    ThreadActionData.purgeActions();
    OTSImpleManager.current().contextManager().purgeActions();
    XAResourceRecord xares;
    DummyRecoverableXAConnection rc = new DummyRecoverableXAConnection();
    Object[] params = new Object[1];
    params[XAResourceRecord.XACONNECTION] = rc;
    xares = new XAResourceRecord(new TransactionImple(), new TestResource(true), new XidImple(new Uid()), params);
    try {
        xares.commit();
        fail();
    } catch (final NotPrepared ex) {
    }
    assertEquals(xares.prepare(), Vote.VoteReadOnly);
}
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.jts.orbspecific.XAResourceRecord) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) TestResource(com.hp.mwtests.ts.jta.common.TestResource) NotPrepared(org.omg.CosTransactions.NotPrepared) 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