Search in sources :

Example 1 with PooledConnectionFactory

use of org.infinispan.persistence.jdbc.common.impl.connectionfactory.PooledConnectionFactory in project infinispan by infinispan.

the class UnitTestDatabaseManager method verifyConnectionLeaks.

public static void verifyConnectionLeaks(ConnectionFactory connectionFactory) {
    if (connectionFactory instanceof PooledConnectionFactory) {
        PooledConnectionFactory pcf = (PooledConnectionFactory) connectionFactory;
        try {
            // C3P0 needs a little delay before reporting the correct number of connections. Bah!
            Thread.sleep(500);
            assertEquals(pcf.getActiveConnections(), 0);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else if (connectionFactory instanceof SimpleConnectionFactory) {
        SimpleConnectionFactory scf = (SimpleConnectionFactory) connectionFactory;
        assertEquals(scf.getConnectionCount(), 0);
    }
}
Also used : SimpleConnectionFactory(org.infinispan.persistence.jdbc.common.impl.connectionfactory.SimpleConnectionFactory) PooledConnectionFactory(org.infinispan.persistence.jdbc.common.impl.connectionfactory.PooledConnectionFactory)

Example 2 with PooledConnectionFactory

use of org.infinispan.persistence.jdbc.common.impl.connectionfactory.PooledConnectionFactory in project infinispan by infinispan.

the class TableManagerTest method testConnectionLeakGuessDialect.

public void testConnectionLeakGuessDialect() {
    JdbcStringBasedStoreConfigurationBuilder storeBuilder = TestCacheManagerFactory.getDefaultCacheConfiguration(false).persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class);
    UnitTestDatabaseManager.buildTableManipulation(storeBuilder.table());
    PooledConnectionFactory connectionFactory = new PooledConnectionFactory();
    ConnectionFactoryConfiguration config = UnitTestDatabaseManager.configureUniqueConnectionFactory(storeBuilder).create();
    connectionFactory.start(config, Thread.currentThread().getContextClassLoader());
    // JdbcStringBasedStoreConfiguration defaults to null dialect, so dialect and versions must be guessed
    TableManager tableManager = TableManagerFactory.getManager(ctx, connectionFactory, storeBuilder.create(), "GuessDialect");
    tableManager.start();
    UnitTestDatabaseManager.verifyConnectionLeaks(connectionFactory);
    tableManager.stop();
    connectionFactory.stop();
}
Also used : PooledConnectionFactory(org.infinispan.persistence.jdbc.common.impl.connectionfactory.PooledConnectionFactory) TableManager(org.infinispan.persistence.jdbc.impl.table.TableManager) JdbcStringBasedStoreConfigurationBuilder(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfigurationBuilder) PooledConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration) ConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.ConnectionFactoryConfiguration) SimpleConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.SimpleConnectionFactoryConfiguration)

Aggregations

PooledConnectionFactory (org.infinispan.persistence.jdbc.common.impl.connectionfactory.PooledConnectionFactory)2 ConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.ConnectionFactoryConfiguration)1 PooledConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration)1 SimpleConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.SimpleConnectionFactoryConfiguration)1 SimpleConnectionFactory (org.infinispan.persistence.jdbc.common.impl.connectionfactory.SimpleConnectionFactory)1 JdbcStringBasedStoreConfigurationBuilder (org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfigurationBuilder)1 TableManager (org.infinispan.persistence.jdbc.impl.table.TableManager)1