diff --git a/pom.xml b/pom.xml
index 160fdbb2d39d1b..005806bb7e71c9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -142,7 +142,7 @@
2.2
4.11.0
4.2.0
- 1.17.6
+ 1.19.3
1.9.0
21.2.0
diff --git a/test/native/pom.xml b/test/native/pom.xml
index bb1b39e93309f1..fa00a4ee966142 100644
--- a/test/native/pom.xml
+++ b/test/native/pom.xml
@@ -54,6 +54,11 @@
postgresql
test
+
+ org.testcontainers
+ postgresql
+ test
+
diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/PostgresTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/PostgresTest.java
index 14dc7f727bf5ad..d804325380b351 100644
--- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/PostgresTest.java
+++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/PostgresTest.java
@@ -20,74 +20,17 @@
import org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
import org.apache.shardingsphere.test.natived.jdbc.commons.AbstractShardingCommonTest;
import org.apache.shardingsphere.test.natived.jdbc.commons.FileTestUtils;
-import org.awaitility.Awaitility;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledInNativeImage;
import javax.sql.DataSource;
-import java.io.File;
import java.io.IOException;
-import java.sql.Connection;
-import java.sql.DriverManager;
import java.sql.SQLException;
-import java.time.Duration;
-import java.util.Properties;
public class PostgresTest {
- private static final String USERNAME = "root";
-
- private static final String PASSWORD = "123456";
-
- private static final String DATABASE = "test";
-
- private static final String JDBC_URL = "jdbc:postgresql://localhost:49965/" + DATABASE;
-
- private static Process process;
-
private AbstractShardingCommonTest abstractShardingCommonTest;
- private static Connection openConnection() throws SQLException {
- Properties props = new Properties();
- props.setProperty("user", USERNAME);
- props.setProperty("password", PASSWORD);
- return DriverManager.getConnection(JDBC_URL, props);
- }
-
- @SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"})
- @BeforeAll
- static void beforeAll() throws IOException {
- System.out.println("Starting PostgreSQL ...");
- process = new ProcessBuilder(
- "docker", "run", "--rm", "-p", "49965:5432", "-e", "POSTGRES_DB=" + DATABASE, "-e", "POSTGRES_USER=" + USERNAME,
- "-e", "POSTGRES_PASSWORD=" + PASSWORD, "postgres:16.1-bookworm")
- .redirectOutput(new File("target/test-classes/postgres-stdout.txt"))
- .redirectError(new File("target/test-classes/postgres-stderr.txt"))
- .start();
- Awaitility.await().atMost(Duration.ofMinutes(1)).ignoreExceptions().until(() -> {
- openConnection().close();
- return true;
- });
- try (Connection connection = openConnection()) {
- connection.createStatement().executeUpdate("CREATE DATABASE demo_ds_0;");
- connection.createStatement().executeUpdate("CREATE DATABASE demo_ds_1;");
- connection.createStatement().executeUpdate("CREATE DATABASE demo_ds_2;");
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- System.out.println("PostgreSQL started");
- }
-
- @AfterAll
- static void tearDown() {
- if (process != null && process.isAlive()) {
- System.out.println("Shutting down PostgreSQL");
- process.destroy();
- }
- }
-
@Test
@EnabledInNativeImage
void assertShardingInLocalTransactions() throws SQLException, IOException {
diff --git a/test/native/src/test/resources/test-native/yaml/databases/postgresql.yaml b/test/native/src/test/resources/test-native/yaml/databases/postgresql.yaml
index 6ff365f35c9b9c..9864c9ff711d5e 100644
--- a/test/native/src/test/resources/test-native/yaml/databases/postgresql.yaml
+++ b/test/native/src/test/resources/test-native/yaml/databases/postgresql.yaml
@@ -23,20 +23,20 @@ mode:
dataSources:
ds_0:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: org.postgresql.Driver
- jdbcUrl: jdbc:postgresql://localhost:49965/demo_ds_0
+ driverClassName: org.testcontainers.jdbc.ContainerDatabaseDriver
+ jdbcUrl: jdbc:tc:postgresql:16.1-bookworm://localhost:49965/demo_ds_0
username: root
password: 123456
ds_1:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: org.postgresql.Driver
- jdbcUrl: jdbc:postgresql://localhost:49965/demo_ds_1
+ driverClassName: org.testcontainers.jdbc.ContainerDatabaseDriver
+ jdbcUrl: jdbc:tc:postgresql:16.1-bookworm://localhost:49965/demo_ds_1
username: root
password: 123456
ds_2:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
- driverClassName: org.postgresql.Driver
- jdbcUrl: jdbc:postgresql://localhost:49965/demo_ds_2
+ driverClassName: org.testcontainers.jdbc.ContainerDatabaseDriver
+ jdbcUrl: jdbc:tc:postgresql:16.1-bookworm://localhost:49965/demo_ds_2
username: root
password: 123456