Search in sources :

Example 6 with HikariPool

use of com.zaxxer.hikari.pool.HikariPool in project HikariCP by brettwooldridge.

the class HikariDataSource method setHealthCheckRegistry.

/**
 * {@inheritDoc}
 */
@Override
public void setHealthCheckRegistry(Object healthCheckRegistry) {
    boolean isAlreadySet = getHealthCheckRegistry() != null;
    super.setHealthCheckRegistry(healthCheckRegistry);
    HikariPool p = pool;
    if (p != null) {
        if (isAlreadySet) {
            throw new IllegalStateException("HealthCheckRegistry can only be set one time");
        } else {
            p.setHealthCheckRegistry(super.getHealthCheckRegistry());
        }
    }
}
Also used : HikariPool(com.zaxxer.hikari.pool.HikariPool)

Example 7 with HikariPool

use of com.zaxxer.hikari.pool.HikariPool in project HikariCP by brettwooldridge.

the class HikariDataSource method setMetricRegistry.

// ***********************************************************************
// HikariConfigMXBean methods
// ***********************************************************************
/**
 * {@inheritDoc}
 */
@Override
public void setMetricRegistry(Object metricRegistry) {
    boolean isAlreadySet = getMetricRegistry() != null;
    super.setMetricRegistry(metricRegistry);
    HikariPool p = pool;
    if (p != null) {
        if (isAlreadySet) {
            throw new IllegalStateException("MetricRegistry can only be set one time");
        } else {
            p.setMetricRegistry(super.getMetricRegistry());
        }
    }
}
Also used : HikariPool(com.zaxxer.hikari.pool.HikariPool)

Example 8 with HikariPool

use of com.zaxxer.hikari.pool.HikariPool in project HikariCP by brettwooldridge.

the class BasicPoolTest method testIdleTimeout.

@Test
public void testIdleTimeout() throws InterruptedException, SQLException {
    HikariConfig config = newHikariConfig();
    config.setMinimumIdle(5);
    config.setMaximumPoolSize(10);
    config.setConnectionTestQuery("SELECT 1");
    config.setDataSourceClassName("org.h2.jdbcx.JdbcDataSource");
    config.addDataSourceProperty("url", "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
    System.setProperty("com.zaxxer.hikari.housekeeping.periodMs", "1000");
    try (HikariDataSource ds = new HikariDataSource(config)) {
        System.clearProperty("com.zaxxer.hikari.housekeeping.periodMs");
        SECONDS.sleep(1);
        HikariPool pool = getPool(ds);
        getUnsealedConfig(ds).setIdleTimeout(3000);
        assertEquals("Total connections not as expected", 5, pool.getTotalConnections());
        assertEquals("Idle connections not as expected", 5, pool.getIdleConnections());
        try (Connection connection = ds.getConnection()) {
            Assert.assertNotNull(connection);
            MILLISECONDS.sleep(1500);
            assertEquals("Second total connections not as expected", 6, pool.getTotalConnections());
            assertEquals("Second idle connections not as expected", 5, pool.getIdleConnections());
        }
        assertEquals("Idle connections not as expected", 6, pool.getIdleConnections());
        SECONDS.sleep(2);
        assertEquals("Third total connections not as expected", 5, pool.getTotalConnections());
        assertEquals("Third idle connections not as expected", 5, pool.getIdleConnections());
    }
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) HikariPool(com.zaxxer.hikari.pool.HikariPool) Connection(java.sql.Connection) HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) Test(org.junit.Test)

Example 9 with HikariPool

use of com.zaxxer.hikari.pool.HikariPool in project bootique-jdbc by bootique.

the class HikariCPDerbyIT method testDerbyDriverDataSource.

@Test
public void testDerbyDriverDataSource() throws SQLException {
    BQRuntime runtime = testFactory.app("-c", "classpath:HikariCPDerbyIT.yml").autoLoadModules().createRuntime();
    DataSource ds5 = runtime.getInstance(DataSourceFactory.class).forName("derby5");
    assertNotNull(ds5);
    assertTrue(ds5 instanceof HikariDataSource);
    HikariDataSource hikariDS = (HikariDataSource) ds5;
    assertEquals("org.apache.derby.jdbc.EmbeddedDriver", hikariDS.getDriverClassName());
    HikariPool pool = (HikariPool) hikariDS.getHikariPoolMXBean();
    assertTrue(pool.getUnwrappedDataSource() instanceof DriverDataSource);
    try (Connection c = hikariDS.getConnection()) {
        assertEquals("jdbc:derby:", c.getMetaData().getURL());
    }
}
Also used : DataSourceFactory(io.bootique.jdbc.DataSourceFactory) HikariDataSource(com.zaxxer.hikari.HikariDataSource) HikariPool(com.zaxxer.hikari.pool.HikariPool) DriverDataSource(com.zaxxer.hikari.util.DriverDataSource) BQRuntime(io.bootique.BQRuntime) Connection(java.sql.Connection) DriverDataSource(com.zaxxer.hikari.util.DriverDataSource) EmbeddedDataSource(org.apache.derby.jdbc.EmbeddedDataSource) HikariDataSource(com.zaxxer.hikari.HikariDataSource) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Aggregations

HikariPool (com.zaxxer.hikari.pool.HikariPool)9 HikariDataSource (com.zaxxer.hikari.HikariDataSource)4 Connection (java.sql.Connection)4 Test (org.junit.Test)4 HikariConfig (com.zaxxer.hikari.HikariConfig)2 TestElf.newHikariConfig (com.zaxxer.hikari.pool.TestElf.newHikariConfig)2 DriverDataSource (com.zaxxer.hikari.util.DriverDataSource)2 BQRuntime (io.bootique.BQRuntime)2 DataSourceFactory (io.bootique.jdbc.DataSourceFactory)2 DataSource (javax.sql.DataSource)2 EmbeddedDataSource (org.apache.derby.jdbc.EmbeddedDataSource)2 PoolInitializationException (com.zaxxer.hikari.pool.HikariPool.PoolInitializationException)1 SQLException (java.sql.SQLException)1