Search in sources :

Example 21 with RootOA

use of com.arjuna.orbportability.RootOA in project narayana by jbosstm.

the class ThreadedCommit method test.

@Test
public void test() throws Exception {
    ORB myORB = null;
    RootOA myOA = null;
    myORB = ORB.getInstance("test");
    myOA = OA.getRootOA(myORB);
    myORB.initORB(new String[] {}, null);
    myOA.initOA();
    ORBManager.setORB(myORB);
    ORBManager.setPOA(myOA);
    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());
    javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
    if (tm != null) {
        System.out.println("Starting top-level transaction.");
        tm.begin();
        javax.transaction.Transaction theTransaction = tm.suspend();
        TWorker worker1 = new TWorker(theTransaction, null);
        TWorker worker2 = new TWorker(theTransaction, worker1);
        worker2.start();
        worker1.start();
        worker1.join();
        worker2.join();
        assertTrue(worker1.success());
        assertTrue(worker2.success());
    } else {
        fail("Error - could not get transaction manager!");
    }
    myOA.destroy();
    myORB.shutdown();
}
Also used : Transaction(javax.transaction.Transaction) RootOA(com.arjuna.orbportability.RootOA) TransactionManager(javax.transaction.TransactionManager) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 22 with RootOA

use of com.arjuna.orbportability.RootOA in project narayana by jbosstm.

the class JTAAbort method test.

@Test
public void test() throws Exception {
    ORB myORB = null;
    RootOA myOA = null;
    myORB = ORB.getInstance("test");
    myOA = OA.getRootOA(myORB);
    myORB.initORB(new String[] {}, null);
    myOA.initOA();
    ORBManager.setORB(myORB);
    ORBManager.setPOA(myOA);
    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());
    javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
    System.out.println("Starting top-level transaction.");
    tm.begin();
    javax.transaction.Transaction theTransaction = tm.getTransaction();
    System.out.println("\nRolling back transaction.");
    theTransaction.rollback();
    System.out.println("\nTransaction now: " + theTransaction);
    System.out.println("\nThread associated: " + JTAHelper.stringForm(tm.getStatus()));
    theTransaction = tm.suspend();
    System.out.println("\nSuspended: " + theTransaction);
    tm.resume(theTransaction);
    myOA.destroy();
    myORB.shutdown();
}
Also used : RootOA(com.arjuna.orbportability.RootOA) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 23 with RootOA

use of com.arjuna.orbportability.RootOA in project narayana by jbosstm.

the class JTATest method test.

@Test
public void test() throws Exception {
    ORB myORB = null;
    RootOA myOA = null;
    myORB = ORB.getInstance("test");
    myOA = OA.getRootOA(myORB);
    myORB.initORB(new String[] {}, null);
    myOA.initOA();
    ORBManager.setORB(myORB);
    ORBManager.setPOA(myOA);
    String xaResource = "com.hp.mwtests.ts.jta.common.DummyCreator";
    String connectionString = null;
    boolean tmCommit = true;
    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());
    try {
        XACreator creator = (XACreator) Thread.currentThread().getContextClassLoader().loadClass(xaResource).newInstance();
        XAResource theResource = creator.create(connectionString, true);
        if (theResource == null) {
            fail("Error - creator " + xaResource + " returned null resource.");
        }
        javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
        if (tm != null) {
            System.out.println("Starting top-level transaction.");
            tm.begin();
            javax.transaction.Transaction theTransaction = tm.getTransaction();
            if (theTransaction != null) {
                System.out.println("\nTrying to register resource with transaction.");
                if (!theTransaction.enlistResource(theResource)) {
                    tm.rollback();
                    fail("Error - could not enlist resource in transaction!");
                } else
                    System.out.println("\nResource enlisted successfully.");
                /*
		     * XA does not support subtransactions.
		     * By default we ignore any attempts to create such
		     * transactions. Appropriate settings can be made which
		     * will cause currently running transactions to also
		     * rollback, if required.
		     */
                System.out.println("\nTrying to start another transaction - should fail!");
                try {
                    tm.begin();
                    fail("Error - transaction started!");
                } catch (Exception e) {
                    System.out.println("Transaction did not begin: " + e);
                }
                /*
		     * Do some work and decide whether to commit or rollback.
		     * (Assume commit for example.)
		     */
                com.hp.mwtests.ts.jta.jts.common.Synchronization s = new com.hp.mwtests.ts.jta.jts.common.Synchronization();
                tm.getTransaction().registerSynchronization(s);
                System.out.println("\nCommitting transaction.");
                if (tmCommit)
                    System.out.println("Using transaction manager.\n");
                else
                    System.out.println("Using transaction.\n");
                if (tmCommit)
                    tm.commit();
                else
                    tm.getTransaction().commit();
            } else {
                tm.rollback();
                fail("Error - could not get transaction!");
            }
            System.out.println("\nTest completed successfully.");
        } else
            System.err.println("Error - could not get transaction manager!");
    } catch (Exception e) {
        e.printStackTrace();
    }
    myOA.destroy();
    myORB.shutdown();
}
Also used : RootOA(com.arjuna.orbportability.RootOA) XAResource(javax.transaction.xa.XAResource) XACreator(com.hp.mwtests.ts.jta.jts.common.XACreator) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 24 with RootOA

use of com.arjuna.orbportability.RootOA in project narayana by jbosstm.

the class SuspendResume method test.

@Test
public void test() throws Exception {
    ORB myORB = null;
    RootOA myOA = null;
    myORB = ORB.getInstance("test");
    myOA = OA.getRootOA(myORB);
    myORB.initORB(new String[] {}, null);
    myOA.initOA();
    ORBManager.setORB(myORB);
    ORBManager.setPOA(myOA);
    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());
    try {
        javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
        System.out.println("Starting top-level transaction.");
        tm.begin();
        javax.transaction.Transaction theTransaction = tm.getTransaction();
        if (theTransaction != null) {
            tm.commit();
            tm.resume(theTransaction);
        } else {
            tm.rollback();
            fail("Error - could not get transaction!");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    myOA.destroy();
    myORB.shutdown();
}
Also used : RootOA(com.arjuna.orbportability.RootOA) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 25 with RootOA

use of com.arjuna.orbportability.RootOA 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

ORB (com.arjuna.orbportability.ORB)70 RootOA (com.arjuna.orbportability.RootOA)70 Test (org.junit.Test)49 ServerORB (com.hp.mwtests.ts.jts.utils.ServerORB)20 Services (com.arjuna.orbportability.Services)18 Control (org.omg.CosTransactions.Control)18 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)9 SystemException (org.omg.CORBA.SystemException)7 IntHolder (org.omg.CORBA.IntHolder)6 UserException (org.omg.CORBA.UserException)5 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)4 Terminator (org.omg.CosTransactions.Terminator)4 AtomicObject (com.hp.mwtests.ts.jts.orbspecific.resources.AtomicObject)3 Coordinator (org.omg.CosTransactions.Coordinator)3 Status (org.omg.CosTransactions.Status)3 TransactionFactory (org.omg.CosTransactions.TransactionFactory)3 TransactionFactoryImple (com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple)2 TestResource (com.hp.mwtests.ts.jta.jts.common.TestResource)2 XACreator (com.hp.mwtests.ts.jta.jts.common.XACreator)2 SetGet (com.hp.mwtests.ts.jts.TestModule.SetGet)2