Package bitronix.tm

Examples of bitronix.tm.BitronixTransactionManager


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

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

        Connection connection1 = poolingDataSource1.getConnection();
        connection1.createStatement();
        Connection connection2 = poolingDataSource2.getConnection();
        connection2.createStatement();

        Transaction tx = tm.suspend();

        assertNull(tm.suspend());

        try {
            tm.resume(null);
            fail("TM has allowed resuming a null TX context");
        } catch (InvalidTransactionException ex) {
            assertEquals("resumed transaction cannot be null", ex.getMessage());
        }

        tm.resume(tx);

        try {
            tm.resume(tx);
            fail("TM has allowed resuming a TX context when another one is still running");
        } catch (IllegalStateException ex) {
            assertEquals("a transaction is already running on this thread", ex.getMessage());
        }

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

        tm.commit();
    }
View Full Code Here


        tm.commit();
    }

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

        try {
            tm.rollback();
            fail("TM allowed rollback with no TX started");
        } catch (IllegalStateException ex) {
            assertEquals("no transaction started on this thread", ex.getMessage());
        }
        try {
            tm.commit();
            fail("TM allowed commit with no TX started");
        } catch (IllegalStateException ex) {
            assertEquals("no transaction started on this thread", ex.getMessage());
        }
    }
View Full Code Here

            assertEquals("no transaction started on this thread", ex.getMessage());
        }
    }

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

         PoolingDataSource lrcDs1 = new PoolingDataSource();
         lrcDs1.setClassName(LrcXADataSource.class.getName());
         lrcDs1.setUniqueName(DATASOURCE1_NAME + "_lrc");
         lrcDs1.setMinPoolSize(POOL_SIZE);
         lrcDs1.setMaxPoolSize(POOL_SIZE);
         lrcDs1.setAllowLocalTransactions(true);
         lrcDs1.getDriverProperties().setProperty("driverClassName", MockDriver.class.getName());
         lrcDs1.getDriverProperties().setProperty("url", "");
         lrcDs1.init();

         PoolingDataSource lrcDs2 = new PoolingDataSource();
         lrcDs2.setClassName(LrcXADataSource.class.getName());
         lrcDs2.setUniqueName(DATASOURCE2_NAME + "_lrc");
         lrcDs2.setMinPoolSize(POOL_SIZE);
         lrcDs2.setMaxPoolSize(POOL_SIZE);
         lrcDs2.setAllowLocalTransactions(true);
         lrcDs2.getDriverProperties().setProperty("driverClassName", MockDriver.class.getName());
         lrcDs2.getDriverProperties().setProperty("url", "");
         lrcDs2.init();

         tm.begin();

         Connection c1 = lrcDs1.getConnection();
         c1.createStatement();
         c1.close();

         Connection c2 = lrcDs2.getConnection();
         try {
             c2.createStatement();
             fail("expected SQLException");
         } catch (SQLException ex) {
           assertTrue(ex.getMessage().startsWith("error enlisting a ConnectionJavaProxy of a JdbcPooledConnection from datasource pds2_lrc in state ACCESSIBLE with usage count 1 wrapping a JDBC LrcXAConnection on a JDBC LrcConnectionJavaProxy on Mock"));
             assertTrue(ex.getCause().getMessage().matches("cannot enlist more than one non-XA resource, tried enlisting an XAResourceHolderState with uniqueName=pds2_lrc XAResource=a JDBC LrcXAResource in state NO_TX with XID null, already enlisted: an XAResourceHolderState with uniqueName=pds1_lrc XAResource=a JDBC LrcXAResource in state STARTED \\(started\\) with XID a Bitronix XID .*"));
         }
         c2.close();

         tm.commit();

         lrcDs2.close();
         lrcDs1.close();
     }
