Search in sources :

Example 11 with HeuristicHazard

use of org.omg.CosTransactions.HeuristicHazard 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 12 with HeuristicHazard

use of org.omg.CosTransactions.HeuristicHazard in project narayana by jbosstm.

the class JTSObjStoreBrowserTest method jtsReplayTest.

/**
 * Similar to aaReplayTest but uses a JTS transaction instead of an AtomicAction
 * @throws Exception if test fails unexpectedly
 */
// TODO for replay to work on JTS participants ExtendedCrashReocrd needs to extend XAResourceRecord
// TODO @Test
public void jtsReplayTest() throws Exception {
    ArjunaTransactionImple A = new ArjunaTransactionImple(null);
    ExtendedCrashRecord[] recs = startTest(A);
    int outcome = ActionStatus.COMMITTED;
    try {
        A.commit(true);
    } catch (HeuristicHazard e) {
        outcome = ActionStatus.H_HAZARD;
    }
    assertEquals(ActionStatus.H_HAZARD, outcome);
    finishTest(A, true, recs);
}
Also used : ExtendedCrashRecord(com.hp.mwtests.ts.jta.jts.common.ExtendedCrashRecord) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard)

Example 13 with HeuristicHazard

use of org.omg.CosTransactions.HeuristicHazard in project narayana by jbosstm.

the class JTSObjStoreBrowserTest method jtsRemoveTest.

/**
 * Similar to aaRemoveTest but uses a JTS transaction instead of an AtomicAction
 * @throws Exception if test fails unexpectedly
 */
@Test
public void jtsRemoveTest() throws Exception {
    ArjunaTransactionImple A = new ArjunaTransactionImple(null);
    ExtendedCrashRecord[] recs = startTest(A);
    int outcome = ActionStatus.COMMITTED;
    try {
        A.commit(true);
    } catch (HeuristicHazard e) {
        outcome = ActionStatus.H_HAZARD;
    }
    assertEquals(ActionStatus.H_HAZARD, outcome);
    finishTest(A, false, recs);
}
Also used : ExtendedCrashRecord(com.hp.mwtests.ts.jta.jts.common.ExtendedCrashRecord) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard) Test(org.junit.Test)

Example 14 with HeuristicHazard

use of org.omg.CosTransactions.HeuristicHazard in project narayana by jbosstm.

the class JTSObjStoreBrowserTest method jtsMBeanTest.

/**
 * Test that MBeans corresponding to JTS record types are created
 * @throws Exception
 */
@Test
public void jtsMBeanTest() throws Exception {
    ArjunaTransactionImple A = new ArjunaTransactionImple(null);
    startTest(A);
    try {
        A.commit(true);
        fail("transaction commit should have produced a heuristic hazzard");
    } catch (HeuristicHazard e) {
    }
    // start an mbean server and object store browser
    createObjStoreBrowser(true);
    // there should now be an MBean entry corresponding to a JTS record, read it via JMX:
    MBeanServer mbs = JMXServer.getAgent().getServer();
    Set<ObjectInstance> transactions = mbs.queryMBeans(new ObjectName("jboss.jta:type=ObjectStore,*"), null);
    boolean foundJTSType = false;
    Pattern pattern = Pattern.compile("itype=(.*?),");
    for (ObjectInstance oi : transactions) {
        String id = oi.getObjectName().getCanonicalName();
        Matcher matcher = pattern.matcher(id);
        while (matcher.find()) // matched type is in matcher.group(1)
        foundJTSType = true;
    }
    assertTrue("MBean for JTS record type not found", foundJTSType);
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) ObjectInstance(javax.management.ObjectInstance) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 15 with HeuristicHazard

use of org.omg.CosTransactions.HeuristicHazard in project narayana by jbosstm.

the class CurrentImple method commit.

/**
 * It's not possible to commit/abort out of order using the current
 * interface.
 *
 * Do we delete the control if the transaction gives an heuristic result?
 * CurrentImplely we do.
 *
 * If another thread has already terminated the transaction then: (i) if it
 * committed, we do nothing - could throw TransactionRequired of
 * INVALID_TRANSACTION, or NoTransaction. Probably not NoTransaction, since
 * it would be better to distinguish between the situation where the
 * transaction has already been terminated and there really is no
 * transaction for this thread. (ii) if it rolledback, we throw
 * TRANSACTION_ROLLEDBACK.
 */
public void commit(boolean report_heuristics) throws NoTransaction, HeuristicMixed, HeuristicHazard, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("CurrentImple::commit ( " + report_heuristics + " )");
    }
    ControlWrapper currentAction = _theManager.current();
    if (currentAction != null) {
        try {
            ThreadAssociationControl.updateAssociation(currentAction, TX_COMMITTED);
        } catch (Exception e) {
            /*
				 * An error happened, so mark the transaction as rollback only
				 * (in case it hasn't already been so marked.)
				 */
            rollback_only();
        }
        try {
            currentAction.commit(report_heuristics);
            _theManager.popAction();
        } catch (TRANSACTION_ROLLEDBACK e1) {
            /*
				 * Is ok to destroy transaction. Different for heuristics.
				 */
            _theManager.popAction();
            throw e1;
        } catch (HeuristicMixed e2) {
            _theManager.popAction();
            if (report_heuristics)
                throw e2;
        } catch (HeuristicHazard e3) {
            _theManager.popAction();
            if (report_heuristics)
                throw e3;
        } catch (SystemException e4) {
            _theManager.popAction();
            throw e4;
        } catch (Unavailable e5) {
            /*
				 * If terminated by some other thread then the reference we have
				 * will no longer be valid.
				 */
            _theManager.popAction();
            throw new INVALID_TRANSACTION();
        }
    } else
        throw new NoTransaction();
}
Also used : NoTransaction(org.omg.CosTransactions.NoTransaction) SystemException(org.omg.CORBA.SystemException) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) SystemException(org.omg.CORBA.SystemException) UserException(org.omg.CORBA.UserException) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard) SubtransactionsUnavailable(org.omg.CosTransactions.SubtransactionsUnavailable) Unavailable(org.omg.CosTransactions.Unavailable)

Aggregations

HeuristicHazard (org.omg.CosTransactions.HeuristicHazard)19 SystemException (org.omg.CORBA.SystemException)13 HeuristicMixed (org.omg.CosTransactions.HeuristicMixed)12 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)11 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)7 ServerTransaction (com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction)5 Test (org.junit.Test)5 ArjunaTransactionImple (com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple)4 UNKNOWN (org.omg.CORBA.UNKNOWN)4 NoTransaction (org.omg.CosTransactions.NoTransaction)4 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)3 NotSerializableException (java.io.NotSerializableException)3 XAException (javax.transaction.xa.XAException)3 NotPrepared (org.omg.CosTransactions.NotPrepared)3 ORB (com.arjuna.orbportability.ORB)2 RootOA (com.arjuna.orbportability.RootOA)2 ExtendedCrashRecord (com.hp.mwtests.ts.jta.jts.common.ExtendedCrashRecord)2 AtomicResource (com.hp.mwtests.ts.jts.orbspecific.resources.AtomicResource)2 Control (org.omg.CosTransactions.Control)2 Coordinator (org.omg.CosTransactions.Coordinator)2