use of com.zaxxer.hikari.HikariPoolMXBean 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");
}
}
Aggregations