Package bitronix.tm

Examples of bitronix.tm.BitronixTransactionManager


        assertEquals(DATASOURCE1_NAME, ((ConnectionQueuedEvent) orderedEvents.get(i++)).getPooledConnectionImpl().getPoolingDataSource().getUniqueName());
    }

    public void testInterleavedGlobalGlobalTransactionsWithDifferentConnections() throws Exception {
        if (log.isDebugEnabled()) { log.debug("*** getting TM"); }
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        if (log.isDebugEnabled()) { log.debug("*** before begin"); }
        tm.begin();
        if (log.isDebugEnabled()) { log.debug("*** after begin"); }

        if (log.isDebugEnabled()) { log.debug("*** getting connection from DS1"); }
        Connection connection1 = poolingDataSource1.getConnection();
        connection1.createStatement();

        if (log.isDebugEnabled()) { log.debug(" *** suspending transaction"); }
        Transaction t1 = tm.suspend();
        assertNull(tm.getTransaction());

        if (log.isDebugEnabled()) { log.debug(" *** begin interleaved transaction"); }
        tm.begin();
        Connection connection2 = poolingDataSource1.getConnection();
        connection2.createStatement();
        connection2.close();
        if (log.isDebugEnabled()) { log.debug(" *** commit interleaved transaction"); }
        tm.commit();

        if (log.isDebugEnabled()) { log.debug(" *** resuming transaction"); }
        tm.resume(t1);

        if (log.isDebugEnabled()) { log.debug("*** closing connection 1"); }
        connection1.close();

        if (log.isDebugEnabled()) { log.debug("*** committing"); }
        tm.commit();
        if (log.isDebugEnabled()) { log.debug("*** TX is done"); }

        // check flow
        List orderedEvents = EventRecorder.getOrderedEvents();
        log.info(EventRecorder.dumpToString());
View Full Code Here


        assertEquals(DATASOURCE1_NAME, ((ConnectionQueuedEvent) orderedEvents.get(i++)).getPooledConnectionImpl().getPoolingDataSource().getUniqueName());
    }

    public void testInterleavedGlobalGlobalTransactionsWithDifferentConnectionsLateSuspend() throws Exception {
        if (log.isDebugEnabled()) { log.debug("*** getting TM"); }
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        if (log.isDebugEnabled()) { log.debug("*** before begin"); }
        tm.begin();
        if (log.isDebugEnabled()) { log.debug("*** after begin"); }

        if (log.isDebugEnabled()) { log.debug("*** getting connection from DS1"); }
        Connection connection1 = poolingDataSource1.getConnection();
        connection1.createStatement();

        if (log.isDebugEnabled()) { log.debug("*** closing connection 1"); }
        connection1.close();

        if (log.isDebugEnabled()) { log.debug(" *** suspending transaction"); }
        Transaction t1 = tm.suspend();
        assertNull(tm.getTransaction());

        if (log.isDebugEnabled()) { log.debug(" *** begin interleaved transaction"); }
        tm.begin();
        Connection connection2 = poolingDataSource1.getConnection();
        assertEquals(POOL_SIZE -2, getPool(poolingDataSource1).inPoolSize());
        connection2.createStatement();
        connection2.close();
        if (log.isDebugEnabled()) { log.debug(" *** commit interleaved transaction"); }
        tm.commit();
        assertEquals(POOL_SIZE -1, getPool(poolingDataSource1).inPoolSize());

        if (log.isDebugEnabled()) { log.debug(" *** resuming transaction"); }
        tm.resume(t1);

        if (log.isDebugEnabled()) { log.debug("*** committing"); }
        tm.commit();
        if (log.isDebugEnabled()) { log.debug("*** TX is done"); }
        assertEquals(POOL_SIZE, getPool(poolingDataSource1).inPoolSize());

        // check flow
        List orderedEvents = EventRecorder.getOrderedEvents();
View Full Code Here

            assertEquals(1, ((JournalLogEvent) orderedEvents.get(i++)).getJndiNames().size());
        assertEquals(DATASOURCE1_NAME, ((ConnectionQueuedEvent) orderedEvents.get(i++)).getPooledConnectionImpl().getPoolingDataSource().getUniqueName());
    }

    public void testJoinAfterSuspend() throws Exception {
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        tm.begin();

        if (log.isDebugEnabled()) { log.debug("*** get C1"); }
        Connection c1 = poolingDataSource1.getConnection();
        c1.createStatement();
        c1.close();

        if (log.isDebugEnabled()) { log.debug("*** get C2"); }
        Connection c2 = poolingDataSource2.getConnection();
        c2.createStatement();
        c2.close();

        Transaction tx = tm.suspend();
        tm.resume(tx);

        if (log.isDebugEnabled()) { log.debug("*** get C3"); }
        Connection c3 = poolingDataSource2.getConnection();
        c3.createStatement();
        c3.close();

        if (log.isDebugEnabled()) { log.debug("*** get C4"); }
        Connection c4 = poolingDataSource1.getConnection();
        c4.createStatement();
        c4.close();

        tm.commit();

        // check flow
        List orderedEvents = EventRecorder.getOrderedEvents();
        log.info(EventRecorder.dumpToString());

View Full Code Here

        assertEquals(DATASOURCE1_NAME, ((ConnectionQueuedEvent) orderedEvents.get(i++)).getPooledConnectionImpl().getPoolingDataSource().getUniqueName());
    }

    public void testReusePreparedStatementAfterSuspendResume() throws Exception {
        if (log.isDebugEnabled()) { log.debug("*** getting TM"); }
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();

        if (log.isDebugEnabled()) { log.debug("*** before begin"); }
        tm.begin();
        if (log.isDebugEnabled()) { log.debug("*** after begin"); }

        if (log.isDebugEnabled()) { log.debug("*** getting connection from DS1"); }
        Connection connection1 = poolingDataSource1.getConnection();

        Transaction tx = tm.suspend();
        tm.resume(tx);

        connection1.prepareStatement("some sql");

        if (log.isDebugEnabled()) { log.debug("*** closing connection 1"); }
        connection1.close();

        if (log.isDebugEnabled()) { log.debug("*** committing"); }
        tm.commit();
        if (log.isDebugEnabled()) { log.debug("*** TX is done"); }

        // check flow
        List orderedEvents = EventRecorder.getOrderedEvents();
        log.info(EventRecorder.dumpToString());
View Full Code Here

        log.info(EventRecorder.dumpToString());
    }

    public void testSuspendResumeSeparateThreads() throws Exception {
        if (log.isDebugEnabled()) { log.debug("*** getting TM"); }
        final BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        if (log.isDebugEnabled()) { log.debug("*** before begin"); }
        tm.begin();
        if (log.isDebugEnabled()) { log.debug("*** after begin"); }

        if (log.isDebugEnabled()) { log.debug("*** suspending transaction"); }
        final Transaction suspended = tm.suspend();

        assertNull(tm.getCurrentTransaction());

        if (log.isDebugEnabled()) { log.debug("*** before 2nd begin"); }
        tm.begin();
        assertNotNull(tm.getCurrentTransaction());
       
        Thread thread = new Thread() {
            public void run() {
                if (log.isDebugEnabled()) { log.debug("*** getting TM"); }
               
                try {
                    if (log.isDebugEnabled()) { log.debug("*** resuming transaction in new thread"); }
                    tm.resume(suspended);
                    if (log.isDebugEnabled()) { log.debug("*** committing transaction in new thread"); }
                    tm.commit();
                    if (log.isDebugEnabled()) { log.debug("*** new thread commit complete, exiting"); }
                    assertNull(tm.getCurrentTransaction());
                } catch (Exception e) {
                    fail(e.getMessage());
                }
            }
        };
        thread.start();
        thread.join();

        assertNotNull(tm.getCurrentTransaction());
        if (log.isDebugEnabled()) { log.debug("*** committing transaction in main thread"); }
        tm.commit();
        if (log.isDebugEnabled()) { log.debug("*** main thread complete"); }
        assertNull(tm.getCurrentTransaction());
    }
