Package bitronix.tm

Examples of bitronix.tm.BitronixTransactionManager


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

    public void testHeuristicRollbackWorkingCase() throws Exception {
        Thread.currentThread().setName("testHeuristicRollbackWorkingCase");
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        tm.begin();

        Connection connection1 = poolingDataSource1.getConnection();
        PooledConnectionProxy handle = (PooledConnectionProxy) connection1;
        JdbcPooledConnection pc1 = handle.getPooledConnection();
            XAConnection mockXAConnection1 = (XAConnection) getWrappedXAConnectionOf(pc1);
            MockXAResource mockXAResource = (MockXAResource) mockXAConnection1.getXAResource();
            mockXAResource.setRollbackException(new XAException(XAException.XA_HEURRB));
        connection1.createStatement();

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

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

        tm.setTransactionTimeout(3);
        tm.rollback();

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


    }

    public void testNonEnlistingMethodInTxContext() throws Exception {
        Thread.currentThread().setName("testNonEnlistingMethodInTxContext");
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();

        tm.begin();
       
        Connection c = poolingDataSource1.getConnection();
        assertTrue(c.getAutoCommit());
        c.close();

        tm.commit();

        tm.shutdown();
    }
View Full Code Here

        tm.shutdown();
    }

    public void testAutoCommitFalseWhenEnlisted() throws Exception {
        Thread.currentThread().setName("testAutoCommitFalseWhenEnlisted");
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();

        tm.begin();

        Connection c = poolingDataSource1.getConnection();
        c.prepareStatement("");
        assertFalse(c.getAutoCommit());
        c.close();

        tm.commit();

        tm.shutdown();
    }
View Full Code Here

        tm.shutdown();
    }

    public void testAutoCommitTrueWhenEnlistedButSuspended() throws Exception {
        Thread.currentThread().setName("testAutoCommitTrueWhenEnlistedButSuspended");
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();

        tm.begin();

        Connection c = poolingDataSource1.getConnection();
        c.prepareStatement("");

        Transaction tx = tm.suspend();
        assertNull(tm.getTransaction());

        assertTrue(c.getAutoCommit());

        tm.resume(tx);
        c.close();

        tm.commit();

        tm.shutdown();
    }
View Full Code Here

public class JdbcProxyTest extends AbstractMockJdbcTest {

    @Test
    public void testSetters() throws Exception {
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        tm.setTransactionTimeout(30);
        tm.begin();

        Connection connection = poolingDataSource1.getConnection();

        long start = System.nanoTime();
        PreparedStatement stmt = connection.prepareStatement("SELECT 1 FROM nothing WHERE a=? AND b=? AND c=? AND d=?");
        Date date = new Date(0);
        for (int i = 0; i < 50000; i++) {
            stmt.setString(1, "foo");
            stmt.setInt(2, 999);
            stmt.setDate(3, date);
            stmt.setFloat(4, 9.99f);
            stmt.clearParameters();
        }
        long totalTime = System.nanoTime() - start;

        stmt.executeQuery();

        connection.close();

        tm.commit();
        tm.shutdown();
    }
View Full Code Here

        tm.shutdown();
    }

    @Test
    public void testPrepares() throws Exception {
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        tm.setTransactionTimeout(60);
        tm.begin();

        Connection connection = poolingDataSource2.getConnection();

        for (int i = 0; i < 1000; i++) {
            PreparedStatement prepareStatement = connection.prepareStatement("SELECT 1 FROM nothing WHERE a=? AND b=? AND c=? AND d=?");
            prepareStatement.close();
        }

        connection.close();

        tm.commit();
        tm.shutdown();
    }
