Search in sources :

Example 6 with StubConnection

use of com.zaxxer.hikari.mocks.StubConnection in project HikariCP by brettwooldridge.

the class ShutdownTest method testShutdown5.

@Test
public void testShutdown5() throws SQLException {
    Assert.assertSame("StubConnection count not as expected", 0, StubConnection.count.get());
    HikariConfig config = newHikariConfig();
    config.setMinimumIdle(5);
    config.setMaximumPoolSize(5);
    config.setInitializationFailTimeout(0);
    config.setConnectionTestQuery("VALUES 1");
    config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
    try (HikariDataSource ds = new HikariDataSource(config)) {
        HikariPool pool = getPool(ds);
        Connection[] connections = new Connection[5];
        for (int i = 0; i < 5; i++) {
            connections[i] = ds.getConnection();
        }
        Assert.assertTrue("Total connection count not as expected, ", pool.getTotalConnections() == 5);
        ds.close();
        Assert.assertSame("Active connection count not as expected, ", 0, pool.getActiveConnections());
        Assert.assertSame("Idle connection count not as expected, ", 0, pool.getIdleConnections());
        Assert.assertSame("Total connection count not as expected, ", 0, pool.getTotalConnections());
    }
}
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 7 with StubConnection

use of com.zaxxer.hikari.mocks.StubConnection 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)

Aggregations

HikariConfig (com.zaxxer.hikari.HikariConfig)7 HikariDataSource (com.zaxxer.hikari.HikariDataSource)7 StubConnection (com.zaxxer.hikari.mocks.StubConnection)7 TestElf.newHikariConfig (com.zaxxer.hikari.pool.TestElf.newHikariConfig)7 Connection (java.sql.Connection)7 Test (org.junit.Test)7 SQLException (java.sql.SQLException)5 PoolInitializationException (com.zaxxer.hikari.pool.HikariPool.PoolInitializationException)2 TestElf.newHikariDataSource (com.zaxxer.hikari.pool.TestElf.newHikariDataSource)2 TestElf.setConfigUnitTest (com.zaxxer.hikari.pool.TestElf.setConfigUnitTest)2 StubDataSource (com.zaxxer.hikari.mocks.StubDataSource)1 SQLTransientConnectionException (java.sql.SQLTransientConnectionException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1