View Full Code Here

        TransactionManagerServices.getTransactionManager().shutdown(); // stop TM
    }

    public void testSimpleWorkingCase() throws Exception {
        if (log.isDebugEnabled()) { log.debug("*** getting TM"); }
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        if (log.isDebugEnabled()) { log.debug("*** before begin"); }
        tm.setTransactionTimeout(10);
        tm.begin();
        if (log.isDebugEnabled()) { log.debug("*** after begin"); }

        if (log.isDebugEnabled()) { log.debug("*** getting connection from CF1"); }
        Connection connection1 = poolingConnectionFactory1.createConnection();

        if (log.isDebugEnabled()) { log.debug("*** creating session 1 on connection 1"); }
        Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);

        if (log.isDebugEnabled()) { log.debug("*** creating queue 1 on session 1"); }
        Queue queue1 = session1.createQueue("queue");

        if (log.isDebugEnabled()) { log.debug("*** creating producer1 on session 1"); }
        MessageProducer producer1 = session1.createProducer(queue1);

        if (log.isDebugEnabled()) { log.debug("*** sending message on producer1"); }
        producer1.send(session1.createTextMessage("testSimpleWorkingCase"));


        if (log.isDebugEnabled()) { log.debug("*** closing connection 1"); }
        connection1.close();

        if (log.isDebugEnabled()) { log.debug("*** committing"); }
        tm.commit();
        if (log.isDebugEnabled()) { log.debug("*** TX is done"); }

        // check flow
        List orderedEvents = EventRecorder.getOrderedEvents();
        log.info(EventRecorder.dumpToString());
View Full Code Here

public class JdbcSharedConnectionTest extends AbstractMockJdbcTest {
    private final static Logger log = LoggerFactory.getLogger(NewJdbcProperUsageMockTest.class);

