Skip to content

Commit 887564d

Browse files
authored
Fix JDBC driver CI test failures (#2333)
Fix JDBC driver CI test failures: encoding, Testcontainers, and Docker compatibility. Note: This PR was created with the help of AI tools and a human. - Set JavaCompile encoding to UTF-8 to fix unicode test failures in CI environments that default to US-ASCII. - Add Testcontainers wait strategy (Wait.forLogMessage) to wait for PostgreSQL to be fully ready before connecting. - Use agensGraphContainer.getHost() instead of hardcoded localhost for Docker-in-Docker compatibility. - Add sslmode=disable to JDBC URL since PostgreSQL driver 42.6.0+ attempts SSL by default. - Remove silent exception swallowing around connection setup to fail fast with meaningful errors instead of NullPointerException. - Upgrade Testcontainers from 1.18.0 to 1.21.4 to fix Docker 29.x detection failure on ubuntu-24.04 runners (docker-java 3.3.x in 1.18.0 cannot negotiate with Docker Engine 29.1.5 API). modified: drivers/jdbc/lib/build.gradle.kts modified: drivers/jdbc/lib/src/test/java/org/apache/age/jdbc/BaseDockerizedTest.java
1 parent 5fe2121 commit 887564d

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

drivers/jdbc/lib/build.gradle.kts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@ dependencies {
3838
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
3939
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
4040

41-
testImplementation("org.testcontainers:testcontainers:1.18.0")
41+
testImplementation("org.testcontainers:testcontainers:1.21.4")
4242
testImplementation("org.postgresql:postgresql:42.6.0")
4343

4444
testImplementation("org.slf4j:slf4j-api:2.0.7")
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)