Search in sources :

Example 81 with XidImple

use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.

the class OnePhaseUnitTest method testPackUnpack.

@Test
public void testPackUnpack() throws Exception {
    DummyXA res = new DummyXA(false);
    XidImple xid = new XidImple(new Uid());
    XAOnePhaseResource xares = new XAOnePhaseResource(res, xid, null);
    OutputObjectState os = new OutputObjectState();
    xares.pack(os);
    InputObjectState is = new InputObjectState(os);
    xares.unpack(is);
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) DummyXA(com.hp.mwtests.ts.jta.common.DummyXA) XAOnePhaseResource(com.arjuna.ats.internal.jta.resources.arjunacore.XAOnePhaseResource) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) Test(org.junit.Test)

Example 82 with XidImple

use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.

the class RecoveryShutdownTest method test.

/**
 * test that the call sequence
 *
 * XARecoveryModule#getNewXAResource()
 * RecoveryManager#terminate();
 * XARecoveryModule#removeXAResourceRecoveryHelper
 *
 * does not hang
 *
 * @throws InterruptedException if the test is interrupted
 */
@Test
public void test() throws InterruptedException {
    recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(1);
    RecoveryManager manager = RecoveryManager.manager(RecoveryManager.DIRECT_MANAGEMENT);
    XARecoveryModule xarm = new XARecoveryModule();
    final SimpleResource testXAResource = new SimpleResource() {

        @Override
        public Xid[] recover(int i) throws XAException {
            return new Xid[] { new Xid() {

                @Override
                public int getFormatId() {
                    return 0;
                }

                @Override
                public byte[] getGlobalTransactionId() {
                    return new byte[0];
                }

                @Override
                public byte[] getBranchQualifier() {
                    return new byte[0];
                }
            } };
        }
    };
    final XAResourceRecoveryHelper xaResourceRecoveryHelper = new XAResourceRecoveryHelper() {

        @Override
        public boolean initialise(String p) throws Exception {
            return true;
        }

        @Override
        public XAResource[] getXAResources() throws Exception {
            return new XAResource[] { testXAResource };
        }
    };
    xarm.addXAResourceRecoveryHelper(xaResourceRecoveryHelper);
    manager.removeAllModules(false);
    manager.addModule(xarm);
    manager.scan();
    manager.terminate();
    xarm.getNewXAResource(new XAResourceRecord(null, null, new XidImple(), null));
    final boolean[] removedHelper = { false };
    Runnable r = () -> {
        // the next call will hang unless JBTM-2837 is fixed
        xarm.removeXAResourceRecoveryHelper(xaResourceRecoveryHelper);
        removedHelper[0] = true;
    };
    Thread t = new Thread(r);
    t.start();
    Thread.sleep(100);
    assertTrue("removal of an XAResourceRecoveryHelper hung", removedHelper[0]);
}
Also used : RecoveryManager(com.arjuna.ats.arjuna.recovery.RecoveryManager) XidImple(com.arjuna.ats.jta.xa.XidImple) Xid(javax.transaction.xa.Xid) XAResource(javax.transaction.xa.XAResource) XAResourceRecord(com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Example 83 with XidImple

use of com.arjuna.ats.jta.xa.XidImple 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 84 with XidImple

use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.

the class xidcheck method testPackUnpack.

@Test
public void testPackUnpack() throws Exception {
    XidImple xid1 = new XidImple(new Uid());
    OutputObjectState os = new OutputObjectState();
    assertTrue(xid1.packInto(os));
    InputObjectState is = new InputObjectState(os);
    XidImple xid2 = new XidImple();
    assertTrue(xid2.unpackFrom(is));
    assertTrue(xid1.equals(xid2));
    os = new OutputObjectState();
    XidImple.pack(os, xid1);
    is = new InputObjectState(os);
    xid2 = (XidImple) XidImple.unpack(is);
    assertTrue(xid1.equals(xid2));
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) Test(org.junit.Test)

Example 85 with XidImple

use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.

the class xidcheck method testBasic.

@Test
public void testBasic() {
    XidImple xid1 = new XidImple();
    AtomicAction A = new AtomicAction();
    assertEquals(xid1.getFormatId(), -1);
    xid1 = new XidImple(A);
    XidImple xid2 = new XidImple(new Uid());
    assertFalse(xid1.isSameTransaction(xid2));
    XidImple xid3 = new XidImple(xid1);
    assertTrue(xid3.isSameTransaction(xid1));
    assertTrue(xid1.getFormatId() != -1);
    assertTrue(xid1.getBranchQualifier().length > 0);
    assertTrue(xid1.getGlobalTransactionId().length > 0);
    assertEquals(xid1.getTransactionUid(), A.get_uid());
    assertTrue(XATxConverter.getNodeName(xid1.getXID()).equals(TxControl.getXANodeName()));
    assertTrue(xid1.getXID() != null);
    assertTrue(xid1.equals(xid3));
    XID x = new XID();
    assertFalse(xid1.equals(x));
    xid1 = new XidImple(x);
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) Uid(com.arjuna.ats.arjuna.common.Uid) XID(com.arjuna.ats.internal.jta.xa.XID) Test(org.junit.Test)

Aggregations

XidImple (com.arjuna.ats.jta.xa.XidImple)90 Uid (com.arjuna.ats.arjuna.common.Uid)71 Test (org.junit.Test)71 Xid (javax.transaction.xa.Xid)35 XAException (javax.transaction.xa.XAException)28 SubordinateTransaction (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)27 Transaction (javax.transaction.Transaction)16 XATerminator (javax.resource.spi.XATerminator)15 TransactionImporter (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter)12 XATerminatorImple (com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple)10 IOException (java.io.IOException)10 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)9 XAOnePhaseResource (com.arjuna.ats.internal.jta.resources.arjunacore.XAOnePhaseResource)9 XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)9 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)8 SampleOnePhaseResource (com.hp.mwtests.ts.jta.common.SampleOnePhaseResource)8 RollbackException (javax.transaction.RollbackException)8 SystemException (javax.transaction.SystemException)8 XAResource (javax.transaction.xa.XAResource)8 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)7