From 5e611b9a20991d7b8d64a5376ee00cde35269d20 Mon Sep 17 00:00:00 2001 From: linghengqian Date: Wed, 29 Jan 2025 11:38:33 +0800 Subject: [PATCH] Remove the test of Local transactions for ClickHouse integration module in nativeTest --- .../graalvm-native-image/_index.cn.md | 4 +- .../graalvm-native-image/_index.en.md | 4 +- .../optional-plugins/clickhouse/_index.cn.md | 178 +---------------- .../optional-plugins/clickhouse/_index.en.md | 180 +----------------- .../optional-plugins/hiveserver2/_index.cn.md | 2 +- .../optional-plugins/hiveserver2/_index.en.md | 2 +- infra/database/type/hive/pom.xml | 7 - .../reflect-config.json | 65 ++----- .../resource-config.json | 9 - .../reflect-config.json | 20 ++ .../hamcrest/3.0/reflect-config.json | 12 ++ pom.xml | 4 +- .../natived/commons/TestShardingService.java | 34 ++-- .../repository/OrderItemRepository.java | 34 +++- .../jdbc/databases/ClickHouseTest.java | 37 +--- .../natived/jdbc/databases/FirebirdTest.java | 2 +- .../natived/proxy/databases/MySQLTest.java | 32 ++-- .../natived/proxy/databases/PostgresTest.java | 32 ++-- .../proxy/transactions/base/SeataTest.java | 32 ++-- .../resource-config.json | 3 - .../test-native/xml/keeper_config.xml | 31 --- .../test-native/xml/transactions.xml | 25 --- 22 files changed, 158 insertions(+), 591 deletions(-) create mode 100644 infra/reachability-metadata/src/main/resources/META-INF/native-image/org.hamcrest/hamcrest/3.0/reflect-config.json delete mode 100644 test/native/src/test/resources/test-native/xml/keeper_config.xml delete mode 100644 test/native/src/test/resources/test-native/xml/transactions.xml 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 f18270218c9f5..4f4474420126c 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 @@ -389,11 +389,11 @@ Reachability Metadata 位于 `shardingsphere-infra-reachability-metadata` 子模 ```bash git clone git@github.com:apache/shardingsphere.git cd ./shardingsphere/ -./mvnw -PgenerateMetadata -DskipNativeTests -e -T 1C clean test native:metadata-copy +./mvnw -PgenerateMetadata -e -T 1C clean test native:metadata-copy ``` 受 https://github.com/apache/shardingsphere/issues/33206 影响, -贡献者执行 `./mvnw -PgenerateMetadata -DskipNativeTests -T 1C -e clean test native:metadata-copy` 后, +贡献者执行 `./mvnw -PgenerateMetadata -T 1C -e clean test native:metadata-copy` 后, `infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/resource-config.json` 会生成不必要的包含绝对路径的 JSON 条目, 类似如下, 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 8ebe31f5e4248..70626b881ae8c 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 @@ -405,11 +405,11 @@ contributors should place it on the classpath of the `shardingsphere-test-native ```bash git clone git@github.com:apache/shardingsphere.git cd ./shardingsphere/ -./mvnw -PgenerateMetadata -DskipNativeTests -e -T 1C clean test native:metadata-copy +./mvnw -PgenerateMetadata -e -T 1C clean test native:metadata-copy ``` Affected by https://github.com/apache/shardingsphere/issues/33206 , -After the contributor executes `./mvnw -PgenerateMetadata -DskipNativeTests -T 1C -e clean test native:metadata-copy`, +After the contributor executes `./mvnw -PgenerateMetadata -T 1C -e clean test native:metadata-copy`, `infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/resource-config.json` will generate unnecessary JSON entries containing absolute paths, similar to the following. diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/clickhouse/_index.cn.md b/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/clickhouse/_index.cn.md index 9e12705225b84..a9594b8f1fccb 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/clickhouse/_index.cn.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/clickhouse/_index.cn.md @@ -213,182 +213,12 @@ public class ExampleTest { ### 事务限制 -ClickHouse 不支持 ShardingSphere 集成级别的 XA 事务, -因为 https://github.com/ClickHouse/clickhouse-java 未实现 `javax.sql.XADataSource` 的相关 Java 接口。 - -ClickHouse 不支持 ShardingSphere 集成级别的 Seata AT 模式事务, -因为 https://github.com/apache/incubator-seata 未实现 ClickHouse 的 SQL 方言解析。 - -ClickHouse 支持 ShardingSphere 集成级别的本地事务,但需要对 ClickHouse 进行额外配置, +ClickHouse 不支持 ShardingSphere 集成级别的本地事务,XA 事务或 Seata 的 AT 模式事务, 更多讨论位于 https://github.com/ClickHouse/clickhouse-docs/issues/2300 。 -引入讨论,编写 Docker Compose 文件来启动 ClickHouse 和 ClickHouse Keeper。 - -```yaml -services: - clickhouse-keeper-01: - image: clickhouse/clickhouse-keeper:24.11.1.2557 - volumes: - - ./keeper_config.xml:/etc/clickhouse-keeper/keeper_config.xml - clickhouse-server: - image: clickhouse/clickhouse-server:24.11.1.2557 - depends_on: - - clickhouse-keeper-01 - ports: - - "8123:8123" - volumes: - - ./transactions.xml:/etc/clickhouse-server/config.d/transactions.xml -``` - -`./keeper_config.xml` 的内容如下, - -```xml - - 0.0.0.0 - - 9181 - 1 - /var/lib/clickhouse/coordination/snapshots - - - 1 - clickhouse-keeper-01 - 9234 - - - - -``` - -`./transactions.xml` 的内容如下, - -```xml - - 1 - - - clickhouse-keeper-01 - 9181 - - - -``` - -在 DBeaver Community 内,使用 `jdbc:ch://localhost:8123/default` 的 `jdbcUrl`,`default` 的`username` 连接至 ClickHouse, -`password` 留空。 -执行如下 SQL, - -```sql --- noinspection SqlNoDataSourceInspectionForFile -CREATE DATABASE demo_ds_0; -CREATE DATABASE demo_ds_1; -CREATE DATABASE demo_ds_2; -``` - -分别使用 `jdbc:ch://localhost:8123/demo_ds_0` , -`jdbc:ch://localhost:8123/demo_ds_1` 和 `jdbc:ch://localhost:8123/demo_ds_2` 的 `jdbcUrl` 连接至 ClickHouse 来执行如下 SQL, - -```sql --- noinspection SqlNoDataSourceInspectionForFile -create table IF NOT EXISTS t_order ( - order_id Int64 NOT NULL, - order_type Int32, - user_id Int32 NOT NULL, - address_id Int64 NOT NULL, - status VARCHAR(50) -) engine = MergeTree - primary key (order_id) - order by (order_id); - -TRUNCATE TABLE t_order; -``` - -在业务项目引入`前提条件`涉及的依赖后,在业务项目的 classpath 上编写 ShardingSphere 数据源的配置文件`demo.yaml`, - -```yaml -dataSources: - ds_0: - dataSourceClassName: com.zaxxer.hikari.HikariDataSource - driverClassName: com.clickhouse.jdbc.ClickHouseDriver - jdbcUrl: jdbc:ch://localhost:8123/demo_ds_0?transactionSupport=true - username: default - password: - ds_1: - dataSourceClassName: com.zaxxer.hikari.HikariDataSource - driverClassName: com.clickhouse.jdbc.ClickHouseDriver - jdbcUrl: jdbc:ch://localhost:8123/demo_ds_1?transactionSupport=true - username: default - password: - ds_2: - dataSourceClassName: com.zaxxer.hikari.HikariDataSource - driverClassName: com.clickhouse.jdbc.ClickHouseDriver - jdbcUrl: jdbc:ch://localhost:8123/demo_ds_2?transactionSupport=true - username: default - password: -rules: -- !SHARDING - tables: - t_order: - actualDataNodes: - keyGenerateStrategy: - column: order_id - keyGeneratorName: snowflake - defaultDatabaseStrategy: - standard: - shardingColumn: user_id - shardingAlgorithmName: inline - shardingAlgorithms: - inline: - type: INLINE - props: - algorithm-expression: ds_${user_id % 2} - keyGenerators: - snowflake: - type: SNOWFLAKE -``` - -创建 ShardingSphere 的数据源后可正常使用本地事务, - -```java -import com.zaxxer.hikari.HikariConfig; -import com.zaxxer.hikari.HikariDataSource; -import java.sql.Connection; -import java.sql.SQLException; -@SuppressWarnings({"SqlNoDataSourceInspection", "AssertWithSideEffects"}) -public class ExampleUtils { - void test() throws SQLException { - HikariConfig config = new HikariConfig(); - config.setJdbcUrl("jdbc:shardingsphere:classpath:demo.yaml"); - config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver"); - try (HikariDataSource dataSource = new HikariDataSource(config); Connection connection = dataSource.getConnection()) { - try { - connection.setAutoCommit(false); - connection.createStatement().executeUpdate("INSERT INTO t_order (user_id, order_type, address_id, status) VALUES (2024, 0, 2024, 'INSERT_TEST')"); - connection.createStatement().executeUpdate("INSERT INTO t_order_does_not_exist (test_id_does_not_exist) VALUES (2024)"); - connection.commit(); - } catch (final SQLException ignored) { - connection.rollback(); - } finally { - connection.setAutoCommit(true); - } - try (Connection conn = dataSource.getConnection()) { - assert !conn.createStatement().executeQuery("SELECT * FROM t_order WHERE user_id = 2024").next(); - } - } - } -} -``` - -一旦在 ShardingSphere 的配置文件为 ClickHouse JDBC Driver 的 jdbcUrl 设置 `transactionSupport=true`, -用户在执行 `alter table` 语句前应确保没有尚未完成执行的 `insert` 语句,以避免如下 Error 的发生, - -```shell -java.sql.BatchUpdateException: Code: 341. DB::Exception: Exception happened during execution of mutation 'mutation_6.txt' with part 'all_1_1_0' reason: 'Serialization error: part all_1_1_0 is locked by transaction 5672402456378293316'. This error maybe retryable or not. In case of unretryable error, mutation can be killed with KILL MUTATION query. (UNFINISHED) (version 24.10.2.80 (official build)) - at com.clickhouse.jdbc.SqlExceptionUtils.batchUpdateError(SqlExceptionUtils.java:107) - at com.clickhouse.jdbc.internal.SqlBasedPreparedStatement.executeAny(SqlBasedPreparedStatement.java:223) - at com.clickhouse.jdbc.internal.SqlBasedPreparedStatement.executeLargeUpdate(SqlBasedPreparedStatement.java:302) - at com.clickhouse.jdbc.internal.AbstractPreparedStatement.executeUpdate(AbstractPreparedStatement.java:135) -``` +这与 https://clickhouse.com/docs/en/guides/developer/transactional 为 ClickHouse 提供的 `Transactions, Commit, and Rollback` 功能无关, +仅与 `com.clickhouse.jdbc.ConnectionImpl` 未实现 `java.sql.Connection#rollback()` 有关。 +参考 https://github.com/ClickHouse/clickhouse-java/issues/2023 。 ### 嵌入式 ClickHouse 限制 diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/clickhouse/_index.en.md b/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/clickhouse/_index.en.md index 0e81b12074829..d2a08b8ce2635 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/clickhouse/_index.en.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/clickhouse/_index.en.md @@ -219,182 +219,12 @@ public class ExampleTest { ### Transaction Limitations -ClickHouse does not support XA transactions at the ShardingSphere integration level, -because https://github.com/ClickHouse/clickhouse-java does not implement the relevant Java interface of `javax.sql.XADataSource`. +ClickHouse does not support local transactions at the ShardingSphere integration level, XA transactions, or AT mode transactions for Seata, +More discussion is at https://github.com/ClickHouse/clickhouse-docs/issues/2300 . -ClickHouse does not support Seata AT mode transactions at the ShardingSphere integration level, -because https://github.com/apache/incubator-seata does not implement ClickHouse's SQL dialect parsing. - -ClickHouse supports local transactions at the ShardingSphere integration level, but additional configuration of ClickHouse is required, -For more discussion, please visit https://github.com/ClickHouse/clickhouse-docs/issues/2300 . - -Introduce the discussion of writing a Docker Compose file to start ClickHouse and ClickHouse Keeper. - -```yaml -services: - clickhouse-keeper-01: - image: clickhouse/clickhouse-keeper:24.11.1.2557 - volumes: - - ./keeper_config.xml:/etc/clickhouse-keeper/keeper_config.xml - clickhouse-server: - image: clickhouse/clickhouse-server:24.11.1.2557 - depends_on: - - clickhouse-keeper-01 - ports: - - "8123:8123" - volumes: - - ./transactions.xml:/etc/clickhouse-server/config.d/transactions.xml -``` - -The content of `./keeper_config.xml` is as follows, - -```xml - - 0.0.0.0 - - 9181 - 1 - /var/lib/clickhouse/coordination/snapshots - - - 1 - clickhouse-keeper-01 - 9234 - - - - -``` - -The content of `./transactions.xml` is as follows, - -```xml - - 1 - - - clickhouse-keeper-01 - 9181 - - - -``` - -In DBeaver Community, use `jdbcUrl` of `jdbc:ch://localhost:8123/default`, `username` of `default` to connect to ClickHouse, -and leave `password` blank. Execute the following SQL, - -```sql --- noinspection SqlNoDataSourceInspectionForFile -CREATE DATABASE demo_ds_0; -CREATE DATABASE demo_ds_1; -CREATE DATABASE demo_ds_2; -``` - -Use `jdbcUrl` of `jdbc:ch://localhost:8123/demo_ds_0`, `jdbc:ch://localhost:8123/demo_ds_1` -and `jdbc:ch://localhost:8123/demo_ds_2` to connect to ClickHouse and execute the following SQL. - -```sql --- noinspection SqlNoDataSourceInspectionForFile -create table IF NOT EXISTS t_order ( - order_id Int64 NOT NULL, - order_type Int32, - user_id Int32 NOT NULL, - address_id Int64 NOT NULL, - status VARCHAR(50) -) engine = MergeTree - primary key (order_id) - order by (order_id); - -TRUNCATE TABLE t_order; -``` - -After the business project introduces the dependencies involved in the `prerequisites`, -write the ShardingSphere data source configuration file `demo.yaml` on the classpath of the business project. - -```yaml -dataSources: - ds_0: - dataSourceClassName: com.zaxxer.hikari.HikariDataSource - driverClassName: com.clickhouse.jdbc.ClickHouseDriver - jdbcUrl: jdbc:ch://localhost:8123/demo_ds_0?transactionSupport=true - username: default - password: - ds_1: - dataSourceClassName: com.zaxxer.hikari.HikariDataSource - driverClassName: com.clickhouse.jdbc.ClickHouseDriver - jdbcUrl: jdbc:ch://localhost:8123/demo_ds_1?transactionSupport=true - username: default - password: - ds_2: - dataSourceClassName: com.zaxxer.hikari.HikariDataSource - driverClassName: com.clickhouse.jdbc.ClickHouseDriver - jdbcUrl: jdbc:ch://localhost:8123/demo_ds_2?transactionSupport=true - username: default - password: -rules: -- !SHARDING - tables: - t_order: - actualDataNodes: - keyGenerateStrategy: - column: order_id - keyGeneratorName: snowflake - defaultDatabaseStrategy: - standard: - shardingColumn: user_id - shardingAlgorithmName: inline - shardingAlgorithms: - inline: - type: INLINE - props: - algorithm-expression: ds_${user_id % 2} - keyGenerators: - snowflake: - type: SNOWFLAKE -``` - -After creating the ShardingSphere data source, local transactions can be used normally. - -```java -import com.zaxxer.hikari.HikariConfig; -import com.zaxxer.hikari.HikariDataSource; -import java.sql.Connection; -import java.sql.SQLException; -@SuppressWarnings({"SqlNoDataSourceInspection", "AssertWithSideEffects"}) -public class ExampleUtils { - void test() throws SQLException { - HikariConfig config = new HikariConfig(); - config.setJdbcUrl("jdbc:shardingsphere:classpath:demo.yaml"); - config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver"); - try (HikariDataSource dataSource = new HikariDataSource(config); Connection connection = dataSource.getConnection()) { - try { - connection.setAutoCommit(false); - connection.createStatement().executeUpdate("INSERT INTO t_order (user_id, order_type, address_id, status) VALUES (2024, 0, 2024, 'INSERT_TEST')"); - connection.createStatement().executeUpdate("INSERT INTO t_order_does_not_exist (test_id_does_not_exist) VALUES (2024)"); - connection.commit(); - } catch (final SQLException ignored) { - connection.rollback(); - } finally { - connection.setAutoCommit(true); - } - try (Connection conn = dataSource.getConnection()) { - assert !conn.createStatement().executeQuery("SELECT * FROM t_order WHERE user_id = 2024").next(); - } - } - } -} -``` - -Once `transactionSupport=true` is set for the jdbcUrl of ClickHouse JDBC Driver in the ShardingSphere configuration file, -users should ensure that there are no unfinished `insert` statements before executing the `alter table` statement to avoid the following Error. - -```shell -java.sql.BatchUpdateException: Code: 341. DB::Exception: Exception happened during execution of mutation 'mutation_6.txt' with part 'all_1_1_0' reason: 'Serialization error: part all_1_1_0 is locked by transaction 5672402456378293316'. This error maybe retryable or not. In case of unretryable error, mutation can be killed with KILL MUTATION query. (UNFINISHED) (version 24.10.2.80 (official build)) - at com.clickhouse.jdbc.SqlExceptionUtils.batchUpdateError(SqlExceptionUtils.java:107) - at com.clickhouse.jdbc.internal.SqlBasedPreparedStatement.executeAny(SqlBasedPreparedStatement.java:223) - at com.clickhouse.jdbc.internal.SqlBasedPreparedStatement.executeLargeUpdate(SqlBasedPreparedStatement.java:302) - at com.clickhouse.jdbc.internal.AbstractPreparedStatement.executeUpdate(AbstractPreparedStatement.java:135) -``` +This has nothing to do with the `Transactions, Commit, and Rollback` feature provided by https://clickhouse.com/docs/en/guides/developer/transactional for ClickHouse, +but only with `com.clickhouse.jdbc.ConnectionImpl` not implementing `java.sql.Connection#rollback()`. +See https://github.com/ClickHouse/clickhouse-java/issues/2023 . ### Embedded ClickHouse Limitations diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/hiveserver2/_index.cn.md b/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/hiveserver2/_index.cn.md index 28637148be326..4ec84b5cf4297 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/hiveserver2/_index.cn.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/hiveserver2/_index.cn.md @@ -80,7 +80,7 @@ ShardingSphere 对 HiveServer2 JDBC Driver 的支持位于可选模块中。 io.github.linghengqian hive-server2-jdbc-driver-thin - 1.6.0 + 1.7.0 com.fasterxml.woodstox diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/hiveserver2/_index.en.md b/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/hiveserver2/_index.en.md index 4bc6a90939d63..66ee9beccbf65 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/hiveserver2/_index.en.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/hiveserver2/_index.en.md @@ -82,7 +82,7 @@ The following is an example of a possible configuration, io.github.linghengqian hive-server2-jdbc-driver-thin - 1.6.0 + 1.7.0 com.fasterxml.woodstox diff --git a/infra/database/type/hive/pom.xml b/infra/database/type/hive/pom.xml index f5495105f4ca2..ea6600e40366b 100644 --- a/infra/database/type/hive/pom.xml +++ b/infra/database/type/hive/pom.xml @@ -33,13 +33,6 @@ ${project.version} - - org.apache.hive - hive-jdbc - ${hive.version} - provided - true - io.github.linghengqian hive-server2-jdbc-driver-thin diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/reflect-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/reflect-config.json index 5ea99760f5590..ae8bd0a05a108 100644 --- a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/reflect-config.json +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/reflect-config.json @@ -28,7 +28,7 @@ "name":"[Lcom.github.dockerjava.api.model.VolumesFrom;" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007f7c3fdf9c28"}, + "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007f1973df8240"}, "name":"[Lcom.zaxxer.hikari.util.ConcurrentBag$IConcurrentBagEntry;" }, { @@ -76,7 +76,7 @@ "name":"[Lcom.zaxxer.hikari.util.ConcurrentBag$IConcurrentBagEntry;" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.MetaDataContexts"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.metadata.service.DatabaseMetaDataPersistService"}, "name":"[Lcom.zaxxer.hikari.util.ConcurrentBag$IConcurrentBagEntry;" }, { @@ -362,7 +362,7 @@ "allDeclaredFields":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistFacade"}, "name":"java.lang.Object", "allDeclaredFields":true }, @@ -372,12 +372,12 @@ "allDeclaredFields":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.metadata.table.TableMetaDataPersistService"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.metadata.service.TableMetaDataPersistService"}, "name":"java.lang.Object", "allDeclaredFields":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.metadata.table.TableRowDataPersistService"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.metadata.service.TableRowDataPersistService"}, "name":"java.lang.Object", "allDeclaredFields":true }, @@ -749,11 +749,6 @@ "queryAllPublicConstructors":true, "methods":[{"name":"","parameterTypes":[] }, {"name":"add","parameterTypes":["long"] }, {"name":"sum","parameterTypes":[] }] }, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask"}, - "name":"java.util.concurrent.atomic.Striped64$Cell", - "fields":[{"name":"value"}] -}, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.expr.groovy.GroovyInlineExpressionParser"}, "name":"java.util.function.DoubleFunction", @@ -963,7 +958,7 @@ "allDeclaredFields":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistFacade"}, "name":"org.apache.shardingsphere.broadcast.yaml.config.YamlBroadcastRuleConfiguration", "allDeclaredFields":true }, @@ -1351,7 +1346,7 @@ "methods":[{"name":"getProps","parameterTypes":[] }, {"name":"getType","parameterTypes":[] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistFacade"}, "name":"org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfiguration", "allDeclaredFields":true, "methods":[{"name":"getProps","parameterTypes":[] }, {"name":"getType","parameterTypes":[] }] @@ -1699,7 +1694,7 @@ "name":"org.apache.shardingsphere.infra.instance.metadata.proxy.ProxyInstanceMetaDataBuilder" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.ComputeNodeOnlineHandler"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.type.ComputeNodeOnlineHandler"}, "name":"org.apache.shardingsphere.infra.instance.yaml.YamlComputeNodeData", "methods":[{"name":"","parameterTypes":[] }] }, @@ -1815,7 +1810,7 @@ "methods":[{"name":"","parameterTypes":[] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.metadata.table.TableRowDataPersistService"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.metadata.service.TableRowDataPersistService"}, "name":"org.apache.shardingsphere.infra.yaml.data.pojo.YamlRowStatistics", "allDeclaredFields":true, "methods":[{"name":"","parameterTypes":[] }, {"name":"getRows","parameterTypes":[] }, {"name":"getUniqueKey","parameterTypes":[] }, {"name":"setRows","parameterTypes":["java.util.List"] }, {"name":"setUniqueKey","parameterTypes":["java.lang.String"] }] @@ -1832,7 +1827,7 @@ "methods":[{"name":"","parameterTypes":[] }, {"name":"setCaseSensitive","parameterTypes":["boolean"] }, {"name":"setDataType","parameterTypes":["int"] }, {"name":"setGenerated","parameterTypes":["boolean"] }, {"name":"setName","parameterTypes":["java.lang.String"] }, {"name":"setPrimaryKey","parameterTypes":["boolean"] }, {"name":"setUnsigned","parameterTypes":["boolean"] }, {"name":"setVisible","parameterTypes":["boolean"] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.metadata.table.TableMetaDataPersistService"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.metadata.service.TableMetaDataPersistService"}, "name":"org.apache.shardingsphere.infra.yaml.schema.pojo.YamlShardingSphereColumn", "allDeclaredFields":true, "methods":[{"name":"","parameterTypes":[] }, {"name":"setCaseSensitive","parameterTypes":["boolean"] }, {"name":"setDataType","parameterTypes":["int"] }, {"name":"setGenerated","parameterTypes":["boolean"] }, {"name":"setName","parameterTypes":["java.lang.String"] }, {"name":"setNullable","parameterTypes":["boolean"] }, {"name":"setPrimaryKey","parameterTypes":["boolean"] }, {"name":"setUnsigned","parameterTypes":["boolean"] }, {"name":"setVisible","parameterTypes":["boolean"] }] @@ -1862,7 +1857,7 @@ "methods":[{"name":"","parameterTypes":[] }, {"name":"setName","parameterTypes":["java.lang.String"] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.metadata.table.TableMetaDataPersistService"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.metadata.service.TableMetaDataPersistService"}, "name":"org.apache.shardingsphere.infra.yaml.schema.pojo.YamlShardingSphereIndex", "allDeclaredFields":true, "methods":[{"name":"","parameterTypes":[] }, {"name":"setName","parameterTypes":["java.lang.String"] }, {"name":"setUnique","parameterTypes":["boolean"] }] @@ -1892,7 +1887,7 @@ "methods":[{"name":"","parameterTypes":[] }, {"name":"setColumns","parameterTypes":["java.util.Map"] }, {"name":"setIndexes","parameterTypes":["java.util.Map"] }, {"name":"setName","parameterTypes":["java.lang.String"] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.metadata.table.TableMetaDataPersistService"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.metadata.service.TableMetaDataPersistService"}, "name":"org.apache.shardingsphere.infra.yaml.schema.pojo.YamlShardingSphereTable", "allDeclaredFields":true, "methods":[{"name":"","parameterTypes":[] }, {"name":"getColumns","parameterTypes":[] }, {"name":"getConstraints","parameterTypes":[] }, {"name":"getIndexes","parameterTypes":[] }, {"name":"getName","parameterTypes":[] }, {"name":"getType","parameterTypes":[] }, {"name":"setColumns","parameterTypes":["java.util.Map"] }, {"name":"setIndexes","parameterTypes":["java.util.Map"] }, {"name":"setName","parameterTypes":["java.lang.String"] }, {"name":"setType","parameterTypes":["org.apache.shardingsphere.infra.database.core.metadata.database.enums.TableType"] }] @@ -2139,10 +2134,6 @@ "name":"org.apache.shardingsphere.mode.manager.cluster.persist.builder.ClusterPersistServiceBuilder", "methods":[{"name":"","parameterTypes":[] }] }, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.mode.persist.coordinator.PersistCoordinatorFacade"}, - "name":"org.apache.shardingsphere.mode.manager.cluster.persist.coordinator.ClusterPersistCoordinatorFacadeBuilder" -}, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.yaml.config.swapper.mode.YamlModeConfigurationSwapper"}, "name":"org.apache.shardingsphere.mode.manager.cluster.yaml.ClusterYamlPersistRepositoryConfigurationSwapper" @@ -2156,10 +2147,6 @@ "name":"org.apache.shardingsphere.mode.manager.standalone.persist.builder.StandalonePersistServiceBuilder", "methods":[{"name":"","parameterTypes":[] }] }, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.mode.persist.coordinator.PersistCoordinatorFacade"}, - "name":"org.apache.shardingsphere.mode.manager.standalone.persist.coordinator.StandalonePersistCoordinatorFacadeBuilder" -}, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.yaml.config.swapper.mode.YamlModeConfigurationSwapper"}, "name":"org.apache.shardingsphere.mode.manager.standalone.yaml.StandaloneYamlPersistRepositoryConfigurationSwapper" @@ -3005,7 +2992,7 @@ "allDeclaredFields":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistFacade"}, "name":"org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration", "allDeclaredFields":true }, @@ -3042,7 +3029,7 @@ "methods":[{"name":"getActualDataNodes","parameterTypes":[] }, {"name":"getAuditStrategy","parameterTypes":[] }, {"name":"getDatabaseStrategy","parameterTypes":[] }, {"name":"getKeyGenerateStrategy","parameterTypes":[] }, {"name":"getLogicTable","parameterTypes":[] }, {"name":"getTableStrategy","parameterTypes":[] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistFacade"}, "name":"org.apache.shardingsphere.sharding.yaml.config.rule.YamlTableRuleConfiguration", "allDeclaredFields":true, "methods":[{"name":"getActualDataNodes","parameterTypes":[] }, {"name":"getAuditStrategy","parameterTypes":[] }, {"name":"getDatabaseStrategy","parameterTypes":[] }, {"name":"getKeyGenerateStrategy","parameterTypes":[] }, {"name":"getLogicTable","parameterTypes":[] }, {"name":"getTableStrategy","parameterTypes":[] }] @@ -3112,7 +3099,7 @@ "methods":[{"name":"getComplex","parameterTypes":[] }, {"name":"getHint","parameterTypes":[] }, {"name":"getNone","parameterTypes":[] }, {"name":"getStandard","parameterTypes":[] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistFacade"}, "name":"org.apache.shardingsphere.sharding.yaml.config.strategy.sharding.YamlShardingStrategyConfiguration", "allDeclaredFields":true, "methods":[{"name":"getComplex","parameterTypes":[] }, {"name":"getHint","parameterTypes":[] }, {"name":"getNone","parameterTypes":[] }, {"name":"getStandard","parameterTypes":[] }] @@ -3233,30 +3220,15 @@ "allDeclaredFields":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistFacade"}, "name":"org.apache.shardingsphere.single.yaml.config.YamlSingleRuleConfiguration", "allDeclaredFields":true }, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement"}, - "name":"org.apache.shardingsphere.sql.parser.clickhouse.parser.ClickHouseLexer", - "methods":[{"name":"","parameterTypes":["org.antlr.v4.runtime.CharStream"] }] -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement"}, - "name":"org.apache.shardingsphere.sql.parser.clickhouse.parser.ClickHouseParser", - "methods":[{"name":"","parameterTypes":["org.antlr.v4.runtime.TokenStream"] }] -}, { "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.core.database.visitor.SQLStatementVisitorFactory"}, "name":"org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.ClickHouseStatementVisitorFacade", "methods":[{"name":"","parameterTypes":[] }] }, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement"}, - "name":"org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.type.ClickHouseDMLStatementVisitor", - "methods":[{"name":"","parameterTypes":[] }] -}, { "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.core.database.cache.ParseTreeCacheBuilder"}, "name":"org.apache.shardingsphere.sql.parser.core.database.cache.ParseTreeCacheLoader" @@ -3441,11 +3413,6 @@ "name":"org.apache.shardingsphere.sql.parser.statement.clickhouse.dml.ClickHouseSelectStatement", "methods":[{"name":"","parameterTypes":[] }] }, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement"}, - "name":"org.apache.shardingsphere.sql.parser.statement.clickhouse.dml.ClickHouseSelectStatement", - "methods":[{"name":"","parameterTypes":[] }] -}, { "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement"}, "name":"org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdCreateTableStatement", diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/resource-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/resource-config.json index 90fc000ab6f76..d21e821b84ab7 100644 --- a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/resource-config.json +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/resource-config.json @@ -87,12 +87,6 @@ }, { "condition":{"typeReachable":"org.apache.shardingsphere.transaction.xa.atomikos.manager.AtomikosTransactionManagerProvider"}, "pattern":"\\QMETA-INF/services/com.atomikos.recovery.OltpLogFactory\\E" - }, { - "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager"}, - "pattern":"\\QMETA-INF/services/com.clickhouse.client.ClickHouseClient\\E" - }, { - "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.connection.DriverDatabaseConnectionManager$$Lambda/0x00007f7c3fca2710"}, - "pattern":"\\QMETA-INF/services/com.clickhouse.client.ClickHouseClient\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource"}, "pattern":"\\QMETA-INF/services/com.clickhouse.client.ClickHouseClient\\E" @@ -339,9 +333,6 @@ }, { "condition":{"typeReachable":"org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.Portal"}, "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.mode.node.spi.RuleNodePathProvider\\E" - }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.persist.coordinator.PersistCoordinatorFacade"}, - "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.mode.persist.coordinator.PersistCoordinatorFacadeBuilder\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.proxy.initializer.BootstrapInitializer"}, "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.mode.persist.service.PersistServiceBuilder\\E" diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json index 7cdc40c4f3c6f..cfcef31c6ef9e 100644 --- a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json @@ -337,6 +337,26 @@ "name":"org.apache.shardingsphere.infra.yaml.data.pojo.YamlShardingSphereRowData", "allPublicMethods": true }, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.infra.yaml.data.pojo.YamlRowStatistics"}, + "name":"org.apache.shardingsphere.infra.yaml.data.pojo.YamlRowStatistics", + "allPublicMethods": true +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.clickhouse.parser.ClickHouseLexer"}, + "name":"org.apache.shardingsphere.sql.parser.clickhouse.parser.ClickHouseLexer", + "methods":[{"name":"","parameterTypes":["org.antlr.v4.runtime.CharStream"] }] +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.clickhouse.parser.ClickHouseParser"}, + "name":"org.apache.shardingsphere.sql.parser.clickhouse.parser.ClickHouseParser", + "methods":[{"name":"","parameterTypes":["org.antlr.v4.runtime.TokenStream"] }] +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.type.ClickHouseDMLStatementVisitor"}, + "name":"org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.type.ClickHouseDMLStatementVisitor", + "methods":[{"name":"","parameterTypes":[] }] +}, { "condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.statement.opengauss.ddl.OpenGaussTruncateStatement"}, "name":"org.apache.shardingsphere.sql.parser.statement.opengauss.ddl.OpenGaussTruncateStatement", diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.hamcrest/hamcrest/3.0/reflect-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.hamcrest/hamcrest/3.0/reflect-config.json new file mode 100644 index 0000000000000..62d58b2e9fc2d --- /dev/null +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.hamcrest/hamcrest/3.0/reflect-config.json @@ -0,0 +1,12 @@ +[ +{ + "condition":{"typeReachable":"org.hamcrest.TypeSafeMatcher"}, + "name":"org.hamcrest.collection.IsEmptyCollection", + "queryAllDeclaredMethods":true +}, +{ + "condition":{"typeReachable":"org.hamcrest.TypeSafeDiagnosingMatcher"}, + "name":"org.hamcrest.collection.IsIterableContainingInAnyOrder", + "queryAllDeclaredMethods":true +} +] diff --git a/pom.xml b/pom.xml index 0dcf96dd3e6bb..aca4752834b95 100644 --- a/pom.xml +++ b/pom.xml @@ -128,8 +128,7 @@ 3.1.0-og 2.4.2 0.6.3 - 4.0.1 - 1.6.0 + 1.7.0 3.3.6 0.288.1 5.0.6.java8 @@ -1065,6 +1064,7 @@ ${native-maven-plugin.version} true + true true Conditional diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/commons/TestShardingService.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/commons/TestShardingService.java index 552484ede967d..52c3047af1c67 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/commons/TestShardingService.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/commons/TestShardingService.java @@ -24,23 +24,22 @@ import org.apache.shardingsphere.test.natived.commons.repository.AddressRepository; import org.apache.shardingsphere.test.natived.commons.repository.OrderItemRepository; import org.apache.shardingsphere.test.natived.commons.repository.OrderRepository; -import org.awaitility.Awaitility; import javax.sql.DataSource; import java.sql.SQLException; import java.sql.Statement; -import java.time.Duration; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.LongStream; -import java.util.stream.Stream; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; @Getter public final class TestShardingService { @@ -73,7 +72,7 @@ public void processSuccess() throws SQLException { } /** - * Process success in ClickHouse. + * Process success in ClickHouse. ClickHouse JDBC Driver does not support the use of transactions. * * @throws SQLException An exception that provides information on a database access error or other errors. */ @@ -84,28 +83,30 @@ public void processSuccessInClickHouse() throws SQLException { assertThat(orderRepository.selectAll(), equalTo(Collections.emptyList())); assertThat(orderItemRepository.selectAll(), equalTo(Collections.emptyList())); assertThat(addressRepository.selectAll(), equalTo(Collections.emptyList())); - orderItemRepository.assertRollbackWithTransactions(); } private void extracted() throws SQLException { Collection orders = orderRepository.selectAll(); + assertThat(orders.stream().map(Order::getOrderId).collect(Collectors.toList()), not(empty())); assertThat(orders.stream().map(Order::getOrderType).collect(Collectors.toList()), - equalTo(Stream.of(0, 0, 0, 0, 0, 1, 1, 1, 1, 1).collect(Collectors.toList()))); - assertThat(orders.stream().map(Order::getUserId).collect(Collectors.toSet()), - equalTo(Stream.of(2, 4, 6, 8, 10, 1, 3, 5, 7, 9).collect(Collectors.toSet()))); - assertThat(orders.stream().map(Order::getAddressId).collect(Collectors.toSet()), - equalTo(Stream.of(2L, 4L, 6L, 8L, 10L, 1L, 3L, 5L, 7L, 9L).collect(Collectors.toSet()))); + containsInAnyOrder(0, 1, 0, 1, 0, 1, 0, 1, 0, 1)); + assertThat(orders.stream().map(Order::getUserId).collect(Collectors.toList()), + containsInAnyOrder(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + assertThat(orders.stream().map(Order::getAddressId).collect(Collectors.toList()), + containsInAnyOrder(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L)); assertThat(orders.stream().map(Order::getStatus).collect(Collectors.toList()), equalTo(IntStream.range(1, 11).mapToObj(i -> "INSERT_TEST").collect(Collectors.toList()))); Collection orderItems = orderItemRepository.selectAll(); - assertThat(orderItems.stream().map(OrderItem::getUserId).collect(Collectors.toSet()), - equalTo(Stream.of(2, 4, 6, 8, 10, 1, 3, 5, 7, 9).collect(Collectors.toSet()))); + assertThat(orderItems.stream().map(OrderItem::getOrderItemId).collect(Collectors.toList()), not(empty())); + assertThat(orderItems.stream().map(OrderItem::getOrderId).collect(Collectors.toList()), not(empty())); + assertThat(orderItems.stream().map(OrderItem::getUserId).collect(Collectors.toList()), + containsInAnyOrder(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); assertThat(orderItems.stream().map(OrderItem::getPhone).collect(Collectors.toList()), equalTo(IntStream.range(1, 11).mapToObj(i -> "13800000001").collect(Collectors.toList()))); assertThat(orderItems.stream().map(OrderItem::getStatus).collect(Collectors.toList()), equalTo(IntStream.range(1, 11).mapToObj(i -> "INSERT_TEST").collect(Collectors.toList()))); - assertThat(new HashSet<>(addressRepository.selectAll()), - equalTo(LongStream.range(1L, 11L).mapToObj(each -> new Address(each, "address_test_" + each)).collect(Collectors.toSet()))); + assertThat(addressRepository.selectAll(), + equalTo(LongStream.range(1L, 11L).mapToObj(each -> new Address(each, "address_test_" + each)).collect(Collectors.toList()))); } /** @@ -174,14 +175,11 @@ public void deleteData(final Collection orderIds) throws SQLException { /** * Delete data in ClickHouse. - * TODO It is necessary to avoid the use of {@code Awaitility.await().pollDelay(Duration.ofSeconds(5L)).until(()->true)}. - * After ClickHouse enables experimental transactions, performance drops significantly. * * @param orderIds orderId of the insert statement. * @throws SQLException An exception that provides information on a database access error or other errors. */ public void deleteDataInClickHouse(final Collection orderIds) throws SQLException { - Awaitility.await().pollDelay(Duration.ofSeconds(5L)).until(() -> true); long count = 1L; for (Long each : orderIds) { orderRepository.deleteInClickHouse(each); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/commons/repository/OrderItemRepository.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/commons/repository/OrderItemRepository.java index 038f283250fb8..2181a37f4b491 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/commons/repository/OrderItemRepository.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/commons/repository/OrderItemRepository.java @@ -321,22 +321,36 @@ public List selectAll() throws SQLException { * @throws SQLException An exception that provides information on a database access error or other errors. */ public void assertRollbackWithTransactions() throws SQLException { - try (Connection connection = dataSource.getConnection()) { + try (Connection conn = dataSource.getConnection()) { try { - connection.setAutoCommit(false); - connection.createStatement().executeUpdate("INSERT INTO t_order_item (order_id, user_id, phone, status) VALUES (2024, 2024, '13800000001', 'INSERT_TEST')"); - connection.createStatement().executeUpdate("INSERT INTO t_order_item_does_not_exist (test_id_does_not_exist) VALUES (2024)"); - connection.commit(); + conn.setAutoCommit(false); + conn.createStatement().executeUpdate("INSERT INTO t_order_item (order_id, user_id, phone, status) VALUES (2024, 2024, '13800000001', 'INSERT_TEST')"); + conn.createStatement().executeUpdate("INSERT INTO t_order_item_does_not_exist (test_id_does_not_exist) VALUES (2024)"); + conn.commit(); } catch (final SQLException ignored) { - connection.rollback(); + conn.rollback(); } finally { - connection.setAutoCommit(true); + conn.setAutoCommit(true); } } - try ( - Connection conn = dataSource.getConnection(); - ResultSet resultSet = conn.createStatement().executeQuery("SELECT * FROM t_order_item WHERE user_id = 2024")) { + try (Connection conn = dataSource.getConnection()) { + ResultSet resultSet = conn.createStatement().executeQuery("SELECT * FROM t_order_item WHERE user_id = 2024"); assertThat(resultSet.next(), is(false)); } + try (Connection conn = dataSource.getConnection()) { + try { + conn.setAutoCommit(false); + conn.createStatement().executeUpdate("INSERT INTO t_order_item (order_id, user_id, phone, status) VALUES (2025, 2025, '13800000001', 'INSERT_TEST')"); + conn.commit(); + } catch (final SQLException ignored) { + conn.rollback(); + } finally { + conn.setAutoCommit(true); + } + } + try (Connection conn = dataSource.getConnection()) { + ResultSet resultSet = conn.createStatement().executeQuery("SELECT * FROM t_order_item WHERE user_id = 2025"); + assertThat(resultSet.next(), is(true)); + } } } 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 593b541a96f54..3a7c6a2f73dc8 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 @@ -19,9 +19,6 @@ import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.CuratorFrameworkFactory; -import org.apache.curator.retry.ExponentialBackoffRetry; import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection; import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; @@ -33,13 +30,10 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledInNativeImage; import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.Network; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; -import org.testcontainers.utility.MountableFile; import javax.sql.DataSource; -import java.nio.file.Paths; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; @@ -61,25 +55,9 @@ @Testcontainers class ClickHouseTest { - private final Network network = Network.newNetwork(); - - @Container - private final GenericContainer clickhouseKeeperContainer = new GenericContainer<>("clickhouse/clickhouse-keeper:24.11.1.2557") - .withCopyFileToContainer( - MountableFile.forHostPath(Paths.get("src/test/resources/test-native/xml/keeper_config.xml").toAbsolutePath()), - "/etc/clickhouse-keeper/keeper_config.xml") - .withNetwork(network) - .withExposedPorts(9181) - .withNetworkAliases("clickhouse-keeper-01"); - @Container private final GenericContainer container = new GenericContainer<>("clickhouse/clickhouse-server:24.11.1.2557") - .withCopyFileToContainer( - MountableFile.forHostPath(Paths.get("src/test/resources/test-native/xml/transactions.xml").toAbsolutePath()), - "/etc/clickhouse-server/config.d/transactions.xml") - .withNetwork(network) - .withExposedPorts(8123) - .dependsOn(clickhouseKeeperContainer); + .withExposedPorts(8123); private final String systemPropKeyPrefix = "fixture.test-native.yaml.database.clickhouse."; @@ -103,7 +81,6 @@ void afterEach() throws SQLException { } contextManager.close(); } - network.close(); System.clearProperty(systemPropKeyPrefix + "ds0.jdbc-url"); System.clearProperty(systemPropKeyPrefix + "ds1.jdbc-url"); System.clearProperty(systemPropKeyPrefix + "ds2.jdbc-url"); @@ -125,13 +102,7 @@ private Connection openConnection(final String databaseName) throws SQLException } private DataSource createDataSource() throws SQLException { - String connectionString = clickhouseKeeperContainer.getHost() + ":" + clickhouseKeeperContainer.getMappedPort(9181); Awaitility.await().atMost(Duration.ofMinutes(1L)).ignoreExceptions().until(() -> { - try ( - CuratorFramework client = CuratorFrameworkFactory.builder().connectString(connectionString) - .retryPolicy(new ExponentialBackoffRetry(1000, 3)).build()) { - client.start(); - } openConnection("default").close(); return true; }); @@ -146,9 +117,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/jdbc/databases/clickhouse.yaml?placeholder-type=system_props"); - System.setProperty(systemPropKeyPrefix + "ds0.jdbc-url", jdbcUrlPrefix + "demo_ds_0?transactionSupport=true"); - System.setProperty(systemPropKeyPrefix + "ds1.jdbc-url", jdbcUrlPrefix + "demo_ds_1?transactionSupport=true"); - System.setProperty(systemPropKeyPrefix + "ds2.jdbc-url", jdbcUrlPrefix + "demo_ds_2?transactionSupport=true"); + System.setProperty(systemPropKeyPrefix + "ds0.jdbc-url", jdbcUrlPrefix + "demo_ds_0"); + System.setProperty(systemPropKeyPrefix + "ds1.jdbc-url", jdbcUrlPrefix + "demo_ds_1"); + System.setProperty(systemPropKeyPrefix + "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/FirebirdTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/FirebirdTest.java index 83e867ea0ab31..4e8dddbd1324f 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/FirebirdTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/FirebirdTest.java @@ -56,7 +56,7 @@ class FirebirdTest { @SuppressWarnings("resource") @Container - private final GenericContainer container = new GenericContainer<>("ghcr.io/fdcastel/firebird:5.0.1") + private final GenericContainer container = new GenericContainer<>("firebirdsql/firebird:5.0.1") .withEnv("FIREBIRD_ROOT_PASSWORD", password) .withEnv("FIREBIRD_USER", "alice") .withEnv("FIREBIRD_PASSWORD", password) diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/databases/MySQLTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/databases/MySQLTest.java index 33ad7b441acc2..6b868b6c4cab6 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/databases/MySQLTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/databases/MySQLTest.java @@ -96,37 +96,37 @@ void assertShardingInLocalTransactions() throws SQLException { statement.execute("CREATE DATABASE sharding_db"); statement.execute("USE sharding_db"); statement.execute("REGISTER STORAGE UNIT ds_0 (\n" - + " URL=\"jdbc:mysql://127.0.0.1:" + mysqlContainer.getMappedPort(3306) + "/demo_ds_0\",\n" - + " USER=\"root\",\n" - + " PASSWORD=\"yourStrongPassword123!\"\n" + + " URL='jdbc:mysql://127.0.0.1:" + mysqlContainer.getMappedPort(3306) + "/demo_ds_0',\n" + + " USER='root',\n" + + " PASSWORD='yourStrongPassword123!'\n" + "),ds_1 (\n" - + " URL=\"jdbc:mysql://127.0.0.1:" + mysqlContainer.getMappedPort(3306) + "/demo_ds_1\",\n" - + " USER=\"root\",\n" - + " PASSWORD=\"yourStrongPassword123!\"\n" + + " URL='jdbc:mysql://127.0.0.1:" + mysqlContainer.getMappedPort(3306) + "/demo_ds_1',\n" + + " USER='root',\n" + + " PASSWORD='yourStrongPassword123!'\n" + "),ds_2 (\n" - + " URL=\"jdbc:mysql://127.0.0.1:" + mysqlContainer.getMappedPort(3306) + "/demo_ds_2\",\n" - + " USER=\"root\",\n" - + " PASSWORD=\"yourStrongPassword123!\"\n" + + " URL='jdbc:mysql://127.0.0.1:" + mysqlContainer.getMappedPort(3306) + "/demo_ds_2',\n" + + " USER='root',\n" + + " PASSWORD='yourStrongPassword123!'\n" + ")"); statement.execute("CREATE DEFAULT SHARDING DATABASE STRATEGY (\n" - + " TYPE=\"standard\", \n" + + " TYPE='standard', \n" + " SHARDING_COLUMN=user_id, \n" + " SHARDING_ALGORITHM(\n" + " TYPE(\n" + " NAME=CLASS_BASED, \n" + " PROPERTIES(\n" - + " \"strategy\"=\"STANDARD\",\n" - + " \"algorithmClassName\"=\"org.apache.shardingsphere.test.natived.commons.algorithm.ClassBasedInlineShardingAlgorithmFixture\"\n" + + " 'strategy'='STANDARD',\n" + + " 'algorithmClassName'='org.apache.shardingsphere.test.natived.commons.algorithm.ClassBasedInlineShardingAlgorithmFixture'\n" + " )\n" + " )\n" + " )\n" + ")"); statement.execute("CREATE SHARDING TABLE RULE t_order (\n" - + " DATANODES(\"ds_0.t_order, ds_1.t_order, ds_2.t_order\"),\n" - + " KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME=\"SNOWFLAKE\"))\n" + + " DATANODES('ds_0.t_order, ds_1.t_order, ds_2.t_order'),\n" + + " KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME='SNOWFLAKE'))\n" + "), t_order_item (\n" - + " DATANODES(\"ds_0.t_order_item, ds_1.t_order_item, ds_2.t_order_item\"),\n" - + " KEY_GENERATE_STRATEGY(COLUMN=order_item_id,TYPE(NAME=\"SNOWFLAKE\"))\n" + + " DATANODES('ds_0.t_order_item, ds_1.t_order_item, ds_2.t_order_item'),\n" + + " KEY_GENERATE_STRATEGY(COLUMN=order_item_id,TYPE(NAME='SNOWFLAKE'))\n" + ")"); statement.execute("CREATE BROADCAST TABLE RULE t_address"); } diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/databases/PostgresTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/databases/PostgresTest.java index ab8511fcb48e9..05acc997fdb16 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/databases/PostgresTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/databases/PostgresTest.java @@ -96,37 +96,37 @@ void assertShardingInLocalTransactions() throws SQLException { Connection connection = openConnection("root", "root", "jdbc:postgresql://127.0.0.1:" + proxyTestingServer.getProxyPort() + "/sharding_db"); Statement statement = connection.createStatement()) { statement.execute("REGISTER STORAGE UNIT ds_0 (\n" - + " URL=\"jdbc:postgresql://127.0.0.1:" + postgresContainer.getMappedPort(5432) + "/demo_ds_0\",\n" - + " USER=\"test\",\n" - + " PASSWORD=\"test\"\n" + + " URL='jdbc:postgresql://127.0.0.1:" + postgresContainer.getMappedPort(5432) + "/demo_ds_0',\n" + + " USER='test',\n" + + " PASSWORD='test'\n" + "),ds_1 (\n" - + " URL=\"jdbc:postgresql://127.0.0.1:" + postgresContainer.getMappedPort(5432) + "/demo_ds_1\",\n" - + " USER=\"test\",\n" - + " PASSWORD=\"test\"\n" + + " URL='jdbc:postgresql://127.0.0.1:" + postgresContainer.getMappedPort(5432) + "/demo_ds_1',\n" + + " USER='test',\n" + + " PASSWORD='test'\n" + "),ds_2 (\n" - + " URL=\"jdbc:postgresql://127.0.0.1:" + postgresContainer.getMappedPort(5432) + "/demo_ds_2\",\n" - + " USER=\"test\",\n" - + " PASSWORD=\"test\"\n" + + " URL='jdbc:postgresql://127.0.0.1:" + postgresContainer.getMappedPort(5432) + "/demo_ds_2',\n" + + " USER='test',\n" + + " PASSWORD='test'\n" + ")"); statement.execute("CREATE DEFAULT SHARDING DATABASE STRATEGY (\n" - + " TYPE=\"standard\", \n" + + " TYPE='standard', \n" + " SHARDING_COLUMN=user_id, \n" + " SHARDING_ALGORITHM(\n" + " TYPE(\n" + " NAME=CLASS_BASED, \n" + " PROPERTIES(\n" - + " \"strategy\"=\"STANDARD\",\n" - + " \"algorithmClassName\"=\"org.apache.shardingsphere.test.natived.commons.algorithm.ClassBasedInlineShardingAlgorithmFixture\"\n" + + " 'strategy'='STANDARD',\n" + + " 'algorithmClassName'='org.apache.shardingsphere.test.natived.commons.algorithm.ClassBasedInlineShardingAlgorithmFixture'\n" + " )\n" + " )\n" + " )\n" + ")"); statement.execute("CREATE SHARDING TABLE RULE t_order (\n" - + " DATANODES(\"ds_0.t_order, ds_1.t_order, ds_2.t_order\"),\n" - + " KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME=\"SNOWFLAKE\"))\n" + + " DATANODES('ds_0.t_order, ds_1.t_order, ds_2.t_order'),\n" + + " KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME='SNOWFLAKE'))\n" + "), t_order_item (\n" - + " DATANODES(\"ds_0.t_order_item, ds_1.t_order_item, ds_2.t_order_item\"),\n" - + " KEY_GENERATE_STRATEGY(COLUMN=order_item_id,TYPE(NAME=\"SNOWFLAKE\"))\n" + + " DATANODES('ds_0.t_order_item, ds_1.t_order_item, ds_2.t_order_item'),\n" + + " KEY_GENERATE_STRATEGY(COLUMN=order_item_id,TYPE(NAME='SNOWFLAKE'))\n" + ")"); statement.execute("CREATE BROADCAST TABLE RULE t_address"); } diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/transactions/base/SeataTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/transactions/base/SeataTest.java index 7f0f8996ef743..4cbd3873915d7 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/transactions/base/SeataTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/transactions/base/SeataTest.java @@ -122,37 +122,37 @@ void assertShardingInLocalTransactions() throws SQLException { Connection connection = openConnection("root", "root", "jdbc:postgresql://127.0.0.1:" + proxyTestingServer.getProxyPort() + "/sharding_db"); Statement statement = connection.createStatement()) { statement.execute("REGISTER STORAGE UNIT ds_0 (\n" - + " URL=\"jdbc:postgresql://127.0.0.1:" + postgresContainer.getMappedPort(5432) + "/demo_ds_0\",\n" - + " USER=\"test\",\n" - + " PASSWORD=\"test\"\n" + + " URL='jdbc:postgresql://127.0.0.1:" + postgresContainer.getMappedPort(5432) + "/demo_ds_0',\n" + + " USER='test',\n" + + " PASSWORD='test'\n" + "),ds_1 (\n" - + " URL=\"jdbc:postgresql://127.0.0.1:" + postgresContainer.getMappedPort(5432) + "/demo_ds_1\",\n" - + " USER=\"test\",\n" - + " PASSWORD=\"test\"\n" + + " URL='jdbc:postgresql://127.0.0.1:" + postgresContainer.getMappedPort(5432) + "/demo_ds_1',\n" + + " USER='test',\n" + + " PASSWORD='test'\n" + "),ds_2 (\n" - + " URL=\"jdbc:postgresql://127.0.0.1:" + postgresContainer.getMappedPort(5432) + "/demo_ds_2\",\n" - + " USER=\"test\",\n" - + " PASSWORD=\"test\"\n" + + " URL='jdbc:postgresql://127.0.0.1:" + postgresContainer.getMappedPort(5432) + "/demo_ds_2',\n" + + " USER='test',\n" + + " PASSWORD='test'\n" + ")"); statement.execute("CREATE DEFAULT SHARDING DATABASE STRATEGY (\n" - + " TYPE=\"standard\", \n" + + " TYPE='standard', \n" + " SHARDING_COLUMN=user_id, \n" + " SHARDING_ALGORITHM(\n" + " TYPE(\n" + " NAME=CLASS_BASED, \n" + " PROPERTIES(\n" - + " \"strategy\"=\"STANDARD\",\n" - + " \"algorithmClassName\"=\"org.apache.shardingsphere.test.natived.commons.algorithm.ClassBasedInlineShardingAlgorithmFixture\"\n" + + " 'strategy'='STANDARD',\n" + + " 'algorithmClassName'='org.apache.shardingsphere.test.natived.commons.algorithm.ClassBasedInlineShardingAlgorithmFixture'\n" + " )\n" + " )\n" + " )\n" + ")"); statement.execute("CREATE SHARDING TABLE RULE t_order (\n" - + " DATANODES(\"ds_0.t_order, ds_1.t_order, ds_2.t_order\"),\n" - + " KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME=\"SNOWFLAKE\"))\n" + + " DATANODES('ds_0.t_order, ds_1.t_order, ds_2.t_order'),\n" + + " KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME='SNOWFLAKE'))\n" + "), t_order_item (\n" - + " DATANODES(\"ds_0.t_order_item, ds_1.t_order_item, ds_2.t_order_item\"),\n" - + " KEY_GENERATE_STRATEGY(COLUMN=order_item_id,TYPE(NAME=\"SNOWFLAKE\"))\n" + + " DATANODES('ds_0.t_order_item, ds_1.t_order_item, ds_2.t_order_item'),\n" + + " KEY_GENERATE_STRATEGY(COLUMN=order_item_id,TYPE(NAME='SNOWFLAKE'))\n" + ")"); statement.execute("CREATE BROADCAST TABLE RULE t_address"); } diff --git a/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/resource-config.json b/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/resource-config.json index 0f6f4683a75bf..5a22d077ea78e 100644 --- a/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/resource-config.json +++ b/test/native/src/test/resources/META-INF/native-image/shardingsphere-test-native-test-metadata/resource-config.json @@ -6,9 +6,6 @@ }, { "condition":{"typeReachable":"org.apache.shardingsphere.test.natived.jdbc.transactions.base.SeataTest"}, "pattern":".*test-native/sql/.+\\.sql$" - }, { - "condition":{"typeReachable":"org.apache.shardingsphere.test.natived.jdbc.databases.ClickHouseTest"}, - "pattern":".*test-native/xml/.+\\.xml$" }, { "condition":{"typeReachable":"org.apache.shardingsphere.test.natived.jdbc.databases.SQLServerTest"}, "pattern":"\\Qcontainer-license-acceptance.txt\\E" diff --git a/test/native/src/test/resources/test-native/xml/keeper_config.xml b/test/native/src/test/resources/test-native/xml/keeper_config.xml deleted file mode 100644 index 2a7d254adfa74..0000000000000 --- a/test/native/src/test/resources/test-native/xml/keeper_config.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - 0.0.0.0 - - 9181 - 1 - /var/lib/clickhouse/coordination/snapshots - - - 1 - clickhouse-keeper-01 - 9234 - - - - diff --git a/test/native/src/test/resources/test-native/xml/transactions.xml b/test/native/src/test/resources/test-native/xml/transactions.xml deleted file mode 100644 index 1c54dd5f003d5..0000000000000 --- a/test/native/src/test/resources/test-native/xml/transactions.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - 1 - - - clickhouse-keeper-01 - 9181 - - -