diff --git a/.github/workflows/graalvm.yml b/.github/workflows/graalvm.yml index 1d769972ebd21..ae2b45f359c86 100644 --- a/.github/workflows/graalvm.yml +++ b/.github/workflows/graalvm.yml @@ -45,7 +45,7 @@ jobs: fail-fast: false matrix: os: [ 'ubuntu-latest' ] - java-version: [ '21.0.2' ] + java-version: [ '22.0.1' ] steps: - uses: actions/checkout@v4 - uses: graalvm/setup-graalvm@v1 diff --git a/.github/workflows/nightly-ci.yml b/.github/workflows/nightly-ci.yml index c81c5350f3a08..77ab6cdaf6f2e 100644 --- a/.github/workflows/nightly-ci.yml +++ b/.github/workflows/nightly-ci.yml @@ -115,7 +115,7 @@ jobs: - uses: actions/checkout@v4 - uses: graalvm/setup-graalvm@v1 with: - java-version: '21.0.2' + java-version: '22.0.1' distribution: 'graalvm-community' github-token: ${{ secrets.GITHUB_TOKEN }} - uses: actions/cache@v4 diff --git a/distribution/proxy-native/pom.xml b/distribution/proxy-native/pom.xml index 47da6f62bf697..222eafaccb7ac 100644 --- a/distribution/proxy-native/pom.xml +++ b/distribution/proxy-native/pom.xml @@ -76,9 +76,6 @@ release.native - - 21 - apache-shardingsphere-${project.version} 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 86607d1f83a37..46339c7bd39de 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 @@ -13,10 +13,17 @@ Image,你需要借助于 GraalVM Native Build Tools。GraalVM Native Build Too CE 的 `native-image` 命令行工具的长篇大论的 shell 命令。 ShardingSphere JDBC 要求在如下或更高版本的 `GraalVM CE` 完成构建 GraalVM Native Image。使用者可通过 SDKMAN! 快速切换 JDK。这同理 -适用于 `Oracle GraalVM`, `Liberica Native Image Kit` 和 `Mandrel` 等 `GraalVM CE` 的下游发行版。 +适用于 `Oracle GraalVM`, `Liberica NIK` 和 `Mandrel` 等 `GraalVM CE` 的下游发行版。 -- GraalVM CE 23.1.2 For JDK 21.0.2,对应于 SDKMAN! 的 `21.0.2-graalce` -- GraalVM CE 24.0.0 For JDK 22,对应于 SDKMAN! 的 `22-graalce` +- GraalVM CE For JDK 22.0.1,对应于 SDKMAN! 的 `22.0.1-graalce` +- Oracle GraalVM For JDK 22.0.1,对应于 SDKMAN! 的 `22.0.1-graal` +- Liberica NIK For JDK 22.0.1,对应于 SDKMAN! 的 `24.0.1.r22-nik` +- Mandrel For JDK 22.0.1,对应于 SDKMAN! 的 `24.0.1.r22-mandrel` + +用户依然可以使用 SDKMAN! 上的 `21.0.2-graalce` 等旧版本的 GraalVM CE 来构建 ShardingSphere 的 GraalVM Native Image 产物。 +但这将导致集成部分第三方依赖时,构建 GraalVM Native Image 失败。 +典型的例子来自 HiveServer2 JDBC Driver 相关的 `org.apache.hive:hive-jdbc:4.0.0`,HiveServer2 JDBC Driver 使用了 AWT 相关的类, +而 GraalVM CE 对 `java.beans.**` package 的支持仅位于 GraalVM CE For JDK22 及更高版本。 ### Maven 生态 @@ -309,8 +316,8 @@ ShardingSphere 定义了 `nativeTestInShardingSphere` 的 Maven Profile 用于 sudo apt install unzip zip curl sed -y curl -s "https://get.sdkman.io" | bash source "$HOME/.sdkman/bin/sdkman-init.sh" -sdk install java 21.0.2-graalce -sdk use java 21.0.2-graalce +sdk install java 22.0.1-graalce +sdk use java 22.0.1-graalce sudo apt-get install build-essential libz-dev zlib1g-dev -y git clone git@github.com:apache/shardingsphere.git 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 9dc087c94a748..3579f37a5a36c 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 @@ -13,11 +13,18 @@ Image, you need to resort to GraalVM Native Build Tools. GraalVM Native Build To to simplify long list of shell commands for GraalVM CE's `native-image` command line tool. ShardingSphere JDBC requires GraalVM Native Image to be built with GraalVM CE as follows or higher. Users can quickly switch -JDK through `SDKMAN!`. Same reason applicable to downstream distributions of `GraalVM CE` such as `Oracle GraalVM`, `Liberica Native Image Kit` +JDK through `SDKMAN!`. Same reason applicable to downstream distributions of `GraalVM CE` such as `Oracle GraalVM`, `Liberica NIK` and `Mandrel`. -- GraalVM CE 23.1.2 For JDK 21.0.2, corresponding to `21.0.2-graalce` of SDKMAN! -- GraalVM CE 24.0.0 For JDK 22, corresponding to `22-graalce` of SDKMAN! +- GraalVM CE For JDK 22.0.1, corresponding to `21.0.2-graalce` of SDKMAN! +- Oracle GraalVM For JDK 22.0.1, corresponding to `22.0.1-graal` of SDKMAN! +- Liberica NIK For JDK 22.0.1, corresponding to `24.0.1.r22-nik` of SDKMAN! +- Mandrel For JDK 22.0.1, corresponding to `24.0.1.r22-mandrel` of SDKMAN! + +Users can still use the old versions of GraalVM CE such as `21.0.2-graalce` on SDKMAN! to build the GraalVM Native Image product of ShardingSphere. +However, this will cause the failure of building the GraalVM Native Image when integrating some third-party dependencies. +A typical example is related to the `org.apache.hive:hive-jdbc:4.0.0` HiveServer2 JDBC Driver, which uses AWT-related classes. +GraalVM CE only supports AWT for GraalVM CE For JDK22 and higher versions. ### Maven Ecology diff --git a/docs/document/content/user-manual/shardingsphere-proxy/startup/graalvm-native-image.cn.md b/docs/document/content/user-manual/shardingsphere-proxy/startup/graalvm-native-image.cn.md index cd18099e3444a..914bc949a8bc9 100644 --- a/docs/document/content/user-manual/shardingsphere-proxy/startup/graalvm-native-image.cn.md +++ b/docs/document/content/user-manual/shardingsphere-proxy/startup/graalvm-native-image.cn.md @@ -31,14 +31,14 @@ services: ## 前提条件 -1. 根据 https://www.graalvm.org/downloads/ 要求安装和配置 JDK 21 对应的 `GraalVM Community Edition` +1. 根据 https://www.graalvm.org/downloads/ 要求安装和配置 JDK 22 对应的 `GraalVM Community Edition` 或 `GraalVM Community Edition` 的下游发行版。若使用 `SDKMAN!`, ```shell -sdk install java 21.0.2-graalce +sdk install java 22.0.1-graalce ``` -2. 根据 https://www.graalvm.org/jdk21/reference-manual/native-image/#prerequisites 的要求安装本地工具链。 +2. 根据 https://www.graalvm.org/jdk22/reference-manual/native-image/#prerequisites 的要求安装本地工具链。 3. 如果需要构建 Docker Image, 确保 `docker-ce` 已安装。 @@ -56,7 +56,7 @@ sdk install java 21.0.2-graalce - 在 Git Source 同级目录下执行如下命令, 直接完成 Native Image 的构建。 ```bash -./mvnw -am -pl distribution/proxy-native -B -T1C -Prelease.native -DskipTests clean package +./mvnw -am -pl distribution/proxy-native -T1C -Prelease.native -DskipTests clean package ``` - 情形二:需要使用存在 SPI 实现的 JAR 或 GPL V2 等 LICENSE 的第三方依赖的 JAR。 @@ -113,7 +113,7 @@ services: - 如果你不对 Git Source 做任何更改, 上文提及的命令将使用 `oraclelinux:9-slim` 作为 Base Docker Image。 但如果你希望使用 `busybox:glic`,`gcr.io/distroless/base` 或 `scratch` 等更小体积的 Docker Image 作为 Base Docker - Image,你需要根据 https://www.graalvm.org/jdk21/reference-manual/native-image/guides/build-static-executables/ 的要求, + Image,你需要根据 https://www.graalvm.org/jdk22/reference-manual/native-image/guides/build-static-executables/ 的要求, 做为 `pom.xml`的 `native profile` 添加 `-H:+StaticExecutableWithDynamicLibC` 的 `jvmArgs` 等操作。 另请注意,某些第三方依赖将需要在 `Dockerfile` 安装更多系统库,例如 `libdl`。 因此请确保根据你的使用情况调整 `distribution/proxy-native` 下的 `pom.xml` 和 `Dockerfile` 的内容。 @@ -123,7 +123,7 @@ services: 针对 GraalVM Native Image 形态的 ShardingSphere Proxy,其提供的可观察性的能力与 https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-proxy/observability/ 并不一致。 -你可以使用 https://www.graalvm.org/jdk21/tools/ 提供的一系列命令行工具或可视化工具观察 GraalVM Native Image 的内部行为, +你可以使用 https://www.graalvm.org/jdk22/tools/ 提供的一系列命令行工具或可视化工具观察 GraalVM Native Image 的内部行为, 并根据其要求使用 VSCode 完成调试工作。如果你正在使用 IntelliJ IDEA 并且希望调试生成的 GraalVM Native Image,你可以关注 https://blog.jetbrains.com/idea/2022/06/intellij-idea-2022-2-eap-5/#Experimental_GraalVM_Native_Debugger_for_Java 及其后继。如果你使用的不是 Linux,则无法对 GraalVM Native Image 进行 Debug,请关注尚未关闭的 diff --git a/docs/document/content/user-manual/shardingsphere-proxy/startup/graalvm-native-image.en.md b/docs/document/content/user-manual/shardingsphere-proxy/startup/graalvm-native-image.en.md index 4ea3b381e4592..1368ece9cad4b 100644 --- a/docs/document/content/user-manual/shardingsphere-proxy/startup/graalvm-native-image.en.md +++ b/docs/document/content/user-manual/shardingsphere-proxy/startup/graalvm-native-image.en.md @@ -34,13 +34,13 @@ services: ## Premise 1. Install and configure `GraalVM Community Edition` or a downstream distribution of `GraalVM Community Edition` for -JDK 21 according to https://www.graalvm.org/downloads/. If `SDKMAN!` is used, +JDK 22 according to https://www.graalvm.org/downloads/. If `SDKMAN!` is used, ```shell -sdk install java 21.0.2-graalce +sdk install java 22.0.1-graalce ``` -2. Install the local toolchain as required by https://www.graalvm.org/jdk21/reference-manual/native-image/#prerequisites. +2. Install the local toolchain as required by https://www.graalvm.org/jdk22/reference-manual/native-image/#prerequisites. 3. If you need to build a Docker Image, make sure `docker-ce` is installed. @@ -99,7 +99,7 @@ sdk install java 21.0.2-graalce exist for SPI implementation or third-party dependencies. ```shell -./mvnw -am -pl distribution/proxy-native -B -T1C -Prelease.native,docker.native -DskipTests clean package +./mvnw -am -pl distribution/proxy-native -T1C -Prelease.native,docker.native -DskipTests clean package ``` - Assuming that there is a `conf` folder containing `global.yaml` as `./custom/conf`, you can start the Docker Image @@ -120,7 +120,7 @@ services: - If you don't make any changes to the Git Source, the commands mentioned above will use `oraclelinux:9-slim` as the Base Docker Image. But if you want to use a smaller Docker Image like `busybox:glic`, `gcr.io/distroless/base` or `scratch` as the Base Docker Image, you need according - to https://www.graalvm.org/jdk21/reference-manual/native-image/guides/build-static-executables/, + to https://www.graalvm.org/jdk22/reference-manual/native-image/guides/build-static-executables/, add operations such as `-H:+StaticExecutableWithDynamicLibC` to `jvmArgs` as the `native profile` of `pom.xml`. Also note that some 3rd-party dependencies will require more system libraries such as `libdl` to be installed in the `Dockerfile`. So make sure to tune `distribution/proxy-native` according to your usage `pom.xml` and `Dockerfile` @@ -133,7 +133,7 @@ with https://shardingsphere.apache.org/document/current/cn/user-manual/shardings not consistent. You can observe GraalVM Native Image using a series of command line tools or visualization tools available -at https://www.graalvm.org/jdk21/tools/, and use VSCode to debug it according to its requirements. +at https://www.graalvm.org/jdk22/tools/, and use VSCode to debug it according to its requirements. If you are using IntelliJ IDEA and want to debug the generated GraalVM Native Image, You can follow https://blog.jetbrains.com/idea/2022/06/intellij-idea-2022-2-eap-5/#Experimental_GraalVM_Native_Debugger_for_Java and its successors. If you are not using Linux, you cannot debug GraalVM Native Image, please pay attention diff --git a/infra/expr/type/espresso/src/main/java/org/apache/shardingsphere/infra/expr/espresso/ReflectContext.java b/infra/expr/type/espresso/src/main/java/org/apache/shardingsphere/infra/expr/espresso/ReflectContext.java index 0f93936f703e9..d9066fd922320 100644 --- a/infra/expr/type/espresso/src/main/java/org/apache/shardingsphere/infra/expr/espresso/ReflectContext.java +++ b/infra/expr/type/espresso/src/main/java/org/apache/shardingsphere/infra/expr/espresso/ReflectContext.java @@ -31,7 +31,6 @@ public final class ReflectContext implements AutoCloseable { /** * This method is a simulation of the following operation. - * // CHECKSTYLE:OFF *
      * private final Context context = Context.newBuilder("java")
      *             .allowAllAccess(true)
