Skip to content

Commit dbf1744

Browse files
committed
Fix JDBC driver CI test failures: encoding and Testcontainers
Note: The PR was created with the help of AI tools and a human. Fix two root causes of CI test failures reproduced in ubuntu:24.04 container with Zulu Java 17 + Gradle 9.3.1 (matching GitHub Actions): build.gradle.kts: Set javac encoding to UTF-8 to prevent Unicode test failures (e.g. Greek Omega) when the CI runner locale defaults to US-ASCII. Without this, source characters are garbled at compile time, causing deterministic assertion failures in AgtypeFactoryTest and AgtypeUtilTest. BaseDockerizedTest.java: Fix Testcontainers setup reliability - - Add Wait.forLogMessage wait strategy with 60s timeout so PostgreSQL is fully ready before JDBC connection attempt - Use getHost() instead of hardcoded "localhost" for correct behavior in Docker-in-Docker and varied CI environments - Add sslmode=disable to JDBC URL since PostgreSQL driver 42.6.0+ attempts SSL negotiation by default and the AGE Docker image has no SSL configured - Remove silent catch/println that swallowed connection errors and produced misleading NullPointerExceptions downstream Verified: 77/77 tests pass across multiple consecutive runs. modified: drivers/jdbc/lib/build.gradle.kts modified: drivers/jdbc/lib/src/test/java/org/apache/age/jdbc/BaseDockerizedTest.java
1 parent 5fe2121 commit dbf1744

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

drivers/jdbc/lib/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ dependencies {
4545
testImplementation("org.slf4j:slf4j-simple:2.0.7")
4646
}
4747

48+
tasks.withType<JavaCompile> {
49+
options.encoding = "UTF-8"
50+
}
51+
4852
tasks.generateGrammarSource {
4953
maxHeapSize = "64m"
5054
source = project.objects

drivers/jdbc/lib/src/test/java/org/apache/age/jdbc/BaseDockerizedTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121

2222
import java.sql.DriverManager;
2323
import java.sql.Statement;
24+
import java.time.Duration;
2425
import org.apache.age.jdbc.base.Agtype;
2526
import org.junit.jupiter.api.AfterAll;
2627
import org.junit.jupiter.api.BeforeAll;
2728
import org.junit.jupiter.api.TestInstance;
2829
import org.junit.jupiter.api.TestInstance.Lifecycle;
2930
import org.postgresql.jdbc.PgConnection;
3031
import org.testcontainers.containers.GenericContainer;
32+
import org.testcontainers.containers.wait.strategy.Wait;
3133
import org.testcontainers.utility.DockerImageName;
3234

3335
@TestInstance(Lifecycle.PER_CLASS)
@@ -54,20 +56,19 @@ public void beforeAll() throws Exception {
5456
agensGraphContainer = new GenericContainer<>(DockerImageName
5557
.parse("apache/age:dev_snapshot_master"))
5658
.withEnv("POSTGRES_PASSWORD", CORRECT_DB_PASSWORDS)
57-
.withExposedPorts(5432);
59+
.withExposedPorts(5432)
60+
.waitingFor(Wait.forLogMessage(".*database system is ready to accept connections.*\\n", 2)
61+
.withStartupTimeout(Duration.ofSeconds(60)));
5862
agensGraphContainer.start();
5963

64+
String host = agensGraphContainer.getHost();
6065
int mappedPort = agensGraphContainer.getMappedPort(5432);
6166
String jdbcUrl = String
62-
.format("jdbc:postgresql://%s:%d/%s", "localhost", mappedPort, "postgres");
67+
.format("jdbc:postgresql://%s:%d/%s?sslmode=disable", host, mappedPort, "postgres");
6368

64-
try {
65-
this.connection = DriverManager.getConnection(jdbcUrl, "postgres", CORRECT_DB_PASSWORDS)
66-
.unwrap(PgConnection.class);
67-
this.connection.addDataType("agtype", Agtype.class);
68-
} catch (Exception e) {
69-
System.out.println(e);
70-
}
69+
this.connection = DriverManager.getConnection(jdbcUrl, "postgres", CORRECT_DB_PASSWORDS)
70+
.unwrap(PgConnection.class);
71+
this.connection.addDataType("agtype", Agtype.class);
7172
try (Statement statement = connection.createStatement()) {
7273
statement.execute("CREATE EXTENSION IF NOT EXISTS age;");
7374
statement.execute("LOAD 'age'");

0 commit comments

Comments
 (0)