use of com.zaxxer.hikari.HikariConfig in project HikariCP by brettwooldridge.
the class TestValidation method validateZeroConnectionTimeout.
@Test
public void validateZeroConnectionTimeout() {
try {
HikariConfig config = newHikariConfig();
config.setConnectionTimeout(0);
config.validate();
assertEquals(Integer.MAX_VALUE, config.getConnectionTimeout());
} catch (IllegalArgumentException ise) {
// pass
}
}
use of com.zaxxer.hikari.HikariConfig in project HikariCP by brettwooldridge.
the class TestValidation method validateInvalidLeakDetection.
@Test
public void validateInvalidLeakDetection() {
try {
HikariConfig config = newHikariConfig();
config.setLeakDetectionThreshold(1000L);
config.validate();
fail();
} catch (IllegalArgumentException ise) {
// pass
}
}
use of com.zaxxer.hikari.HikariConfig in project HikariCP by brettwooldridge.
the class UnwrapTest method testUnwrapConnection.
@Test
public void testUnwrapConnection() 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)) {
ds.getConnection().close();
assertSame("Idle connections not as expected", 1, getPool(ds).getIdleConnections());
Connection connection = ds.getConnection();
assertNotNull(connection);
StubConnection unwrapped = connection.unwrap(StubConnection.class);
assertTrue("unwrapped connection is not instance of StubConnection: " + unwrapped, (unwrapped != null && unwrapped instanceof StubConnection));
}
}
use of com.zaxxer.hikari.HikariConfig in project HikariCP by brettwooldridge.
the class TestConnections method testPopulationSlowAcquisition.
@Test
public void testPopulationSlowAcquisition() throws InterruptedException, SQLException {
HikariConfig config = newHikariConfig();
config.setMaximumPoolSize(20);
config.setConnectionTestQuery("VALUES 1");
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
System.setProperty("com.zaxxer.hikari.housekeeping.periodMs", "1000");
StubConnection.slowCreate = true;
try (HikariDataSource ds = new HikariDataSource(config)) {
System.clearProperty("com.zaxxer.hikari.housekeeping.periodMs");
ds.setIdleTimeout(3000);
SECONDS.sleep(2);
HikariPool pool = getPool(ds);
assertSame("Total connections not as expected", 2, pool.getTotalConnections());
assertSame("Idle connections not as expected", 2, pool.getIdleConnections());
try (Connection connection = ds.getConnection()) {
assertNotNull(connection);
SECONDS.sleep(20);
assertSame("Second total connections not as expected", 20, pool.getTotalConnections());
assertSame("Second idle connections not as expected", 19, pool.getIdleConnections());
}
assertSame("Idle connections not as expected", 20, pool.getIdleConnections());
SECONDS.sleep(5);
assertSame("Third total connections not as expected", 20, pool.getTotalConnections());
assertSame("Third idle connections not as expected", 20, pool.getIdleConnections());
} finally {
StubConnection.slowCreate = false;
}
}
use of com.zaxxer.hikari.HikariConfig in project HikariCP by brettwooldridge.
the class TestConnections method testCreate.
@Test
public void testCreate() throws SQLException {
HikariConfig config = newHikariConfig();
config.setMinimumIdle(1);
config.setMaximumPoolSize(1);
config.setConnectionTestQuery("VALUES 1");
config.setConnectionInitSql("SELECT 1");
config.setReadOnly(true);
config.setConnectionTimeout(2500);
config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(30));
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
try (HikariDataSource ds = new HikariDataSource(config)) {
ds.setLoginTimeout(10);
assertSame(10, ds.getLoginTimeout());
HikariPool pool = getPool(ds);
ds.getConnection().close();
assertSame("Total connections not as expected", 1, pool.getTotalConnections());
assertSame("Idle connections not as expected", 1, pool.getIdleConnections());
try (Connection connection = ds.getConnection();
PreparedStatement statement = connection.prepareStatement("SELECT * FROM device WHERE device_id=?")) {
assertNotNull(connection);
assertNotNull(statement);
assertSame("Total connections not as expected", 1, pool.getTotalConnections());
assertSame("Idle connections not as expected", 0, pool.getIdleConnections());
statement.setInt(1, 0);
try (ResultSet resultSet = statement.executeQuery()) {
assertNotNull(resultSet);
assertFalse(resultSet.next());
}
}
assertSame("Total connections not as expected", 1, pool.getTotalConnections());
assertSame("Idle connections not as expected", 1, pool.getIdleConnections());
}
}
Aggregations