@@ -39,7 +38,6 @@ public final class ReflectContext implements AutoCloseable {
      *             .option("java.Classpath", JAVA_CLASSPATH)
      *             .build();
      * 
- * // CHECKSTYLE:ON * TODO oracle/graal#4555 not yet closed. * Maybe sometimes shardingsphere need `.option("java.Properties.org.graalvm.home", System.getenv("JAVA_HOME")). * 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 50dce54f451eb..9340b35d3be20 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 @@ -1,4 +1,8 @@ [ +{ + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory"}, + "name":"JdkLogger" +}, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.sql.JDBCRepositorySQLLoader"}, "name":"[Lcom.fasterxml.jackson.databind.deser.BeanDeserializerModifier;" @@ -7,6 +11,10 @@ "condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.sql.JDBCRepositorySQLLoader"}, "name":"[Lcom.fasterxml.jackson.databind.ser.BeanSerializerModifier;" }, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory"}, + "name":"[Lcom.github.dockerjava.api.model.VolumesFrom;" +}, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.datasource.pool.CatalogSwitchableDataSource"}, "name":"[Lcom.zaxxer.hikari.util.ConcurrentBag$IConcurrentBagEntry;" @@ -16,11 +24,11 @@ "name":"[Lcom.zaxxer.hikari.util.ConcurrentBag$IConcurrentBagEntry;" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.infra.database.DatabaseTypeEngine"}, - "name":"[Ljava.sql.Statement;" + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory"}, + "name":"[Ljava.lang.String;" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.infra.state.datasource.DataSourceStateManager"}, + "condition":{"typeReachable":"org.apache.shardingsphere.infra.database.DatabaseTypeEngine"}, "name":"[Ljava.sql.Statement;" }, { @@ -92,10 +100,6 @@ "condition":{"typeReachable":"org.apache.shardingsphere.infra.database.DatabaseTypeEngine"}, "name":"org.apache.shardingsphere.driver.ShardingSphereDriver" }, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.infra.state.datasource.DataSourceStateManager"}, - "name":"org.apache.shardingsphere.driver.ShardingSphereDriver" -}, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.JDBCRepository"}, "name":"org.apache.shardingsphere.driver.ShardingSphereDriver" @@ -364,6 +368,10 @@ "condition":{"typeReachable":"org.apache.shardingsphere.infra.datasource.pool.creator.DataSourcePoolReflection"}, "name":"org.apache.shardingsphere.infra.database.mysql.connector.MySQLConnectionPropertiesParser" }, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement"}, + "name":"org.apache.shardingsphere.infra.database.mysql.keygen.MySQLGeneratedKeyColumnProvider" +}, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.database.core.metadata.data.loader.MetaDataLoader"}, "name":"org.apache.shardingsphere.infra.database.mysql.metadata.data.loader.MySQLMetaDataLoader" @@ -572,7 +580,7 @@ "queryAllDeclaredMethods":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.subsciber.EventSubscriberRegistry$$Lambda/0x00007ffa03398208"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mode.subsciber.EventSubscriberRegistry$$Lambda/0x00007fce3b398818"}, "name":"org.apache.shardingsphere.infra.util.eventbus.EventSubscriber" }, { @@ -894,28 +902,32 @@ }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcherFactory"}, - "name":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.data.ShardingSphereDataChangedWatcher" + "name":"org.apache.shardingsphere.mode.manager.cluster.coordinator.listener.watch.ListenerAssistedChangedWatcher" }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcherFactory"}, - "name":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.watcher.MetaDataChangedWatcher" + "name":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.data.ShardingSphereDataChangedWatcher" }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcherFactory"}, - "name":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.cluster.watcher.ClusterStateChangedWatcher" + "name":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.nodes.compute.online.watcher.ComputeNodeOnlineWatcher" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.ClusterContextManagerBuilder"}, + "name":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.nodes.storage.subscriber.internal.QualifiedDataSourceStatusSubscriber", + "queryAllDeclaredMethods":true }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcherFactory"}, - "name":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.watcher.ComputeNodeStateChangedWatcher" + "name":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.nodes.storage.watcher.QualifiedDataSourceWatcher" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.ClusterContextManagerBuilder"}, - "name":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.subscriber.QualifiedDataSourceStatusSubscriber", - "queryAllDeclaredMethods":true + "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcherFactory"}, + "name":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.cluster.watcher.ClusterStateChangedWatcher" }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcherFactory"}, - "name":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.watcher.QualifiedDataSourceChangedWatcher" + "name":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.watcher.ComputeNodeStateChangedWatcher" }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcherFactory"}, @@ -930,6 +942,14 @@ "name":"org.apache.shardingsphere.mode.manager.cluster.coordinator.subscriber.CacheEvictedSubscriber", "methods":[{"name":"onGovernanceEvent","parameterTypes":["org.apache.shardingsphere.infra.rule.event.GovernanceEvent"] }] }, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.infra.util.eventbus.EventBusContext"}, + "name":"org.apache.shardingsphere.mode.manager.cluster.coordinator.subscriber.ResourceMetaDataChangedSubscriber" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.coordinator.listener.MetaDataChangedListener$$Lambda/0x00007fce3b8eaca0"}, + "name":"org.apache.shardingsphere.mode.manager.cluster.coordinator.subscriber.ResourceMetaDataChangedSubscriber" +}, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.service.PersistServiceFacade"}, "name":"org.apache.shardingsphere.mode.manager.cluster.service.ClusterPersistServiceBuilder", @@ -952,6 +972,58 @@ "condition":{"typeReachable":"org.apache.shardingsphere.infra.yaml.config.swapper.mode.YamlModeConfigurationSwapper"}, "name":"org.apache.shardingsphere.mode.manager.standalone.yaml.StandaloneYamlPersistRepositoryConfigurationSwapper" }, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.refresher.MetaDataRefreshEngine"}, + "name":"org.apache.shardingsphere.mode.metadata.refresher.type.index.AlterIndexStatementSchemaRefresher" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.refresher.MetaDataRefreshEngine"}, + "name":"org.apache.shardingsphere.mode.metadata.refresher.type.index.CreateIndexStatementSchemaRefresher" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.refresher.MetaDataRefreshEngine"}, + "name":"org.apache.shardingsphere.mode.metadata.refresher.type.index.DropIndexStatementSchemaRefresher" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.refresher.MetaDataRefreshEngine"}, + "name":"org.apache.shardingsphere.mode.metadata.refresher.type.schema.AlterSchemaStatementSchemaRefresher" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.refresher.MetaDataRefreshEngine"}, + "name":"org.apache.shardingsphere.mode.metadata.refresher.type.schema.CreateSchemaStatementSchemaRefresher" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.refresher.MetaDataRefreshEngine"}, + "name":"org.apache.shardingsphere.mode.metadata.refresher.type.schema.DropSchemaStatementSchemaRefresher" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.refresher.MetaDataRefreshEngine"}, + "name":"org.apache.shardingsphere.mode.metadata.refresher.type.table.AlterTableStatementSchemaRefresher" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.refresher.MetaDataRefreshEngine"}, + "name":"org.apache.shardingsphere.mode.metadata.refresher.type.table.CreateTableStatementSchemaRefresher" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.refresher.MetaDataRefreshEngine"}, + "name":"org.apache.shardingsphere.mode.metadata.refresher.type.table.DropTableStatementSchemaRefresher" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.refresher.MetaDataRefreshEngine"}, + "name":"org.apache.shardingsphere.mode.metadata.refresher.type.table.RenameTableStatementSchemaRefresher" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.refresher.MetaDataRefreshEngine"}, + "name":"org.apache.shardingsphere.mode.metadata.refresher.type.view.AlterViewStatementSchemaRefresher" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.refresher.MetaDataRefreshEngine"}, + "name":"org.apache.shardingsphere.mode.metadata.refresher.type.view.CreateViewStatementSchemaRefresher" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.refresher.MetaDataRefreshEngine"}, + "name":"org.apache.shardingsphere.mode.metadata.refresher.type.view.DropViewStatementSchemaRefresher" +}, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.ClusterContextManagerBuilder"}, "name":"org.apache.shardingsphere.mode.repository.cluster.etcd.EtcdRepository", 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 e9293e80b97ee..a3789763eda02 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 @@ -54,6 +54,18 @@ }, { "condition":{"typeReachable":"org.apache.shardingsphere.transaction.xa.atomikos.manager.AtomikosTransactionManagerProvider"}, "pattern":"\\QMETA-INF/services/com.atomikos.recovery.OltpLogFactory\\E" + }, { + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory"}, + "pattern":"\\QMETA-INF/services/com.clickhouse.client.ClickHouseClient\\E" + }, { + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory"}, + "pattern":"\\QMETA-INF/services/com.clickhouse.client.ClickHouseRequestManager\\E" + }, { + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory"}, + "pattern":"\\QMETA-INF/services/com.clickhouse.data.ClickHouseDataStreamFactory\\E" + }, { + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory"}, + "pattern":"\\QMETA-INF/services/com.clickhouse.jdbc.JdbcTypeMapping\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.cluster.etcd.EtcdRepository"}, "pattern":"\\QMETA-INF/services/io.grpc.LoadBalancerProvider\\E" @@ -99,6 +111,9 @@ }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.JDBCRepository"}, "pattern":"\\QMETA-INF/services/java.time.zone.ZoneRulesProvider\\E" + }, { + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory"}, + "pattern":"\\QMETA-INF/services/javax.xml.datatype.DatatypeFactory\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.sql.JDBCRepositorySQLLoader"}, "pattern":"\\QMETA-INF/services/javax.xml.stream.XMLInputFactory\\E" @@ -123,6 +138,9 @@ }, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.datasource.pool.creator.DataSourcePoolReflection"}, "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.infra.database.core.connector.ConnectionPropertiesParser\\E" + }, { + "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement"}, + "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.infra.database.core.keygen.GeneratedKeyColumnProvider\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.database.core.metadata.data.loader.MetaDataLoader"}, "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.infra.database.core.metadata.data.loader.DialectMetaDataLoader\\E" @@ -201,6 +219,9 @@ }, { "condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource"}, "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.mode.manager.listener.ContextManagerLifecycleListener\\E" + }, { + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.refresher.MetaDataRefreshEngine"}, + "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.mode.metadata.refresher.MetaDataRefresher\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.manager.cluster.ClusterContextManagerBuilder"}, "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository\\E" @@ -234,6 +255,12 @@ }, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.expr.groovy.GroovyInlineExpressionParser"}, "pattern":"\\QMETA-INF/services/org.codehaus.groovy.runtime.ExtensionModule\\E" + }, { + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory"}, + "pattern":"\\QMETA-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider\\E" + }, { + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory"}, + "pattern":"\\QMETA-INF/services/org.testcontainers.core.CreateContainerCmdModifier\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.transaction.base.seata.at.SeataATShardingSphereTransactionManager"}, "pattern":"\\Q\\E" @@ -246,6 +273,12 @@ }, { "condition":{"typeReachable":"org.apache.shardingsphere.transaction.xa.atomikos.manager.AtomikosTransactionManagerProvider"}, "pattern":"\\Qcom/atomikos/icatch/provider/imp/transactions.properties\\E" + }, { + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory"}, + "pattern":"\\Qcom/clickhouse/client/internal/jpountz/util/linux/amd64/liblz4-java.so\\E" + }, { + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory"}, + "pattern":"\\Qcontainer-license-acceptance.txt\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.cluster.etcd.EtcdRepository"}, "pattern":"\\Qjndi.properties\\E" @@ -255,9 +288,15 @@ }, { "condition":{"typeReachable":"org.apache.shardingsphere.transaction.base.seata.at.SeataATShardingSphereTransactionManager"}, "pattern":"\\Qlib/sqlparser/druid.jar\\E" + }, { + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory"}, + "pattern":"\\Qorg/apache/hc/core5/version.properties\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.JDBCRepository"}, "pattern":"\\Qorg/h2/util/data.zip\\E" + }, { + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory"}, + "pattern":"\\Qorg/postgresql/driverconfig.properties\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.transaction.base.seata.at.SeataATShardingSphereTransactionManager"}, "pattern":"\\Qregistry.conf\\E" @@ -2718,6 +2757,12 @@ }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.sql.JDBCRepositorySQLLoader"}, "pattern":"\\Qsql\\E" + }, { + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory"}, + "pattern":"\\Qtest-native/sql/seata-script-client-at-postgresql.sql\\E" + }, { + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory"}, + "pattern":"\\Qtest-native/sql/test-native-databases-clickhouse.sql\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.url.classpath.ClassPathURLLoader"}, "pattern":"\\Qtest-native/yaml/databases/clickhouse.yaml\\E" @@ -2772,8 +2817,14 @@ }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.cluster.etcd.EtcdRepository"}, "pattern":"\\Qvertx-default-jul-logging.properties\\E" + }, { + "condition":{"typeReachable":"org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory"}, + "pattern":"java.base:\\Qjdk/internal/icu/impl/data/icudt74b/nfkc.nrm\\E" }]}, "bundles":[{ + "name":"com.microsoft.sqlserver.jdbc.SQLServerResource", + "locales":["zh-CN"] + }, { "name":"sun.text.resources.cldr.FormatData", "locales":["en"] }] diff --git a/pom.xml b/pom.xml index d539451795a73..216d0e7da082d 100644 --- a/pom.xml +++ b/pom.xml @@ -979,9 +979,6 @@
generateMetadata - - 21 - @@ -1043,9 +1040,6 @@ nativeTestInShardingSphere - - 21 - diff --git a/test/native/native-image-filter/extra-filter.json b/test/native/native-image-filter/extra-filter.json index efcbfe3d48b15..ca2b00516a04f 100644 --- a/test/native/native-image-filter/extra-filter.json +++ b/test/native/native-image-filter/extra-filter.json @@ -18,7 +18,7 @@ {"excludeClasses": "com.arjuna.**"}, {"excludeClasses": "com.atomikos.**"}, {"excludeClasses": "com.alibaba.druid.**"}, - {"excludeClasses": "com.clickhouse.jdbc.**"}, + {"excludeClasses": "com.clickhouse.**"}, {"excludeClasses": "com.ctc.wstx.stax.**"}, {"excludeClasses": "com.fasterxml.jackson.databind.**"}, {"excludeClasses": "com.github.benmanes.caffeine.cache.**"}, diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/TestShardingService.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/TestShardingService.java index 02f6906ce883b..12980ee22ee59 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/TestShardingService.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/TestShardingService.java @@ -27,6 +27,7 @@ import javax.sql.DataSource; import java.sql.SQLException; +import java.sql.Statement; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -60,7 +61,7 @@ public TestShardingService(final DataSource dataSource) { * @throws SQLException An exception that provides information on a database access error or other errors. */ public void processSuccess() throws SQLException { - final Collection orderIds = insertData(); + final Collection orderIds = insertData(Statement.RETURN_GENERATED_KEYS); Collection orders = orderRepository.selectAll(); assertThat(orders.stream().map(Order::getOrderType).collect(Collectors.toList()), equalTo(Arrays.asList(0, 0, 0, 0, 0, 1, 1, 1, 1, 1))); @@ -89,12 +90,12 @@ public void processSuccess() throws SQLException { /** * Process success in ClickHouse. * ClickHouse has not fully supported transactions. Refer to ClickHouse/clickhouse-docs#2300. - * So ShardingSphere should not use {@code orderItemRepository.assertRollbackWithTransactions()} in the method here. + * So ShardingSphere should not use {@link OrderItemRepository#assertRollbackWithTransactions()} in the method here. * * @throws SQLException An exception that provides information on a database access error or other errors. */ public void processSuccessInClickHouse() throws SQLException { - Collection orderIds = insertDataInClickHouse(); + Collection orderIds = insertData(Statement.NO_GENERATED_KEYS); assertThat(orderIds, notNullValue()); Collection orders = orderRepository.selectAll(); assertThat(orders.stream().map(Order::getOrderType).collect(Collectors.toList()), @@ -122,11 +123,15 @@ public void processSuccessInClickHouse() throws SQLException { /** * Insert data. + * @param autoGeneratedKeys a flag indicating whether auto-generated keys + * should be returned; one of + * {@code Statement.RETURN_GENERATED_KEYS} or + * {@code Statement.NO_GENERATED_KEYS} * * @return orderId of the insert statement. * @throws SQLException An exception that provides information on a database access error or other errors. */ - public Collection insertData() throws SQLException { + public Collection insertData(final int autoGeneratedKeys) throws SQLException { Collection result = new ArrayList<>(10); for (int i = 1; i <= 10; i++) { Order order = new Order(); @@ -134,13 +139,13 @@ public Collection insertData() throws SQLException { order.setOrderType(i % 2); order.setAddressId(i); order.setStatus("INSERT_TEST"); - orderRepository.insert(order); + orderRepository.insert(order, autoGeneratedKeys); OrderItem orderItem = new OrderItem(); orderItem.setOrderId(order.getOrderId()); orderItem.setUserId(i); orderItem.setPhone("13800000001"); orderItem.setStatus("INSERT_TEST"); - orderItemRepository.insert(orderItem); + orderItemRepository.insert(orderItem, autoGeneratedKeys); Address address = new Address((long) i, "address_test_" + i); addressRepository.insert(address); result.add(order.getOrderId()); @@ -162,13 +167,13 @@ public Collection insertDataInClickHouse() throws SQLException { order.setOrderType(i % 2); order.setAddressId(i); order.setStatus("INSERT_TEST"); - orderRepository.insertWithoutAutoGeneratedKey(order); + orderRepository.insert(order, Statement.NO_GENERATED_KEYS); OrderItem orderItem = new OrderItem(); orderItem.setOrderId(order.getOrderId()); orderItem.setUserId(i); orderItem.setPhone("13800000001"); orderItem.setStatus("INSERT_TEST"); - orderItemRepository.insertWithoutAutoGeneratedKey(orderItem); + orderItemRepository.insert(orderItem, Statement.NO_GENERATED_KEYS); Address address = new Address((long) i, "address_test_" + i); addressRepository.insert(address); result.add(order.getOrderId()); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/AddressRepository.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/AddressRepository.java index 1e519f617a758..182913898cd47 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/AddressRepository.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/AddressRepository.java @@ -38,11 +38,11 @@ public AddressRepository(final DataSource dataSource) { } /** - * create table t_address if not exists. + * create table t_address if not exists in MySQL. * * @throws SQLException SQL exception */ - public void createTableIfNotExists() throws SQLException { + public void createTableIfNotExistsInMySQL() throws SQLException { String sql = "CREATE TABLE IF NOT EXISTS t_address (address_id BIGINT NOT NULL, address_name VARCHAR(100) NOT NULL, PRIMARY KEY (address_id))"; try ( Connection connection = dataSource.getConnection(); @@ -62,7 +62,7 @@ public void createTableInSQLServer() throws SQLException { + " address_id bigint NOT NULL,\n" + " address_name varchar(100) NOT NULL,\n" + " PRIMARY KEY (address_id)\n" - + ");"; + + ")"; try ( Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderItemRepository.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderItemRepository.java index 8979e284eff26..b53071fb09087 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderItemRepository.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderItemRepository.java @@ -52,7 +52,7 @@ public void createTableIfNotExistsInMySQL() throws SQLException { + "user_id INT NOT NULL,\n" + "phone VARCHAR(50),\n" + "status VARCHAR(50),\n" - + "PRIMARY KEY (order_item_id));"; + + "PRIMARY KEY (order_item_id))"; try ( Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { @@ -72,7 +72,7 @@ public void createTableIfNotExistsInPostgres() throws SQLException { + " user_id INTEGER NOT NULL,\n" + " phone VARCHAR(50),\n" + " status VARCHAR(50)\n" - + ");"; + + ")"; try ( Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { @@ -94,7 +94,7 @@ public void createTableInSQLServer() throws SQLException { + " phone varchar(50),\n" + " status varchar(50),\n" + " PRIMARY KEY (order_item_id)\n" - + ");"; + + ")"; try ( Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { @@ -104,6 +104,7 @@ public void createTableInSQLServer() throws SQLException { /** * create table if not exists in ClickHouse. + * ClickHouse does not support `AUTO_INCREMENT`, refer to ClickHouse/ClickHouse#56228 . * * @throws SQLException SQL exception */ @@ -208,7 +209,8 @@ public Long insert(final OrderItem orderItem) throws SQLException { } /** - * insert OrderItem to table. + * insert OrderItem to table. Databases like ClickHouse do not support returning auto generated keys after executing SQL, + * see ClickHouse/ClickHouse#56228 . * * @param orderItem orderItem * @param autoGeneratedKeys a flag indicating whether auto-generated keys @@ -237,17 +239,6 @@ public Long insert(final OrderItem orderItem, final int autoGeneratedKeys) throw return orderItem.getOrderItemId(); } - /** - * insert OrderItem to table without auto generated key. Databases like ClickHouse do not support returning auto generated keys after executing SQL, - * see ClickHouse/ClickHouse#56228 . - * - * @param orderItem orderItem - * @throws SQLException SQL Exception - */ - public void insertWithoutAutoGeneratedKey(final OrderItem orderItem) throws SQLException { - insert(orderItem, Statement.NO_GENERATED_KEYS); - } - /** * delete by orderItemId. * 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 0919940a71661..01e69141d9c97 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 @@ -49,7 +49,7 @@ public void createTableIfNotExistsInMySQL() throws SQLException { + "user_id INT NOT NULL,\n" + "address_id BIGINT NOT NULL,\n" + "status VARCHAR(50),\n" - + "PRIMARY KEY (order_id));"; + + "PRIMARY KEY (order_id))"; try ( Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { @@ -69,7 +69,7 @@ public void createTableIfNotExistsInPostgres() throws SQLException { + " user_id INTEGER NOT NULL,\n" + " address_id BIGINT NOT NULL,\n" + " status VARCHAR(50)\n" - + ");"; + + ")"; try ( Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { @@ -91,7 +91,7 @@ public void createTableInSQLServer() throws SQLException { + " address_id bigint NOT NULL,\n" + " status varchar(50),\n" + " PRIMARY KEY (order_id)\n" - + ");"; + + ")"; try ( Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { @@ -101,6 +101,7 @@ public void createTableInSQLServer() throws SQLException { /** * create table in ClickHouse. + * ClickHouse does not support `AUTO_INCREMENT`, refer to ClickHouse/ClickHouse#56228 . * * @throws SQLException SQL exception */ @@ -113,7 +114,7 @@ public void createTableIfNotExistsInClickHouse() throws SQLException { + "status String\n" + ") engine = MergeTree \n" + "primary key (order_id)\n" - + "order by(order_id); "; + + "order by(order_id)"; try ( Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { @@ -234,7 +235,8 @@ public Long insert(final Order order) throws SQLException { } /** - * insert Order to table. + * insert Order to table. Databases like ClickHouse do not support returning auto generated keys after executing SQL, + * see ClickHouse/ClickHouse#56228 . * * @param order order * @param autoGeneratedKeys a flag indicating whether auto-generated keys 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 0c526f833d94d..6b2d46e673b71 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 @@ -31,8 +31,8 @@ class ClickHouseTest { private TestShardingService testShardingService; /** - * TODO Need to fix `shardingsphere-parser-sql-clickhouse` module to use `testShardingService.cleanEnvironment()` - * after `testShardingService.processSuccessInClickHouse()`. + * TODO Need to fix `shardingsphere-parser-sql-clickhouse` module to use {@link TestShardingService#cleanEnvironment()} + * after {@link TestShardingService#processSuccessInClickHouse()}. * * @throws SQLException An exception that provides information on a database access error or other errors. */ @@ -49,7 +49,7 @@ void assertShardingInLocalTransactions() throws SQLException { /** * TODO Need to fix `shardingsphere-parser-sql-clickhouse` module to use `initEnvironment()` - * before `testShardingService.processSuccess()`. + * before {@link TestShardingService#processSuccessInClickHouse()}. * * @throws SQLException An exception that provides information on a database access error or other errors. */ @@ -57,7 +57,7 @@ void assertShardingInLocalTransactions() throws SQLException { private void initEnvironment() throws SQLException { testShardingService.getOrderRepository().createTableIfNotExistsInClickHouse(); testShardingService.getOrderItemRepository().createTableIfNotExistsInClickHouse(); - testShardingService.getAddressRepository().createTableIfNotExists(); + testShardingService.getAddressRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderRepository().truncateTable(); testShardingService.getOrderItemRepository().truncateTable(); testShardingService.getAddressRepository().truncateTable(); 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 7e1a53706d69d..1403a074110b7 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 @@ -31,6 +31,7 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; +import java.sql.Statement; import java.time.Duration; import java.util.Properties; @@ -78,7 +79,7 @@ void assertShardingInLocalTransactions() throws SQLException { private void initEnvironment() throws SQLException { testShardingService.getOrderRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderItemRepository().createTableIfNotExistsInMySQL(); - testShardingService.getAddressRepository().createTableIfNotExists(); + testShardingService.getAddressRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderRepository().truncateTable(); testShardingService.getOrderItemRepository().truncateTable(); testShardingService.getAddressRepository().truncateTable(); @@ -92,18 +93,18 @@ private Connection openConnection() throws SQLException { } @SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"}) - private DataSource createDataSource() { + private DataSource createDataSource() throws SQLException { Awaitility.await().atMost(Duration.ofMinutes(1L)).ignoreExceptionsMatching(e -> e instanceof CommunicationsException) .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 (final SQLException ex) { - throw new RuntimeException(ex); + try ( + Connection connection = openConnection(); + Statement statement = connection.createStatement()) { + statement.executeUpdate("CREATE DATABASE demo_ds_0"); + statement.executeUpdate("CREATE DATABASE demo_ds_1"); + statement.executeUpdate("CREATE DATABASE demo_ds_2"); } HikariConfig config = new HikariConfig(); config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver"); 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 edff542ce3e58..ad96a195fa24c 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 @@ -30,6 +30,7 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; +import java.sql.Statement; import java.time.Duration; import java.util.Properties; @@ -72,7 +73,7 @@ void assertShardingInLocalTransactions() throws SQLException { private void initEnvironment() throws SQLException { testShardingService.getOrderRepository().createTableIfNotExistsInPostgres(); testShardingService.getOrderItemRepository().createTableIfNotExistsInPostgres(); - testShardingService.getAddressRepository().createTableIfNotExists(); + testShardingService.getAddressRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderRepository().truncateTable(); testShardingService.getOrderItemRepository().truncateTable(); testShardingService.getAddressRepository().truncateTable(); @@ -86,17 +87,17 @@ private Connection openConnection() throws SQLException { } @SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"}) - private DataSource createDataSource() { + private DataSource createDataSource() throws SQLException { Awaitility.await().atMost(Duration.ofMinutes(1L)).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 (final SQLException ex) { - throw new RuntimeException(ex); + try ( + Connection connection = openConnection(); + Statement statement = connection.createStatement()) { + statement.executeUpdate("CREATE DATABASE demo_ds_0"); + statement.executeUpdate("CREATE DATABASE demo_ds_1"); + statement.executeUpdate("CREATE DATABASE demo_ds_2"); } HikariConfig config = new HikariConfig(); config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver"); 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 a9852c3ca31da..f2fd80218fbd0 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 @@ -46,7 +46,7 @@ void assertShardingInLocalTransactions() throws SQLException { private void initEnvironment() throws SQLException { testShardingService.getOrderRepository().createTableIfNotExistsInPostgres(); testShardingService.getOrderItemRepository().createTableIfNotExistsInPostgres(); - testShardingService.getAddressRepository().createTableIfNotExists(); + testShardingService.getAddressRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderRepository().truncateTable(); testShardingService.getOrderItemRepository().truncateTable(); testShardingService.getAddressRepository().truncateTable(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/EncryptTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/EncryptTest.java index bd6a2874ce42f..31565acf93198 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/EncryptTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/EncryptTest.java @@ -63,7 +63,7 @@ void assertEncryptInLocalTransactions() throws SQLException { private void initEnvironment() throws SQLException { orderRepository.createTableIfNotExistsInMySQL(); orderItemRepository.createTableIfNotExistsInMySQL(); - addressRepository.createTableIfNotExists(); + addressRepository.createTableIfNotExistsInMySQL(); orderRepository.truncateTable(); orderItemRepository.truncateTable(); addressRepository.truncateTable(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/MaskTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/MaskTest.java index f6fbd6320c48c..660719488731c 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/MaskTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/MaskTest.java @@ -64,7 +64,7 @@ void assertMaskInLocalTransactions() throws SQLException { private void initEnvironment() throws SQLException { orderRepository.createTableIfNotExistsInMySQL(); orderItemRepository.createTableIfNotExistsInMySQL(); - addressRepository.createTableIfNotExists(); + addressRepository.createTableIfNotExistsInMySQL(); orderRepository.truncateTable(); orderItemRepository.truncateTable(); addressRepository.truncateTable(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ReadWriteSplittingTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ReadWriteSplittingTest.java index d2c52b66a6556..2bb48c20d21a9 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ReadWriteSplittingTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ReadWriteSplittingTest.java @@ -60,7 +60,7 @@ void assertReadWriteSplittingInLocalTransactions() throws SQLException { private void initEnvironment() throws SQLException { orderRepository.createTableIfNotExistsInMySQL(); orderItemRepository.createTableIfNotExistsInMySQL(); - addressRepository.createTableIfNotExists(); + addressRepository.createTableIfNotExistsInMySQL(); orderRepository.truncateTable(); orderItemRepository.truncateTable(); addressRepository.truncateTable(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ShadowTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ShadowTest.java index f195e623f0f00..c7e29830dccf9 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ShadowTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ShadowTest.java @@ -64,7 +64,7 @@ void assertShadowInLocalTransactions() throws SQLException { private void initEnvironment() throws SQLException { orderRepository.createTableIfNotExistsInMySQL(); orderItemRepository.createTableIfNotExistsInMySQL(); - addressRepository.createTableIfNotExists(); + addressRepository.createTableIfNotExistsInMySQL(); orderRepository.truncateTable(); orderItemRepository.truncateTable(); addressRepository.truncateTable(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ShardingTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ShardingTest.java index 99d18af28438b..32efaef02140c 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ShardingTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ShardingTest.java @@ -44,7 +44,7 @@ void assertShardingInLocalTransactions() throws SQLException { private void initEnvironment() throws SQLException { testShardingService.getOrderRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderItemRepository().createTableIfNotExistsInMySQL(); - testShardingService.getAddressRepository().createTableIfNotExists(); + testShardingService.getAddressRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderRepository().truncateTable(); testShardingService.getOrderItemRepository().truncateTable(); testShardingService.getAddressRepository().truncateTable(); 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 325047d48ff76..f8ceff784eb38 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 @@ -21,19 +21,12 @@ import com.zaxxer.hikari.HikariDataSource; import io.etcd.jetcd.launcher.Etcd; import io.etcd.jetcd.launcher.EtcdCluster; -import org.apache.hc.client5.http.classic.methods.HttpGet; -import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; -import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; -import org.apache.hc.client5.http.impl.classic.HttpClients; -import org.apache.hc.core5.http.HttpStatus; -import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.shardingsphere.test.natived.jdbc.commons.TestShardingService; import org.awaitility.Awaitility; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledInNativeImage; import javax.sql.DataSource; -import java.io.IOException; import java.net.URI; import java.sql.SQLException; import java.time.Duration; @@ -80,7 +73,7 @@ void assertShardingInLocalTransactions() throws SQLException { private void initEnvironment() throws SQLException { testShardingService.getOrderRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderItemRepository().createTableIfNotExistsInMySQL(); - testShardingService.getAddressRepository().createTableIfNotExists(); + testShardingService.getAddressRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderRepository().truncateTable(); testShardingService.getOrderItemRepository().truncateTable(); testShardingService.getAddressRepository().truncateTable(); @@ -88,7 +81,6 @@ private void initEnvironment() throws SQLException { private DataSource createDataSource(final List clientEndpoints) { URI clientEndpoint = clientEndpoints.get(0); - Awaitility.await().atMost(Duration.ofSeconds(30L)).ignoreExceptions().until(() -> verifyEtcdClusterRunning(clientEndpoint)); 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"); @@ -100,18 +92,4 @@ private DataSource createDataSource(final List clientEndpoints) { System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "server-lists"); } } - - private Boolean verifyEtcdClusterRunning(final URI clientEndpoint) throws IOException { - boolean flag = false; - HttpGet httpGet = new HttpGet(clientEndpoint.toString() + "/health"); - try ( - CloseableHttpClient httpclient = HttpClients.createDefault(); - CloseableHttpResponse response = httpclient.execute(httpGet)) { - if (HttpStatus.SC_OK == response.getCode()) { - flag = true; - } - EntityUtils.consume(response.getEntity()); - } - return flag; - } } 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 9c9d1d5617cef..88836303e1a26 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 @@ -68,7 +68,7 @@ void assertShardingInLocalTransactions() throws Exception { private void initEnvironment() throws SQLException { testShardingService.getOrderRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderItemRepository().createTableIfNotExistsInMySQL(); - testShardingService.getAddressRepository().createTableIfNotExists(); + testShardingService.getAddressRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderRepository().truncateTable(); testShardingService.getOrderItemRepository().truncateTable(); testShardingService.getAddressRepository().truncateTable(); 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 b3f0b73301ade..827d856a1c13c 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 @@ -60,7 +60,7 @@ void assertShardingInSeataTransactions() throws SQLException { private void initEnvironment() throws SQLException { testShardingService.getOrderRepository().createTableIfNotExistsInPostgres(); testShardingService.getOrderItemRepository().createTableIfNotExistsInPostgres(); - testShardingService.getAddressRepository().createTableIfNotExists(); + testShardingService.getAddressRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderRepository().truncateTable(); testShardingService.getOrderItemRepository().truncateTable(); testShardingService.getAddressRepository().truncateTable(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/xa/AtomikosTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/xa/AtomikosTest.java index 9df766bec81e6..141c4f87d6dfe 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/xa/AtomikosTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/xa/AtomikosTest.java @@ -44,7 +44,7 @@ void assertShardingInAtomikosTransactions() throws SQLException { private void initEnvironment() throws SQLException { testShardingService.getOrderRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderItemRepository().createTableIfNotExistsInMySQL(); - testShardingService.getAddressRepository().createTableIfNotExists(); + testShardingService.getAddressRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderRepository().truncateTable(); testShardingService.getOrderItemRepository().truncateTable(); testShardingService.getAddressRepository().truncateTable(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/xa/NarayanaTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/xa/NarayanaTest.java index 87993a5215099..ba7103fd8851a 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/xa/NarayanaTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/xa/NarayanaTest.java @@ -47,7 +47,7 @@ void assertShardingInNarayanaTransactions() throws SQLException, CoreEnvironment private void initEnvironment() throws SQLException { testShardingService.getOrderRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderItemRepository().createTableIfNotExistsInMySQL(); - testShardingService.getAddressRepository().createTableIfNotExists(); + testShardingService.getAddressRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderRepository().truncateTable(); testShardingService.getOrderItemRepository().truncateTable(); testShardingService.getAddressRepository().truncateTable();