Search in sources :

Example 1 with XARecoveryModule

use of com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule in project narayana by jbosstm.

the class XAResourceRecord method getXAResourceDeserializers.

private List<SerializableXAResourceDeserializer> getXAResourceDeserializers() {
    if (serializableXAResourceDeserializers != null) {
        return serializableXAResourceDeserializers;
    }
    synchronized (this) {
        if (serializableXAResourceDeserializers != null) {
            return serializableXAResourceDeserializers;
        }
        serializableXAResourceDeserializers = new ArrayList<SerializableXAResourceDeserializer>();
        for (RecoveryModule recoveryModule : RecoveryManager.manager().getModules()) {
            if (recoveryModule instanceof XARecoveryModule) {
                XARecoveryModule xaRecoveryModule = (XARecoveryModule) recoveryModule;
                serializableXAResourceDeserializers.addAll(xaRecoveryModule.getSeriablizableXAResourceDeserializers());
                return serializableXAResourceDeserializers;
            }
        }
    }
    return serializableXAResourceDeserializers;
}
Also used : SerializableXAResourceDeserializer(com.arjuna.ats.jta.recovery.SerializableXAResourceDeserializer) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule)

Example 2 with XARecoveryModule

use of com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule in project narayana by jbosstm.

the class XATerminatorImpleUnitTest method testXARMERR.

@Test
public void testXARMERR() throws Exception {
    Uid uid = new Uid();
    XidImple xid = new XidImple(uid);
    TransactionImporter imp = SubordinationManager.getTransactionImporter();
    SubordinateTransaction subordinateTransaction = imp.importTransaction(xid);
    Uid savingUid = getImportedSubordinateTransactionUid(subordinateTransaction);
    subordinateTransaction.enlistResource(new TestXAResource() {

        @Override
        public void commit(Xid xid, boolean b) throws XAException {
            this.xid = null;
        }

        @Override
        public int prepare(Xid xid) throws XAException {
            return 0;
        }

        @Override
        public void rollback(Xid xid) throws XAException {
            fail("Resource was rolled back");
        }
    });
    subordinateTransaction.enlistResource(new TestXAResource() {

        @Override
        public void commit(Xid xid, boolean b) throws XAException {
            throw new XAException(XAException.XA_HEURHAZ);
        }

        @Override
        public int prepare(Xid xid) throws XAException {
            failedResourceXid = xid;
            return 0;
        }

        @Override
        public void rollback(Xid xid) throws XAException {
            fail("Resource was rolled back");
        }
    });
    XATerminatorImple xa = new XATerminatorImple();
    xa.prepare(xid);
    try {
        xa.commit(xid, false);
        fail("Expecting heuristic mixed exception being thrown on commit");
    } catch (final XAException ex) {
        assertEquals(XAException.XA_HEURMIX, ex.errorCode);
    }
    try {
        xa.commit(xid, false);
    } catch (XAException e) {
        assertEquals(XAException.XA_RETRY, e.errorCode);
    }
    ObjStoreBrowser osb = new ObjStoreBrowser();
    osb.viewSubordinateAtomicActions(true);
    osb.setExposeAllRecordsAsMBeans(true);
    osb.start();
    osb.probe();
    Set<ObjectName> participants = JMXServer.getAgent().queryNames("jboss.jta:type=ObjectStore,itype=" + com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.coordinator.ServerTransaction.getType().substring(1) + ",uid=" + savingUid.stringForm().replaceAll(":", "_") + ",puid=*", null);
    assertEquals(1, participants.size());
    JMXServer.getAgent().getServer().invoke(participants.iterator().next(), "clearHeuristic", null, null);
    xa.recover(XAResource.TMSTARTRSCAN);
    xa.recover(XAResource.TMENDRSCAN);
    Set<ObjectName> xaResourceRecords = JMXServer.getAgent().queryNames("jboss.jta:type=ObjectStore,itype=" + XAResourceRecord.typeName().substring(1) + ",uid=*", null);
    for (ObjectName xaResourceRecord : xaResourceRecords) {
        Object getGlobalTransactionId = JMXServer.getAgent().getServer().getAttribute(xaResourceRecord, "GlobalTransactionId");
        Object getBranchQualifier = JMXServer.getAgent().getServer().getAttribute(xaResourceRecord, "BranchQualifier");
        if (Arrays.equals(failedResourceXid.getGlobalTransactionId(), (byte[]) getGlobalTransactionId) && Arrays.equals(failedResourceXid.getBranchQualifier(), (byte[]) getBranchQualifier)) {
            Object getHeuristicValue = JMXServer.getAgent().getServer().getAttribute(xaResourceRecord, "HeuristicValue");
            assertTrue(getHeuristicValue.equals(new Integer(6)));
            JMXServer.getAgent().getServer().invoke(xaResourceRecord, "clearHeuristic", null, null);
        }
    }
    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[] { new TestXAResource() {

                public Xid[] recover(int var) throws XAException {
                    if (var == XAResource.TMSTARTRSCAN) {
                        if (failedResourceXid != null) {
                            return new Xid[] { failedResourceXid };
                        }
                    }
                    return new Xid[0];
                }

                @Override
                public void commit(Xid xid, boolean b) throws XAException {
                    failedResourceXid = null;
                }

                @Override
                public int prepare(Xid xid) throws XAException {
                    return 0;
                }

                @Override
                public void rollback(Xid xid) throws XAException {
                    fail("Resource was rolled back");
                }
            } };
        }
    });
    xaRecoveryModule.periodicWorkFirstPass();
    Field safetyIntervalMillis = RecoveryXids.class.getDeclaredField("safetyIntervalMillis");
    safetyIntervalMillis.setAccessible(true);
    Object o1 = safetyIntervalMillis.get(null);
    safetyIntervalMillis.set(null, 0);
    try {
        xaRecoveryModule.periodicWorkSecondPass();
    } finally {
        safetyIntervalMillis.set(null, o1);
    }
    xa.recover(XAResource.TMSTARTRSCAN);
    try {
        xa.commit(xid, false);
        Assert.fail("Expecting XAException being thrown indicating more recover to be called");
    } 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);
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) TestXAResource(com.hp.mwtests.ts.jta.jts.TestXAResource) XAException(javax.transaction.xa.XAException) ObjStoreBrowser(com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) XAException(javax.transaction.xa.XAException) RollbackException(javax.transaction.RollbackException) SystemException(javax.transaction.SystemException) ObjectName(javax.management.ObjectName) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Uid(com.arjuna.ats.arjuna.common.Uid) Field(java.lang.reflect.Field) Xid(javax.transaction.xa.Xid) TransactionImporter(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter) XATerminatorImple(com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule) Test(org.junit.Test)

