Search in sources :

Example 41 with HikariConfig

use of com.zaxxer.hikari.HikariConfig in project HikariCP by brettwooldridge.

the class TestSealedConfig method testSealedAccessibleMethods.

@Test
public void testSealedAccessibleMethods() throws SQLException {
    HikariConfig config = newHikariConfig();
    config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
    try (HikariDataSource ds = new HikariDataSource(config)) {
        ds.setConnectionTimeout(5000);
        ds.setValidationTimeout(5000);
        ds.setIdleTimeout(30000);
        ds.setLeakDetectionThreshold(60000);
        ds.setMaxLifetime(1800000);
        ds.setMinimumIdle(5);
        ds.setMaximumPoolSize(8);
        ds.setPassword("password");
        ds.setUsername("username");
    }
}
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 42 with HikariConfig

use of com.zaxxer.hikari.HikariConfig in project HikariCP by brettwooldridge.

the class BasicPoolTest method testIdleTimeout2.

@Test
public void testIdleTimeout2() throws InterruptedException, SQLException {
    HikariConfig config = newHikariConfig();
    config.setMaximumPoolSize(50);
    config.setConnectionTestQuery("SELECT 1");
    config.setDataSourceClassName("org.h2.jdbcx.JdbcDataSource");
    config.addDataSourceProperty("url", "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
    System.setProperty("com.zaxxer.hikari.housekeeping.periodMs", "1000");
    try (HikariDataSource ds = new HikariDataSource(config)) {
        System.clearProperty("com.zaxxer.hikari.housekeeping.periodMs");
        SECONDS.sleep(1);
        HikariPool pool = getPool(ds);
        getUnsealedConfig(ds).setIdleTimeout(3000);
        assertEquals("Total connections not as expected", 50, pool.getTotalConnections());
        assertEquals("Idle connections not as expected", 50, pool.getIdleConnections());
        try (Connection connection = ds.getConnection()) {
            assertNotNull(connection);
            MILLISECONDS.sleep(1500);
            assertEquals("Second total connections not as expected", 50, pool.getTotalConnections());
            assertEquals("Second idle connections not as expected", 49, pool.getIdleConnections());
        }
        assertEquals("Idle connections not as expected", 50, pool.getIdleConnections());
        SECONDS.sleep(3);
        assertEquals("Third total connections not as expected", 50, pool.getTotalConnections());
        assertEquals("Third idle connections not as expected", 50, pool.getIdleConnections());
    }
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) HikariPool(com.zaxxer.hikari.pool.HikariPool) Connection(java.sql.Connection) HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) Test(org.junit.Test)

Example 43 with HikariConfig

use of com.zaxxer.hikari.HikariConfig in project HikariCP by brettwooldridge.

the class HikariCPCollectorTest method noConnectionWithoutPoolName.

@Test
public void noConnectionWithoutPoolName() throws Exception {
    HikariConfig config = new HikariConfig();
    config.setMinimumIdle(0);
    config.setMetricsTrackerFactory(new PrometheusMetricsTrackerFactory());
    config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
    StubConnection.slowCreate = true;
    try (HikariDataSource ds = new HikariDataSource(config)) {
        String poolName = ds.getHikariConfigMXBean().getPoolName();
        assertThat(getValue("hikaricp_active_connections", poolName), is(0.0));
        assertThat(getValue("hikaricp_idle_connections", poolName), is(0.0));
        assertThat(getValue("hikaricp_pending_threads", poolName), is(0.0));
        assertThat(getValue("hikaricp_connections", poolName), is(0.0));
        assertThat(getValue("hikaricp_max_connections", poolName), is(10.0));
        assertThat(getValue("hikaricp_min_connections", poolName), is(0.0));
    } finally {
        StubConnection.slowCreate = false;
    }
}
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 44 with HikariConfig

use of com.zaxxer.hikari.HikariConfig in project HikariCP by brettwooldridge.

the class HikariCPCollectorTest method connection1.

@Test
public void connection1() throws Exception {
    HikariConfig config = newHikariConfig();
    config.setMetricsTrackerFactory(new PrometheusMetricsTrackerFactory());
    config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
    config.setMaximumPoolSize(1);
    StubConnection.slowCreate = true;
    try (HikariDataSource ds = new HikariDataSource(config);
        Connection connection1 = ds.getConnection()) {
        quietlySleep(1000);
        assertThat(getValue("hikaricp_active_connections", "connection1"), is(1.0));
        assertThat(getValue("hikaricp_idle_connections", "connection1"), is(0.0));
        assertThat(getValue("hikaricp_pending_threads", "connection1"), is(0.0));
        assertThat(getValue("hikaricp_connections", "connection1"), is(1.0));
        assertThat(getValue("hikaricp_max_connections", "connection1"), is(1.0));
        assertThat(getValue("hikaricp_min_connections", "connection1"), is(1.0));
    } finally {
        StubConnection.slowCreate = false;
    }
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) Connection(java.sql.Connection) StubConnection(com.zaxxer.hikari.mocks.StubConnection) HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) Test(org.junit.Test)

Example 45 with HikariConfig

use of com.zaxxer.hikari.HikariConfig in project HikariCP by brettwooldridge.

the class PrometheusMetricsTrackerTest method checkSummaryMetricFamily.

private void checkSummaryMetricFamily(String metricName) {
    HikariConfig config = newHikariConfig();
    config.setMetricsTrackerFactory(new PrometheusMetricsTrackerFactory());
    config.setJdbcUrl("jdbc:h2:mem:");
    try (HikariDataSource ignored = new HikariDataSource(config)) {
        Double count = collectorRegistry.getSampleValue(metricName + "_count", new String[] { POOL_LABEL_NAME }, new String[] { config.getPoolName() });
        assertNotNull(count);
        Double sum = collectorRegistry.getSampleValue(metricName + "_sum", new String[] { POOL_LABEL_NAME }, new String[] { config.getPoolName() });
        assertNotNull(sum);
        for (String quantileLabelValue : QUANTILE_LABEL_VALUES) {
            Double quantileValue = collectorRegistry.getSampleValue(metricName, new String[] { POOL_LABEL_NAME, QUANTILE_LABEL_NAME }, new String[] { config.getPoolName(), quantileLabelValue });
            assertNotNull("q = " + quantileLabelValue, quantileValue);
        }
    }
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig)

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