use of com.arjuna.ats.internal.jta.transaction.jts.TransactionImple 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());
}
use of com.arjuna.ats.internal.jta.transaction.jts.TransactionImple in project narayana by jbosstm.
the class JtsTransactionImple method controlToTx.
/**
* Convert an IOR representing an OTS transaction into a JTA transaction
*
* @param orb
*
* @param ior the CORBA reference for the OTS transaction
* @return a JTA transaction that wraps the OTS transaction
*/
private static Transaction controlToTx(String ior) {
log.debug("controlToTx: ior: " + ior);
ControlWrapper cw = createControlWrapper(ior);
TransactionImple tx = (TransactionImple) TransactionImple.getTransactions().get(cw.get_uid());
if (tx == null) {
log.debug("controlToTx: creating a new tx - wrapper: " + cw);
tx = new JtsTransactionImple(cw);
putTransaction(tx);
}
return tx;
}
use of com.arjuna.ats.internal.jta.transaction.jts.TransactionImple in project narayana by jbosstm.
the class Client01 method main.
public static void main(String[] args) {
int crashIn = Resource01.NOCRASH;
;
if (args.length >= 1) {
if (args[0].startsWith("p") || args[0].startsWith("P")) {
crashIn = Resource01.PREPARE;
}
if (args[0].startsWith("c") || args[0].startsWith("C")) {
crashIn = Resource01.COMMIT;
}
if (args[0].startsWith("r") || args[0].startsWith("R")) {
crashIn = Resource01.ROLLBACK;
}
}
if (args.length >= 2) {
resultsFile = args[1];
}
try {
ORB myORB = ORB.getInstance("Client01");
RootOA myOA = OA.getRootOA(myORB);
myORB.initORB(args, null);
myOA.initOA();
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Failed");
}
System.out.println("Ready");
try {
UserTransaction ut = com.arjuna.ats.jta.UserTransaction.userTransaction();
ut.begin();
TransactionImple txImple = (TransactionImple) TransactionManager.transactionManager().getTransaction();
txImple.enlistResource(new Resource01(crashIn, resultsFile));
txImple.enlistResource(new Resource02());
ut.commit();
System.out.println("Passed");
} catch (javax.transaction.RollbackException rbx) {
System.out.println("Passed");
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Failed");
}
}
Aggregations