Search in sources :

Example 1 with HikariConfigMXBean

use of com.zaxxer.hikari.HikariConfigMXBean in project midpoint by Evolveum.

the class TaskManagerQuartzImpl method getDBPoolStats.

// TODO move to more appropriate place
@Override
public Number[] getDBPoolStats() {
    if (dataSource instanceof HikariDataSource) {
        HikariPoolMXBean pool = ((HikariDataSource) dataSource).getHikariPoolMXBean();
        HikariConfigMXBean config = ((HikariDataSource) dataSource).getHikariConfigMXBean();
        if (pool == null || config == null) {
            return null;
        }
        return new Number[] { pool.getActiveConnections(), pool.getIdleConnections(), pool.getThreadsAwaitingConnection(), pool.getTotalConnections(), config.getMaximumPoolSize() };
    }
    return null;
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) HikariPoolMXBean(com.zaxxer.hikari.HikariPoolMXBean) HikariConfigMXBean(com.zaxxer.hikari.HikariConfigMXBean)

Example 2 with HikariConfigMXBean

use of com.zaxxer.hikari.HikariConfigMXBean 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");
    }
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) SQLException(java.sql.SQLException) Connection(java.sql.Connection) HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) StubDataSource(com.zaxxer.hikari.mocks.StubDataSource) HikariConfigMXBean(com.zaxxer.hikari.HikariConfigMXBean) Test(org.junit.Test)

Example 3 with HikariConfigMXBean

use of com.zaxxer.hikari.HikariConfigMXBean 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());
    }
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) HikariConfigMXBean(com.zaxxer.hikari.HikariConfigMXBean) Test(org.junit.Test)

Aggregations

HikariConfigMXBean (com.zaxxer.hikari.HikariConfigMXBean)3 HikariDataSource (com.zaxxer.hikari.HikariDataSource)3 HikariConfig (com.zaxxer.hikari.HikariConfig)2 TestElf.newHikariConfig (com.zaxxer.hikari.pool.TestElf.newHikariConfig)2 Test (org.junit.Test)2 HikariPoolMXBean (com.zaxxer.hikari.HikariPoolMXBean)1 StubDataSource (com.zaxxer.hikari.mocks.StubDataSource)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1