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));
}
}
}
}
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);
}
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);
}
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);
}
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();
}
Aggregations