use of com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction in project narayana by jbosstm.
the class TransactionImporterUnitTest method testDifferentInstanceFromRecovery.
@Test
public void testDifferentInstanceFromRecovery() throws XAException, RollbackException, SystemException, HeuristicRollbackException, HeuristicMixedException, HeuristicCommitException {
Uid uid = new Uid();
XidImple xid = new XidImple(uid);
SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().importTransaction(xid);
Uid subordinateTransactionUid = subordinateTransaction.get_uid();
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();
Implementations.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.internal.jta.transaction.arjunacore.jca.SubordinateTransaction in project narayana by jbosstm.
the class XATerminatorImple method rollback.
public void rollback(Xid xid) throws XAException {
// JBTM-927 this can happen if the transaction has been rolled back by
// the TransactionReaper
SubordinateTransaction tx = null;
try {
tx = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
} catch (XAException xae) {
if (xae.errorCode == XAException.XA_RBROLLBACK) {
SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
return;
}
throw xae;
}
try {
if (tx == null)
throw new XAException(XAException.XAER_INVAL);
if (tx.baseXid() != null) {
tx.doRollback();
SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
} else
throw new XAException(XAException.XA_RETRY);
} catch (XAException ex) {
if (ex.errorCode != XAException.XA_RETRY) {
SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
}
throw ex;
} catch (HeuristicCommitException ex) {
XAException xaException = new XAException(XAException.XA_HEURCOM);
xaException.initCause(ex);
throw xaException;
} catch (final HeuristicRollbackException ex) {
XAException xaException = new XAException(XAException.XA_HEURRB);
xaException.initCause(ex);
throw xaException;
} catch (HeuristicMixedException ex) {
XAException xaException = new XAException(XAException.XA_HEURMIX);
xaException.initCause(ex);
throw xaException;
} catch (final IllegalStateException ex) {
SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
XAException xaException = new XAException(XAException.XAER_NOTA);
xaException.initCause(ex);
throw xaException;
} catch (SystemException ex) {
SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
XAException xaException = new XAException(XAException.XAER_RMERR);
xaException.initCause(ex);
throw xaException;
}
}
use of com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction in project narayana by jbosstm.
the class TransactionImporterImple method removeImportedTransaction.
/**
* Remove the subordinate (imported) transaction.
*
* @param xid the global transaction.
*
* @throws XAException thrown if there are any errors.
*/
public void removeImportedTransaction(Xid xid) throws XAException {
if (xid == null)
throw new IllegalArgumentException();
AtomicReference<SubordinateTransaction> remove = _transactions.remove(new SubordinateXidImple(xid));
if (remove != null) {
synchronized (remove) {
com.arjuna.ats.internal.jta.transaction.jts.TransactionImple transactionImple = (com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) remove.get();
while (transactionImple == null) {
try {
remove.wait();
transactionImple = (com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) remove.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new XAException(XAException.XAER_RMFAIL);
}
}
TransactionImple.removeTransaction(transactionImple);
}
}
}
use of com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction in project narayana by jbosstm.
the class SubordinationManagerXAResourceOrphanFilter method checkXid.
@Override
public Vote checkXid(Xid xid) {
if (xid.getFormatId() != XATxConverter.FORMAT_ID) {
// we only care about Xids created by the JTA
return Vote.ABSTAIN;
}
List<String> _xaRecoveryNodes = jtaPropertyManager.getJTAEnvironmentBean().getXaRecoveryNodes();
if (_xaRecoveryNodes == null || _xaRecoveryNodes.size() == 0) {
jtaLogger.i18NLogger.info_recovery_noxanodes();
return Vote.ABSTAIN;
}
String nodeName = XATxConverter.getSubordinateNodeName(new XidImple(xid).getXID());
if (jtaLogger.logger.isDebugEnabled()) {
jtaLogger.logger.debug("subordinate node name of " + xid + " is " + nodeName);
}
if (!_xaRecoveryNodes.contains(nodeName)) {
// It either doesn't have a subordinate node name or isn't for this server
return Vote.ABSTAIN;
}
if (!getSubordinateAtomicActionRecoveryModule().isRecoveryScanCompletedWithoutError()) {
// Xid alone
return Vote.LEAVE_ALONE;
}
XidImple theXid = new XidImple(xid);
SubordinateTransaction importedTransaction = null;
try {
importedTransaction = SubordinationManager.getTransactionImporter().getImportedTransaction(theXid);
} catch (XAException e) {
return Vote.LEAVE_ALONE;
}
if (importedTransaction != null) {
return Vote.LEAVE_ALONE;
} else {
return Vote.ROLLBACK;
}
}
use of com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction in project narayana by jbosstm.
the class XATerminatorImpleUnitTest method testXARetry.
@Test
public void testXARetry() throws Exception {
XidImple xid = new XidImple(new Uid());
TransactionImporter imp = SubordinationManager.getTransactionImporter();
SubordinateTransaction subordinateTransaction = imp.importTransaction(xid);
XATerminatorImple xa = new XATerminatorImple();
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.enlistResource(new XAResource() {
boolean firstAttempt = true;
@Override
public void commit(Xid xid, boolean b) throws XAException {
if (firstAttempt) {
try {
failedResourceXid = xid;
throw new XAException(XAException.XA_RETRY);
} finally {
firstAttempt = false;
}
}
if (failedResourceXid != null) {
failedResourceXid = null;
} else {
throw new XAException(XAException.XAER_PROTO);
}
}
@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 {
}
});
assertEquals(xa.prepare(xid), XAResource.XA_OK);
try {
xa.commit(xid, false);
fail("Expecting XATerminator throwing XAException as commit should fail" + " as TestXAResource was instructed to throw an exception");
} catch (final XAException ex) {
assertEquals("XATerminator commit should throw XAER_RMFAIL when commit fails", XAException.XAER_RMFAIL, ex.errorCode);
}
Implementationsx.initialise();
xa.recover(XAResource.TMSTARTRSCAN);
assertNotNull(failedResourceXid);
try {
xa.commit(xid, false);
} catch (XAException expected) {
Assert.assertTrue("On commit XAException error code indicating more recover call is expected but it's " + expected.errorCode, XAException.XA_RETRY == expected.errorCode || XAException.XAER_RMFAIL == expected.errorCode);
} finally {
xa.recover(XAResource.TMENDRSCAN);
}
assertNull(failedResourceXid);
}
Aggregations