Package bitronix.tm.resource.jdbc

Examples of bitronix.tm.resource.jdbc.PoolingDataSource


    }

     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


         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

        field.setAccessible(true);
        AtomicReference<Journal> journalRef = (AtomicReference<Journal>) field.get(TransactionManagerServices.class);
        journalRef.set(new MockJournal());


        poolingDataSource1 = new PoolingDataSource();
        poolingDataSource1.setClassName(MockitoXADataSource.class.getName());
        poolingDataSource1.setUniqueName("pds1");
        poolingDataSource1.setMinPoolSize(5);
        poolingDataSource1.setMaxPoolSize(5);
        poolingDataSource1.setAutomaticEnlistingEnabled(true);
View Full Code Here

        Field field = TransactionManagerServices.class.getDeclaredField("journalRef");
        field.setAccessible(true);
        AtomicReference<Journal> journalRef = (AtomicReference<Journal>) field.get(TransactionManagerServices.class);
        journalRef.set(new MockJournal());

        poolingDataSource1 = new PoolingDataSource();
        poolingDataSource1.setClassName(MockitoXADataSource.class.getName());
        poolingDataSource1.setUniqueName("pds1");
        poolingDataSource1.setMinPoolSize(5);
        poolingDataSource1.setMaxPoolSize(5);
        poolingDataSource1.setAutomaticEnlistingEnabled(true);
        poolingDataSource1.init();

        poolingDataSource2 = new PoolingDataSource();
        poolingDataSource2.setClassName(MockitoXADataSource.class.getName());
        poolingDataSource2.setUniqueName("pds2");
        poolingDataSource2.setMinPoolSize(5);
        poolingDataSource2.setMaxPoolSize(5);
        poolingDataSource2.setAutomaticEnlistingEnabled(true);
        poolingDataSource2.init();

        poolingDataSource3 = new PoolingDataSource();
        poolingDataSource3.setClassName(MockitoXADataSource.class.getName());
        poolingDataSource3.setUniqueName("pds3");
        poolingDataSource3.setMinPoolSize(5);
        poolingDataSource3.setMaxPoolSize(5);
        poolingDataSource3.setAutomaticEnlistingEnabled(true);
        poolingDataSource3.init();
       
        poolingDataSourceLrc = new PoolingDataSource();
        poolingDataSourceLrc.setClassName(LrcXADataSource.class.getName());
        poolingDataSourceLrc.setUniqueName("pds4_lrc");
        poolingDataSourceLrc.setMinPoolSize(5);
        poolingDataSourceLrc.setMaxPoolSize(5);
        poolingDataSourceLrc.setAllowLocalTransactions(true);
View Full Code Here

        assertEquals("java", xads.getUserName());
        assertEquals("java", xads.getPassword());
    }

    public void testNoRestartOfTaskSchedulerDuringClose() throws Exception {
        PoolingDataSource pds = new PoolingDataSource();
        pds.setClassName(MockitoXADataSource.class.getName());
        pds.setMaxPoolSize(1);
        pds.setUniqueName("mock");
        pds.init();

        BitronixTransactionManager btm = TransactionManagerServices.getTransactionManager();
        btm.shutdown();

        pds.close();

        assertFalse(TransactionManagerServices.isTaskSchedulerRunning());
    }
View Full Code Here

        }
    }

    public void testRestartWithoutLoaderNoReuseResource() throws Exception {
        for (int i=0; i<3 ;i++) {
            PoolingDataSource pds = new PoolingDataSource();
            pds.setClassName(MockitoXADataSource.class.getName());
            pds.setUniqueName("ds");
            pds.setMaxPoolSize(1);
            pds.init();

            try {
                ResourceRegistrar.register(pds);
                fail("expected IllegalStateException");
            } catch (IllegalStateException ex) {
                String expected = "A resource with uniqueName 'ds' has already been registered";
                assertEquals(expected, ex.getMessage().substring(0, expected.length()));
            }

            BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
            tm.shutdown();
            assertEquals(1, ResourceRegistrar.getResourcesUniqueNames().size());

            pds.close();
        }
    }
