Examples of XAPool


Examples of bitronix.tm.resource.common.XAPool

    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
        List orderedEvents = EventRecorder.getOrderedEvents();
        log.info(EventRecorder.dumpToString());

View Full Code Here

Examples of bitronix.tm.resource.common.XAPool

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

        // Use DataSource2 because it does not have shared accessible connections
        XAPool pool2 = getPool(poolingDataSource2);

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

        assertEquals(POOL_SIZE, pool2.inPoolSize());

        if (log.isDebugEnabled()) log.debug("*** getting connection 1 from DS1");
        Connection connection1 = poolingDataSource2.getConnection();
        connection1.createStatement();

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

        if (log.isDebugEnabled()) log.debug("*** getting connection 2 from DS1");
        Connection connection2 = poolingDataSource2.getConnection();
        connection2.createStatement();

        assertEquals(POOL_SIZE -2, pool2.inPoolSize());

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

        assertEquals(POOL_SIZE -2, pool2.inPoolSize());

        if (log.isDebugEnabled()) log.debug("*** closing connection 2");
        connection2.close();

        assertEquals(POOL_SIZE -2, pool2.inPoolSize());

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

        assertEquals(POOL_SIZE, pool2.inPoolSize());

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

View Full Code Here

Examples of bitronix.tm.resource.common.XAPool

        BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();

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

        XAPool pool1 = getPool(poolingDataSource1);

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

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

        if (log.isDebugEnabled()) log.debug("*** starting 2nd tx");
        tm.begin();

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

        if (log.isDebugEnabled()) log.debug("*** closing connection 1 too eagerly within another context");
        try {
            // TODO: the ConnectionHandler 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());
        }
        assertEquals(POOL_SIZE -1, pool1.inPoolSize());

        if (log.isDebugEnabled()) log.debug("*** committing 2nd tx");
        tm.commit();

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

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

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

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

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

        assertEquals(POOL_SIZE, pool1.inPoolSize());

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

View Full Code Here

