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);
}
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]);
}
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()));
}
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));
}
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);
}
Aggregations