Search in sources :

Example 91 with HikariConfig

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

Example 92 with HikariConfig

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");
    }
}
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 93 with HikariConfig

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

Example 94 with HikariConfig

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);
    }
}
Also used : TestElf.newHikariDataSource(com.zaxxer.hikari.pool.TestElf.newHikariDataSource) HikariDataSource(com.zaxxer.hikari.HikariDataSource) MetricFilter(com.codahale.metrics.MetricFilter) Timer(com.codahale.metrics.Timer) MetricRegistry(com.codahale.metrics.MetricRegistry) Metric(com.codahale.metrics.Metric) HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) Test(org.junit.Test)

Example 95 with HikariConfig

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);
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) HikariConfig(com.zaxxer.hikari.HikariConfig) Properties(java.util.Properties) Signature(php.runtime.annotation.Reflection.Signature)

Aggregations

HikariConfig (com.zaxxer.hikari.HikariConfig)136 HikariDataSource (com.zaxxer.hikari.HikariDataSource)109 Test (org.junit.Test)82 TestElf.newHikariConfig (com.zaxxer.hikari.pool.TestElf.newHikariConfig)79 Connection (java.sql.Connection)41 StubConnection (com.zaxxer.hikari.mocks.StubConnection)29 SQLException (java.sql.SQLException)26 Properties (java.util.Properties)11 StubDataSource (com.zaxxer.hikari.mocks.StubDataSource)9 PoolInitializationException (com.zaxxer.hikari.pool.HikariPool.PoolInitializationException)6 FacesMessage (javax.faces.application.FacesMessage)6 DataSource (javax.sql.DataSource)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Statement (java.sql.Statement)5 PrintStream (java.io.PrintStream)4 PreparedStatement (java.sql.PreparedStatement)4 Connexion (mom.trd.opentheso.bdd.helper.Connexion)4 MetricRegistry (com.codahale.metrics.MetricRegistry)3 TestElf.newHikariDataSource (com.zaxxer.hikari.pool.TestElf.newHikariDataSource)3 File (java.io.File)3