Search in sources :

Example 1 with RecordTypeMap

use of com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap in project narayana by jbosstm.

the class OrderedOnePhaseResourcesUnitTest method testOrderedOnePhase.

@Test
public void testOrderedOnePhase() throws Exception {
    System.setProperty("com.arjuna.ats.arjuna.common.propertiesFile", "jbossts-properties.xml");
    Uid firstToCommit = new Uid();
    Uid secondToCommit = new Uid();
    AtomicAction A = new AtomicAction();
    // These user defined records could wrap anything such as 1PC JDBC or messages
    OrderedOnePhaseAbstractRecord rec1 = new OrderedOnePhaseAbstractRecord(secondToCommit);
    OrderedOnePhaseAbstractRecord rec2 = new OrderedOnePhaseAbstractRecord(firstToCommit);
    A.begin();
    // Doesn't matter of the order
    A.add(rec1);
    A.add(rec2);
    // Do some work you could save some concept of the work in the abstract record save_state
    // rec1.sendMessage
    // rec2.doSQL
    // This is just so we can see the opportunity for failure recovery
    rec1.causeTransientFailure();
    // Commit, this would make sure the database (rec2) was committed first
    A.commit();
    // This shows recovery working, we should see Uid2 called again, if you had encoded some information in rec2 you could
    // maybe
    // retry the sending of a message or similar
    RecordTypeManager.manager().add(new RecordTypeMap() {

        @Override
        public int getType() {
            return OrderedOnePhaseAbstractRecord.typeId();
        }

        @Override
        public Class<? extends AbstractRecord> getRecordClass() {
            return OrderedOnePhaseAbstractRecord.class;
        }
    });
    recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(1);
    RecoveryManager.manager(RecoveryManager.DIRECT_MANAGEMENT).addModule(new AtomicActionRecoveryModule());
    RecoveryManager.manager().scan();
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) AtomicActionRecoveryModule(com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule) RecordTypeMap(com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord) OrderedOnePhaseAbstractRecord(com.hp.mwtests.ts.arjuna.abstractrecords.OrderedOnePhaseAbstractRecord) OrderedOnePhaseAbstractRecord(com.hp.mwtests.ts.arjuna.abstractrecords.OrderedOnePhaseAbstractRecord) Test(org.junit.Test)

Example 2 with RecordTypeMap

use of com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap in project narayana by jbosstm.

the class ObjStoreBrowserTest method aaTest.

public void aaTest(boolean replay) throws Exception {
    ObjStoreBrowser osb = createObjStoreBrowser();
    AtomicAction A = new AtomicAction();
    CrashRecord[] recs = { new CrashRecord(CrashRecord.CrashLocation.NoCrash, CrashRecord.CrashType.Normal), new CrashRecord(CrashRecord.CrashLocation.CrashInCommit, CrashRecord.CrashType.HeuristicHazard) };
    // register CrashRecord record type so that it is persisted in the object store correctly
    RecordTypeManager.manager().add(new RecordTypeMap() {

        public Class<? extends AbstractRecord> getRecordClass() {
            return CrashRecord.class;
        }

        public int getType() {
            return RecordType.USER_DEF_FIRST0;
        }
    });
    // create an atomic action, register crash records with it and then commit
    A.begin();
    for (CrashRecord rec : recs) A.add(rec);
    int outcome = A.commit();
    // the second participant should have generated a heuristic during commit
    assertEquals(ActionStatus.H_HAZARD, outcome);
    // generate MBeans representing the atomic action that was just committed
    osb.start();
    osb.probe();
    // there should be one MBean corresponding to the AtomicAction A
    UidWrapper w = osb.findUid(A.get_uid());
    assertNotNull(w);
    OSEntryBean ai = w.getMBean();
    assertNotNull(ai);
    // the MBean should wrap an ActionBean
    assertTrue(ai instanceof ActionBean);
    ActionBean actionBean = (ActionBean) ai;
    // and there should be one MBean corresponding to the CrashRecord that got the heuristic:
    int recCount = 0;
    for (CrashRecord rec : recs) {
        LogRecordWrapper lw = actionBean.getParticipant(rec);
        if (lw != null) {
            recCount += 1;
            assertTrue(lw.isHeuristic());
            // put the participant back onto the pending list
            lw.setStatus("PREPARED");
            // and check that the record is no longer in a heuristic state
            assertFalse(lw.isHeuristic());
        }
    }
    assertEquals(1, recCount);
    if (!replay) {
        actionBean.remove();
    } else {
        /*
			* prompt the recovery manager to replay the record that was
			* moved off the heuristic list and back onto the prepared list
			*/
        rcm.scan();
    }
    /*
		 * Since the recovery scan (or explicit remove request) will have successfully removed the record from
		 * the object store another probe should cause the MBean representing the record to be unregistered
		 */
    osb.probe();
    // look up the MBean and verify that it no longer exists
    w = osb.findUid(A.get_uid());
    assertNull(w);
    osb.dump(new StringBuilder());
    osb.stop();
}
Also used : OSEntryBean(com.arjuna.ats.arjuna.tools.osb.mbean.OSEntryBean) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord) ObjStoreBrowser(com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser) ActionBean(com.arjuna.ats.arjuna.tools.osb.mbean.ActionBean) CrashRecord(com.hp.mwtests.ts.arjuna.resources.CrashRecord) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) RecordTypeMap(com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap) UidWrapper(com.arjuna.ats.arjuna.tools.osb.mbean.UidWrapper) LogRecordWrapper(com.arjuna.ats.arjuna.tools.osb.mbean.LogRecordWrapper)

