Search in sources :

Example 1 with TransactionFactoryImple

use of com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple in project narayana by jbosstm.

the class TransactionFactoryUnitTest method testContext.

@Test
public void testContext() throws Exception {
    TransactionFactoryImple factory = new TransactionFactoryImple("test");
    ControlImple tx = factory.createLocal(1000);
    org.omg.CosTransactions.otid_t txId = Utility.uidToOtid(tx.get_uid());
    Uid theUid = Utility.otidToUid(txId);
    assertEquals(theUid, tx.get_uid());
    // no state in OS yet!
    assertEquals(factory.getOSStatus(tx.get_uid()), org.omg.CosTransactions.Status.StatusNoTransaction);
    PropagationContext ctx = tx.get_coordinator().get_txcontext();
    Control cont = factory.recreate(ctx);
    String toString = Utility.getHierarchy(ctx);
    System.out.println(toString);
    assertTrue(toString != null);
    assertTrue(toString.length() > 1);
    assertTrue(Utility.getUid(cont).equals(tx.get_uid()));
    try {
        tx.getImplHandle().rollback();
    } catch (final Throwable ex) {
    }
}
Also used : CosTransactions.otid_t(org.omg.CosTransactions.otid_t) Uid(com.arjuna.ats.arjuna.common.Uid) Control(org.omg.CosTransactions.Control) PropagationContext(org.omg.CosTransactions.PropagationContext) TransactionFactoryImple(com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) Test(org.junit.Test)

Example 2 with TransactionFactoryImple

use of com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple in project narayana by jbosstm.

the class TransactionFactoryImpleUnitTest method before.

@Before
public void before() {
    clearObjectStore();
    transactionFactory = new TransactionFactoryImple();
}
Also used : TransactionFactoryImple(com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple) Before(org.junit.Before)

Example 3 with TransactionFactoryImple

use of com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple in project narayana by jbosstm.

the class ServerControlWrapperUnitTest method testNested.

@Test
public void testNested() throws Exception {
    TransactionFactoryImple imple = new TransactionFactoryImple("test");
    ControlImple tx = imple.createLocal(1000);
    ServerControlWrapper wrap = new ServerControlWrapper(tx);
    ControlWrapper sub = wrap.create_subtransaction();
    assertTrue(sub != null);
    assertEquals(sub.cancel(), ActionStatus.ABORTED);
}
Also used : ServerControlWrapper(com.arjuna.ats.internal.jts.interposition.ServerControlWrapper) ServerControlWrapper(com.arjuna.ats.internal.jts.interposition.ServerControlWrapper) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) TransactionFactoryImple(com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) Test(org.junit.Test)

Example 4 with TransactionFactoryImple

use of com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple in project narayana by jbosstm.

the class ExplicitInterposition method registerTransaction.

private final synchronized void registerTransaction(PropagationContext ctx) throws InterpositionFailed, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ExplicitInterposition::registerTransaction ( PropagationContext ctx )");
    }
    if (_inUse) {
        jtsLogger.i18NLogger.warn_excalledagain("ExplicitInterposition.registerTransaction");
        throw new InterpositionFailed();
    }
    if (// invalid
    (ctx == null) || (ctx.current.coord == null))
        throw new INVALID_TRANSACTION(ExceptionCodes.INVALID_ACTION, CompletionStatus.COMPLETED_NO);
    _inUse = true;
    TransactionFactoryImple _localFactory = OTSImpleManager.factory();
    try {
        ControlImple cont = _localFactory.recreateLocal(ctx);
        CurrentImple current = OTSImpleManager.current();
        if (_remember) {
            try {
                _oldControl = current.suspendWrapper();
            } catch (Exception e) {
                throw new InterpositionFailed();
            }
        }
        current.resumeImple(cont);
        // current.resume(cont.getControl());
        cont = null;
    } catch (InterpositionFailed ex) {
        throw ex;
    } catch (Exception e) {
        jtsLogger.i18NLogger.warn_eicaughtexception("ExplicitInterposition.registerTransaction(PropagationContext)", e);
        throw new InterpositionFailed();
    }
}
Also used : InterpositionFailed(com.arjuna.ArjunaOTS.InterpositionFailed) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) TransactionFactoryImple(com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) SystemException(org.omg.CORBA.SystemException)

Example 5 with TransactionFactoryImple

use of com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple in project narayana by jbosstm.

the class GridTest method test.

