Search in sources :

Example 86 with HikariDataSource

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

the class TestElf method newHikariDataSource.

static HikariDataSource newHikariDataSource() {
    final StackTraceElement callerStackTrace = Thread.currentThread().getStackTrace()[2];
    String poolName = callerStackTrace.getMethodName();
    if ("setup".equals(poolName)) {
        poolName = callerStackTrace.getClassName();
    }
    final HikariDataSource ds = new HikariDataSource();
    ds.setPoolName(poolName);
    return ds;
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource)

Example 87 with HikariDataSource

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

the class ExceptionTest 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 88 with HikariDataSource

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

the class HouseKeeperCleanupTest method testHouseKeeperCleanupWithCustomExecutor.

@Test
public void testHouseKeeperCleanupWithCustomExecutor() throws Exception {
    HikariConfig config = newHikariConfig();
    config.setMinimumIdle(0);
    config.setMaximumPoolSize(10);
    config.setInitializationFailTimeout(Long.MAX_VALUE);
    config.setConnectionTimeout(2500);
    config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
    config.setScheduledExecutor(executor);
    HikariConfig config2 = newHikariConfig();
    config.copyState(config2);
    try (final HikariDataSource ds1 = new HikariDataSource(config);
        final HikariDataSource ds2 = new HikariDataSource(config2)) {
        assertEquals("Scheduled tasks count not as expected, ", 2, executor.getQueue().size());
    }
    assertEquals("Scheduled tasks count not as expected, ", 0, executor.getQueue().size());
}
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 89 with HikariDataSource

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

the class JdbcDriverTest method driverTest2.

@Test
public void driverTest2() throws SQLException {
    HikariConfig config = newHikariConfig();
    config.setMinimumIdle(1);
    config.setMaximumPoolSize(1);
    config.setConnectionTestQuery("VALUES 1");
    config.setDriverClassName("com.zaxxer.hikari.mocks.StubDriver");
    config.setJdbcUrl("jdbc:invalid");
    try {
        ds = new HikariDataSource(config);
    } catch (RuntimeException e) {
        assertTrue(e.getMessage().contains("claims to not accept"));
    }
}
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 90 with HikariDataSource

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

the class MiscTest method testLogWriter.

@Test
public void testLogWriter() throws SQLException {
    HikariConfig config = newHikariConfig();
    config.setMinimumIdle(0);
    config.setMaximumPoolSize(4);
    config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
    setConfigUnitTest(true);
    try (HikariDataSource ds = new HikariDataSource(config)) {
        PrintWriter writer = new PrintWriter(System.out);
        ds.setLogWriter(writer);
        assertSame(writer, ds.getLogWriter());
        assertEquals("testLogWriter", config.getPoolName());
    } finally {
        setConfigUnitTest(false);
    }
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) PrintWriter(java.io.PrintWriter) Test(org.junit.Test) TestElf.setConfigUnitTest(com.zaxxer.hikari.pool.TestElf.setConfigUnitTest)

Aggregations

HikariDataSource (com.zaxxer.hikari.HikariDataSource)114 Test (org.junit.Test)78 HikariConfig (com.zaxxer.hikari.HikariConfig)75 TestElf.newHikariConfig (com.zaxxer.hikari.pool.TestElf.newHikariConfig)63 Connection (java.sql.Connection)63 TestElf.newHikariDataSource (com.zaxxer.hikari.pool.TestElf.newHikariDataSource)33 StubConnection (com.zaxxer.hikari.mocks.StubConnection)29 SQLException (java.sql.SQLException)27 TestElf.setConfigUnitTest (com.zaxxer.hikari.pool.TestElf.setConfigUnitTest)16 StubDataSource (com.zaxxer.hikari.mocks.StubDataSource)10 MetricRegistry (com.codahale.metrics.MetricRegistry)8 PreparedStatement (java.sql.PreparedStatement)6 Statement (java.sql.Statement)6 PoolInitializationException (com.zaxxer.hikari.pool.HikariPool.PoolInitializationException)5 SQLTransientConnectionException (java.sql.SQLTransientConnectionException)5 Properties (java.util.Properties)5 ResultSet (java.sql.ResultSet)4 HealthCheckRegistry (com.codahale.metrics.health.HealthCheckRegistry)3 ArrayList (java.util.ArrayList)3 ExecutorService (java.util.concurrent.ExecutorService)3