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