Search in sources :

Example 1 with UidWrapper

use of com.arjuna.ats.arjuna.tools.osb.mbean.UidWrapper in project narayana by jbosstm.

the class ObjStoreBrowserTest method getTransactionBean.

private JTAActionBean getTransactionBean(ObjStoreBrowser osb, TransactionImple tx, boolean present) {
    // there should be one MBean corresponding to the Transaction tx
    UidWrapper w = osb.findUid(tx.get_uid());
    if (!present) {
        assertNull(w);
        return null;
    }
    assertNotNull(w);
    OSEntryBean ai = w.getMBean();
    assertNotNull(ai);
    // the MBean should wrap a JTAActionBean
    assertTrue(ai instanceof JTAActionBean);
    return (JTAActionBean) ai;
}
Also used : OSEntryBean(com.arjuna.ats.arjuna.tools.osb.mbean.OSEntryBean) UidWrapper(com.arjuna.ats.arjuna.tools.osb.mbean.UidWrapper) JTAActionBean(com.arjuna.ats.internal.jta.tools.osb.mbean.jta.JTAActionBean)

Example 2 with UidWrapper

use of com.arjuna.ats.arjuna.tools.osb.mbean.UidWrapper 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 UidWrapper

use of com.arjuna.ats.arjuna.tools.osb.mbean.UidWrapper in project narayana by jbosstm.

the class JTSXARTest method injectCommitException.

void injectCommitException(String exceptionType) throws Exception {
    XAFailureSpec fault = new XAFailureSpec("JTSXARTest", XAFailureMode.XAEXCEPTION, XAFailureType.XARES_COMMIT, exceptionType, 0);
    XAException xae = XAFailureResource.getXAExceptionType(exceptionType);
    int expectedXAE = xae == null ? HeuristicStatus.UNKNOWN_XA_ERROR_CODE : xae.errorCode;
    TransactionManagerImple tm = new TransactionManagerImple();
    Uid txUid;
    TransactionImple txn;
    // clean the thread that will create the transaction
    ThreadActionData.purgeActions();
    // begin a transaction
    tm.begin();
    txn = (TransactionImple) tm.getTransaction();
    txUid = txn.get_uid();
    // enlist two XA resources
    tm.getTransaction().enlistResource(new XAFailureResource());
    tm.getTransaction().enlistResource(new XAFailureResource(fault));
    // commit the transaction and check for any expected exceptions
    try {
        tm.commit();
    } catch (HeuristicRollbackException e) {
        if (!XAFailureSpec.compatibleHeuristics(XAException.XA_HEURRB, expectedXAE))
            throw e;
    } catch (RollbackException e) {
        if (!XAFailureSpec.compatibleHeuristics(XAException.XA_RBROLLBACK, expectedXAE))
            throw e;
    } catch (HeuristicMixedException e) {
        if (!XAFailureSpec.compatibleHeuristics(XAException.XA_HEURMIX, expectedXAE))
            throw e;
    } catch (SystemException e) {
        if (!XAFailureSpec.compatibleHeuristics(XAException.XAER_RMFAIL, expectedXAE))
            throw e;
    }
    // Validate that the correct MBeans were created to instrument the transaction and participants
    // and validate they have the correct heuristic status
    ObjStoreBrowser osb = createObjStoreBrowser(true);
    UidWrapper w = osb.findUid(txUid);
    assertNotNull(w);
    Set<UidWrapper> wrappers = validateChildBeans(osb, w.getName(), 1, expectedXAE);
    assertTrue(wrappers.size() > 0);
}
Also used : XAException(javax.transaction.xa.XAException) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) ObjStoreBrowser(com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser) Uid(com.arjuna.ats.arjuna.common.Uid) TransactionManagerImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionManagerImple) UidWrapper(com.arjuna.ats.arjuna.tools.osb.mbean.UidWrapper)

Example 4 with UidWrapper

use of com.arjuna.ats.arjuna.tools.osb.mbean.UidWrapper in project narayana by jbosstm.

the class JTSObjStoreBrowserTest method finishTest.

/*
	 * Make sure there is an MBean corresponding to A and that at least one of recs has a heuristic.
	 * Then either remove the action or replay (via the MBean) the record that got the heuristic
	 * checking that the MBeans have all been unregistered from the MBeanServer.
	 */