View Full Code Here

            pds.close();
        }
    }

    public void testRestartWithoutLoaderReuseResource() throws Exception {
        PoolingDataSource pds = new PoolingDataSource();
        pds.setClassName(MockitoXADataSource.class.getName());
        pds.setUniqueName("ds");
        pds.setMaxPoolSize(1);
        pds.init();

        for (int i=0; i<3 ;i++) {
            try {
                ResourceRegistrar.register(pds);
                fail("expected IllegalStateException");
            } catch (IllegalStateException ex) {
                String expected = "A resource with uniqueName 'ds' has already been registered";
                assertEquals(expected, ex.getMessage().substring(0, expected.length()));
            }

            BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
            tm.shutdown();
            assertEquals(1, ResourceRegistrar.getResourcesUniqueNames().size());
        }

        pds.close();
    }
View Full Code Here

        assertEquals(1, sync.beforeCount);
        assertEquals(1, sync.afterCount);
    }

    public void testRecycleAfterSuspend() throws Exception {
        PoolingDataSource pds = new PoolingDataSource();
        pds.setClassName(LrcXADataSource.class.getName());
        pds.setUniqueName("lrc-pds");
        pds.setMaxPoolSize(2);
        pds.getDriverProperties().setProperty("driverClassName", MockDriver.class.getName());
        pds.init();

        btm.begin();

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

        Transaction tx = btm.suspend();

            btm.begin();

            Connection c11 = pds.getConnection();
            c11.createStatement();
            c11.close();

            btm.commit();


        btm.resume(tx);

        Connection c2 = pds.getConnection();
        c2.createStatement();
        c2.close();

        btm.commit();

        pds.close();
    }
View Full Code Here

        TransactionManagerServices.getJournal().close();
        TransactionManagerServices.getTaskScheduler().shutdown();
    }

    public void testAcquiringConnectionAfterRecoveryDoesNotMarkAsFailed() throws Exception {
        PoolingDataSource poolingDataSource = new PoolingDataSource();
        poolingDataSource.setClassName(MockitoXADataSource.class.getName());
        poolingDataSource.setUniqueName("ds1");
        poolingDataSource.setMaxPoolSize(1);
        poolingDataSource.setMaxIdleTime(1); // set low shrink timeout
        poolingDataSource.init();

        IncrementalRecoverer.recover(poolingDataSource);

        MockitoXADataSource.setStaticGetXAConnectionException(new SQLException("creating a new connection does not work"));
        Thread.sleep(2000); // wait for shrink

        // should not work but should not mark the pool as failed as it could recover
        try {
            poolingDataSource.getConnection();
            fail("expected SQLException");
        } catch (SQLException ex) {
            assertEquals("unable to get a connection from pool of a PoolingDataSource containing an XAPool of resource ds1 with 0 connection(s) (0 still available)", ex.getMessage());
        }

        poolingDataSource.close();
    }
View Full Code Here

    }

    public void testFailingRecoveryMarksAsFailed() throws Exception {
        MockitoXADataSource.setStaticGetXAConnectionException(new SQLException("creating a new connection does not work"));

        PoolingDataSource poolingDataSource = new PoolingDataSource();
        poolingDataSource.setClassName(MockitoXADataSource.class.getName());
        poolingDataSource.setUniqueName("ds1");
        poolingDataSource.setMaxPoolSize(1);
        poolingDataSource.init();

        Recoverer recoverer = new Recoverer();
        recoverer.run();
        assertEquals("a PoolingDataSource containing an XAPool of resource ds1 with 0 connection(s) (0 still available) -failed-", poolingDataSource.toString());
        // recoverer must not unregister the resource
        assertSame(poolingDataSource, ResourceRegistrar.get("ds1"));

        MockitoXADataSource.setStaticGetXAConnectionException(null);

        recoverer.run();
        assertEquals("a PoolingDataSource containing an XAPool of resource ds1 with 1 connection(s) (1 still available)", poolingDataSource.toString());
        // recoverer must not unregister the resource
        assertSame(poolingDataSource, ResourceRegistrar.get("ds1"));

        poolingDataSource.close();
    }
View Full Code Here

TOP

Related Classes of bitronix.tm.resource.jdbc.PoolingDataSource

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.