View Full Code Here

         lrcDs2.close();
         lrcDs1.close();
     }

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

         PoolingConnectionFactory pcf = new PoolingConnectionFactory();
         pcf.setClassName(LrcXAConnectionFactory.class.getName());
         pcf.setUniqueName("pcf_lrc");
         pcf.setMaxPoolSize(1);
         pcf.getDriverProperties().setProperty("connectionFactoryClassName", MockConnectionFactory.class.getName());
         pcf.init();

         PoolingDataSource lrcDs2 = new PoolingDataSource();
         lrcDs2.setClassName(LrcXADataSource.class.getName());
         lrcDs2.setUniqueName(DATASOURCE2_NAME + "_lrc");
         lrcDs2.setMinPoolSize(POOL_SIZE);
         lrcDs2.setMaxPoolSize(POOL_SIZE);
         lrcDs2.setAllowLocalTransactions(true);
         lrcDs2.getDriverProperties().setProperty("driverClassName", MockDriver.class.getName());
         lrcDs2.getDriverProperties().setProperty("url", "");
         lrcDs2.init();

         tm.begin();

         javax.jms.Connection c = pcf.createConnection();
         javax.jms.Session s = c.createSession(true, 0);
         javax.jms.MessageProducer p = s.createProducer(null);
         p.send(null);
         c.close();

         Connection c2 = lrcDs2.getConnection();
         try {
             c2.createStatement();
             fail("expected SQLException");
         } catch (SQLException ex) {
           assertTrue(ex.getMessage().startsWith("error enlisting a ConnectionJavaProxy of a JdbcPooledConnection from datasource pds2_lrc in state ACCESSIBLE with usage count 1 wrapping a JDBC LrcXAConnection on a JDBC LrcConnectionJavaProxy on Mock"));
             assertTrue(ex.getCause().getMessage().startsWith("cannot enlist more than one non-XA resource, tried enlisting an XAResourceHolderState with uniqueName=pds2_lrc XAResource=a JDBC LrcXAResource in state NO_TX with XID null, already enlisted: an XAResourceHolderState with uniqueName=pcf_lrc XAResource=a JMS LrcXAResource in state STARTED of session Mock for Session"));
         }
         c2.close();

         tm.commit();

         lrcDs2.close();
         pcf.close();
     }
View Full Code Here

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

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

        assertNull(tm.suspend());

        try {
            tm.resume(null);
            fail("expected InvalidTransactionException");
        } catch (InvalidTransactionException ex) {
            assertEquals("resumed transaction cannot be null", ex.getMessage());
        }

        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("*** committing"); }
        tm.commit();
        if (log.isDebugEnabled()) { log.debug("*** TX is done"); }
    }
View Full Code Here

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

    public void testSimpleWorkingCase() 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 t1 = tm.suspend();

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

        connection1.createStatement();

        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 void testNoTmJoin() throws Exception {
        poolingDataSource1.setUseTmJoin(false);

        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 t1 = tm.suspend();

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

        connection1.createStatement();

        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 testReEnlistmentAfterSuspend() 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 t1 = tm.suspend();

        if (log.isDebugEnabled()) { log.debug("*** before begin2"); }
        tm.begin();
        if (log.isDebugEnabled()) { log.debug("*** after begin2"); }
        if (log.isDebugEnabled()) { log.debug("*** reusing connection 1"); }
        connection1.createStatement();
        if (log.isDebugEnabled()) { log.debug("*** marking subTX as rollback only"); }
        tm.setRollbackOnly();
        if (log.isDebugEnabled()) { log.debug("*** rolling back"); }
        tm.rollback();
        if (log.isDebugEnabled()) { log.debug("*** rolling back"); }

        if (log.isDebugEnabled()) { log.debug("*** subTX is done"); }
        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 testClosingSuspendedConnections() 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("*** getting connection from DS1"); }
        Connection connection1 = poolingDataSource1.getConnection();
        connection1.createStatement();

        assertEquals(POOL_SIZE -1, getPool(poolingDataSource1).inPoolSize());

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

        assertEquals(POOL_SIZE -1, getPool(poolingDataSource1).inPoolSize());

        if (log.isDebugEnabled()) { log.debug("*** closing connection 1 too eagerly"); }
        try {
            // TODO: the TM tries to 'veto' the connection close here like the old pool did.
            // Instead, close the resource immediately or defer its release.
            connection1.close();
            fail("successfully closed a connection participating in a global transaction, this should never be allowed");
        } catch (SQLException ex) {
            assertEquals("cannot close a resource when its XAResource is taking part in an unfinished global transaction", ex.getCause().getMessage());
        }
        assertFalse(connection1.isClosed());

        assertEquals(POOL_SIZE -1, getPool(poolingDataSource1).inPoolSize());

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

        assertEquals(POOL_SIZE -1, getPool(poolingDataSource1).inPoolSize());

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

        assertEquals(POOL_SIZE -1, getPool(poolingDataSource1).inPoolSize());

        if (log.isDebugEnabled()) { log.debug("*** closing connection 1"); }
View Full Code Here

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

    public void testInterleavedLocalGlobalTransactions() 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 t1 = tm.suspend();

        Connection connection2 = poolingDataSource1.getConnection();
        assertNull(tm.getTransaction());
        connection2.createStatement();
        connection2.close();

        if (log.isDebugEnabled()) { log.debug("*** resuming"); }
        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

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.