private void finishTest(TwoPhaseCoordinator A, boolean replay, ExtendedCrashRecord... recs) throws Exception {
    ObjStoreBrowser osb = createObjStoreBrowser(false);
    // there should now be an entry in the object store containing two participants
    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 (ExtendedCrashRecord rec : recs) {
        LogRecordWrapper lw = actionBean.getParticipant(rec);
        if (lw != null) {
            recCount += 1;
            if (lw.isHeuristic()) {
                if (replay) {
                    rec.forget();
                    lw.setStatus("PREPARED");
                    // the participant record should no longer be on the heuristic list
                    assertFalse(lw.isHeuristic());
                }
            }
        }
    }
    assertEquals(1, recCount);
    if (!replay) {
        actionBean.remove();
    } else {
        /*
			* prompt the recovery manager to have a go at replaying the record that was
			* moved off the heuristic list and back onto the prepared list
			*/
        recoveryManager.scan();
    }
    // another probe should no longer find the record that got the heuristic
    // (since it was either removed or the RecoveryManager replayed the commit
    // phase) so its corresponding MBean will have been unregistered
    osb.probe();
    // look up the MBean and verify that it no longer exists
    w = osb.findUid(A.get_uid());
    assertNull(w);
    osb.stop();
}
Also used : ExtendedCrashRecord(com.hp.mwtests.ts.jta.jts.common.ExtendedCrashRecord) OSEntryBean(com.arjuna.ats.arjuna.tools.osb.mbean.OSEntryBean) UidWrapper(com.arjuna.ats.arjuna.tools.osb.mbean.UidWrapper) ObjStoreBrowser(com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser) LogRecordWrapper(com.arjuna.ats.arjuna.tools.osb.mbean.LogRecordWrapper) ActionBean(com.arjuna.ats.arjuna.tools.osb.mbean.ActionBean)

Example 5 with UidWrapper

use of com.arjuna.ats.arjuna.tools.osb.mbean.UidWrapper in project narayana by jbosstm.

the class TestCommitMarkableResourceMBeansFailAfterPrepare method testObjStoreBrowser.

@Test
@BMScript("commitMarkableResourceFailAfterPrepare")
public void testObjStoreBrowser() throws Exception {
    final DataSource dataSource = new JdbcDataSource();
    ObjStoreBrowser osb = new ObjStoreBrowser();
    Uid uid = generateCMRRecord(dataSource);
    osb.start();
    osb.probe();
    // there should be one MBean corresponding to the Transaction
    UidWrapper w = osb.findUid(uid);
    assertNotNull("ObjStoreBrowser could not find CMR uid wrapper", w);
    OSEntryBean ai = w.getMBean();
    assertNotNull("ObjStoreBrowser could not find CMR uid", ai);
    assertEquals("ObjStoreBrowser found the wrong uid", ai.getUid(), uid);
    checkCMRRecovery(dataSource);
    w = osb.findUid(uid);
    assertNotNull("CMR uid still exists after a recovery can", w);
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) OSEntryBean(com.arjuna.ats.arjuna.tools.osb.mbean.OSEntryBean) UidWrapper(com.arjuna.ats.arjuna.tools.osb.mbean.UidWrapper) ObjStoreBrowser(com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) DataSource(javax.sql.DataSource) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Aggregations

UidWrapper (com.arjuna.ats.arjuna.tools.osb.mbean.UidWrapper)8 OSEntryBean (com.arjuna.ats.arjuna.tools.osb.mbean.OSEntryBean)5 ObjStoreBrowser (com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser)5 Uid (com.arjuna.ats.arjuna.common.Uid)4 ActionBean (com.arjuna.ats.arjuna.tools.osb.mbean.ActionBean)2 LogRecordWrapper (com.arjuna.ats.arjuna.tools.osb.mbean.LogRecordWrapper)2 JTAActionBean (com.arjuna.ats.internal.jta.tools.osb.mbean.jta.JTAActionBean)2 Test (org.junit.Test)2 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)1 AbstractRecord (com.arjuna.ats.arjuna.coordinator.AbstractRecord)1 RecordTypeMap (com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap)1 HeuristicStatus (com.arjuna.ats.arjuna.tools.osb.mbean.HeuristicStatus)1 OSBTypeHandler (com.arjuna.ats.arjuna.tools.osb.mbean.OSBTypeHandler)1 JCAServerTransactionHeaderReader (com.arjuna.ats.internal.jta.tools.osb.mbean.jts.JCAServerTransactionHeaderReader)1 TransactionImple (com.arjuna.ats.internal.jta.transaction.jts.TransactionImple)1 TransactionManagerImple (com.arjuna.ats.internal.jta.transaction.jts.TransactionManagerImple)1 CrashRecord (com.hp.mwtests.ts.arjuna.resources.CrashRecord)1 ExtendedCrashRecord (com.hp.mwtests.ts.jta.jts.common.ExtendedCrashRecord)1 HashSet (java.util.HashSet)1 DataSource (javax.sql.DataSource)1