use of com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple in project narayana by jbosstm.
the class ServerTopLevelOSIActionUnitTest method testCommitOnePhase.
@Test
public void testCommitOnePhase() throws Exception {
ControlImple cont = new ControlImple(null, null);
Control theControl = cont.getControl();
ArjunaTransactionImple tx = cont.getImplHandle();
ServerControl sc = new ServerControl(tx.get_uid(), theControl, tx, theControl.get_coordinator(), theControl.get_terminator());
ServerOSITopLevelAction act = new ServerOSITopLevelAction(sc, true);
act.commit_one_phase();
assertTrue(act.type() != null);
}
use of com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple in project narayana by jbosstm.
the class ServerTopLevelOSIActionUnitTest method testRollback.
@Test
public void testRollback() throws Exception {
ControlImple cont = new ControlImple(null, null);
Control theControl = cont.getControl();
ArjunaTransactionImple tx = cont.getImplHandle();
ServerControl sc = new ServerControl(tx.get_uid(), theControl, tx, theControl.get_coordinator(), theControl.get_terminator());
ServerOSITopLevelAction act = new ServerOSITopLevelAction(sc, true);
assertEquals(act.prepare(), Vote.VoteReadOnly);
try {
act.rollback();
fail();
} catch (final INVALID_TRANSACTION ex) {
}
act.forget();
}
use of com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple 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 com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple 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 com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple in project narayana by jbosstm.
the class JTSInterpositionSynchronizationTest method test.
@Test
public void test() throws Exception {
InterpositionCreator creator = new InterpositionCreator();
jtaPropertyManager.getJTAEnvironmentBean().setTransactionManagerClassName(com.arjuna.ats.internal.jta.transaction.jts.TransactionManagerImple.class.getName());
jtaPropertyManager.getJTAEnvironmentBean().setUserTransactionClassName(com.arjuna.ats.internal.jta.transaction.jts.UserTransactionImple.class.getName());
jtsPropertyManager.getJTSEnvironmentBean().setSupportInterposedSynchronization(true);
javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
tm.setTransactionTimeout(1000000);
tm.begin();
TransactionImple transaction = (TransactionImple) tm.getTransaction();
transaction.enlistResource(new XAResource() {
@Override
public int prepare(Xid arg0) throws XAException {
prepareCalled = true;
beforeCompletionCalledFirst = beforeCompletionCalled;
return 0;
}
@Override
public void commit(Xid arg0, boolean arg1) throws XAException {
}
@Override
public void end(Xid arg0, int arg1) throws XAException {
}
@Override
public void forget(Xid arg0) throws XAException {
}
@Override
public int getTransactionTimeout() throws XAException {
return 0;
}
@Override
public boolean isSameRM(XAResource arg0) throws XAException {
return false;
}
@Override
public Xid[] recover(int arg0) throws XAException {
return null;
}
@Override
public void rollback(Xid arg0) throws XAException {
}
@Override
public boolean setTransactionTimeout(int arg0) throws XAException {
return false;
}
@Override
public void start(Xid arg0, int arg1) throws XAException {
}
});
ControlWrapper controlWrapper = transaction.getControlWrapper();
Uid get_uid = transaction.get_uid();
ControlImple cont = controlWrapper.getImple();
ArjunaTransactionImple tx = cont.getImplHandle();
CurrentImple current = OTSImpleManager.current();
Control get_control = current.get_control();
PropagationContext ctx = cont.get_coordinator().get_txcontext();
ControlImple recreateLocal = creator.recreateLocal(ctx);
assertTrue(recreateLocal != null);
Control recreate = creator.recreate(ctx);
assertTrue(recreate != null);
Object remove = ControlImple.allControls.remove(get_uid);
ServerControl sc = new ServerControl(get_uid, get_control, null, cont.get_coordinator(), cont.get_terminator());
ControlImple.allControls.put(get_uid, remove);
ServerTopLevelAction serverTopLevelAction = new ServerTopLevelAction(sc);
sc.getImplHandle().register_synchronization(new ManagedSynchronizationImple(new Synchronization() {
@Override
public void beforeCompletion() {
beforeCompletionCalled = true;
}
@Override
public void afterCompletion(int status) {
afterCompletionCalled = true;
}
}).getSynchronization());
transaction.commit();
assertTrue(prepareCalled == true);
assertTrue(beforeCompletionCalled);
assertTrue(afterCompletionCalled);
assertTrue(beforeCompletionCalledFirst == jtsPropertyManager.getJTSEnvironmentBean().isSupportInterposedSynchronization());
}
Aggregations