Search in sources :

Example 56 with HikariConfig

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

the class TestValidation method validateInvalidValidationTimeout.

@Test
public void validateInvalidValidationTimeout() {
    try {
        HikariConfig config = newHikariConfig();
        config.setValidationTimeout(10L);
        fail();
    } catch (IllegalArgumentException ise) {
        assertTrue(ise.getMessage().contains("validationTimeout cannot be less than 250ms"));
    }
}
Also used : HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) Test(org.junit.Test)

Example 57 with HikariConfig

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

the class TestValidation method validateInvalidMinIdle.

@Test
public void validateInvalidMinIdle() {
    try {
        HikariConfig config = newHikariConfig();
        config.setMinimumIdle(-1);
        fail();
    } catch (IllegalArgumentException ise) {
        assertTrue(ise.getMessage().contains("minimumIdle cannot be negative"));
    }
}
Also used : HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) Test(org.junit.Test)

Example 58 with HikariConfig

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

the class UnwrapTest method testUnwrapDataSource.

@Test
public void testUnwrapDataSource() throws SQLException {
    HikariConfig config = newHikariConfig();
    config.setMinimumIdle(1);
    config.setMaximumPoolSize(1);
    config.setInitializationFailTimeout(0);
    config.setConnectionTestQuery("VALUES 1");
    config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
    try (HikariDataSource ds = new HikariDataSource(config)) {
        StubDataSource unwrap = ds.unwrap(StubDataSource.class);
        assertNotNull(unwrap);
        assertTrue(unwrap instanceof StubDataSource);
        assertTrue(ds.isWrapperFor(HikariDataSource.class));
        assertTrue(ds.unwrap(HikariDataSource.class) instanceof HikariDataSource);
        assertFalse(ds.isWrapperFor(getClass()));
        try {
            ds.unwrap(getClass());
        } catch (SQLException e) {
            assertTrue(e.getMessage().contains("Wrapped DataSource"));
        }
    }
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) SQLException(java.sql.SQLException) HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) StubDataSource(com.zaxxer.hikari.mocks.StubDataSource) Test(org.junit.Test)

Example 59 with HikariConfig

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

the class TestJNDI method testJndiLookup4.

@Test
public void testJndiLookup4() throws Exception {
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.osjava.sj.memory.MemoryContextFactory");
    System.setProperty("org.osjava.sj.jndi.shared", "true");
    InitialContext ic = new InitialContext();
    StubDataSource ds = new StubDataSource();
    Context subcontext = ic.createSubcontext("java:/comp/env/jdbc");
    subcontext.bind("java:/comp/env/jdbc/myDS", ds);
    HikariConfig config = newHikariConfig();
    config.setDataSourceJNDI("java:/comp/env/jdbc/myDS");
    try (HikariDataSource hds = new HikariDataSource(config);
        Connection conn = hds.getConnection()) {
        assertNotNull(conn);
    }
}
Also used : InitialContext(javax.naming.InitialContext) AbstractContext(org.osjava.sj.jndi.AbstractContext) Context(javax.naming.Context) TestElf.newHikariDataSource(com.zaxxer.hikari.pool.TestElf.newHikariDataSource) HikariDataSource(com.zaxxer.hikari.HikariDataSource) Connection(java.sql.Connection) HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) StubDataSource(com.zaxxer.hikari.mocks.StubDataSource) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 60 with HikariConfig

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

the class TestMBean method testMBeanRegistration.

@Test
public void testMBeanRegistration() throws SQLException {
    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");
    try (HikariDataSource ds = new HikariDataSource(config)) {
    // Close immediately
    }
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) 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