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());
}
}
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
}
}
}
Aggregations