Skip to content

Commit 139e4db

Browse files
committed
Added integration tests
1 parent f1f4d9d commit 139e4db

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

document-store/src/integrationTest/java/org/hypertrace/core/documentstore/postgres/PostgresConnectionPoolIntegrationTest.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,13 @@ public void testGetConnection() throws SQLException {
7474

7575
@Test
7676
public void testGetTransactionalConnection() throws SQLException {
77-
final PostgresConnectionConfig config = createTestConfig();
77+
final PostgresConnectionConfig config = createTestConfig(1);
7878
final PostgresConnectionPool pool = new PostgresConnectionPool(config);
7979

80+
Connection transactionalConnection;
81+
8082
try (final Connection connection = pool.getTransactionalConnection()) {
83+
transactionalConnection = connection;
8184
assertNotNull(connection);
8285
assertFalse(
8386
connection.getAutoCommit(), "Transactional connection should have autoCommit=false");
@@ -94,6 +97,12 @@ public void testGetTransactionalConnection() throws SQLException {
9497
connection.commit();
9598
}
9699

100+
try (final Connection connection = pool.getConnection()) {
101+
// validate that after the connection was returned back to the pool earlier, auto-commit was
102+
// reset successfully
103+
assertTrue(connection.getAutoCommit());
104+
}
105+
97106
pool.close();
98107
}
99108

@@ -271,4 +280,21 @@ private static PostgresConnectionConfig createTestConfig() {
271280
.build())
272281
.build();
273282
}
283+
284+
private static PostgresConnectionConfig createTestConfig(int maxConnections) {
285+
return (PostgresConnectionConfig)
286+
ConnectionConfig.builder()
287+
.type(DatabaseType.POSTGRES)
288+
.addEndpoint(Endpoint.builder().host(host).port(port).build())
289+
.database("postgres")
290+
.credentials(
291+
ConnectionCredentials.builder().username("postgres").password("postgres").build())
292+
.connectionPoolConfig(
293+
ConnectionPoolConfig.builder()
294+
.maxConnections(maxConnections)
295+
.connectionAccessTimeout(Duration.ofSeconds(10))
296+
.connectionSurrenderTimeout(Duration.ofSeconds(30))
297+
.build())
298+
.build();
299+
}
274300
}

0 commit comments

Comments
 (0)