use of com.zaxxer.hikari.HikariConfig in project HikariCP by brettwooldridge.
the class TestMBean method testMBeanRegistration.
@Test
public void testMBeanRegistration() {
HikariConfig config = newHikariConfig();
config.setMinimumIdle(0);
config.setMaximumPoolSize(1);
config.setRegisterMbeans(true);
config.setConnectionTimeout(2800);
config.setConnectionTestQuery("VALUES 1");
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
new HikariDataSource(config).close();
}
use of com.zaxxer.hikari.HikariConfig in project HikariCP by brettwooldridge.
the class TestMBean method testMBeanConnectionTimeoutChange.
@Test
public void testMBeanConnectionTimeoutChange() throws SQLException {
HikariConfig config = newHikariConfig();
config.setMinimumIdle(1);
config.setMaximumPoolSize(2);
config.setRegisterMbeans(true);
config.setConnectionTimeout(2800);
config.setConnectionTestQuery("VALUES 1");
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
System.setProperty("com.zaxxer.hikari.housekeeping.periodMs", "250");
try (HikariDataSource ds = new HikariDataSource(config)) {
HikariConfigMXBean hikariConfigMXBean = ds.getHikariConfigMXBean();
assertEquals(2800, hikariConfigMXBean.getConnectionTimeout());
final StubDataSource stubDataSource = ds.unwrap(StubDataSource.class);
// connection acquisition takes more than 0 ms in a real system
stubDataSource.setConnectionAcquistionTime(1200);
hikariConfigMXBean.setConnectionTimeout(1000);
quietlySleep(500);
try (Connection conn1 = ds.getConnection();
Connection conn2 = ds.getConnection()) {
fail("Connection should have timed out.");
conn1.close();
conn2.close();
} catch (SQLException e) {
assertEquals(1000, ds.getConnectionTimeout());
}
} finally {
System.clearProperty("com.zaxxer.hikari.housekeeping.periodMs");
}
}
use of com.zaxxer.hikari.HikariConfig in project HikariCP by brettwooldridge.
the class TestMBean method testMBeanChange.
@Test
public void testMBeanChange() {
HikariConfig config = newHikariConfig();
config.setMinimumIdle(3);
config.setMaximumPoolSize(5);
config.setRegisterMbeans(true);
config.setConnectionTimeout(2800);
config.setConnectionTestQuery("VALUES 1");
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
try (HikariDataSource ds = new HikariDataSource(config)) {
HikariConfigMXBean hikariConfigMXBean = ds.getHikariConfigMXBean();
hikariConfigMXBean.setIdleTimeout(3000);
assertEquals(3000, ds.getIdleTimeout());
}
}
use of com.zaxxer.hikari.HikariConfig in project HikariCP by brettwooldridge.
the class TestMetrics method testMetricWait.
@Test
public void testMetricWait() throws SQLException {
MetricRegistry metricRegistry = new MetricRegistry();
HikariConfig config = newHikariConfig();
config.setMinimumIdle(1);
config.setMaximumPoolSize(1);
config.setMetricRegistry(metricRegistry);
config.setInitializationFailTimeout(Long.MAX_VALUE);
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
try (HikariDataSource ds = new HikariDataSource(config)) {
ds.getConnection().close();
Timer timer = metricRegistry.getTimers(new MetricFilter() {
/**
* {@inheritDoc}
*/
@Override
public boolean matches(String name, Metric metric) {
return "testMetricWait.pool.Wait".equals(MetricRegistry.name("testMetricWait", "pool", "Wait"));
}
}).values().iterator().next();
assertEquals(1, timer.getCount());
assertTrue(timer.getMeanRate() > 0.0);
}
}
use of com.zaxxer.hikari.HikariConfig in project jphp by jphp-compiler.
the class PSqlDriverManager method getPool.
@Signature
public static PSqlConnectionPool getPool(Environment env, String url, String driverName, @Nullable Properties properties) throws SQLException {
HikariConfig config = new HikariConfig(properties == null ? new Properties() : properties);
if (config.getDataSourceClassName() == null) {
config.setDataSourceClassName(dataSourceClasses.get(driverName));
}
HikariDataSource pool = new HikariDataSource(config);
pool.setDriverClassName(_getDriverClass(driverName));
pool.setJdbcUrl("jdbc:" + url);
return new PSqlConnectionPool(env, pool);
}
Aggregations