Package org.apache.tuscany.sca.policy.transaction.runtime

Examples of org.apache.tuscany.sca.policy.transaction.runtime.TransactionManagerHelper


    public void testHelper() throws Exception {
        TransactionManagerWrapper activator = new TransactionManagerWrapper();
        activator.start();
        TransactionManager tm = activator.getTransactionManager();
        // GeronimoUserTransaction tx = new GeronimoUserTransaction(tm);
        TransactionManagerHelper helper = new TransactionManagerHelper(tm);

        // No TX yet
        assertNull(tm.getTransaction());
        Transaction t1 = helper.managedGlobalTransactionPreInvoke();
        // Should create T1
        assertNotNull(t1);
        // The current TX should be T1
        assertSame(t1, tm.getTransaction());
       
        XAResource res1 = new MockXAResource("Derby", "001");
        XAResource res2 = new MockXAResource("DB2", "002");
        tm.getTransaction().enlistResource(res1);
        tm.getTransaction().enlistResource(res2);

        Transaction suspended = helper.suspendsTransactionPreInvoke();
        suspended.delistResource(res1, XAResource.TMSUSPEND);
        suspended.delistResource(res2, XAResource.TMSUSPEND);
      
        // T1 is suspended
        assertSame(t1, suspended);
        // No more active TX
        assertNull(tm.getTransaction());

        Transaction t2 = helper.managedGlobalTransactionPreInvoke();
        assertNotNull(t2);
        // The current TX should be T2
        assertSame(t2, tm.getTransaction());
       
        XAResource res3 = new MockXAResource("Oracle", "003");
        tm.getTransaction().enlistResource(res3);

        tm.getTransaction().delistResource(res3, XAResource.TMSUCCESS);
        tm.rollback();

        // Skip post
        // helper.managedGlobalTransactionPostInvoke(t2);

        helper.suspendsTransactionPostInvoke(suspended);
        suspended.enlistResource(res1);
        suspended.enlistResource(res2);
        // T1 is now resumed
        assertSame(t1, tm.getTransaction());

        helper.managedGlobalTransactionPostInvoke(t1, false);
        assertNotNull(tm.getTransaction());
        assertEquals(6, t1.getStatus());

        activator.stop();
    }
View Full Code Here


    public void testHelper() throws Exception {
        TransactionManagerWrapper activator = new TransactionManagerWrapper();
        activator.start();
        TransactionManager tm = activator.getTransactionManager();
        // GeronimoUserTransaction tx = new GeronimoUserTransaction(tm);
        TransactionManagerHelper helper = new TransactionManagerHelper(tm);

        // No TX yet
        assertNull(tm.getTransaction());
        Transaction t1 = helper.managedGlobalTransactionPreInvoke();
        // Should create T1
        assertNotNull(t1);
        // The current TX should be T1
        assertSame(t1, tm.getTransaction());
       
        XAResource res1 = new MockXAResource("Derby", "001");
        XAResource res2 = new MockXAResource("DB2", "002");
        tm.getTransaction().enlistResource(res1);
        tm.getTransaction().enlistResource(res2);

        Transaction suspended = helper.suspendsTransactionPreInvoke();
        suspended.delistResource(res1, XAResource.TMSUSPEND);
        suspended.delistResource(res2, XAResource.TMSUSPEND);
      
        // T1 is suspended
        assertSame(t1, suspended);
        // No more active TX
        assertNull(tm.getTransaction());

        Transaction t2 = helper.managedGlobalTransactionPreInvoke();
        assertNotNull(t2);
        // The current TX should be T2
        assertSame(t2, tm.getTransaction());
       
        XAResource res3 = new MockXAResource("Oracle", "003");
        tm.getTransaction().enlistResource(res3);

        tm.getTransaction().delistResource(res3, XAResource.TMSUCCESS);
        tm.rollback();

        // Skip post
        // helper.managedGlobalTransactionPostInvoke(t2);

        helper.suspendsTransactionPostInvoke(suspended);
        suspended.enlistResource(res1);
        suspended.enlistResource(res2);
        // T1 is now resumed
        assertSame(t1, tm.getTransaction());

        helper.managedGlobalTransactionPostInvoke(t1, false);
        assertNotNull(tm.getTransaction());
        assertEquals(6, t1.getStatus());

        activator.stop();
    }
View Full Code Here

    public void testHelper() throws Exception {
        TransactionManagerWrapper activator = new TransactionManagerWrapper();
        activator.start();
        TransactionManager tm = activator.getTransactionManager();
        // GeronimoUserTransaction tx = new GeronimoUserTransaction(tm);
        TransactionManagerHelper helper = new TransactionManagerHelper(tm);

        // No TX yet
        assertNull(tm.getTransaction());
        Transaction t1 = helper.managedGlobalTransactionPreInvoke();
        // Should create T1
        assertNotNull(t1);
        // The current TX should be T1
        assertSame(t1, tm.getTransaction());
       
        XAResource res1 = new MockXAResource("Derby", "001");
        XAResource res2 = new MockXAResource("DB2", "002");
        tm.getTransaction().enlistResource(res1);
        tm.getTransaction().enlistResource(res2);

        Transaction suspended = helper.suspendsTransactionPreInvoke();
        suspended.delistResource(res1, XAResource.TMSUSPEND);
        suspended.delistResource(res2, XAResource.TMSUSPEND);
      
        // T1 is suspended
        assertSame(t1, suspended);
        // No more active TX
        assertNull(tm.getTransaction());

        Transaction t2 = helper.managedGlobalTransactionPreInvoke();
        assertNotNull(t2);
        // The current TX should be T2
        assertSame(t2, tm.getTransaction());
       
        XAResource res3 = new MockXAResource("Oracle", "003");
        tm.getTransaction().enlistResource(res3);

        tm.getTransaction().delistResource(res3, XAResource.TMSUCCESS);
        tm.rollback();

        // Skip post
        // helper.managedGlobalTransactionPostInvoke(t2);

        helper.suspendsTransactionPostInvoke(suspended);
        suspended.enlistResource(res1);
        suspended.enlistResource(res2);
        // T1 is now resumed
        assertSame(t1, tm.getTransaction());

        helper.managedGlobalTransactionPostInvoke(t1, false);
        assertNotNull(tm.getTransaction());
        assertEquals(6, t1.getStatus());

        activator.stop();
    }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.policy.transaction.runtime.TransactionManagerHelper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.