use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.
the class SubordinateTxUnitTest method testAtomicTransaction.
@Test
public void testAtomicTransaction() throws Exception {
XidImple xid = new XidImple(new Uid());
SubordinateAtomicTransaction saa1 = new SubordinateAtomicTransaction(new Uid());
SubordinateAtomicTransaction saa2 = new SubordinateAtomicTransaction(new Uid(), xid, 0);
assertEquals(saa2.getXid(), xid);
try {
saa2.end(true);
fail();
} catch (final WrongTransaction ex) {
}
try {
saa2.abort();
fail();
} catch (final WrongTransaction ex) {
}
DummySubordinateAtomicTransaction dsat = new DummySubordinateAtomicTransaction();
assertFalse(dsat.checkForCurrent());
}
use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.
the class TransactionImporterUnitTest method testDifferentInstanceFromRecovery.
@Test
public void testDifferentInstanceFromRecovery() throws XAException, RollbackException, SystemException, HeuristicRollbackException, HeuristicMixedException, HeuristicCommitException, NoSuchFieldException, IllegalAccessException {
Uid uid = new Uid();
XidImple xid = new XidImple(uid);
SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().importTransaction(xid);
// This is required because it JTS records are stored with a dynamic _savingUid
// Normally they are recovered using XATerminator but for this test I would like to stick to testing
// transaction importer
Field field = TransactionImple.class.getDeclaredField("_theTransaction");
field.setAccessible(true);
Object o = field.get(subordinateTransaction);
field = AtomicTransaction.class.getDeclaredField("_theAction");
field.setAccessible(true);
o = field.get(o);
field = ControlWrapper.class.getDeclaredField("_controlImpl");
field.setAccessible(true);
o = field.get(o);
field = ControlImple.class.getDeclaredField("_transactionHandle");
field.setAccessible(true);
o = field.get(o);
field = ServerTransaction.class.getDeclaredField("_savingUid");
field.setAccessible(true);
Uid subordinateTransactionUid = (Uid) field.get(o);
Xid subordinateTransactionXid = subordinateTransaction.baseXid();
SubordinateTransaction importedTransaction = SubordinationManager.getTransactionImporter().getImportedTransaction(subordinateTransactionXid);
assertTrue(subordinateTransaction == importedTransaction);
subordinateTransaction.enlistResource(new XAResource() {
@Override
public void commit(Xid xid, boolean b) throws XAException {
}
@Override
public void end(Xid xid, int i) throws XAException {
}
@Override
public void forget(Xid xid) throws XAException {
}
@Override
public int getTransactionTimeout() throws XAException {
return 0;
}
@Override
public boolean isSameRM(XAResource xaResource) throws XAException {
return false;
}
@Override
public int prepare(Xid xid) throws XAException {
return 0;
}
@Override
public Xid[] recover(int i) throws XAException {
return new Xid[0];
}
@Override
public void rollback(Xid xid) throws XAException {
}
@Override
public boolean setTransactionTimeout(int i) throws XAException {
return false;
}
@Override
public void start(Xid xid, int i) throws XAException {
}
});
subordinateTransaction.doPrepare();
Implementationsx.initialise();
SubordinateTransaction subordinateTransaction1 = SubordinationManager.getTransactionImporter().recoverTransaction(subordinateTransactionUid);
assertTrue(subordinateTransaction != subordinateTransaction1);
SubordinateTransaction importedTransaction1 = SubordinationManager.getTransactionImporter().getImportedTransaction(subordinateTransactionXid);
assertTrue(importedTransaction != importedTransaction1);
SubordinateTransaction importedTransaction2 = SubordinationManager.getTransactionImporter().getImportedTransaction(subordinateTransactionXid);
assertTrue(importedTransaction1 == importedTransaction2);
importedTransaction2.doCommit();
}
use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.
the class XATerminatorImpleUnitTest method testPrepareAbort.
@Test
public void testPrepareAbort() throws Exception {
XidImple xid = new XidImple(new Uid());
TransactionImporter imp = SubordinationManager.getTransactionImporter();
imp.importTransaction(xid);
XATerminatorImple xa = new XATerminatorImple();
assertEquals(xa.prepare(xid), XAResource.XA_RDONLY);
try {
xa.rollback(xid);
} catch (final XAException ex) {
}
}
use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.
the class XATerminatorImpleUnitTest method testImportMultipleTx.
@Test
public void testImportMultipleTx() throws XAException, RollbackException, SystemException {
Implementations.initialise();
Implementationsx.initialise();
XidImple xid = new XidImple(new Uid());
TransactionImporter imp = SubordinationManager.getTransactionImporter();
SubordinateTransaction subordinateTransaction = imp.importTransaction(xid);
XATerminatorImple xa = new XATerminatorImple();
XAResourceImple xar1 = new XAResourceImple(XAResource.XA_OK);
XAResourceImple xar2 = new XAResourceImple(XAException.XAER_RMFAIL);
subordinateTransaction.enlistResource(xar1);
subordinateTransaction.enlistResource(xar2);
xa.prepare(xid);
try {
xa.commit(xid, false);
fail("Did not expect to pass");
} catch (XAException xae) {
assertTrue(xae.errorCode == XAException.XAER_RMFAIL);
}
Xid[] xids = xa.recover(XAResource.TMSTARTRSCAN);
assertTrue(Arrays.binarySearch(xids, xid, new Comparator<Xid>() {
@Override
public int compare(Xid o1, Xid o2) {
if (((XidImple) o1).equals(o2)) {
return 0;
} else {
return -1;
}
}
}) != -1);
// Will throw a heuristic. The doRollback should be allowed but when we realise that the XAR1 is commited it shouldn't be allowed. Maybe we should also not shutdown the first XAR or maybe we need to rely on bottom up.
xa.rollback(xid);
assertTrue(xar2.rollbackCalled());
xa.recover(XAResource.TMENDRSCAN);
}
use of com.arjuna.ats.jta.xa.XidImple 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);
}
Aggregations