Search in sources :

Example 21 with HikariConfig

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

the class ShutdownTest method testShutdown2.

@Test
public void testShutdown2() throws SQLException {
    assertSame("StubConnection count not as expected", 0, StubConnection.count.get());
    StubConnection.slowCreate = true;
    HikariConfig config = newHikariConfig();
    config.setMinimumIdle(10);
    config.setMaximumPoolSize(10);
    config.setInitializationFailTimeout(0);
    config.setConnectionTestQuery("VALUES 1");
    config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
    try (HikariDataSource ds = new HikariDataSource(config)) {
        HikariPool pool = getPool(ds);
        quietlySleep(1200L);
        assertTrue("Total connection count not as expected, ", pool.getTotalConnections() > 0);
        ds.close();
        assertSame("Active connection count not as expected, ", 0, pool.getActiveConnections());
        assertSame("Idle connection count not as expected, ", 0, pool.getIdleConnections());
        assertSame("Total connection count not as expected, ", 0, pool.getTotalConnections());
        assertTrue(ds.toString().startsWith("HikariDataSource (") && ds.toString().endsWith(")"));
    }
}
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 22 with HikariConfig

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

the class ShutdownTest method testAfterShutdown.

@Test
public void testAfterShutdown() throws Exception {
    HikariConfig config = newHikariConfig();
    config.setMinimumIdle(0);
    config.setMaximumPoolSize(5);
    config.setInitializationFailTimeout(0);
    config.setConnectionTestQuery("VALUES 1");
    config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
    try (HikariDataSource ds = new HikariDataSource(config)) {
        ds.close();
        try {
            ds.getConnection();
        } catch (SQLException e) {
            Assert.assertTrue(e.getMessage().contains("has been closed."));
        }
    }
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) SQLException(java.sql.SQLException) HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) Test(org.junit.Test)

Example 23 with HikariConfig

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

the class StatementTest method setup.

@Before
public void setup() {
    HikariConfig config = newHikariConfig();
    config.setMinimumIdle(1);
    config.setMaximumPoolSize(2);
    config.setConnectionTestQuery("VALUES 1");
    config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
    ds = new HikariDataSource(config);
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) Before(org.junit.Before)

Example 24 with HikariConfig

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

the class TestValidation method validateMissingProperties.

@Test
public void validateMissingProperties() {
    try {
        HikariConfig config = new HikariConfig("missing");
        config.validate();
    } catch (IllegalArgumentException ise) {
        assertTrue(ise.getMessage().contains("property file"));
    }
}
Also used : HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) Test(org.junit.Test)

Example 25 with HikariConfig

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

the class TestValidation method validateMissingDS.

@Test
public void validateMissingDS() {
    try {
        HikariConfig config = newHikariConfig();
        config.validate();
        fail();
    } catch (IllegalArgumentException ise) {
        assertTrue(ise.getMessage().contains("dataSource or dataSourceClassName or jdbcUrl is required."));
    }
}
Also used : HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) Test(org.junit.Test)

Aggregations

HikariConfig (com.zaxxer.hikari.HikariConfig)101 TestElf.newHikariConfig (com.zaxxer.hikari.pool.TestElf.newHikariConfig)85 HikariDataSource (com.zaxxer.hikari.HikariDataSource)75 Test (org.junit.Test)75 Connection (java.sql.Connection)48 StubConnection (com.zaxxer.hikari.mocks.StubConnection)28 SQLException (java.sql.SQLException)23 TestElf.newHikariDataSource (com.zaxxer.hikari.pool.TestElf.newHikariDataSource)17 TestElf.setConfigUnitTest (com.zaxxer.hikari.pool.TestElf.setConfigUnitTest)15 Properties (java.util.Properties)10 StubDataSource (com.zaxxer.hikari.mocks.StubDataSource)8 PreparedStatement (java.sql.PreparedStatement)6 DataSource (javax.sql.DataSource)6 PoolInitializationException (com.zaxxer.hikari.pool.HikariPool.PoolInitializationException)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 SQLTransientConnectionException (java.sql.SQLTransientConnectionException)5 Statement (java.sql.Statement)5 PrintStream (java.io.PrintStream)4 MetricRegistry (com.codahale.metrics.MetricRegistry)3 ResultSet (java.sql.ResultSet)3