use of com.hp.mwtests.ts.jts.orbspecific.resources.DemoResource in project narayana by jbosstm.
the class AsyncTest method test.
@Test
public void test() throws Exception {
boolean errorp = false;
boolean errorc = false;
ServerORB orb = new ServerORB();
ORB myORB = orb.getORB();
RootOA myOA = orb.getOA();
try {
Current current = OTSManager.get_current();
DemoResource.printThread = true;
current.begin();
for (int j = 0; j < 100; j++) {
if ((j == 10) && (errorp || errorc)) {
boolean heuristicPrepare = errorp;
heuristic h = new heuristic(heuristicPrepare);
current.get_control().get_coordinator().register_resource(h.getReference());
h = null;
}
DemoResource r = new DemoResource();
r.registerResource();
r = null;
}
System.out.println("committing top-level transaction");
current.commit(false);
System.out.println("Test completed.");
} catch (org.omg.CORBA.TRANSACTION_ROLLEDBACK e) {
System.out.println("Caught exception: " + e);
assertTrue(errorp || errorc);
}
myOA.destroy();
myORB.shutdown();
}
use of com.hp.mwtests.ts.jts.orbspecific.resources.DemoResource 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.DemoResource 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) {
}
}
use of com.hp.mwtests.ts.jts.orbspecific.resources.DemoResource in project narayana by jbosstm.
the class ResourceRecordUnitTest method test.
@Test
public void test() throws Exception {
DemoResource res = new DemoResource();
ResourceRecord rec = new ResourceRecord(false, res.getResource(), new Uid());
PrintWriter writer = new PrintWriter(new ByteArrayOutputStream());
rec.print(writer);
assertTrue(rec.resourceHandle() != null);
OutputObjectState os = new OutputObjectState();
assertTrue(rec.save_state(os, ObjectType.ANDPERSISTENT));
InputObjectState is = new InputObjectState(os);
assertTrue(rec.restore_state(is, ObjectType.ANDPERSISTENT));
}
use of com.hp.mwtests.ts.jts.orbspecific.resources.DemoResource in project narayana by jbosstm.
the class RecoveredTransactionReplayerUnitTest method testCommitted.
@Test
public void testCommitted() throws Exception {
/*
* Deliberately choose a Uid that doesn't represent a state
* on disk.
*
* Use un-threaded.
*/
Uid dummyUid = new Uid();
String dummyState = "/StateManager/DummyState";
RecoveredTransactionReplayer replayer = new RecoveredTransactionReplayer(dummyUid, dummyState);
DemoResource res = new DemoResource();
assertTrue(RecoveredTransactionReplayer.isPresent(dummyUid) != null);
replayer.swapResource(dummyUid, res.getResource());
replayer.run();
assertTrue(RecoveredTransactionReplayer.isPresent(dummyUid) == null);
}
Aggregations