use of com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction in project narayana by jbosstm.
the class XARecoveryModuleUnitTest method testEmptyResourceEnlistmentParams.
/**
* Test which uses method {@link TransactionImple#enlistResource(XAResource, Object[])} could be used
* with empty object array and still works.
*/
@Test
public void testEmptyResourceEnlistmentParams() throws Exception {
final Uid uid = new Uid();
final Xid xid = XidUtils.getXid(uid, true);
SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().importTransaction(xid);
TransactionImple subordinateTransactionImple = (TransactionImple) subordinateTransaction;
TestXAResourceWrapper xar = new TestXAResourceWrapper("narayana", "narayana", "java:/test1");
subordinateTransactionImple.enlistResource(xar, new Object[] {});
int statusPrepare = subordinateTransaction.doPrepare();
subordinateTransaction.doCommit();
assertEquals("transaction should be prepared", TwoPhaseOutcome.PREPARE_OK, statusPrepare);
assertEquals("XAResource can't be rolled-back", 0, xar.rollbackCount());
assertEquals("XAResource has to be committed", 1, xar.commitCount());
}
use of com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction 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