use of org.hibernate.agroal.internal.AgroalConnectionProvider in project hibernate-orm by hibernate.
the class AgroalConnectionProviderTest method testAgroalConnectionProvider.
@Test
public void testAgroalConnectionProvider() throws Exception {
JdbcServices jdbcServices = serviceRegistry().getService(JdbcServices.class);
ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping(ConnectionProviderJdbcConnectionAccess.class, jdbcServices.getBootstrapJdbcConnectionAccess());
assertTyping(AgroalConnectionProvider.class, connectionAccess.getConnectionProvider());
AgroalConnectionProvider agroalConnectionProvider = (AgroalConnectionProvider) connectionAccess.getConnectionProvider();
// For simplicity's sake, using the following in hibernate.properties:
// hibernate.agroal.maxSize 2
// hibernate.agroal.minSize 2
List<Connection> conns = new ArrayList<>();
for (int i = 0; i < 2; i++) {
Connection conn = agroalConnectionProvider.getConnection();
assertNotNull(conn);
assertFalse(conn.isClosed());
conns.add(conn);
}
try {
agroalConnectionProvider.getConnection();
fail("SQLException expected -- no more connections should have been available in the pool.");
} catch (SQLException e) {
// expected
assertTrue(e.getMessage().contains("timeout"));
}
for (Connection conn : conns) {
agroalConnectionProvider.closeConnection(conn);
assertTrue(conn.isClosed());
}
releaseSessionFactory();
try {
agroalConnectionProvider.getConnection();
fail("Exception expected -- the pool should have been shutdown.");
} catch (Exception e) {
// expected
assertTrue(e.getMessage().contains("closed"));
}
}
Aggregations