View Full Code Here

        tm.shutdown();
    }

    @Test
    public void testCachedPrepared() throws Exception {
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        tm.setTransactionTimeout(60);
        tm.begin();

        Connection connection = poolingDataSource1.getConnection();

        PreparedStatement prepareStatement1 = connection.prepareStatement("SELECT 1 FROM nothing WHERE a=? AND b=? AND c=? AND d=?");
        PreparedStatement prepareStatement2 = connection.prepareStatement("SELECT 1 FROM nothing WHERE a=? AND b=? AND c=? AND d=?");

        Assert.assertSame(prepareStatement1, prepareStatement2);

        prepareStatement2.close();

        prepareStatement2 = connection.prepareStatement("SELECT 1 FROM nothing WHERE a=? AND b=? AND c=? AND d=?");
        Assert.assertSame(prepareStatement1, prepareStatement2);

        prepareStatement1.close();
        prepareStatement2.close();

        connection.close();
        tm.shutdown();
    }
View Full Code Here

        tm.shutdown();
    }

    @Test
    public void testUnCachedPrepared() throws Exception {
        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
        tm.setTransactionTimeout(60);
        tm.begin();

        Connection connection = poolingDataSource2.getConnection();

        PreparedStatement prepareStatement1 = connection.prepareStatement("SELECT 1 FROM nothing WHERE a=? AND b=? AND c=? AND d=?");
        PreparedStatement prepareStatement2 = connection.prepareStatement("SELECT 1 FROM nothing WHERE a=? AND b=? AND c=? AND d=?");

        Assert.assertNotSame(prepareStatement1, prepareStatement2);

        prepareStatement2.close();

        prepareStatement2 = connection.prepareStatement("SELECT 1 FROM nothing WHERE a=? AND b=? AND c=? AND d=?");
        Assert.assertNotSame(prepareStatement1, prepareStatement2);

        prepareStatement1.close();
        prepareStatement2.close();

        connection.close();
        tm.shutdown();
    }
View Full Code Here

public class NewJdbcWrongUsageMockTest extends AbstractMockJdbcTest {

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

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

        Connection connection1 = poolingDataSource1.getConnection();
        PooledConnectionProxy handle = (PooledConnectionProxy) connection1;
        JdbcPooledConnection pc1 = handle.getPooledConnection();

        XAConnection xaConnection1 = (XAConnection) getWrappedXAConnectionOf(pc1);
            MockXAResource mockXAResource = (MockXAResource) xaConnection1.getXAResource();
            XAException xaException = new XAException("resource failed");
            xaException.errorCode = XAException.XAER_RMERR;
            mockXAResource.setPrepareException(xaException);
        connection1.createStatement();

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

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

        try {
            tm.commit();
            fail("TM should have thrown rollback exception");
        } catch (RollbackException ex) {
            assertTrue("Got: " + ex.getMessage(), ex.getMessage().matches("transaction failed to prepare: a Bitronix Transaction with GTRID (.*?) status=ROLLEDBACK, 2 resource\\(s\\) enlisted (.*?)"));
            assertTrue("Got: " + ex.getCause().getMessage(), ex.getCause().getMessage().matches("transaction failed during prepare of a Bitronix Transaction with GTRID (.*?) status=PREPARING, 2 resource\\(s\\) enlisted (.*?) resource\\(s\\) \\[pds1\\] threw unexpected exception"));

View Full Code Here

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

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

        Connection connection1 = poolingDataSource1.getConnection();
        PooledConnectionProxy handle = (PooledConnectionProxy) connection1;
        JdbcPooledConnection pc1 = handle.getPooledConnection();
            XAConnection xaConnection1 = (XAConnection) getWrappedXAConnectionOf(pc1);
            MockXAResource mockXAResource = (MockXAResource) xaConnection1.getXAResource();
            mockXAResource.setPrepareException(new RuntimeException("driver error"));
        connection1.createStatement();

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

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

        try {
            tm.commit();
            fail("TM should have thrown exception");
        } catch (RollbackException ex) {
            assertTrue("Got: " + ex.getMessage(), ex.getMessage().matches("transaction failed to prepare: a Bitronix Transaction with GTRID (.*?) status=ROLLEDBACK, 2 resource\\(s\\) enlisted (.*?)"));
            assertTrue("Got: " + ex.getCause().getMessage(), ex.getCause().getMessage().matches("transaction failed during prepare of a Bitronix Transaction with GTRID (.*?) status=PREPARING, 2 resource\\(s\\) enlisted (.*?) resource\\(s\\) \\[pds1\\] threw unexpected exception"));

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.