Example 3 with RecordTypeMap

use of com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap in project narayana by jbosstm.

the class HeuristicInformationTest method heuristicInformationTest.

@Test
public void heuristicInformationTest() throws Exception {
    ArjunaTransactionImple A = new ArjunaTransactionImple(null);
    int expectedHeuristic = TwoPhaseOutcome.HEURISTIC_ROLLBACK;
    ThreadActionData.purgeActions();
    UserExtendedCrashRecord[] recs = { new UserExtendedCrashRecord(UserExtendedCrashRecord.CrashLocation.NoCrash, UserExtendedCrashRecord.CrashType.Normal, null), new UserExtendedCrashRecord(UserExtendedCrashRecord.CrashLocation.CrashInCommit, UserExtendedCrashRecord.CrashType.HeuristicHazard, // this value will override HeuristicHazard
    new UserExtendedCrashRecord.HeuristicInformationOverride(expectedHeuristic)) };
    RecordTypeManager.manager().add(new RecordTypeMap() {

        public Class<? extends AbstractRecord> getRecordClass() {
            return UserExtendedCrashRecord.class;
        }

        public int getType() {
            return RecordType.USER_DEF_FIRST1;
        }
    });
    A.start();
    for (UserExtendedCrashRecord rec : recs) A.add(rec);
    try {
        A.commit(true);
        fail("transaction commit should have produced a heuristic hazard");
    } catch (HeuristicHazard e) {
    // expected
    }
    ObjStoreBrowser osb = getOSB();
    osb.start();
    osb.probe();
    // there should now be an MBean entry corresponding to a JTS record, read it via JMX:
    MBeanServer mbs = JMXServer.getAgent().getServer();
    UidWrapper w = osb.findUid(A.get_uid());
    ObjectName txnON = new ObjectName(w.getName());
    Object aid = mbs.getAttribute(txnON, "Id");
    assertNotNull(aid);
    Set<ObjectName> participants = mbs.queryNames(new ObjectName(w.getName() + ",puid=*"), null);
    for (ObjectName on : participants) {
        AttributeList al = mbs.getAttributes(on, new String[] { "Id", "Status", "HeuristicStatus", "GlobalTransactionId" });
        for (Attribute a : al.asList()) {
            if ("HeuristicStatus".equals(a.getName())) {
                HeuristicStatus ahs = HeuristicStatus.valueOf(a.getValue().toString());
                HeuristicStatus ehs = HeuristicStatus.intToStatus(expectedHeuristic);
                // assert that the instrumented heuristic status has the expected value
                assertTrue(ahs.equals(ehs));
            }
        }
    }
}
Also used : AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard) RecordTypeMap(com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) Test(org.junit.Test)

Example 4 with RecordTypeMap

use of com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap in project narayana by jbosstm.

the class XARecoveryModuleUnitTest method testRecoverFromMultipleXAResourceRecovery.

