use of com.hp.mwtests.ts.jts.orbspecific.resources.DemoSubTranResource in project narayana by jbosstm.
the class NestedTester method test.
@Test
public void test() {
boolean registerSubtran = false;
boolean doAbort = false;
DemoResource r = null;
DemoSubTranResource sr = null;
ORB myORB = null;
RootOA myOA = null;
try {
myORB = ORB.getInstance("test");
myOA = OA.getRootOA(myORB);
myORB.initORB(new String[] {}, null);
myOA.initOA();
ORBManager.setORB(myORB);
ORBManager.setPOA(myOA);
org.omg.CosTransactions.Current current = OTSManager.get_current();
r = new DemoResource();
sr = new DemoSubTranResource();
current.begin();
current.begin();
current.begin();
sr.registerResource(registerSubtran);
r.registerResource();
System.out.println("committing first nested transaction");
current.commit(true);
System.out.println("committing second nested transaction");
current.commit(true);
if (!doAbort) {
System.out.println("committing top-level transaction");
current.commit(true);
} else {
System.out.println("aborting top-level transaction");
current.rollback();
}
System.out.println("Test completed successfully.");
if ((!doAbort) && (!registerSubtran) && (sr.getNumberOfSubtransactionsRolledBack() == 0) && (sr.getNumberOfSubtransactionsCommitted() == 1) && (sr.getResourceTrace().getTrace() == ResourceTrace.ResourceTracePrepareCommit) && (r.getResourceTrace().getTrace() == ResourceTrace.ResourceTracePrepareCommit)) {
// assertSuccess();
} else {
if ((doAbort) && (!registerSubtran) && (sr.getNumberOfSubtransactionsRolledBack() == 0) && (sr.getNumberOfSubtransactionsCommitted() == 1) && (sr.getResourceTrace().getTrace() == ResourceTrace.ResourceTraceRollback) && (r.getResourceTrace().getTrace() == ResourceTrace.ResourceTraceRollback)) {
// assertSuccess();
} else {
if ((!doAbort) && (registerSubtran) && (sr.getNumberOfSubtransactionsRolledBack() == 0) && (sr.getNumberOfSubtransactionsCommitted() == 1) && (sr.getResourceTrace().getTrace() == ResourceTrace.ResourceTraceNone) && (r.getResourceTrace().getTrace() == ResourceTrace.ResourceTraceCommitOnePhase)) {
// assertSuccess();
} else {
if ((doAbort) && (registerSubtran) && (sr.getNumberOfSubtransactionsRolledBack() == 0) && (sr.getNumberOfSubtransactionsCommitted() == 1) && (sr.getResourceTrace().getTrace() == ResourceTrace.ResourceTraceNone) && (r.getResourceTrace().getTrace() == ResourceTrace.ResourceTraceRollback)) {
// assertSuccess();
} else
fail();
}
}
}
} catch (UserException e) {
fail("Caught UserException: " + e);
e.printStackTrace(System.err);
} catch (SystemException e) {
fail("Caught SystemException: " + e);
e.printStackTrace(System.err);
}
myOA.shutdownObject(r);
myOA.shutdownObject(sr);
myOA.destroy();
myORB.shutdown();
}
use of com.hp.mwtests.ts.jts.orbspecific.resources.DemoSubTranResource in project narayana by jbosstm.
the class AtomicTransactionUnitTest method testCommit.
@Test
public void testCommit() throws Exception {
AtomicTransaction A = new AtomicTransaction();
A.begin();
assertTrue(A.get_txcontext() != null);
A.registerResource(new DemoResource().getResource());
AtomicTransaction B = new AtomicTransaction();
B.begin();
B.registerSubtranAware(new DemoSubTranResource().getReference());
B.commit(true);
A.commit(true);
A = new AtomicTransaction();
A.begin();
A.rollbackOnly();
try {
A.commit(true);
fail();
} catch (final TRANSACTION_ROLLEDBACK ex) {
}
}
Aggregations