Examples of bitronix.tm.resource.common.XAPool

    private void buildXAPool() throws Exception {
        if (pool != null)
            return;

        if (log.isDebugEnabled()) { log.debug("building XA pool for " + getUniqueName() + " with " + getMinPoolSize() + " connection(s)"); }
        pool = new XAPool(this, this, xaDataSource);
        boolean builtXaFactory = false;
        if (xaDataSource == null) {
            xaDataSource = (XADataSource) pool.getXAFactory();
            builtXaFactory = true;
        }
View Full Code Here

Examples of bitronix.tm.resource.common.XAPool

    private void buildXAPool() throws Exception {
        if (pool != null)
            return;

        if (log.isDebugEnabled()) { log.debug("building JMS XA pool for " + getUniqueName() + " with " + getMinPoolSize() + " connection(s)"); }
        pool = new XAPool(this, this, xaConnectionFactory);
        boolean builtXaFactory = false;
        if (this.xaConnectionFactory == null) {
            this.xaConnectionFactory = (XAConnectionFactory) pool.getXAFactory();
            builtXaFactory = true;
        }
View Full Code Here

Examples of bitronix.tm.resource.common.XAPool

    private void buildXAPool() throws Exception {
        if (pool != null)
            return;

        if (log.isDebugEnabled()) { log.debug("building XA pool for " + getUniqueName() + " with " + getMinPoolSize() + " connection(s)"); }
        pool = new XAPool(this, this, xaDataSource);
        boolean builtXaFactory = false;
        if (xaDataSource == null) {
            xaDataSource = (XADataSource) pool.getXAFactory();
            builtXaFactory = true;
        }
View Full Code Here

Examples of bitronix.tm.resource.common.XAPool

        @SuppressWarnings("unchecked")
        AtomicReference<Journal> journalRef = (AtomicReference<Journal>) field.get(TransactionManagerServices.class);
        journalRef.set(new MockJournal());

        // change connection pools into mock pools
        XAPool p1 = getPool(this.poolingDataSource1);
        registerPoolEventListener(p1);
        XAPool p2 = getPool(this.poolingDataSource2);
        registerPoolEventListener(p2);

        TransactionManagerServices.getConfiguration().setGracefulShutdownInterval(2);

        // start TM
View Full Code Here

Examples of bitronix.tm.resource.common.XAPool

    public void testPoolGrowth() throws Exception {
        if (log.isDebugEnabled()) { log.debug("*** Starting testPoolGrowth"); }
        Field poolField = pds.getClass().getDeclaredField("pool");
        poolField.setAccessible(true);
        XAPool pool = (XAPool) poolField.get(pds);

        assertEquals(1, pool.inPoolSize());
        assertEquals(1, pool.totalPoolSize());

        Connection c1 = pds.getConnection();
        assertEquals(0, pool.inPoolSize());
        assertEquals(1, pool.totalPoolSize());

        Connection c2 = pds.getConnection();
        assertEquals(0, pool.inPoolSize());
        assertEquals(2, pool.totalPoolSize());

        try {
            pds.getConnection();
            fail("should not be able to get a 3rd connection");
        } catch (SQLException ex) {
            assertEquals("unable to get a connection from pool of a PoolingDataSource containing an XAPool of resource pds with 2 connection(s) (0 still available)", ex.getMessage());
        }

        c1.close();
        c2.close();
        assertEquals(2, pool.inPoolSize());
        assertEquals(2, pool.totalPoolSize());
    }
View Full Code Here

Examples of bitronix.tm.resource.common.XAPool

    public void testPoolShrink() throws Exception {
        if (log.isDebugEnabled()) { log.debug("*** Starting testPoolShrink"); }
        Field poolField = pds.getClass().getDeclaredField("pool");
        poolField.setAccessible(true);
        XAPool pool = (XAPool) poolField.get(pds);

        assertEquals(1, pool.inPoolSize());
        assertEquals(1, pool.totalPoolSize());

        Connection c1 = pds.getConnection();
        assertEquals(0, pool.inPoolSize());
        assertEquals(1, pool.totalPoolSize());

        Connection c2 = pds.getConnection();
        assertEquals(0, pool.inPoolSize());
        assertEquals(2, pool.totalPoolSize());

        c1.close();
        c2.close();

        Thread.sleep(1100); // leave enough time for the idle connections to expire
        TransactionManagerServices.getTaskScheduler().interrupt(); // wake up the task scheduler
        Thread.sleep(1200); // leave enough time for the scheduled shrinking task to do its work

        if (log.isDebugEnabled()) { log.debug("*** checking pool sizes"); }       
        assertEquals(1, pool.inPoolSize());
        assertEquals(1, pool.totalPoolSize());
    }
View Full Code Here

Examples of bitronix.tm.resource.common.XAPool

    public void testPoolShrinkErrorHandling() throws Exception {
        if (log.isDebugEnabled()) { log.debug("*** Starting testPoolShrinkErrorHandling"); }

        Field poolField = pds.getClass().getDeclaredField("pool");
        poolField.setAccessible(true);
        XAPool pool = (XAPool) poolField.get(pds);

        pds.setMinPoolSize(0);
        pds.reset();
        pds.setMinPoolSize(1);
        MockitoXADataSource.setStaticCloseXAConnectionException(new SQLException("close fails because datasource broken"));
        pds.reset();

        // the pool is now loaded with one connection which will throw an exception when closed
        Thread.sleep(1100); // leave enough time for the ide connections to expire
        TransactionManagerServices.getTaskScheduler().interrupt(); // wake up the task scheduler
        Thread.sleep(100); // leave enough time for the scheduled shrinking task to do its work
        assertEquals(1, pool.inPoolSize());

        MockitoXADataSource.setStaticGetXAConnectionException(new SQLException("getXAConnection fails because datasource broken"));
        Thread.sleep(1100); // leave enough time for the ide connections to expire
        TransactionManagerServices.getTaskScheduler().interrupt(); // wake up the task scheduler
        Thread.sleep(100); // leave enough time for the scheduled shrinking task to do its work
        assertEquals(0, pool.inPoolSize());

        MockitoXADataSource.setStaticGetXAConnectionException(null);
        Thread.sleep(1100); // leave enough time for the ide connections to expire
        TransactionManagerServices.getTaskScheduler().interrupt(); // wake up the task scheduler
        Thread.sleep(100); // leave enough time for the scheduled shrinking task to do its work
        assertEquals(1, pool.inPoolSize());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.