@Test
public void testRecoverFromMultipleXAResourceRecovery() throws Exception {
    // Make sure the file doesn't exist
    assertFalse(new File("XARR.txt").exists());
    ArrayList<String> r = new ArrayList<String>();
    AtomicAction aa = new AtomicAction();
    aa.begin();
    assertEquals(AddOutcome.AR_ADDED, aa.add(new XAResourceRecord(null, new XARRTestResource(), new XidImple(aa), null)));
    Class c = BasicAction.class;
    Method method = c.getDeclaredMethod("prepare", boolean.class);
    method.setAccessible(true);
    int result = (Integer) method.invoke(aa, new Object[] { true });
    assertEquals(result, TwoPhaseOutcome.PREPARE_OK);
    // Make sure the file exists
    assertTrue(new File("XARR.txt").exists());
    // AtomicActionRecoveryModule aaRecoveryModule = new AtomicActionRecoveryModule();
    // aaRecoveryModule.periodicWorkFirstPass();
    // aaRecoveryModule.periodicWorkSecondPass();
    RecordTypeManager.manager().add(new RecordTypeMap() {

        @SuppressWarnings("unchecked")
        public Class getRecordClass() {
            return XAResourceRecord.class;
        }

        public int getType() {
            return RecordType.JTA_RECORD;
        }
    });
    List<String> xarn = new ArrayList<String>();
    xarn.add(NodeNameXAResourceOrphanFilter.RECOVER_ALL_NODES);
    jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(xarn);
    XARecoveryModule xaRecoveryModule = new XARecoveryModule();
    Field safetyIntervalMillis = RecoveryXids.class.getDeclaredField("safetyIntervalMillis");
    safetyIntervalMillis.setAccessible(true);
    safetyIntervalMillis.set(null, 0);
    xaRecoveryModule.addXAResourceRecoveryHelper(new XARROne());
    xaRecoveryModule.addXAResourceRecoveryHelper(new XARRTwo());
    xaRecoveryModule.addXAResourceOrphanFilter(new com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter());
    xaRecoveryModule.addXAResourceOrphanFilter(new com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter());
    RecoveryManager.manager().addModule(xaRecoveryModule);
    // This is done rather than using the AtomicActionRecoveryModule as the transaction is inflight
    RecoverAtomicAction rcvAtomicAction = new RecoverAtomicAction(aa.get_uid(), ActionStatus.COMMITTED);
    rcvAtomicAction.replayPhase2();
    // The XARM would execute next
    xaRecoveryModule.periodicWorkFirstPass();
    xaRecoveryModule.periodicWorkSecondPass();
    // Make sure the file doesn't exist
    assertFalse(new File("XARR.txt").exists());
    aa.abort();
}
Also used : JTANodeNameXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter) ArrayList(java.util.ArrayList) AtomicAction(com.arjuna.ats.internal.jta.transaction.arjunacore.AtomicAction) RecoverAtomicAction(com.arjuna.ats.arjuna.recovery.RecoverAtomicAction) Field(java.lang.reflect.Field) RecoverAtomicAction(com.arjuna.ats.arjuna.recovery.RecoverAtomicAction) XidImple(com.arjuna.ats.jta.xa.XidImple) XAResourceRecord(com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord) BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) Method(java.lang.reflect.Method) RecordTypeMap(com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap) File(java.io.File) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Example 5 with RecordTypeMap

use of com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap 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);
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) UnexpectedConditionException(com.arjuna.ats.jta.exceptions.UnexpectedConditionException) RollbackException(javax.transaction.RollbackException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException) Uid(com.arjuna.ats.arjuna.common.Uid) TransactionManagerImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple) RecordTypeMap(com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Transaction(javax.transaction.Transaction) XATerminatorImple(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.XATerminatorImple) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Aggregations

RecordTypeMap (com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap)6 AbstractRecord (com.arjuna.ats.arjuna.coordinator.AbstractRecord)4 Test (org.junit.Test)4 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)2 Uid (com.arjuna.ats.arjuna.common.Uid)2 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)2 XidImple (com.arjuna.ats.jta.xa.XidImple)2 BasicAction (com.arjuna.ats.arjuna.coordinator.BasicAction)1 RecoverAtomicAction (com.arjuna.ats.arjuna.recovery.RecoverAtomicAction)1 ActionBean (com.arjuna.ats.arjuna.tools.osb.mbean.ActionBean)1 LogRecordWrapper (com.arjuna.ats.arjuna.tools.osb.mbean.LogRecordWrapper)1 OSEntryBean (com.arjuna.ats.arjuna.tools.osb.mbean.OSEntryBean)1 ObjStoreBrowser (com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser)1 UidWrapper (com.arjuna.ats.arjuna.tools.osb.mbean.UidWrapper)1 AtomicActionRecoveryModule (com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule)1 JTANodeNameXAResourceOrphanFilter (com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter)1 XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)1 AtomicAction (com.arjuna.ats.internal.jta.transaction.arjunacore.AtomicAction)1 TransactionManagerImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple)1 SubordinateTransaction (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)1