Search in sources :

Example 21 with TransactionImple

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

the class XARecoveryModuleUnitTest method testRecover.

@Test
public void testRecover() throws Exception {
    ArrayList<String> r = new ArrayList<String>();
    TransactionImple tx = new TransactionImple();
    assertTrue(tx.enlistResource(new RecoveryXAResource()));
    SubordinateAtomicTransaction sat = new SubordinateAtomicTransaction(tx.get_uid(), tx.getTxId(), 0);
    assertEquals(sat.doPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    r.add("com.hp.mwtests.ts.jta.recovery.DummyXARecoveryResource");
    jtaPropertyManager.getJTAEnvironmentBean().setXaResourceRecoveryClassNames(r);
    XARecoveryModule xarm = new XARecoveryModule();
    for (int i = 0; i < 11; i++) {
        xarm.periodicWorkFirstPass();
        xarm.periodicWorkSecondPass();
    }
}
Also used : SubordinateAtomicTransaction(com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.SubordinateAtomicTransaction) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) ArrayList(java.util.ArrayList) RecoveryXAResource(com.hp.mwtests.ts.jta.common.RecoveryXAResource) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule) Test(org.junit.Test)

Example 22 with TransactionImple

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

the class XARecoveryModuleUnitTest method testEmptyResourceEnlistmentParams.

/**
 * Test which uses method {@link TransactionImple#enlistResource(XAResource, Object[])} could be used
 * with empty object array and still works.
 */
@Test
public void testEmptyResourceEnlistmentParams() throws Exception {
    final Uid uid = new Uid();
    final Xid xid = XidUtils.getXid(uid, true);
    SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().importTransaction(xid);
    TransactionImple subordinateTransactionImple = (TransactionImple) subordinateTransaction;
    TestXAResourceWrapper xar = new TestXAResourceWrapper("narayana", "narayana", "java:/test1");
    subordinateTransactionImple.enlistResource(xar, new Object[] {});
    int statusPrepare = subordinateTransaction.doPrepare();
    subordinateTransaction.doCommit();
    assertEquals("transaction should be prepared", TwoPhaseOutcome.PREPARE_OK, statusPrepare);
    assertEquals("XAResource can't be rolled-back", 0, xar.rollbackCount());
    assertEquals("XAResource has to be committed", 1, xar.commitCount());
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) Xid(javax.transaction.xa.Xid) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) TestXAResourceWrapper(com.hp.mwtests.ts.jta.recovery.TestXAResourceWrapper) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Example 23 with TransactionImple

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

the class WorkUnitTest method testWorkSynchronization.

@Test
public void testWorkSynchronization() throws Exception {
    Transaction tx = new TransactionImple();
    Synchronization ws = new WorkSynchronization(tx);
    DummyWork work = new DummyWork();
    TxWorkManager.addWork(work, tx);
    try {
        ws.beforeCompletion();
        fail();
    } catch (final IllegalStateException ex) {
    }
    ws.afterCompletion(Status.STATUS_COMMITTED);
}
Also used : Transaction(javax.transaction.Transaction) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) WorkSynchronization(com.arjuna.ats.internal.jta.transaction.jts.jca.WorkSynchronization) Synchronization(javax.transaction.Synchronization) WorkSynchronization(com.arjuna.ats.internal.jta.transaction.jts.jca.WorkSynchronization) Test(org.junit.Test)

Example 24 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.jts.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();
    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.jts.TransactionImple) Test(org.junit.Test)

Example 25 with TransactionImple

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

the class LastResourceRecordUnitTest method test.

@Test
public void test() throws Exception {
    TransactionImple tx = new TransactionImple();
    LastResourceRecord rec = new LastResourceRecord(tx, new DummyXA(false), tx.getTxId(), null);
    rec.commit();
    assertEquals(rec.prepare(), Vote.VoteCommit);
    assertTrue(rec.toString() != null);
    assertFalse(rec.saveRecord());
    assertTrue(rec.type() != null);
}
Also used : DummyXA(com.hp.mwtests.ts.jta.jts.common.DummyXA) LastResourceRecord(com.arjuna.ats.internal.jta.resources.jts.orbspecific.LastResourceRecord) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) Test(org.junit.Test)

Aggregations

TransactionImple (com.arjuna.ats.internal.jta.transaction.jts.TransactionImple)28 Test (org.junit.Test)23 DummyXA (com.hp.mwtests.ts.jta.jts.common.DummyXA)9 Uid (com.arjuna.ats.arjuna.common.Uid)7 XAResourceRecord (com.arjuna.ats.internal.jta.resources.jts.orbspecific.XAResourceRecord)7 Transaction (javax.transaction.Transaction)5 XidImple (com.arjuna.ats.jta.xa.XidImple)4 DummyRecoverableXAConnection (com.hp.mwtests.ts.jta.common.DummyRecoverableXAConnection)4 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)3 FailureXAResource (com.hp.mwtests.ts.jta.common.FailureXAResource)3 Synchronization (javax.transaction.Synchronization)3 SystemException (javax.transaction.SystemException)3 WorkSynchronization (com.arjuna.ats.internal.jta.transaction.jts.jca.WorkSynchronization)2 FailureXAResource (com.hp.mwtests.ts.jta.tools.FailureXAResource)2 RollbackException (javax.transaction.RollbackException)2 XAException (javax.transaction.xa.XAException)2 Xid (javax.transaction.xa.Xid)2 Control (org.omg.CosTransactions.Control)2 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)1 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)1