use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.
the class XATerminatorUnitTest method testCommitMid.
@Test
public void testCommitMid() throws Exception {
TransactionManagerImple tm = new TransactionManagerImple();
RecordTypeManager.manager().add(new RecordTypeMap() {
@SuppressWarnings("unchecked")
public Class getRecordClass() {
return XAResourceRecord.class;
}
public int getType() {
return RecordType.JTA_RECORD;
}
});
XATerminatorImple xaTerminator = new XATerminatorImple();
XidImple xid = new XidImple(new Uid());
XAResourceImple toCommit = new XAResourceImple(XAResource.XA_OK, XAResource.XA_OK);
{
SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().importTransaction(xid);
tm.resume(subordinateTransaction);
subordinateTransaction.enlistResource(new XAResourceImple(XAResource.XA_RDONLY, XAResource.XA_OK));
subordinateTransaction.enlistResource(toCommit);
Transaction suspend = tm.suspend();
}
{
SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
tm.resume(subordinateTransaction);
subordinateTransaction.doPrepare();
Transaction suspend = tm.suspend();
}
XARecoveryModule xaRecoveryModule = new XARecoveryModule();
xaRecoveryModule.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {
@Override
public boolean initialise(String p) throws Exception {
return false;
}
@Override
public XAResource[] getXAResources() throws Exception {
return new XAResource[] { toCommit };
}
});
RecoveryManager.manager().addModule(xaRecoveryModule);
xaTerminator.doRecover(null, null);
{
SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
tm.resume(subordinateTransaction);
subordinateTransaction.doCommit();
tm.suspend();
}
RecoveryManager.manager().removeModule(xaRecoveryModule, false);
assertTrue(toCommit.wasCommitted());
SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
}
use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.
the class ForgetTest method testCommitHeuristic.
@Test
public void testCommitHeuristic() {
SampleOnePhaseResource res = new SampleOnePhaseResource(SampleOnePhaseResource.ErrorType.heurcom);
XidImple xid = new XidImple(new Uid());
XAOnePhaseResource xares = new XAOnePhaseResource(res, xid, null);
assertEquals(xares.commit(), TwoPhaseOutcome.FINISH_OK);
assertTrue(res.forgetCalled());
}
use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.
the class UtilsUnitTest method testXAHelper.
@Test
public void testXAHelper() throws Exception {
assertTrue(XAHelper.printXAErrorCode(null) != null);
XAException ex = new XAException(XAException.XA_HEURCOM);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_HEURCOM");
ex = new XAException(XAException.XA_HEURHAZ);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_HEURHAZ");
ex = new XAException(XAException.XA_HEURMIX);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_HEURMIX");
ex = new XAException(XAException.XA_HEURRB);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_HEURRB");
ex = new XAException(XAException.XA_NOMIGRATE);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_NOMIGRATE");
ex = new XAException(XAException.XA_RBCOMMFAIL);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_RBCOMMFAIL");
ex = new XAException(XAException.XA_RBDEADLOCK);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_RBDEADLOCK");
ex = new XAException(XAException.XA_RBINTEGRITY);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_RBINTEGRITY");
ex = new XAException(XAException.XA_RBOTHER);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_RBOTHER");
ex = new XAException(XAException.XA_RBPROTO);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_RBPROTO");
ex = new XAException(XAException.XA_RBROLLBACK);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_RBROLLBACK");
ex = new XAException(XAException.XA_RBTIMEOUT);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_RBTIMEOUT");
ex = new XAException(XAException.XA_RBTRANSIENT);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_RBTRANSIENT");
ex = new XAException(XAException.XA_RDONLY);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_RDONLY");
ex = new XAException(XAException.XA_RETRY);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XA_RETRY");
ex = new XAException(XAException.XAER_RMERR);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XAER_RMERR");
ex = new XAException(XAException.XAER_ASYNC);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XAER_ASYNC");
ex = new XAException(XAException.XAER_DUPID);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XAER_DUPID");
ex = new XAException(XAException.XAER_INVAL);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XAER_INVAL");
ex = new XAException(XAException.XAER_NOTA);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XAER_NOTA");
ex = new XAException(XAException.XAER_OUTSIDE);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XAER_OUTSIDE");
ex = new XAException(XAException.XAER_PROTO);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XAER_PROTO");
ex = new XAException(XAException.XAER_RMFAIL);
assertEquals(XAHelper.printXAErrorCode(ex), "XAException.XAER_RMFAIL");
assertTrue(XAHelper.printXAErrorCode(new XAException(-1)) != null);
XidImple xid1 = new XidImple(new Uid());
XidImple xid2 = new XidImple(new Uid());
XidImple xid3 = new XidImple(xid1);
assertFalse(XAHelper.sameXID(xid1, xid2));
assertTrue(XAHelper.sameXID(xid1, xid3));
assertTrue(XAHelper.sameTransaction(xid1, xid1));
assertTrue(XAHelper.sameTransaction(xid1, xid3));
assertTrue(XAHelper.xidToString(xid1) != null);
XID x = new XID();
x.bqual_length = 1;
x.gtrid_length = 1;
x.data = new byte[] { '1', '2' };
assertTrue(x.toString() != null);
XAHelper.xidToString(new DummyXid());
}
use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.
the class OnePhaseUnitTest method testCommitHeuristic.
@Test
public void testCommitHeuristic() {
SampleOnePhaseResource res = new SampleOnePhaseResource(ErrorType.heurcom);
XidImple xid = new XidImple(new Uid());
XAOnePhaseResource xares = new XAOnePhaseResource(res, xid, null);
assertEquals(xares.commit(), TwoPhaseOutcome.FINISH_OK);
assertTrue(res.forgetCalled());
}
use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.
the class OnePhaseUnitTest method testRollbackHeuristic.
@Test
public void testRollbackHeuristic() {
SampleOnePhaseResource res = new SampleOnePhaseResource(ErrorType.heurrb);
XidImple xid = new XidImple(new Uid());
XAOnePhaseResource xares = new XAOnePhaseResource(res, xid, null);
assertEquals(xares.commit(), TwoPhaseOutcome.ONE_PHASE_ERROR);
assertTrue(res.forgetCalled());
}
Aggregations