diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.cn.md b/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.cn.md index 01e3523414c791..8bfab142d29922 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.cn.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.cn.md @@ -281,6 +281,14 @@ Caused by: java.io.UnsupportedEncodingException: Codepage Cp1252 is not supporte org.antlr antlr4-runtime + + commons-lang + commons-lang + + + org.apache.commons + commons-pool2 + diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.en.md b/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.en.md index 35b038fd8826d8..5e2a1d7f868caf 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.en.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.en.md @@ -296,6 +296,14 @@ Possible configuration examples are as follows, org.antlr antlr4-runtime + + commons-lang + commons-lang + + + org.apache.commons + commons-pool2 + diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/com.github.docker-java/docker-java-api/3.3.6/reflect-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/com.github.docker-java/docker-java-api/3.3.6/reflect-config.json new file mode 100644 index 00000000000000..f3f5e1ef247432 --- /dev/null +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/com.github.docker-java/docker-java-api/3.3.6/reflect-config.json @@ -0,0 +1,7 @@ +[ +{ + "condition":{"typeReachable":"com.github.dockerjava.api.model.RuntimeInfo"}, + "name":"com.github.dockerjava.api.model.RuntimeInfo", + "allPublicConstructors": true +} +] diff --git a/pom.xml b/pom.xml index 24062f9e23b2cf..d08c07677c3446 100644 --- a/pom.xml +++ b/pom.xml @@ -136,14 +136,14 @@ 1.31.0 1.9.10 - 5.10.2 + 5.10.3 2.2 4.11.0 4.2.0 - 1.19.3 + 1.19.8 1.9.0 - 24.0.0 + 24.0.1 4.4.6 diff --git a/test/native/pom.xml b/test/native/pom.xml index 1266875230cdda..71f1c36005ddb9 100644 --- a/test/native/pom.xml +++ b/test/native/pom.xml @@ -115,6 +115,14 @@ using Seata Client under GraalVM Native Image requires using the version release org.antlr antlr4-runtime + + commons-lang + commons-lang + + + org.apache.commons + commons-pool2 + diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderRepository.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderRepository.java index 01e69141d9c97e..7cded2baf10f56 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderRepository.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderRepository.java @@ -265,17 +265,6 @@ public Long insert(final Order order, final int autoGeneratedKeys) throws SQLExc return order.getOrderId(); } - /** - * insert Order to table without auto generated key. Databases like ClickHouse do not support returning auto generated keys after executing SQL, - * see ClickHouse/ClickHouse#56228 . - * - * @param order order - * @throws SQLException SQL Exception - */ - public void insertWithoutAutoGeneratedKey(final Order order) throws SQLException { - insert(order, Statement.NO_GENERATED_KEYS); - } - /** * delete by orderId. * diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/ClickHouseTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/ClickHouseTest.java index 6b57356d87e810..1291caa9f1cac6 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/ClickHouseTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/ClickHouseTest.java @@ -28,6 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +@EnabledInNativeImage class ClickHouseTest { private TestShardingService testShardingService; @@ -37,7 +38,6 @@ class ClickHouseTest { * after {@link TestShardingService#processSuccessInClickHouse()}. * */ - @EnabledInNativeImage @Test void assertShardingInLocalTransactions() { HikariConfig config = new HikariConfig(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/MySQLTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/MySQLTest.java index 1403a074110b7c..4124e975e2adc4 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/MySQLTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/MySQLTest.java @@ -22,6 +22,9 @@ import com.zaxxer.hikari.HikariDataSource; import org.apache.shardingsphere.test.natived.jdbc.commons.TestShardingService; import org.awaitility.Awaitility; +import org.junit.ClassRule; +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 org.testcontainers.containers.GenericContainer; @@ -43,6 +46,7 @@ * Unable to use `org.testcontainers:mysql:1.19.3` under GraalVM Native Image. * Background comes from testcontainers/testcontainers-java#7954. */ +@EnabledInNativeImage class MySQLTest { private static final String SYSTEM_PROP_KEY_PREFIX = "fixture.test-native.yaml.database.mysql."; @@ -53,27 +57,40 @@ class MySQLTest { private static final String DATABASE = "test"; + @SuppressWarnings("resource") + @ClassRule + public static GenericContainer container = new GenericContainer<>(DockerImageName.parse("mysql:8.4.0-oracle")) + .withEnv("MYSQL_DATABASE", DATABASE) + .withEnv("MYSQL_ROOT_PASSWORD", PASSWORD) + .withExposedPorts(3306); + private String jdbcUrlPrefix; private TestShardingService testShardingService; - @SuppressWarnings("resource") + @BeforeAll + static void beforeAll() { + assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url"), is(nullValue())); + assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url"), is(nullValue())); + assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url"), is(nullValue())); + } + + @AfterAll + static void afterAll() { + System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url"); + System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url"); + System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url"); + } + @Test - @EnabledInNativeImage void assertShardingInLocalTransactions() throws SQLException { - try ( - GenericContainer container = new GenericContainer<>(DockerImageName.parse("mysql:8.4.0-oracle")) - .withEnv("MYSQL_DATABASE", DATABASE) - .withEnv("MYSQL_ROOT_PASSWORD", PASSWORD) - .withExposedPorts(3306)) { - container.start(); - jdbcUrlPrefix = "jdbc:mysql://localhost:" + container.getMappedPort(3306) + "/"; - DataSource dataSource = createDataSource(); - testShardingService = new TestShardingService(dataSource); - initEnvironment(); - testShardingService.processSuccess(); - testShardingService.cleanEnvironment(); - } + container.start(); + jdbcUrlPrefix = "jdbc:mysql://localhost:" + container.getMappedPort(3306) + "/"; + DataSource dataSource = createDataSource(); + testShardingService = new TestShardingService(dataSource); + initEnvironment(); + testShardingService.processSuccess(); + testShardingService.cleanEnvironment(); } private void initEnvironment() throws SQLException { @@ -94,11 +111,10 @@ private Connection openConnection() throws SQLException { @SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"}) private DataSource createDataSource() throws SQLException { - Awaitility.await().atMost(Duration.ofMinutes(1L)).ignoreExceptionsMatching(e -> e instanceof CommunicationsException) - .until(() -> { - openConnection().close(); - return true; - }); + Awaitility.await().atMost(Duration.ofMinutes(1L)).ignoreExceptionsMatching(e -> e instanceof CommunicationsException).until(() -> { + openConnection().close(); + return true; + }); try ( Connection connection = openConnection(); Statement statement = connection.createStatement()) { @@ -109,18 +125,9 @@ private DataSource createDataSource() throws SQLException { HikariConfig config = new HikariConfig(); config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver"); config.setJdbcUrl("jdbc:shardingsphere:classpath:test-native/yaml/databases/mysql.yaml?placeholder-type=system_props"); - try { - assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url"), is(nullValue())); - assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url"), is(nullValue())); - assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url"), is(nullValue())); - System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url", jdbcUrlPrefix + "demo_ds_0"); - System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url", jdbcUrlPrefix + "demo_ds_1"); - System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url", jdbcUrlPrefix + "demo_ds_2"); - return new HikariDataSource(config); - } finally { - System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url"); - System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url"); - System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url"); - } + System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url", jdbcUrlPrefix + "demo_ds_0"); + System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url", jdbcUrlPrefix + "demo_ds_1"); + System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url", jdbcUrlPrefix + "demo_ds_2"); + return new HikariDataSource(config); } } diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/OpenGaussTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/OpenGaussTest.java index ad96a195fa24c5..9e03e9a77065af 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/OpenGaussTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/OpenGaussTest.java @@ -21,6 +21,9 @@ import com.zaxxer.hikari.HikariDataSource; import org.apache.shardingsphere.test.natived.jdbc.commons.TestShardingService; import org.awaitility.Awaitility; +import org.junit.ClassRule; +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 org.testcontainers.containers.GenericContainer; @@ -38,6 +41,7 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; +@EnabledInNativeImage class OpenGaussTest { private static final String SYSTEM_PROP_KEY_PREFIX = "fixture.test-native.yaml.database.opengauss."; @@ -48,26 +52,39 @@ class OpenGaussTest { private static final String DATABASE = "postgres"; + @SuppressWarnings("resource") + @ClassRule + public static GenericContainer container = new GenericContainer<>(DockerImageName.parse("opengauss/opengauss:5.0.0")) + .withEnv("GS_PASSWORD", PASSWORD) + .withExposedPorts(5432); + private String jdbcUrlPrefix; private TestShardingService testShardingService; - @SuppressWarnings("resource") + @BeforeAll + static void beforeAll() { + assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url"), is(nullValue())); + assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url"), is(nullValue())); + assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url"), is(nullValue())); + } + + @AfterAll + static void afterAll() { + System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url"); + System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url"); + System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url"); + } + @Test - @EnabledInNativeImage void assertShardingInLocalTransactions() throws SQLException { - try ( - GenericContainer openGaussContainer = new GenericContainer<>(DockerImageName.parse("opengauss/opengauss:5.0.0")) - .withEnv("GS_PASSWORD", PASSWORD) - .withExposedPorts(5432)) { - openGaussContainer.start(); - jdbcUrlPrefix = "jdbc:opengauss://localhost:" + openGaussContainer.getMappedPort(5432) + "/"; - DataSource dataSource = createDataSource(); - testShardingService = new TestShardingService(dataSource); - initEnvironment(); - testShardingService.processSuccess(); - testShardingService.cleanEnvironment(); - } + container.start(); + jdbcUrlPrefix = "jdbc:opengauss://localhost:" + container.getMappedPort(5432) + "/"; + DataSource dataSource = createDataSource(); + testShardingService = new TestShardingService(dataSource); + initEnvironment(); + testShardingService.processSuccess(); + testShardingService.cleanEnvironment(); } private void initEnvironment() throws SQLException { @@ -102,18 +119,9 @@ private DataSource createDataSource() throws SQLException { HikariConfig config = new HikariConfig(); config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver"); config.setJdbcUrl("jdbc:shardingsphere:classpath:test-native/yaml/databases/opengauss.yaml?placeholder-type=system_props"); - try { - assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url"), is(nullValue())); - assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url"), is(nullValue())); - assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url"), is(nullValue())); - System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url", jdbcUrlPrefix + "demo_ds_0"); - System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url", jdbcUrlPrefix + "demo_ds_1"); - System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url", jdbcUrlPrefix + "demo_ds_2"); - return new HikariDataSource(config); - } finally { - System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url"); - System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url"); - System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url"); - } + System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url", jdbcUrlPrefix + "demo_ds_0"); + System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url", jdbcUrlPrefix + "demo_ds_1"); + System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url", jdbcUrlPrefix + "demo_ds_2"); + return new HikariDataSource(config); } } 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 f2fd80218fbd08..d64abb1965083a 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 @@ -26,11 +26,11 @@ import javax.sql.DataSource; import java.sql.SQLException; +@EnabledInNativeImage class PostgresTest { private TestShardingService testShardingService; - @EnabledInNativeImage @Test void assertShardingInLocalTransactions() throws SQLException { HikariConfig config = new HikariConfig(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/SQLServerTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/SQLServerTest.java index 85cda9696060de..4cdaa36d2f89a5 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/SQLServerTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/SQLServerTest.java @@ -26,11 +26,11 @@ import javax.sql.DataSource; import java.sql.SQLException; +@EnabledInNativeImage class SQLServerTest { private TestShardingService testShardingService; - @EnabledInNativeImage @Test void assertShardingInLocalTransactions() throws SQLException { HikariConfig config = new HikariConfig(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/EtcdTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/EtcdTest.java index f8ceff784eb38e..abf2e44b903d0b 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/EtcdTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/EtcdTest.java @@ -19,12 +19,14 @@ import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; -import io.etcd.jetcd.launcher.Etcd; -import io.etcd.jetcd.launcher.EtcdCluster; +import io.etcd.jetcd.test.EtcdClusterExtension; import org.apache.shardingsphere.test.natived.jdbc.commons.TestShardingService; 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 org.junit.jupiter.api.extension.RegisterExtension; import javax.sql.DataSource; import java.net.URI; @@ -36,12 +38,29 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; +@EnabledInNativeImage class EtcdTest { + @RegisterExtension + public static final EtcdClusterExtension CLUSTER = EtcdClusterExtension.builder() + .withNodes(1) + .withMountDirectory(false) + .build(); + private static final String SYSTEM_PROP_KEY_PREFIX = "fixture.test-native.yaml.mode.cluster.etcd."; private TestShardingService testShardingService; + @BeforeAll + static void beforeAll() { + assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "server-lists"), is(nullValue())); + } + + @AfterAll + static void afterAll() { + System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "server-lists"); + } + /** * TODO On low-performance devices in Github Actions, `INSERT` related SQLs may throw a table not found error under nativeTest. * So that we need to wait for a period of time after executing `CREATE TABLE` related SQLs before executing `INSERT` related SQLs. @@ -50,24 +69,16 @@ class EtcdTest { * @see org.apache.shardingsphere.mode.repository.cluster.etcd.EtcdRepository */ @Test - @EnabledInNativeImage void assertShardingInLocalTransactions() throws SQLException { - try ( - EtcdCluster etcd = Etcd.builder() - .withNodes(1) - .withMountedDataDirectory(false) - .build()) { - etcd.start(); - DataSource dataSource = createDataSource(etcd.clientEndpoints()); - testShardingService = new TestShardingService(dataSource); - initEnvironment(); - Awaitility.await().atMost(Duration.ofSeconds(30L)).ignoreExceptions().until(() -> { - dataSource.getConnection().close(); - return true; - }); - testShardingService.processSuccess(); - testShardingService.cleanEnvironment(); - } + DataSource dataSource = createDataSource(CLUSTER.clientEndpoints()); + testShardingService = new TestShardingService(dataSource); + initEnvironment(); + Awaitility.await().atMost(Duration.ofSeconds(30L)).ignoreExceptions().until(() -> { + dataSource.getConnection().close(); + return true; + }); + testShardingService.processSuccess(); + testShardingService.cleanEnvironment(); } private void initEnvironment() throws SQLException { @@ -84,12 +95,7 @@ private DataSource createDataSource(final List clientEndpoints) { HikariConfig config = new HikariConfig(); config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver"); config.setJdbcUrl("jdbc:shardingsphere:classpath:test-native/yaml/modes/cluster/etcd.yaml?placeholder-type=system_props"); - try { - assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "server-lists"), is(nullValue())); - System.setProperty(SYSTEM_PROP_KEY_PREFIX + "server-lists", clientEndpoint.toString()); - return new HikariDataSource(config); - } finally { - System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "server-lists"); - } + System.setProperty(SYSTEM_PROP_KEY_PREFIX + "server-lists", clientEndpoint.toString()); + return new HikariDataSource(config); } } diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/ZookeeperTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/ZookeeperTest.java index 88836303e1a26c..5ff2a61e44ed5e 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/ZookeeperTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/ZookeeperTest.java @@ -25,6 +25,8 @@ import org.apache.curator.test.TestingServer; import org.apache.shardingsphere.test.natived.jdbc.commons.TestShardingService; import org.awaitility.Awaitility; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import javax.sql.DataSource; @@ -42,6 +44,16 @@ class ZookeeperTest { private TestShardingService testShardingService; + @BeforeAll + static void beforeAll() { + assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "server-lists"), is(nullValue())); + } + + @AfterAll + static void afterAll() { + System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "server-lists"); + } + /** * TODO On low-performance devices in Github Actions, `INSERT` related SQLs may throw a table not found error under nativeTest. * So that we need to wait for a period of time after executing `CREATE TABLE` related SQLs before executing `INSERT` related SQLs. @@ -84,12 +96,7 @@ private DataSource createDataSource(final String connectString) { HikariConfig config = new HikariConfig(); config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver"); config.setJdbcUrl("jdbc:shardingsphere:classpath:test-native/yaml/modes/cluster/zookeeper.yaml?placeholder-type=system_props"); - try { - assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "server-lists"), is(nullValue())); - System.setProperty(SYSTEM_PROP_KEY_PREFIX + "server-lists", connectString); - return new HikariDataSource(config); - } finally { - System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "server-lists"); - } + System.setProperty(SYSTEM_PROP_KEY_PREFIX + "server-lists", connectString); + return new HikariDataSource(config); } } diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/base/SeataTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/base/SeataTest.java index 827d856a1c13cb..91d0f825e9bff0 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/base/SeataTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/base/SeataTest.java @@ -21,40 +21,55 @@ import com.zaxxer.hikari.HikariDataSource; import org.apache.hc.core5.http.HttpStatus; import org.apache.shardingsphere.test.natived.jdbc.commons.TestShardingService; +import org.junit.ClassRule; +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 org.testcontainers.containers.FixedHostPortGenericContainer; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.Wait; import javax.sql.DataSource; import java.sql.SQLException; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +@EnabledInNativeImage class SeataTest { - private TestShardingService testShardingService; + private static final String SERVICE_DEFAULT_GROUP_LIST_KEY = "service.default.grouplist"; /** - * TODO Since Seata Client 1.8.0 does not provide the function of defining `service.default.grouplist` through Java API, we need to use a hard-defined host port `39567` here. * TODO Further processing of `/health` awaits apache/incubator-seata#6356. - * @throws SQLException An exception that provides information on a database access error or other errors. */ - @SuppressWarnings({"resource", "deprecation"}) + @SuppressWarnings("resource") + @ClassRule + public static GenericContainer container = new GenericContainer<>("seataio/seata-server:1.8.0") + .withExposedPorts(7091, 8091) + .waitingFor(Wait.forHttp("/health").forPort(7091).forStatusCode(HttpStatus.SC_UNAUTHORIZED)); + + private TestShardingService testShardingService; + + @BeforeAll + static void beforeAll() { + assertThat(System.getProperty(SERVICE_DEFAULT_GROUP_LIST_KEY), is(nullValue())); + } + + @AfterAll + static void afterAll() { + System.clearProperty(SERVICE_DEFAULT_GROUP_LIST_KEY); + } + @Test - @EnabledInNativeImage void assertShardingInSeataTransactions() throws SQLException { - try ( - GenericContainer container = new FixedHostPortGenericContainer<>("seataio/seata-server:1.8.0") - .withFixedExposedPort(39567, 8091) - .withExposedPorts(7091) - .waitingFor(Wait.forHttp("/health").forPort(7091).forStatusCode(HttpStatus.SC_UNAUTHORIZED))) { - container.start(); - DataSource dataSource = createDataSource(); - testShardingService = new TestShardingService(dataSource); - initEnvironment(); - testShardingService.processSuccess(); - testShardingService.cleanEnvironment(); - } + container.start(); + DataSource dataSource = createDataSource(container.getMappedPort(8091)); + testShardingService = new TestShardingService(dataSource); + initEnvironment(); + testShardingService.processSuccess(); + testShardingService.cleanEnvironment(); } private void initEnvironment() throws SQLException { @@ -66,7 +81,8 @@ private void initEnvironment() throws SQLException { testShardingService.getAddressRepository().truncateTable(); } - private DataSource createDataSource() { + private DataSource createDataSource(final int hostPort) { + System.setProperty(SERVICE_DEFAULT_GROUP_LIST_KEY, "127.0.0.1:" + hostPort); HikariConfig config = new HikariConfig(); config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver"); config.setJdbcUrl("jdbc:shardingsphere:classpath:test-native/yaml/transactions/base/seata.yaml"); diff --git a/test/native/src/test/resources/seata-script-client-conf-file.conf b/test/native/src/test/resources/seata-script-client-conf-file.conf index 7e3b7556951e48..28a355c0ca7d41 100644 --- a/test/native/src/test/resources/seata-script-client-conf-file.conf +++ b/test/native/src/test/resources/seata-script-client-conf-file.conf @@ -15,10 +15,8 @@ # limitations under the License. # -# TODO Due to limitations of `io.seata:seata-all:1.8.0`, -# there is no ability to dynamically define `service.default.grouplist` without using Spring Boot. -# This requires further investigation. +# Please note that this file only contains part of the Seata Client configuration. +# Additional configurations such as `service.default.grouplist` are defined in `org.apache.shardingsphere.test.natived.jdbc.transactions.base.SeataTest` through `java.lang.System#setProperty(String, String)`. service { vgroupMapping.default_tx_group = "default" - default.grouplist = "127.0.0.1:39567" }