    public void testSharedConnectionMultithreaded() throws Exception {
        if (log.isDebugEnabled()) { log.debug("*** Starting testSharedConnectionMultithreaded: getting TM"); }
        final BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        tm.setTransactionTimeout(120);

        if (log.isDebugEnabled()) { log.debug("*** before begin"); }
        tm.begin();
        if (log.isDebugEnabled()) { log.debug("*** after begin"); }

        final Transaction suspended = tm.suspend();

        final ArrayList twoConnections = new ArrayList();
        Thread thread1 = new Thread() {
          public void run() {
            try {
          tm.resume(suspended);
              if (log.isDebugEnabled()) { log.debug("*** getting connection from DS1"); }
              Connection connection = poolingDataSource1.getConnection();
              connection.createStatement();
              twoConnections.add(connection);
        } catch (Exception e) {
          e.printStackTrace();
          fail(e.getMessage());
        }
          }
        };
        thread1.start();
        thread1.join();

        Thread thread2 = new Thread() {
          public void run() {
            try {
          tm.resume(suspended);
              if (log.isDebugEnabled()) { log.debug("*** getting connection from DS1"); }
              Connection connection = poolingDataSource1.getConnection();
              connection.createStatement();
              twoConnections.add(connection);
              tm.commit();
        } catch (Exception e) {
          e.printStackTrace();
          fail(e.getMessage());
        }
          }
View Full Code Here

    }

    public void testUnSharedConnection() throws Exception {
        if (log.isDebugEnabled()) { log.debug("*** Starting testUnSharedConnection: getting TM"); }
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        tm.setTransactionTimeout(120);

        if (log.isDebugEnabled()) { log.debug("*** before begin"); }
        tm.begin();
        if (log.isDebugEnabled()) { log.debug("*** after begin"); }

        if (log.isDebugEnabled()) { log.debug("*** getting connection from DS2"); }
        Connection connection1 = poolingDataSource2.getConnection();
        // createStatement causes enlistment
        connection1.createStatement();

        if (log.isDebugEnabled()) { log.debug("*** getting second connection from DS2"); }
        Connection connection2 = poolingDataSource2.getConnection();

        PooledConnectionProxy handle1 = (PooledConnectionProxy) connection1;
        PooledConnectionProxy handle2 = (PooledConnectionProxy) connection2;
        assertNotSame(handle1.getProxiedDelegate(), handle2.getProxiedDelegate());

        connection1.close();
        connection2.close();

        tm.commit();
    }
View Full Code Here

        connection2.close();
    }

    public void testSharedConnectionInGlobal() throws Exception {
        if (log.isDebugEnabled()) { log.debug("*** testSharedConnectionInGlobal: Starting getting TM"); }
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        tm.setTransactionTimeout(120);

        if (log.isDebugEnabled()) { log.debug("*** before begin"); }
        tm.begin();
        if (log.isDebugEnabled()) { log.debug("*** after begin"); }

        if (log.isDebugEnabled()) { log.debug("*** getting connection from DS1"); }
        Connection connection1 = poolingDataSource1.getConnection();

        if (log.isDebugEnabled()) { log.debug("*** getting second connection from DS1"); }
        Connection connection2 = poolingDataSource1.getConnection();

        PooledConnectionProxy handle1 = (PooledConnectionProxy) connection1;
        PooledConnectionProxy handle2 = (PooledConnectionProxy) connection2;
        assertSame(handle1.getProxiedDelegate(), handle2.getProxiedDelegate());

        connection1.close();
        connection2.close();

        tm.commit();
    }
View Full Code Here

    private final static Logger log = LoggerFactory.getLogger(NewJdbcStrangeUsageMockTest.class);


    public void testDeferredReuse() throws Exception {
        if (log.isDebugEnabled()) { log.debug("*** getting TM"); }
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();

        XAPool pool1 = getPool(poolingDataSource1);

        if (log.isDebugEnabled()) { log.debug("*** before begin"); }
        tm.begin();
        if (log.isDebugEnabled()) { log.debug("*** after begin"); }

        assertEquals(POOL_SIZE, pool1.inPoolSize());

        if (log.isDebugEnabled()) { log.debug("*** getting connection from DS1"); }
        Connection connection1 = poolingDataSource1.getConnection();
        connection1.createStatement();

        assertEquals(POOL_SIZE -1, pool1.inPoolSize());

        if (log.isDebugEnabled()) { log.debug("*** closing connection 1"); }
        connection1.close();

        assertEquals(POOL_SIZE -1, pool1.inPoolSize());

        if (log.isDebugEnabled()) { log.debug("*** getting again connection from DS1"); }
        connection1 = poolingDataSource1.getConnection();
        connection1.createStatement();

        assertEquals(POOL_SIZE -1, pool1.inPoolSize());

        if (log.isDebugEnabled()) { log.debug("*** closing again connection 1"); }
        connection1.close();

        assertEquals(POOL_SIZE -1, pool1.inPoolSize());

        if (log.isDebugEnabled()) { log.debug("*** committing"); }
        tm.commit();
        if (log.isDebugEnabled()) { log.debug("*** TX is done"); }

        assertEquals(POOL_SIZE, pool1.inPoolSize());

        // check flow
View Full Code Here

TOP

Related Classes of bitronix.tm.BitronixTransactionManager

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.