Search in sources :

Example 1 with HikariCPConnectionFactory

use of org.opennms.core.db.HikariCPConnectionFactory in project opennms by OpenNMS.

the class TemporaryDatabaseExecutionListener method prepareTestInstance.

@Override
public void prepareTestInstance(final TestContext testContext) throws Exception {
    //System.err.println(String.format("TemporaryDatabaseExecutionListener.prepareTestInstance(%s); details: %s", testContext.hashCode(), testContext));
    final JUnitTemporaryDatabase jtd = findAnnotation(testContext);
    if (jtd == null) {
        return;
    }
    m_database = m_databases.remove();
    //
    if (jtd.poolConnections()) {
        JdbcDataSource ds = new JdbcDataSource();
        ds.setDatabaseName(m_database.getTestDatabase());
        ds.setUserName(System.getProperty(TemporaryDatabase.ADMIN_USER_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_USER));
        ds.setPassword(System.getProperty(TemporaryDatabase.ADMIN_PASSWORD_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_PASSWORD));
        ds.setUrl(System.getProperty(TemporaryDatabase.URL_PROPERTY, TemporaryDatabase.DEFAULT_URL) + m_database.getTestDatabase());
        ds.setClassName(System.getProperty(TemporaryDatabase.DRIVER_PROPERTY, TemporaryDatabase.DEFAULT_DRIVER));
        HikariCPConnectionFactory pool = new HikariCPConnectionFactory(ds);
        // NMS-8911: Reduce the max connection lifetime so that HikariCP recycles 
        // connections more aggressively during tests
        pool.setMaxLifetime(500);
        DataSourceFactory.setInstance(pool);
    } else {
        DataSourceFactory.setInstance(m_database);
    }
    XADataSourceFactory.setInstance(m_database);
//System.err.println(String.format("TemporaryDatabaseExecutionListener.prepareTestInstance(%s) prepared db %s; details: %s", testContext.hashCode(), m_database.toString(), testContext));
//System.err.println("Temporary Database Name: " + m_database.getTestDatabase());
}
Also used : JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) JdbcDataSource(org.opennms.netmgt.config.opennmsDataSources.JdbcDataSource) HikariCPConnectionFactory(org.opennms.core.db.HikariCPConnectionFactory)

Aggregations

HikariCPConnectionFactory (org.opennms.core.db.HikariCPConnectionFactory)1 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)1 JdbcDataSource (org.opennms.netmgt.config.opennmsDataSources.JdbcDataSource)1