Example 3 with XARecoveryModule

use of com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule in project narayana by jbosstm.

the class UnserializableSerializableXAResourceTest method test.

@Test
public void test() throws Exception {
    XAResource res1 = new XAResource() {

        @Override
        public void start(Xid xid, int flags) throws XAException {
        // TODO Auto-generated method stub
        }

        @Override
        public void end(Xid xid, int flags) throws XAException {
        // TODO Auto-generated method stub
        }

        @Override
        public int prepare(Xid xid) throws XAException {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public void commit(Xid xid, boolean onePhase) throws XAException {
        // TODO Auto-generated method stub
        }

        @Override
        public void rollback(Xid xid) throws XAException {
        // TODO Auto-generated method stub
        }

        @Override
        public void forget(Xid xid) throws XAException {
        // TODO Auto-generated method stub
        }

        @Override
        public Xid[] recover(int flag) throws XAException {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public boolean isSameRM(XAResource xaRes) throws XAException {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public int getTransactionTimeout() throws XAException {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public boolean setTransactionTimeout(int seconds) throws XAException {
            // TODO Auto-generated method stub
            return false;
        }
    };
    UnserializableSerializableXAResource res2 = new UnserializableSerializableXAResource(true);
    final javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
    tm.getStatus();
    tm.begin();
    javax.transaction.Transaction theTransaction = tm.getTransaction();
    assertTrue(theTransaction.enlistResource(res1));
    assertTrue(theTransaction.enlistResource(res2));
    tm.commit();
    XARecoveryModule xaRecoveryModule = null;
    for (RecoveryModule recoveryModule : ((Vector<RecoveryModule>) recoveryManager.getModules())) {
        if (recoveryModule instanceof XARecoveryModule) {
            xaRecoveryModule = (XARecoveryModule) recoveryModule;
            break;
        }
    }
    final Xid xid = res2.getXid();
    xaRecoveryModule.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {

        @Override
        public boolean initialise(String p) throws Exception {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public XAResource[] getXAResources() throws Exception {
            return new XAResource[] { new XAResource() {

                @Override
                public void start(Xid xid, int flags) throws XAException {
                // TODO Auto-generated method stub
                }

                @Override
                public void end(Xid xid, int flags) throws XAException {
                // TODO Auto-generated method stub
                }

                @Override
                public int prepare(Xid xid) throws XAException {
                    // TODO Auto-generated method stub
                    return 0;
                }

                @Override
                public void commit(Xid xid, boolean onePhase) throws XAException {
                    committed = true;
                }

                @Override
                public void rollback(Xid xid) throws XAException {
                // TODO Auto-generated method stub
                }

                @Override
                public void forget(Xid xid) throws XAException {
                // TODO Auto-generated method stub
                }

                @Override
                public Xid[] recover(int flag) throws XAException {
                    if (committed) {
                        return null;
                    } else {
                        return new Xid[] { xid };
                    }
                }

                @Override
                public boolean isSameRM(XAResource xaRes) throws XAException {
                    // TODO Auto-generated method stub
                    return false;
                }

                @Override
                public int getTransactionTimeout() throws XAException {
                    // TODO Auto-generated method stub
                    return 0;
                }

                @Override
                public boolean setTransactionTimeout(int seconds) throws XAException {
                    // TODO Auto-generated method stub
                    return false;
                }
            } };
        }
    });
    recoveryManager.scan();
    assertTrue(committed);
}
Also used : XAException(javax.transaction.xa.XAException) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) SystemException(org.omg.CORBA.SystemException) XAException(javax.transaction.xa.XAException) XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule) Test(org.junit.Test)

Example 4 with XARecoveryModule

use of com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule in project narayana by jbosstm.

the class ImportedTransactionRecoveryUnitTest method testMultipleXAResourceForImportedJcaTransaction.

/**
 * <p>
 * Testing that multiple {@link XAResource}s could be used under imported transaction.<br>
 * Previously there was no check of xid format which resulted to fact of merging usage of multiple XAResources
 * under one Xid even when the subordinate transaction was under management of Narayana (meaning created by Narayana).
 * That could lead to non-recoverable behavior for particular XAResource.
 * <p>
 * By adding check for format of xid Narayana generates new Xid for any XAResource used under transaction
 * created by Narayana. If transaction comes from EIS there is returned the same Xid (as expected).
 */
@Test
public void testMultipleXAResourceForImportedJcaTransaction() throws Exception {
    final Xid xid = XidUtils.getXid(new Uid(), true);
    SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().importTransaction(xid);
    TestXAResourceWrapper xar1 = new TestXAResourceWrapper("narayana", "narayana", "java:/test1") {

        boolean wasThrown = false;

        @Override
        public void commit(Xid xid, boolean onePhase) throws XAException {
            if (!wasThrown) {
                wasThrown = true;
                throw new XAException(XAException.XAER_RMFAIL);
            } else {
                super.commit(xid, onePhase);
            }
        }
    };
    TestXAResourceWrapper xar2 = new TestXAResourceWrapper("narayana", "narayana", "java:/test2") {

        boolean wasThrown = false;

        @Override
        public void commit(Xid xid, boolean onePhase) throws XAException {
            if (!wasThrown) {
                wasThrown = true;
                throw new XAException(XAException.XAER_RMFAIL);
            } else {
                super.commit(xid, onePhase);
            }
        }
    };
    assertTrue("Fail to enlist first test XAResource", subordinateTransaction.enlistResource(xar1));
    assertTrue("Fail to enlist second XAResource", subordinateTransaction.enlistResource(xar2));
    assertEquals("transaction should be prepared", TwoPhaseOutcome.PREPARE_OK, subordinateTransaction.doPrepare());
    assertFalse("first resource should fail on transaction commit, thus whole txn can't be committed", subordinateTransaction.doCommit());
    assertNotEquals("XAResources should be enlisted with different xids", xar1.getXid(), xar2.getXid());
    ((XARecoveryModule) recoveryManager.getModules().get(0)).addXAResourceRecoveryHelper(new TestXARecoveryHelper(xar1, xar2));
    recoveryManager.scan();
    assertEquals("XAResource1 can't be rolled-back", 0, xar1.rollbackCount());
    assertEquals("XAResource2 can't be rolled-back", 0, xar2.rollbackCount());
    assertEquals("XAResource1 has to be committed", 1, xar1.commitCount());
    assertEquals("XAResource2 has to be committed", 1, xar2.commitCount());
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) TestXAResourceWrapper(com.hp.mwtests.ts.jta.recovery.TestXAResourceWrapper) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule) Test(org.junit.Test)

Example 5 with XARecoveryModule

use of com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule in project narayana by jbosstm.

the class JTSObjStoreBrowserTest method beforeTest.

@Before
public void beforeTest() throws Exception {
    recoveryPropertyManager.getRecoveryEnvironmentBean().setPeriodicRecoveryPeriod(1);
    recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(1);
    xarm = new XARecoveryModule();
    aarm = new AtomicActionRecoveryModule();
    recoveryManager.addModule(xarm);
    recoveryManager.addModule(aarm);
}
Also used : AtomicActionRecoveryModule(com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule) Before(org.junit.Before)

Aggregations

XARecoveryModule (com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule)7 Test (org.junit.Test)5 XAException (javax.transaction.xa.XAException)3 Xid (javax.transaction.xa.Xid)3 Uid (com.arjuna.ats.arjuna.common.Uid)2 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)2 SubordinateTransaction (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)2 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)2 ObjStoreBrowser (com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser)1 AtomicActionRecoveryModule (com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule)1 TransactionImporter (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter)1 TransactionImple (com.arjuna.ats.internal.jta.transaction.jts.TransactionImple)1 XATerminatorImple (com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple)1 SubordinateAtomicTransaction (com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.SubordinateAtomicTransaction)1 SerializableXAResourceDeserializer (com.arjuna.ats.jta.recovery.SerializableXAResourceDeserializer)1 XidImple (com.arjuna.ats.jta.xa.XidImple)1 RecoveryXAResource (com.hp.mwtests.ts.jta.common.RecoveryXAResource)1 TestXAResource (com.hp.mwtests.ts.jta.jts.TestXAResource)1 TestXAResourceWrapper (com.hp.mwtests.ts.jta.recovery.TestXAResourceWrapper)1 Field (java.lang.reflect.Field)1