Search in sources :

Example 96 with HikariDataSource

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

the class ShutdownTest method testShutdownDuringInit.

@Test
public void testShutdownDuringInit() throws Exception {
    final HikariConfig config = newHikariConfig();
    config.setMinimumIdle(5);
    config.setMaximumPoolSize(5);
    config.setConnectionTimeout(1000);
    config.setValidationTimeout(1000);
    config.setInitializationFailTimeout(0);
    config.setConnectionTestQuery("VALUES 1");
    config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
    try (HikariDataSource ds = new HikariDataSource(config)) {
        StubConnection.slowCreate = true;
        UtilityElf.quietlySleep(3000L);
    }
}
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 97 with HikariDataSource

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

the class TestProxies method testProxyCreation.

@Test
public void testProxyCreation() throws SQLException {
    HikariConfig config = newHikariConfig();
    config.setMinimumIdle(0);
    config.setMaximumPoolSize(1);
    config.setConnectionTestQuery("VALUES 1");
    config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
    try (HikariDataSource ds = new HikariDataSource(config)) {
        Connection conn = ds.getConnection();
        assertNotNull(conn.createStatement(ResultSet.FETCH_FORWARD, ResultSet.TYPE_SCROLL_INSENSITIVE));
        assertNotNull(conn.createStatement(ResultSet.FETCH_FORWARD, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.HOLD_CURSORS_OVER_COMMIT));
        assertNotNull(conn.prepareCall("some sql"));
        assertNotNull(conn.prepareCall("some sql", ResultSet.FETCH_FORWARD, ResultSet.TYPE_SCROLL_INSENSITIVE));
        assertNotNull(conn.prepareCall("some sql", ResultSet.FETCH_FORWARD, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.HOLD_CURSORS_OVER_COMMIT));
        assertNotNull(conn.prepareStatement("some sql", PreparedStatement.NO_GENERATED_KEYS));
        assertNotNull(conn.prepareStatement("some sql", new int[3]));
        assertNotNull(conn.prepareStatement("some sql", new String[3]));
        assertNotNull(conn.prepareStatement("some sql", ResultSet.FETCH_FORWARD, ResultSet.TYPE_SCROLL_INSENSITIVE));
        assertNotNull(conn.prepareStatement("some sql", ResultSet.FETCH_FORWARD, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.HOLD_CURSORS_OVER_COMMIT));
        assertNotNull(conn.toString());
        assertTrue(conn.isWrapperFor(Connection.class));
        assertTrue(conn.isValid(10));
        assertFalse(conn.isClosed());
        assertTrue(conn.unwrap(StubConnection.class) instanceof StubConnection);
        try {
            conn.unwrap(TestProxies.class);
            fail();
        } catch (SQLException e) {
        // pass
        }
    }
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) SQLException(java.sql.SQLException) StubConnection(com.zaxxer.hikari.mocks.StubConnection) 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 98 with HikariDataSource

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

the class TestProxies method testStatementProxy.

@Test
public void testStatementProxy() throws SQLException {
    HikariConfig config = newHikariConfig();
    config.setMinimumIdle(0);
    config.setMaximumPoolSize(1);
    config.setConnectionTestQuery("VALUES 1");
    config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
    try (HikariDataSource ds = new HikariDataSource(config)) {
        Connection conn = ds.getConnection();
        PreparedStatement stmt = conn.prepareStatement("some sql");
        stmt.executeQuery();
        stmt.executeQuery("some sql");
        assertFalse(stmt.isClosed());
        assertNotNull(stmt.getGeneratedKeys());
        assertNotNull(stmt.getResultSet());
        assertNotNull(stmt.getConnection());
        assertTrue(stmt.unwrap(StubStatement.class) instanceof StubStatement);
        try {
            stmt.unwrap(TestProxies.class);
            fail();
        } catch (SQLException e) {
        // pass
        }
    }
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) SQLException(java.sql.SQLException) StubStatement(com.zaxxer.hikari.mocks.StubStatement) Connection(java.sql.Connection) StubConnection(com.zaxxer.hikari.mocks.StubConnection) PreparedStatement(java.sql.PreparedStatement) HikariConfig(com.zaxxer.hikari.HikariConfig) TestElf.newHikariConfig(com.zaxxer.hikari.pool.TestElf.newHikariConfig) Test(org.junit.Test)

Example 99 with HikariDataSource

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

the class HikariConnectionProvider method configure.

// *************************************************************************
// Configurable
// *************************************************************************
@SuppressWarnings("rawtypes")
@Override
public void configure(Map props) throws HibernateException {
    try {
        LOGGER.debug("Configuring HikariCP");
        this.hcfg = HikariConfigurationUtil.loadConfiguration(props);
        this.hds = new HikariDataSource(this.hcfg);
    } catch (Exception e) {
        throw new HibernateException(e);
    }
    LOGGER.debug("HikariCP Configured");
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) HibernateException(org.hibernate.HibernateException) UnknownUnwrapTypeException(org.hibernate.service.UnknownUnwrapTypeException) SQLException(java.sql.SQLException) HibernateException(org.hibernate.HibernateException)

Example 100 with HikariDataSource

use of com.zaxxer.hikari.HikariDataSource 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

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