Package bitronix.tm.resource.jdbc

Examples of bitronix.tm.resource.jdbc.PoolingDataSource


        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();

//        try {
//            IncrementalRecoverer.recover(poolingDataSource);
//            fail("expected RecoveryException");
//        } catch (RecoveryException ex) {
//            assertEquals("cannot start recovery on a PoolingDataSource containing an XAPool of resource ds1 with 0 connection(s) (0 still available)", ex.getMessage());
//        }
//
//        assertEquals("a PoolingDataSource containing an XAPool of resource ds1 with 0 connection(s) (0 still available) -failed-", poolingDataSource.toString());

        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

    }

    public void testSuccessfulRecoveryMarksAsNotFailed() 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();

        try {
            IncrementalRecoverer.recover(poolingDataSource);
            fail("expected RecoveryException");
        } catch (RecoveryException ex) {
            assertEquals("cannot start recovery on a PoolingDataSource containing an XAPool of resource ds1 with 0 connection(s) (0 still available)", ex.getMessage());
        }

        assertEquals("a PoolingDataSource containing an XAPool of resource ds1 with 0 connection(s) (0 still available) -failed-", poolingDataSource.toString());


        MockitoXADataSource.setStaticGetXAConnectionException(null);

        Recoverer recoverer = new Recoverer();
        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

    protected void tearDown() throws Exception {
        transactionManager.shutdown();
    }

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

        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY, BitronixInitialContextFactory.class.getName());
        Context ctx = new InitialContext(env);

        assertTrue(transactionManager == ctx.lookup("java:comp/UserTransaction"));

        try {
            ctx.lookup("aaa");
            fail("expected NameNotFoundException");
        } catch (NameNotFoundException ex) {
            assertEquals("unable to find a bound object at name 'aaa'", ex.getMessage());
        }

        assertTrue(pds == ctx.lookup("jdbc/pds"));

        ctx.close();

        pds.close();
    }
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

        // change disk journal into mock journal
        Field field = TransactionManagerServices.class.getDeclaredField("journal");
        field.setAccessible(true);
        field.set(TransactionManagerServices.class, 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);
View Full Code Here

        Map dataSources = loader.getResources();

        assertEquals(1, dataSources.size());
        String uniqueName = (String) dataSources.keySet().iterator().next();
        assertEquals("dataSource1", uniqueName);
        PoolingDataSource pds = (PoolingDataSource) dataSources.get(uniqueName);
        assertEquals("bitronix.tm.mock.resource.jdbc.MockitoXADataSource", pds.getClassName());
        assertEquals("dataSource1", pds.getUniqueName());
        assertEquals(123, pds.getMaxPoolSize());
        assertEquals(3, pds.getDriverProperties().size());

    }
View Full Code Here

        Map dataSources = loader.getResources();

        assertEquals(1, dataSources.size());
        String uniqueName = (String) dataSources.keySet().iterator().next();
        assertEquals("dataSource10", uniqueName);
        PoolingDataSource pds = (PoolingDataSource) dataSources.get(uniqueName);
        assertEquals("bitronix.tm.mock.resource.jdbc.MockitoXADataSource", pds.getClassName());
        assertEquals("dataSource10", pds.getUniqueName());
        assertEquals(123, pds.getMaxPoolSize());
        assertEquals(3, pds.getDriverProperties().size());
        String decryptedPassword = (String) PropertyUtils.getProperty(getXADataSource(pds), "password");
        assertEquals("java", decryptedPassword);
    }
View Full Code Here

        loader.initXAResourceProducers(p);
        Map dataSources = loader.getResources();

        assertEquals(2, dataSources.size());
        PoolingDataSource pds = (PoolingDataSource) dataSources.get("dataSource2");
        assertEquals("bitronix.tm.mock.resource.jdbc.MockitoXADataSource", pds.getClassName());
        assertEquals("dataSource2", pds.getUniqueName());
        assertEquals(123, pds.getMaxPoolSize());
        assertEquals(3, pds.getDriverProperties().size());

        pds = (PoolingDataSource) dataSources.get("some.unique.Name");
        assertEquals("bitronix.tm.mock.resource.jdbc.MockitoXADataSource", pds.getClassName());
        assertEquals("some.unique.Name", pds.getUniqueName());
        assertEquals(123, pds.getMaxPoolSize());
        assertEquals(true, pds.getDeferConnectionRelease());
        assertEquals(true, pds.getAutomaticEnlistingEnabled());
        assertEquals(true, pds.getUseTmJoin());
        assertEquals(0, pds.getDriverProperties().size());
    }
View Full Code Here

        p.setProperty("resource.ds2.maxPoolSize", "123");
        p.setProperty("resource.ds2.useTmJoin", "unknown"); // incorrect format, will default to false
        loader.initXAResourceProducers(p);


        PoolingDataSource pds = (PoolingDataSource) loader.getResources().get("some.also.other.unique.Name");
        assertFalse(pds.getUseTmJoin());
    }
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.