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/native-image-filter/extra-filter.json b/test/native/native-image-filter/extra-filter.json index 60e08572a138ff..ce94e860bc8d9a 100644 --- a/test/native/native-image-filter/extra-filter.json +++ b/test/native/native-image-filter/extra-filter.json @@ -27,6 +27,7 @@ {"excludeClasses": "org.locationtech.jts.geom.**"}, {"excludeClasses": "org.postgresql.**"}, {"excludeClasses": "org.slf4j.event.**"}, + {"excludeClasses": "org.testcontainers.jdbc.**"}, {"excludeClasses": "org.apache.shardingsphere.test.natived.**"} ], 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/META-INF/native-image/shardingsphere-test-native-test-metadata/reflect-config.json b/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/reflect-config.json index b726a0fd881cf8..9713c71f296c60 100644 --- a/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/reflect-config.json +++ b/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/reflect-config.json @@ -1,13 +1,13 @@ [ - { - "condition":{"typeReachable":"org.apache.shardingsphere.sharding.algorithm.sharding.classbased.ClassBasedShardingAlgorithmFactory"}, - "name":"org.apache.shardingsphere.test.natived.jdbc.commons.algorithm.ClassBasedInlineShardingAlgorithmFixture", - "methods":[{"name":"","parameterTypes":[] }] - }, - { - "condition":{"typeReachable":"org.apache.shardingsphere.encrypt.rule.EncryptRule"}, - "name":"org.apache.shardingsphere.test.natived.jdbc.commons.algorithm.TestQueryAssistedShardingEncryptAlgorithm", - "methods":[{"name":"","parameterTypes":[] }] - } +{ + "condition":{"typeReachable":"org.apache.shardingsphere.sharding.algorithm.sharding.classbased.ClassBasedShardingAlgorithmFactory"}, + "name":"org.apache.shardingsphere.test.natived.jdbc.commons.algorithm.ClassBasedInlineShardingAlgorithmFixture", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.encrypt.rule.EncryptRule"}, + "name":"org.apache.shardingsphere.test.natived.jdbc.commons.algorithm.TestQueryAssistedShardingEncryptAlgorithm", + "methods":[{"name":"","parameterTypes":[] }] +} ] \ No newline at end of file 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..6011240591694e 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,22 +23,16 @@ mode: dataSources: ds_0: dataSourceClassName: com.zaxxer.hikari.HikariDataSource - driverClassName: org.postgresql.Driver - jdbcUrl: jdbc:postgresql://localhost:49965/demo_ds_0 - username: root - password: 123456 + driverClassName: org.testcontainers.jdbc.ContainerDatabaseDriver + jdbcUrl: jdbc:tc:postgresql:16.1-bookworm://test-native-databases-postgres/demo_ds_0?TC_DAEMON=true ds_1: dataSourceClassName: com.zaxxer.hikari.HikariDataSource - driverClassName: org.postgresql.Driver - jdbcUrl: jdbc:postgresql://localhost:49965/demo_ds_1 - username: root - password: 123456 + driverClassName: org.testcontainers.jdbc.ContainerDatabaseDriver + jdbcUrl: jdbc:tc:postgresql:16.1-bookworm://test-native-databases-postgres/demo_ds_1?TC_DAEMON=true ds_2: dataSourceClassName: com.zaxxer.hikari.HikariDataSource - driverClassName: org.postgresql.Driver - jdbcUrl: jdbc:postgresql://localhost:49965/demo_ds_2 - username: root - password: 123456 + driverClassName: org.testcontainers.jdbc.ContainerDatabaseDriver + jdbcUrl: jdbc:tc:postgresql:16.1-bookworm://test-native-databases-postgres/demo_ds_2?TC_DAEMON=true rules: - !SHARDING