diff --git a/.github/workflows/nightly-build.yml b/.github/workflows/nightly-build.yml index c0b8614438f5aa..bc4cd9b0f71ab3 100644 --- a/.github/workflows/nightly-build.yml +++ b/.github/workflows/nightly-build.yml @@ -119,7 +119,7 @@ jobs: ref: ${{ inputs.commit-id }} - uses: graalvm/setup-graalvm@v1 with: - java-version: '17.0.7' + java-version: '17.0.8' distribution: 'graalvm-community' components: 'espresso,native-image' github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/distribution/proxy-native/Dockerfile b/distribution/proxy-native/Dockerfile index a21b8b0db9ee40..a65a1b219d32ff 100644 --- a/distribution/proxy-native/Dockerfile +++ b/distribution/proxy-native/Dockerfile @@ -22,14 +22,11 @@ ENV LOCAL_PATH /opt/shardingsphere-proxy-native ADD target/${APP_NAME}.tar.gz /opt RUN mv /opt/${APP_NAME} ${LOCAL_PATH} -FROM ghcr.io/graalvm/graalvm-community:17.0.7-ol9 +FROM oraclelinux:9-slim MAINTAINER ShardingSphere "dev@shardingsphere.apache.org" ARG NATIVE_IMAGE_NAME ENV LOCAL_PATH /opt/shardingsphere-proxy-native -RUN $JAVA_HOME/bin/gu install espresso && \ - $JAVA_HOME/bin/gu remove native-image - COPY --from=prepare ${LOCAL_PATH} ${LOCAL_PATH} ENTRYPOINT ${LOCAL_PATH}/${NATIVE_IMAGE_NAME} 3307 ${LOCAL_PATH}/conf "0.0.0.0" false diff --git a/distribution/proxy-native/pom.xml b/distribution/proxy-native/pom.xml index bc06f5e4972741..be4fa65314fb14 100644 --- a/distribution/proxy-native/pom.xml +++ b/distribution/proxy-native/pom.xml @@ -68,7 +68,6 @@ release.native - 23.0.1 true true true @@ -96,8 +95,6 @@ false true - --language:java - -H:+AllowDeprecatedBuilderClassesOnImageClasspath --report-unsupported-elements-at-runtime diff --git a/distribution/proxy-native/src/main/release-docs/LICENSE b/distribution/proxy-native/src/main/release-docs/LICENSE index b9f565cca71f90..80a331318e3ac6 100644 --- a/distribution/proxy-native/src/main/release-docs/LICENSE +++ b/distribution/proxy-native/src/main/release-docs/LICENSE @@ -360,13 +360,3 @@ The text of each license is also included at licenses/LICENSE-[project].txt. jul-to-slf4j 1.7.36: https://www.slf4j.org, MIT slf4j-api 1.7.36: https://www.slf4j.org, MIT jnanoid 2.0.0: /~https://github.com/aventrix/jnanoid, MIT - -======================================================================== -UPL licenses -======================================================================== - -The following components are provided under the UPL License. See project link for details. -The text of each license is also included at licenses/LICENSE-[project].txt. - - graal-sdk 23.0.1: /~https://github.com/oracle/graal, UPL 1.0 - truffle-api 23.0.1: /~https://github.com/oracle/graal/tree/master/truffle, UPL 1.0 diff --git a/distribution/proxy-native/src/main/release-docs/licenses/LICENSE-truffle-api.txt b/distribution/proxy-native/src/main/release-docs/licenses/LICENSE-truffle-api.txt deleted file mode 100644 index d656a31cb15d73..00000000000000 --- a/distribution/proxy-native/src/main/release-docs/licenses/LICENSE-truffle-api.txt +++ /dev/null @@ -1,35 +0,0 @@ -The Universal Permissive License (UPL), Version 1.0 - -Subject to the condition set forth below, permission is hereby granted to any -person obtaining a copy of this software, associated documentation and/or -data (collectively the "Software"), free of charge and under any and all -copyright rights in the Software, and any and all patent rights owned or -freely licensable by each licensor hereunder covering either (i) the -unmodified Software as contributed to or provided by such licensor, or (ii) -the Larger Works (as defined below), to deal in both - -(a) the Software, and - -(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if -one is included with the Software each a "Larger Work" to which the Software -is contributed by such licensors), - -without restriction, including without limitation the rights to copy, create -derivative works of, display, perform, and distribute the Software and make, -use, sell, offer for sale, import, export, have made, and have sold the -Software and the Larger Work(s), and to sublicense the foregoing rights on -either these or other terms. - -This license is subject to the following condition: - -The above copyright notice and either this complete permission notice or at a -minimum a reference to the UPL must be included in all copies or substantial -portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/distribution/proxy/src/main/release-docs/LICENSE b/distribution/proxy/src/main/release-docs/LICENSE index baea69f611e0bb..00b8283675ce73 100644 --- a/distribution/proxy/src/main/release-docs/LICENSE +++ b/distribution/proxy/src/main/release-docs/LICENSE @@ -372,13 +372,3 @@ The text of each license is also included at licenses/LICENSE-[project].txt. jul-to-slf4j 1.7.36: https://www.slf4j.org, MIT slf4j-api 1.7.36: https://www.slf4j.org, MIT jnanoid 2.0.0: /~https://github.com/aventrix/jnanoid, MIT - -======================================================================== -UPL licenses -======================================================================== - -The following components are provided under the UPL License. See project link for details. -The text of each license is also included at licenses/LICENSE-[project].txt. - - graal-sdk 21.2.0: /~https://github.com/oracle/graal, UPL 1.0 - truffle-api 21.2.0: /~https://github.com/oracle/graal/tree/master/truffle, UPL 1.0 diff --git a/distribution/proxy/src/main/release-docs/licenses/LICENSE-truffle-api.txt b/distribution/proxy/src/main/release-docs/licenses/LICENSE-truffle-api.txt deleted file mode 100644 index d656a31cb15d73..00000000000000 --- a/distribution/proxy/src/main/release-docs/licenses/LICENSE-truffle-api.txt +++ /dev/null @@ -1,35 +0,0 @@ -The Universal Permissive License (UPL), Version 1.0 - -Subject to the condition set forth below, permission is hereby granted to any -person obtaining a copy of this software, associated documentation and/or -data (collectively the "Software"), free of charge and under any and all -copyright rights in the Software, and any and all patent rights owned or -freely licensable by each licensor hereunder covering either (i) the -unmodified Software as contributed to or provided by such licensor, or (ii) -the Larger Works (as defined below), to deal in both - -(a) the Software, and - -(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if -one is included with the Software each a "Larger Work" to which the Software -is contributed by such licensors), - -without restriction, including without limitation the rights to copy, create -derivative works of, display, perform, and distribute the Software and make, -use, sell, offer for sale, import, export, have made, and have sold the -Software and the Larger Work(s), and to sublicense the foregoing rights on -either these or other terms. - -This license is subject to the following condition: - -The above copyright notice and either this complete permission notice or at a -minimum a reference to the UPL must be included in all copies or substantial -portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. 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 741cdb74345eeb..ef8d3a0ec7087a 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 @@ -5,8 +5,7 @@ weight = 2 ## 背景信息 -本节主要介绍如何通过 `GraalVM` 的 `native-image` 组件构建 ShardingSphere-Proxy 的 `Native Image` 和对应的 `Docker Image` -。 +本节主要介绍如何通过 `GraalVM` 的 `native-image` 组件构建 ShardingSphere-Proxy 的 `Native Image` 和对应的 `Docker Image`。 ## 注意事项 @@ -30,20 +29,17 @@ services: 应当在 /~https://github.com/oracle/graalvm-reachability-metadata 打开新的 issue , 并提交包含 ShardingSphere 自身或依赖的第三方库缺失的 GraalVM Reachability Metadata 的 PR。 -- ShardingSphere 的 master 分支尚未准备好处理 Native Image 中的单元测试, 你总是需要在构建 GraalVM Native Image 的过程中, +- ShardingSphere 的 master 分支尚未准备好处理 Native Image 中的单元测试 , 你总是需要在构建 GraalVM Native Image 的过程中, 加上特定于 `GraalVM Native Build Tools` 的 `-DskipNativeTests` 或 `-DskipTests` 参数跳过 Native Image 中的单元测试。 -- 如下 3 个算法类由于涉及到 GraalVM Truffle Espresso 不方便在 host JVM 和 guest JVM 之间交互的 `groovy.lang.Closure` - 类,暂未可在 GraalVM Native Image 下使用。 +- 如下的算法类由于涉及到 /~https://github.com/oracle/graal/issues/5522 , 暂未可在 GraalVM Native Image 下使用。 - `org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm` - `org.apache.shardingsphere.sharding.algorithm.sharding.inline.ComplexInlineShardingAlgorithm` - `org.apache.shardingsphere.sharding.algorithm.sharding.hint.HintInlineShardingAlgorithm` -- 当前阶段,GraalVM Native Image 形态的 ShardingSphere Proxy 处于混合 AOT ( GraalVM Native Image ) 和 JIT ( GraalVM - Truffle Espresso ) 运行的阶段。由于 /~https://github.com/oracle/graal/issues/4555 尚未关闭,GraalVM Truffle Espresso - 运行需要的 `.so` 文件并不会进入 GraalVM Native Image 内。因此如果你需要在 Docker Image 外运行 ShardingSphere Proxy - Native 的二进制文件,你需要确保系统环境变量 `JAVA_HOME` 指向 GraalVM 的目录,并且此 GraalVM - 实例已经通过 `GraalVM Updater` 安装了 `espresso` 组件。 +- 当前阶段,GraalVM Native Image 形态的 ShardingSphere Proxy 不支持使用带 Groovy + 语法的 `行表达式`, 这首先导致 `数据分片` 功能的`actualDataNodes`属性只能使用纯列表来配置, 例如 `ds_0.t_order_0, ds_0.t_order_1` + 或 `ds_0.t_user_0, ds_15.t_user_1023`。此问题在 /~https://github.com/oracle/graal/issues/5522 追踪。 - 本节假定处于 Linux(amd64,aarch64), MacOS(amd64)或 Windows(amd64)环境。 如果你位于 MacOS(aarch64/M1) 环境,你需要关注尚未关闭的 /~https://github.com/oracle/graal/issues/2666 。 @@ -53,20 +49,14 @@ services: 1. 根据 https://www.graalvm.org/downloads/ 要求安装和配置 JDK 17 对应的 `GraalVM Community Edition` 或 `Oracle GraalVM`。或者使用 `SDKMAN!`。 ```shell -sdk install java 17.0.7-graalce +sdk install java 17.0.8-graalce ``` -2. 通过 `GraalVM Updater` 工具安装 `espresso` 组件。 +2. 根据 https://www.graalvm.org/latest/reference-manual/native-image/#prerequisites 的要求安装本地工具链。 -```shell -gu install espresso -``` - -3. 根据 https://www.graalvm.org/latest/reference-manual/native-image/#prerequisites 的要求安装本地工具链。 - -4. 如果需要构建 Docker Image, 确保 `docker-ce` 已安装。 +3. 如果需要构建 Docker Image, 确保 `docker-ce` 已安装。 -5. 首先需要在项目的根目录下,执行如下命令以为所有子模块采集 Standard 形态的 GraalVM 可达性元数据。 +4. 首先需要在项目的根目录下,执行如下命令以为所有子模块采集 Standard 形态的 GraalVM 可达性元数据。 ```shell ./mvnw -PgenerateStandardMetadata -DskipNativeTests -B -T1C clean test @@ -146,7 +136,7 @@ services: - "3307:3307" ``` -- 如果你不对 Git Source 做任何更改, 上文提及的命令将使用 `ghcr.io/graalvm/graalvm-community:17.0.7-ol9` 作为 Base Docker Image。 +- 如果你不对 Git Source 做任何更改, 上文提及的命令将使用 `oraclelinux:9-slim` 作为 Base Docker Image。 但如果你希望使用 `busybox:glic`,`gcr.io/distroless/base` 或 `scratch` 等更小体积的 Docker Image 作为 Base Docker Image,你需要根据 https://www.graalvm.org/latest/reference-manual/native-image/guides/build-static-executables/ 的要求, 做为 `pom.xml`的 `native profile` 添加 `-H:+StaticExecutableWithDynamicLibC` 的 `jvmArgs` 等操作。 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 edf43894b36728..53ca4c40d4f08e 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 @@ -36,19 +36,15 @@ services: Plus `-DskipNativeTests` or `-DskipTests` parameter specific to `GraalVM Native Build Tools` to skip unit tests in Native Image. -- The following three algorithm classes are not available under GraalVM Native Image because they involve - the `groovy.lang.Closure` class that is inconvenient for GraalVM Truffle Espresso to interact between the host JVM and - the guest JVM. +- The following algorithm classes are not available under GraalVM Native Image due to /~https://github.com/oracle/graal/issues/5522 involved. - `org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm` - `org.apache.shardingsphere.sharding.algorithm.sharding.inline.ComplexInlineShardingAlgorithm` - `org.apache.shardingsphere.sharding.algorithm.sharding.hint.HintInlineShardingAlgorithm` -- At the current stage, ShardingSphere Proxy in GraalVM Native Image is in the stage of mixed AOT ( GraalVM - Native Image ) and JIT ( GraalVM Truffle Espresso ) operation. Since /~https://github.com/oracle/graal/issues/4555 has - not been closed, the `.so` file required for GraalVM Truffle Espresso to run does not enter the GraalVM Native Image. - So if you need to run ShardingSphere Proxy outside of Docker Image For Native binaries, - you need to make sure that the system environment variable `JAVA_HOME` points to GraalVM's - directory and this GraalVM instance already has the `espresso` component installed via `GraalVM Updater`. +- At this stage, ShardingSphere Proxy in the form of GraalVM Native Image does not support the use of `Row Value Expressions` + with Groovy syntax, which first results in the `actualDataNodes` property of the `Sharding` feature being only + configurable using a pure list, such as `ds_0.t_order_0, ds_0.t_order_1` or `ds_0.t_user_0, ds_15.t_user_1023`. This + issue is tracked in /~https://github.com/oracle/graal/issues/5522 . - This section assumes a Linux (amd64, aarch64), MacOS (amd64) or Windows (amd64) environment. If you are on MacOS (aarch64/M1) environment, you need to follow /~https://github.com/oracle/graal/issues/2666 which is @@ -59,20 +55,14 @@ services: 1. Install and configure `GraalVM Community Edition` or `Oracle GraalVM` for JDK 17 according to https://www.graalvm.org/downloads/. Or use `SDKMAN!`. ```shell -sdk install java 17.0.7-graalce +sdk install java 17.0.8-graalce ``` -2. Install the `espresso` component via the `GraalVM Updater` tool. +2. Install the local toolchain as required by https://www.graalvm.org/latest/reference-manual/native-image/#prerequisites. -```shell -gu install espresso -``` - -3. Install the local toolchain as required by https://www.graalvm.org/latest/reference-manual/native-image/#prerequisites. - -4. If you need to build a Docker Image, make sure `docker-ce` is installed. +3. If you need to build a Docker Image, make sure `docker-ce` is installed. -5. First, you need to execute the following command in the root directory of the project to collect the GraalVM +4. First, you need to execute the following command in the root directory of the project to collect the GraalVM Reachability Metadata of the Standard form for all submodules. ```shell @@ -158,8 +148,7 @@ services: - "3307:3307" ``` -- If you don't make any changes to the Git Source, the commands mentioned above will use `ghcr.io/graalvm/graalvm-community:17.0.7-ol9` as the - Base Docker Image. +- 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/latest/reference-manual/native-image/guides/build-static-executables/, add operations such as `-H:+StaticExecutableWithDynamicLibC` to `jvmArgs` as the `native profile` of `pom.xml`. diff --git a/infra/expr/core/pom.xml b/infra/expr/core/pom.xml index fdc41cd673c0db..84f274b57cf14d 100644 --- a/infra/expr/core/pom.xml +++ b/infra/expr/core/pom.xml @@ -39,7 +39,7 @@ org.apache.shardingsphere - shardingsphere-infra-expr-espresso + shardingsphere-infra-expr-purelist ${project.version} diff --git a/infra/expr/core/src/main/java/org/apache/shardingsphere/infra/expr/core/InlineExpressionParserFactory.java b/infra/expr/core/src/main/java/org/apache/shardingsphere/infra/expr/core/InlineExpressionParserFactory.java index 088d4da9eae813..11a03cd4948e4b 100644 --- a/infra/expr/core/src/main/java/org/apache/shardingsphere/infra/expr/core/InlineExpressionParserFactory.java +++ b/infra/expr/core/src/main/java/org/apache/shardingsphere/infra/expr/core/InlineExpressionParserFactory.java @@ -37,6 +37,6 @@ public final class InlineExpressionParserFactory { * @return created instance */ public static InlineExpressionParser newInstance() { - return TypedSPILoader.getService(InlineExpressionParser.class, IS_SUBSTRATE_VM ? "ESPRESSO" : "HOTSPOT"); + return TypedSPILoader.getService(InlineExpressionParser.class, IS_SUBSTRATE_VM ? "PURELIST" : "HOTSPOT"); } } diff --git a/infra/expr/pom.xml b/infra/expr/pom.xml index ee51962feb40d8..14aa380d873ee4 100644 --- a/infra/expr/pom.xml +++ b/infra/expr/pom.xml @@ -32,5 +32,6 @@ core hotsopt espresso + purelist diff --git a/infra/expr/purelist/pom.xml b/infra/expr/purelist/pom.xml new file mode 100644 index 00000000000000..b45ff489b37702 --- /dev/null +++ b/infra/expr/purelist/pom.xml @@ -0,0 +1,41 @@ + + + + + 4.0.0 + + org.apache.shardingsphere + shardingsphere-infra-expr + 5.4.1-SNAPSHOT + + shardingsphere-infra-expr-purelist + ${project.artifactId} + + + + org.apache.shardingsphere + shardingsphere-infra-expr-spi + ${project.version} + + + + org.apache.groovy + groovy + + + diff --git a/infra/expr/purelist/src/main/java/org/apache/shardingsphere/infra/expr/purelist/PureListInlineExpressionParser.java b/infra/expr/purelist/src/main/java/org/apache/shardingsphere/infra/expr/purelist/PureListInlineExpressionParser.java new file mode 100644 index 00000000000000..e6ea43f053d16d --- /dev/null +++ b/infra/expr/purelist/src/main/java/org/apache/shardingsphere/infra/expr/purelist/PureListInlineExpressionParser.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.expr.purelist; + +import com.google.common.base.Strings; +import groovy.lang.Closure; +import org.apache.shardingsphere.infra.expr.spi.InlineExpressionParser; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Pure List inline expression parser. + */ +public final class PureListInlineExpressionParser implements InlineExpressionParser { + + private static final char SPLITTER = ','; + + @Override + public String handlePlaceHolder(final String inlineExpression) { + return inlineExpression.contains("$->{") ? inlineExpression.replaceAll("\\$->\\{", "\\$\\{") : inlineExpression; + } + + @Override + public List splitAndEvaluate(final String inlineExpression) { + return Strings.isNullOrEmpty(inlineExpression) ? Collections.emptyList() : split(inlineExpression); + } + + @Override + public Closure evaluateClosure(final String inlineExpression) { + throw new RuntimeException("Groovy classes cannot be used directly within GraalVM Native Image."); + } + + private List split(final String inlineExpression) { + List result = new ArrayList<>(); + StringBuilder segment = new StringBuilder(); + for (int i = 0; i < inlineExpression.length(); i++) { + char each = inlineExpression.charAt(i); + if (each == SPLITTER) { + result.add(segment.toString().trim()); + segment.setLength(0); + } else { + segment.append(each); + } + } + if (segment.length() > 0) { + result.add(segment.toString().trim()); + } + return result; + } + + @Override + public String getType() { + return "PURELIST"; + } +} diff --git a/infra/expr/purelist/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.expr.spi.InlineExpressionParser b/infra/expr/purelist/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.expr.spi.InlineExpressionParser new file mode 100644 index 00000000000000..9f038f1b9fb551 --- /dev/null +++ b/infra/expr/purelist/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.expr.spi.InlineExpressionParser @@ -0,0 +1,18 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +org.apache.shardingsphere.infra.expr.purelist.PureListInlineExpressionParser diff --git a/infra/expr/purelist/src/test/java/org/apache/shardingsphere/infra/expr/purelist/PureListInlineExpressionParserTest.java b/infra/expr/purelist/src/test/java/org/apache/shardingsphere/infra/expr/purelist/PureListInlineExpressionParserTest.java new file mode 100644 index 00000000000000..bb8ebbf8855ce1 --- /dev/null +++ b/infra/expr/purelist/src/test/java/org/apache/shardingsphere/infra/expr/purelist/PureListInlineExpressionParserTest.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.expr.purelist; + +import org.junit.jupiter.api.Test; + +import java.util.Collections; +import java.util.List; + +import static org.hamcrest.CoreMatchers.hasItems; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class PureListInlineExpressionParserTest { + + @Test + void assertEvaluateForExpressionIsNull() { + List expected = new PureListInlineExpressionParser().splitAndEvaluate(null); + assertThat(expected, is(Collections.emptyList())); + } + + @Test + void assertEvaluateForSimpleString() { + List expected = new PureListInlineExpressionParser().splitAndEvaluate(" t_order_0, t_order_1 "); + assertThat(expected.size(), is(2)); + assertThat(expected, hasItems("t_order_0", "t_order_1")); + } + + @Test + void assertEvaluateForLong() { + StringBuilder expression = new StringBuilder(); + for (int i = 0; i < 1024; i++) { + expression.append("ds_"); + expression.append(i / 64); + expression.append(".t_user_"); + expression.append(i); + if (i != 1023) { + expression.append(","); + } + } + List expected = new PureListInlineExpressionParser().splitAndEvaluate(expression.toString()); + assertThat(expected.size(), is(1024)); + assertThat(expected, hasItems("ds_0.t_user_0", "ds_15.t_user_1023")); + } +}