use of com.zaxxer.hikari.HikariDataSource in project HikariCP by brettwooldridge.
the class TestMBean method testMBeanReporting.
@Test
public void testMBeanReporting() throws SQLException, InterruptedException, MalformedObjectNameException {
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");
System.setProperty("com.zaxxer.hikari.housekeeping.periodMs", "100");
try (HikariDataSource ds = new HikariDataSource(config)) {
getUnsealedConfig(ds).setIdleTimeout(3000);
TimeUnit.SECONDS.sleep(1);
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName poolName = new ObjectName("com.zaxxer.hikari:type=Pool (testMBeanReporting)");
HikariPoolMXBean hikariPoolMXBean = JMX.newMXBeanProxy(mBeanServer, poolName, HikariPoolMXBean.class);
assertEquals(0, hikariPoolMXBean.getActiveConnections());
assertEquals(3, hikariPoolMXBean.getIdleConnections());
try (Connection ignored = ds.getConnection()) {
assertEquals(1, hikariPoolMXBean.getActiveConnections());
TimeUnit.SECONDS.sleep(1);
assertEquals(3, hikariPoolMXBean.getIdleConnections());
assertEquals(4, hikariPoolMXBean.getTotalConnections());
}
TimeUnit.SECONDS.sleep(2);
assertEquals(0, hikariPoolMXBean.getActiveConnections());
assertEquals(3, hikariPoolMXBean.getIdleConnections());
assertEquals(3, hikariPoolMXBean.getTotalConnections());
} finally {
System.clearProperty("com.zaxxer.hikari.housekeeping.periodMs");
}
}
use of com.zaxxer.hikari.HikariDataSource in project HikariCP by brettwooldridge.
the class TestMetrics method testMetricRegistrySubclassIsAllowed.
@Test
public void testMetricRegistrySubclassIsAllowed() {
try (HikariDataSource ds = newHikariDataSource()) {
ds.setMaximumPoolSize(1);
ds.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
ds.setMetricRegistry(new MetricRegistry() {
@Override
public Timer timer(String name) {
return super.timer(name);
}
});
}
}
use of com.zaxxer.hikari.HikariDataSource in project HikariCP by brettwooldridge.
the class TestMetrics method testMetricUsage.
@Test
public void testMetricUsage() throws SQLException {
assumeFalse(System.getProperty("os.name").contains("Windows"));
MetricRegistry metricRegistry = new MetricRegistry();
HikariConfig config = newHikariConfig();
config.setMinimumIdle(1);
config.setMaximumPoolSize(1);
config.setMetricRegistry(metricRegistry);
config.setInitializationFailTimeout(0);
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
try (HikariDataSource ds = new HikariDataSource(config)) {
try (Connection connection = ds.getConnection()) {
UtilityElf.quietlySleep(250L);
}
Histogram histo = metricRegistry.getHistograms(new MetricFilter() {
/**
* {@inheritDoc}
*/
@Override
public boolean matches(String name, Metric metric) {
return name.equals(MetricRegistry.name("testMetricUsage", "pool", "Usage"));
}
}).values().iterator().next();
assertEquals(1, histo.getCount());
double seventyFifth = histo.getSnapshot().get75thPercentile();
assertTrue("Seventy-fith percentile less than 250ms: " + seventyFifth, seventyFifth >= 250.0);
}
}
use of com.zaxxer.hikari.HikariDataSource in project waltz by khartec.
the class DIConfiguration method dataSource.
@Bean
public DataSource dataSource() {
HikariConfig dsConfig = new HikariConfig();
dsConfig.setJdbcUrl(dbUrl);
dsConfig.setUsername(dbUser);
dsConfig.setPassword(dbPassword);
dsConfig.setDriverClassName(dbDriver);
dsConfig.setMaximumPoolSize(dbPoolMax);
dsConfig.setMinimumIdle(dbPoolMin);
return new HikariDataSource(dsConfig);
}
use of com.zaxxer.hikari.HikariDataSource in project hive by apache.
the class TestDataSourceProviderFactory method testSetHikariCpStringProperty.
@Test
public void testSetHikariCpStringProperty() throws SQLException {
MetastoreConf.setVar(conf, ConfVars.CONNECTION_POOLING_TYPE, HikariCPDataSourceProvider.HIKARI);
conf.set(HikariCPDataSourceProvider.HIKARI + ".connectionInitSql", "select 1 from dual");
conf.set(HikariCPDataSourceProvider.HIKARI + ".initializationFailTimeout", "-1");
DataSourceProvider dsp = DataSourceProviderFactory.getDataSourceProvider(conf);
Assert.assertNotNull(dsp);
DataSource ds = dsp.create(conf);
Assert.assertTrue(ds instanceof HikariDataSource);
Assert.assertEquals("select 1 from dual", ((HikariDataSource) ds).getConnectionInitSql());
}
Aggregations