@Test
public void test() {
    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);
        TransactionFactoryImple theOTS = new TransactionFactoryImple();
        Control myControl;
        grid_i localGrid = new grid_i(100, 100);
        int h, w, v;
        myControl = theOTS.create(0);
        assertNotNull(myControl);
        h = localGrid.height();
        w = localGrid.width();
        localGrid.set(2, 4, 123, myControl);
        v = localGrid.get(2, 4, myControl);
        // no problem setting and getting the elememt:
        System.out.println("grid[2,4] is " + v);
        assertEquals(123, v);
        Terminator handle = myControl.get_terminator();
        try {
            if (handle != null) {
                handle.commit(false);
            } else
                System.err.println("Error - no transaction terminator!");
        } catch (Exception ex) {
            System.out.println("Test error! Caught: " + ex);
        }
        ORBManager.getPOA().shutdownObject(theOTS);
        ORBManager.getPOA().shutdownObject(localGrid);
    } catch (UserException e) {
        fail("Caught UserException: " + e);
        e.printStackTrace();
    } catch (SystemException e) {
        fail("Caught SystemException: " + e);
        e.printStackTrace();
    }
    System.out.println("\nWill now try different thread terminating transaction.\n");
    try {
        org.omg.CosTransactions.Current current = OTSManager.get_current();
        System.out.println("Starting new transaction.");
        current.begin();
        Control tc = current.get_control();
        if (tc != null) {
            System.out.println("Creating new thread.");
            TransactionalThread tranThread = new TransactionalThread(tc);
            System.out.println("Waiting for thread to terminate transaction.\n");
            tranThread.start();
            while (!tranThread.finished()) Thread.yield();
            System.out.println("\nCreator will now attempt to rollback transaction. Should fail.");
            try {
                current.rollback();
                fail("Error - managed to rollback transaction!");
            } catch (NoTransaction e1) {
                System.out.println("Correct termination - caught: " + e1);
            } catch (INVALID_TRANSACTION e2) {
                System.out.println("Correct termination - caught: " + e2);
            } catch (Exception e3) {
                fail("Wrong termination - caught unexpected exception: " + e3);
                e3.printStackTrace();
            }
            System.out.println("Test completed successfully.");
        } else
            System.err.println("Error - null transaction control!");
    } catch (Exception e) {
        System.out.println("Caught unexpected exception: " + e);
    }
    myOA.destroy();
    myORB.shutdown();
}
Also used : TransactionalThread(com.hp.mwtests.ts.jts.resources.TransactionalThread) NoTransaction(org.omg.CosTransactions.NoTransaction) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) RootOA(com.arjuna.orbportability.RootOA) Terminator(org.omg.CosTransactions.Terminator) com.hp.mwtests.ts.jts.orbspecific.resources.grid_i(com.hp.mwtests.ts.jts.orbspecific.resources.grid_i) SystemException(org.omg.CORBA.SystemException) UserException(org.omg.CORBA.UserException) Control(org.omg.CosTransactions.Control) SystemException(org.omg.CORBA.SystemException) TransactionFactoryImple(com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple) UserException(org.omg.CORBA.UserException) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Aggregations

TransactionFactoryImple (com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple)15 Test (org.junit.Test)12 ControlImple (com.arjuna.ats.internal.jts.orbspecific.ControlImple)10 Control (org.omg.CosTransactions.Control)6 SystemException (org.omg.CORBA.SystemException)4 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)3 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)3 UserException (org.omg.CORBA.UserException)3 GlobalTransactionInfo (com.arjuna.ArjunaOTS.GlobalTransactionInfo)2 Uid (com.arjuna.ats.arjuna.common.Uid)2 ServerControlWrapper (com.arjuna.ats.internal.jts.interposition.ServerControlWrapper)2 ORB (com.arjuna.orbportability.ORB)2 RootOA (com.arjuna.orbportability.RootOA)2 NoTransaction (org.omg.CosTransactions.NoTransaction)2 PropagationContext (org.omg.CosTransactions.PropagationContext)2 Status (org.omg.CosTransactions.Status)2 Terminator (org.omg.CosTransactions.Terminator)2 CosTransactions.otid_t (org.omg.CosTransactions.otid_t)2 InterpositionFailed (com.arjuna.ArjunaOTS.InterpositionFailed)1 TransactionInfo (com.arjuna.ArjunaOTS.TransactionInfo)1