use of com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple 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.internal.jta.transaction.jts.jca.XATerminatorImple 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.internal.jta.transaction.jts.jca.XATerminatorImple in project narayana by jbosstm.
the class JCAServerTransactionRecoveryModuleTest method testReloadStateAcceptable.
@Test
public void testReloadStateAcceptable() throws XAException, RollbackException, SystemException {
JCAServerTransactionRecoveryModule module = new JCAServerTransactionRecoveryModule();
XATerminator terminator = new XATerminatorImple();
Xid 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];
}
};
SubordinationManager.getTransactionImporter().importTransaction(xid);
SubordinateTransaction importedTransaction = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
importedTransaction.enlistResource(new XAResource() {
@Override
public void commit(Xid xid, boolean b) throws XAException {
commitCalled = true;
}
@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 {
}
});
terminator.prepare(xid);
module.periodicWorkFirstPass();
module.periodicWorkSecondPass();
module.periodicWorkFirstPass();
module.periodicWorkSecondPass();
assertFalse(commitCalled);
terminator.commit(xid, false);
assertTrue(commitCalled);
}
Aggregations