From 9258e1f974b2f83e5632c1edc81927f43a5b799d Mon Sep 17 00:00:00 2001 From: linghengqian Date: Mon, 29 Jul 2024 16:20:17 +0800 Subject: [PATCH] Provides built-in GraalVM Reachability Metadata and nativeTest on Elasticjob Spring Boot Starter under Spring Boot 3.3.2 --- .github/workflows/graalvm.yml | 2 +- .github/workflows/maven.yml | 37 +++++- .../configuration/graalvm-native-image.cn.md | 107 ++++++++++++++++- .../configuration/graalvm-native-image.en.md | 107 ++++++++++++++++- pom.xml | 21 +++- .../proxy-config.json | 2 +- .../reflect-config.json | 75 ++++++------ .../resource-config.json | 14 ++- .../native-image-filter/extra-filter.json | 9 +- test/native/pom.xml | 28 ++++- .../test/natived/SpirngBootTest.java | 110 ++++++++++++++++++ .../natived/TestSpringBootApplication.java | 31 +++++ .../controller/OneOffJobController.java | 52 +++++++++ .../job/dataflow/SpringBootDataflowJob.java | 62 ++++++++++ .../job/simple/SpringBootSimpleJob.java | 51 ++++++++ .../repository/SpringBootFooRepository.java | 74 ++++++++++++ .../native/src/test/resources/application.yml | 53 +++++++++ 17 files changed, 766 insertions(+), 69 deletions(-) create mode 100644 test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/SpirngBootTest.java create mode 100644 test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/TestSpringBootApplication.java create mode 100644 test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/commons/controller/OneOffJobController.java create mode 100644 test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/commons/job/dataflow/SpringBootDataflowJob.java create mode 100644 test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/commons/job/simple/SpringBootSimpleJob.java create mode 100644 test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/commons/repository/SpringBootFooRepository.java create mode 100644 test/native/src/test/resources/application.yml diff --git a/.github/workflows/graalvm.yml b/.github/workflows/graalvm.yml index 1216b9307..b396737ff 100644 --- a/.github/workflows/graalvm.yml +++ b/.github/workflows/graalvm.yml @@ -45,4 +45,4 @@ jobs: native-image-job-reports: 'true' - name: Run nativeTest with GraalVM CE for ${{ matrix.java-version }} continue-on-error: true - run: ./mvnw -PnativeTestInElasticJob -T1C -B -e clean test + run: ./mvnw -PnativeTestInElasticJob -T1C -B -e -Dspring-boot-dependencies.version=3.3.2 clean test diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 8bc9771b2..23da1f5b9 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -26,23 +26,22 @@ on: jobs: build: + if: github.repository == 'apache/shardingsphere-elasticjob' strategy: matrix: - java: [ 8, 17, 21, 22 ] + java: [ 17, 21, 22 ] os: [ 'windows-latest', 'macos-latest', 'ubuntu-latest' ] - runs-on: ${{ matrix.os }} - steps: - name: Configure Git if: matrix.os == 'windows-latest' run: | git config --global core.longpaths true - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up JDK ${{ matrix.java }} - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: - distribution: 'zulu' + distribution: 'temurin' java-version: ${{ matrix.java }} cache: 'maven' - name: Build with Maven in Windows @@ -60,3 +59,29 @@ jobs: file: '**/target/site/jacoco/jacoco.xml' - name: Build Examples with Maven run: ./mvnw clean package -B -f examples/pom.xml -T1C + ci-jdk8: + if: github.repository == 'apache/shardingsphere-elasticjob' + name: CI - JDK 8 on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest, macos-latest, windows-latest ] + steps: + - name: Support Long Paths in Windows + if: matrix.os == 'windows-latest' + run: git config --global core.longpaths true + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: 17 + cache: 'maven' + - name: Build prod with Maven + run: ./mvnw clean install -DskipTests -B -e -T1C + - name: Setup JDK 8 for Test + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 8 + - name: Run Tests with JDK 8 + run: ./mvnw test -B -e -T1C diff --git a/docs/content/user-manual/configuration/graalvm-native-image.cn.md b/docs/content/user-manual/configuration/graalvm-native-image.cn.md index e0e65f97a..79ca6f43b 100644 --- a/docs/content/user-manual/configuration/graalvm-native-image.cn.md +++ b/docs/content/user-manual/configuration/graalvm-native-image.cn.md @@ -91,6 +91,107 @@ graalvmNative { } ``` +## 使用 ElasticJob 的 Spring Boot Starter + +### Maven 生态 + +使用者需要主动使用 GraalVM Reachability Metadata 中央仓库。 +如下配置可供参考,以配置项目额外的 Maven Profiles,以 GraalVM Native Build Tools 的文档为准。 + +```xml + + + + org.apache.shardingsphere.elasticjob + elasticjob-spring-boot-starter + ${elasticjob.version} + test + + + org.springframework.boot + spring-boot-starter-jdbc + 3.3.2 + test + + + org.springframework.boot + spring-boot-starter-web + 3.3.2 + test + + + + + + + org.graalvm.buildtools + native-maven-plugin + 0.10.2 + true + + + build-native + + compile-no-fork + + package + + + test-native + + test + + test + + + + + org.springframework.boot + spring-boot-maven-plugin + 3.3.2 + + + process-test-aot + + process-test-aot + + + + + + + +``` + +### Gradle 生态 + +使用者需要主动使用 GraalVM Reachability Metadata 中央仓库。 +如下配置可供参考,以配置项目额外的 Gradle Tasks,以 GraalVM Native Build Tools 的文档为准。 +由于 https://github.com/gradle/gradle/issues/17559 的限制,用户需要通过 Maven 依赖的形式引入 Metadata Repository 的 JSON 文件。 +参考 https://github.com/graalvm/native-build-tools/issues/572 。 + +```groovy +plugins { + id 'org.springframework.boot' version '3.3.2' + id 'io.spring.dependency-management' version '1.1.6' + id 'org.graalvm.buildtools.native' version '0.10.2' +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-jdbc' + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.apache.shardingsphere.elasticjob:elasticjob-spring-boot-starter:${elasticjob.version}' + implementation(group: 'org.graalvm.buildtools', name: 'graalvm-reachability-metadata', version: '0.10.2', classifier: 'repository', ext: 'zip') +} + +graalvmNative { + metadataRepository { + enabled.set(false) + } +} +``` + + ## 对于 sbt 等不被 GraalVM Native Build Tools 支持的构建工具 此类需求需要在 https://github.com/graalvm/native-build-tools 打开额外的 issue 并提供对应构建工具的 Plugin 实现。 @@ -128,8 +229,6 @@ public class ExampleUtils { 4. ElasticJob 的 Spring 命名空间集成模块 `org.apache.shardingsphere.elasticjob:elasticjob-spring-namespace` 尚未在 GraalVM Native Image 下可用。 -5. ElasticJob 的 Spring Boot Starter 集成模块 `org.apache.shardingsphere.elasticjob:elasticjob-spring-boot-starter` 尚未在 GraalVM Native Image 下可用。 - ## 贡献 GraalVM Reachability Metadata ElasticJob 对在 GraalVM Native Image 下的可用性的验证,是通过 GraalVM Native Build Tools 的 Maven Plugin 子项目来完成的。 @@ -157,7 +256,7 @@ sudo apt-get install build-essential zlib1g-dev -y git clone git@github.com:apache/shardingsphere-elasticjob.git cd ./shardingsphere-elasticjob/ -./mvnw -PnativeTestInElasticJob -T1C -e clean test +./mvnw -PnativeTestInElasticJob -T1C -e -Dspring-boot-dependencies.version=3.3.2 clean test ``` 当贡献者发现缺少与 ElasticJob 无关的第三方库的 GraalVM Reachability Metadata 时,应当在 @@ -186,5 +285,5 @@ ElasticJob 定义了 `generateMetadata` 的 Maven Profile 用于在 GraalVM JIT ```bash git clone git@github.com:apache/shardingsphere.git cd ./shardingsphere/ -./mvnw -PgenerateMetadata -DskipNativeTests -e -T1C clean test native:metadata-copy +./mvnw -PgenerateMetadata -DskipNativeTests -e -T1C -Dspring-boot-dependencies.version=3.3.2 clean test native:metadata-copy ``` diff --git a/docs/content/user-manual/configuration/graalvm-native-image.en.md b/docs/content/user-manual/configuration/graalvm-native-image.en.md index 513a58a85..fb86d608e 100644 --- a/docs/content/user-manual/configuration/graalvm-native-image.en.md +++ b/docs/content/user-manual/configuration/graalvm-native-image.en.md @@ -93,6 +93,107 @@ graalvmNative { } ``` +## Using ElasticJob's Spring Boot Starter + +### Maven Ecosystem + +Users need to actively use the GraalVM Reachability Metadata Central Repository. +The following configuration is for reference. +To configure additional Maven Profiles for the project, refer to the documentation of GraalVM Native Build Tools. + +```xml + + + + org.apache.shardingsphere.elasticjob + elasticjob-spring-boot-starter + ${elasticjob.version} + test + + + org.springframework.boot + spring-boot-starter-jdbc + 3.3.2 + test + + + org.springframework.boot + spring-boot-starter-web + 3.3.2 + test + + + + + + + org.graalvm.buildtools + native-maven-plugin + 0.10.2 + true + + + build-native + + compile-no-fork + + package + + + test-native + + test + + test + + + + + org.springframework.boot + spring-boot-maven-plugin + 3.3.2 + + + process-test-aot + + process-test-aot + + + + + + + +``` + +### Gradle Ecosystem + +Users need to actively use the GraalVM Reachability Metadata Central Repository. +The following configuration is for reference. To configure additional Gradle Tasks for the project, refer to the documentation of GraalVM Native Build Tools. +Due to the limitations of https://github.com/gradle/gradle/issues/17559, users need to introduce the Metadata Repository JSON file in the form of Maven dependencies. +Refer to https://github.com/graalvm/native-build-tools/issues/572 . + +```groovy +plugins { + id 'org.springframework.boot' version '3.3.2' + id 'io.spring.dependency-management' version '1.1.6' + id 'org.graalvm.buildtools.native' version '0.10.2' +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-jdbc' + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.apache.shardingsphere.elasticjob:elasticjob-spring-boot-starter:${elasticjob.version}' + implementation(group: 'org.graalvm.buildtools', name: 'graalvm-reachability-metadata', version: '0.10.2', classifier: 'repository', ext: 'zip') +} + +graalvmNative { + metadataRepository { + enabled.set(false) + } +} +``` + ## For build tools such as sbt that are not supported by GraalVM Native Build Tools Such requirements require opening additional issues at https://github.com/graalvm/native-build-tools and providing plugin implementations for the corresponding build tools. @@ -130,8 +231,6 @@ public class ExampleUtils { 4. The Spring namespace integration module `org.apache.shardingsphere.elasticjob:elasticjob-spring-namespace` of ElasticJob is not yet available under GraalVM Native Image. -5. The Spring Boot Starter integration module `org.apache.shardingsphere.elasticjob:elasticjob-spring-boot-starter` for ElasticJob is not yet available under GraalVM Native Image. - ## Contribute GraalVM Reachability Metadata ElasticJob's usability verification under GraalVM Native Image is done by the Maven Plugin subproject of GraalVM Native Build Tools. @@ -160,7 +259,7 @@ sudo apt-get install build-essential zlib1g-dev -y git clone git@github.com:apache/shardingsphere-elasticjob.git cd ./shardingsphere-elasticjob/ -./mvnw -PnativeTestInElasticJob -T1C -e clean test +./mvnw -PnativeTestInElasticJob -T1C -e -Dspring-boot-dependencies.version=3.3.2 clean test ``` When contributors find that GraalVM Reachability Metadata for third-party libraries not related to ElasticJob is missing, @@ -190,5 +289,5 @@ contributors should place it in the classpath of the shardingsphere-test-native ```bash git clone git@github.com:apache/shardingsphere.git cd ./shardingsphere/ -./mvnw -PgenerateMetadata -DskipNativeTests -e -T1C clean test native:metadata-copy +./mvnw -PgenerateMetadata -DskipNativeTests -e -T1C -Dspring-boot-dependencies.version=3.3.2 clean test native:metadata-copy ``` diff --git a/pom.xml b/pom.xml index 15a3aa9ca..32a9c029c 100644 --- a/pom.xml +++ b/pom.xml @@ -93,6 +93,9 @@ 2.2.224 4.0.3 + + 2.7.18 + 3.2.1 3.11.0 @@ -755,13 +758,16 @@ [11,) + + 8 + maven-surefire-plugin - @{argLine} --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED + @{argLine} --add-opens java.base/java.lang.reflect=ALL-UNNAMED @@ -1015,6 +1021,19 @@ + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot-dependencies.version} + + + process-test-aot + + process-test-aot + + + + diff --git a/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere.elasticjob/generated-reachability-metadata/proxy-config.json b/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere.elasticjob/generated-reachability-metadata/proxy-config.json index fd2d4325f..25cf82054 100644 --- a/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere.elasticjob/generated-reachability-metadata/proxy-config.json +++ b/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere.elasticjob/generated-reachability-metadata/proxy-config.json @@ -1,6 +1,6 @@ [ { - "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.tracing.rdb.storage.converter.RDBTracingStorageConfigurationConverter"}, + "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.spring.boot.tracing.ElasticJobTracingConfiguration$RDBTracingConfiguration"}, "interfaces":["java.sql.Connection"] } ] \ No newline at end of file diff --git a/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere.elasticjob/generated-reachability-metadata/reflect-config.json b/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere.elasticjob/generated-reachability-metadata/reflect-config.json index b934e8520..5dfc6c97c 100644 --- a/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere.elasticjob/generated-reachability-metadata/reflect-config.json +++ b/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere.elasticjob/generated-reachability-metadata/reflect-config.json @@ -4,9 +4,8 @@ "name":"[Lcom.zaxxer.hikari.util.ConcurrentBag$IConcurrentBagEntry;" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.bootstrap.type.ScheduleJobBootstrap"}, - "name":"java.util.Properties", - "methods":[{"name":"","parameterTypes":[] }] + "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.spring.boot.tracing.ElasticJobTracingConfiguration$RDBTracingConfiguration"}, + "name":"[Ljava.sql.Statement;" }, { "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.executor.ElasticJobExecutor"}, @@ -23,6 +22,11 @@ "name":"java.util.Properties", "methods":[{"name":"","parameterTypes":[] }] }, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.internal.sharding.ShardingListenerManager$ListenServersChangedJobListener"}, + "name":"java.util.Properties", + "methods":[{"name":"","parameterTypes":[] }] +}, { "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.internal.sharding.ShardingListenerManager$ShardingTotalCountChangedJobListener"}, "name":"java.util.Properties", @@ -48,7 +52,7 @@ "methods":[{"name":"","parameterTypes":[] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.executor.ElasticJobExecutor"}, + "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.spring.boot.job.ElasticJobBootstrapConfiguration"}, "name":"org.apache.shardingsphere.elasticjob.http.executor.HttpJobExecutor" }, { @@ -59,21 +63,15 @@ "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.executor.threadpool.ExecutorServiceReloader"}, "name":"org.apache.shardingsphere.elasticjob.kernel.executor.threadpool.type.SingleThreadJobExecutorThreadPoolSizeProvider" }, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.bootstrap.type.OneOffJobBootstrap"}, - "name":"org.apache.shardingsphere.elasticjob.kernel.internal.config.JobConfigurationPOJO", - "queryAllPublicMethods":true -}, { "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.bootstrap.type.ScheduleJobBootstrap"}, "name":"org.apache.shardingsphere.elasticjob.kernel.internal.config.JobConfigurationPOJO", - "queryAllPublicMethods":true, - "methods":[{"name":"setCron","parameterTypes":["java.lang.String"] }, {"name":"setProps","parameterTypes":["java.util.Properties"] }] + "methods":[{"name":"setCron","parameterTypes":["java.lang.String"] }] }, { "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.executor.ElasticJobExecutor"}, "name":"org.apache.shardingsphere.elasticjob.kernel.internal.config.JobConfigurationPOJO", - "methods":[{"name":"setCron","parameterTypes":["java.lang.String"] }, {"name":"setProps","parameterTypes":["java.util.Properties"] }] + "methods":[{"name":"setProps","parameterTypes":["java.util.Properties"] }] }, { "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.infra.yaml.YamlEngine"}, @@ -98,15 +96,20 @@ "methods":[{"name":"setCron","parameterTypes":["java.lang.String"] }, {"name":"setProps","parameterTypes":["java.util.Properties"] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobScheduler"}, + "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.internal.sharding.ShardingListenerManager$ListenServersChangedJobListener"}, "name":"org.apache.shardingsphere.elasticjob.kernel.internal.config.JobConfigurationPOJO", - "queryAllPublicMethods":true + "methods":[{"name":"setCron","parameterTypes":["java.lang.String"] }, {"name":"setProps","parameterTypes":["java.util.Properties"] }] }, { "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.internal.sharding.ShardingListenerManager$ShardingTotalCountChangedJobListener"}, "name":"org.apache.shardingsphere.elasticjob.kernel.internal.config.JobConfigurationPOJO", "methods":[{"name":"setCron","parameterTypes":["java.lang.String"] }, {"name":"setProps","parameterTypes":["java.util.Properties"] }] }, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.spring.boot.job.ElasticJobBootstrapConfiguration"}, + "name":"org.apache.shardingsphere.elasticjob.kernel.internal.config.JobConfigurationPOJO", + "queryAllPublicMethods":true +}, { "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.bootstrap.type.ScheduleJobBootstrap"}, "name":"org.apache.shardingsphere.elasticjob.kernel.internal.config.JobConfigurationPOJOBeanInfo" @@ -115,22 +118,20 @@ "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.bootstrap.type.ScheduleJobBootstrap"}, "name":"org.apache.shardingsphere.elasticjob.kernel.internal.config.JobConfigurationPOJOCustomizer" }, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.bootstrap.type.OneOffJobBootstrap"}, - "name":"org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobShutdownHookPlugin", - "queryAllPublicMethods":true -}, { "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.bootstrap.type.ScheduleJobBootstrap"}, - "name":"org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobShutdownHookPlugin", - "queryAllPublicMethods":true + "name":"org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobShutdownHookPlugin" }, { "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobScheduler"}, "name":"org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobShutdownHookPlugin", - "queryAllPublicMethods":true, "methods":[{"name":"","parameterTypes":[] }, {"name":"setCleanShutdown","parameterTypes":["boolean"] }] }, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.spring.boot.job.ElasticJobBootstrapConfiguration"}, + "name":"org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobShutdownHookPlugin", + "queryAllPublicMethods":true +}, { "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.bootstrap.type.ScheduleJobBootstrap"}, "name":"org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobShutdownHookPluginBeanInfo" @@ -139,15 +140,9 @@ "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.bootstrap.type.ScheduleJobBootstrap"}, "name":"org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobShutdownHookPluginCustomizer" }, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.bootstrap.type.OneOffJobBootstrap"}, - "name":"org.apache.shardingsphere.elasticjob.kernel.internal.sharding.JobInstance", - "queryAllPublicMethods":true -}, { "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.bootstrap.type.ScheduleJobBootstrap"}, - "name":"org.apache.shardingsphere.elasticjob.kernel.internal.sharding.JobInstance", - "queryAllPublicMethods":true + "name":"org.apache.shardingsphere.elasticjob.kernel.internal.sharding.JobInstance" }, { "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.internal.instance.InstanceNode"}, @@ -156,18 +151,10 @@ "methods":[{"name":"getJobInstanceId","parameterTypes":[] }, {"name":"getLabels","parameterTypes":[] }, {"name":"getServerIp","parameterTypes":[] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.internal.instance.InstanceService"}, - "name":"org.apache.shardingsphere.elasticjob.kernel.internal.sharding.JobInstance" -}, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobScheduler"}, + "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.spring.boot.job.ElasticJobBootstrapConfiguration"}, "name":"org.apache.shardingsphere.elasticjob.kernel.internal.sharding.JobInstance", "queryAllPublicMethods":true }, -{ - "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.internal.setup.SetUpFacade"}, - "name":"org.apache.shardingsphere.elasticjob.kernel.internal.sharding.JobInstance" -}, { "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.bootstrap.type.ScheduleJobBootstrap"}, "name":"org.apache.shardingsphere.elasticjob.kernel.internal.sharding.JobInstanceBeanInfo" @@ -191,7 +178,7 @@ "name":"org.apache.shardingsphere.elasticjob.reg.zookeeper.exception.ZookeeperCuratorIgnoredExceptionProvider" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.executor.ElasticJobExecutor"}, + "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.spring.boot.job.ElasticJobBootstrapConfiguration"}, "name":"org.apache.shardingsphere.elasticjob.script.executor.ScriptJobExecutor" }, { @@ -199,17 +186,21 @@ "name":"org.apache.shardingsphere.elasticjob.simple.executor.SimpleJobExecutor" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.tracing.event.JobTracingEventBus"}, + "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.spring.boot.job.ElasticJobBootstrapConfiguration"}, "name":"org.apache.shardingsphere.elasticjob.spi.tracing.listener.TracingListener", "queryAllDeclaredMethods":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.tracing.event.JobTracingEventBus"}, + "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.internal.setup.JobClassNameProviderFactory"}, + "name":"org.apache.shardingsphere.elasticjob.spring.core.setup.SpringProxyJobClassNameProvider" +}, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.spring.boot.job.ElasticJobBootstrapConfiguration"}, "name":"org.apache.shardingsphere.elasticjob.tracing.rdb.listener.RDBTracingListener", "queryAllDeclaredMethods":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.tracing.event.JobTracingEventBus"}, + "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.spring.boot.job.ElasticJobBootstrapConfiguration"}, "name":"org.apache.shardingsphere.elasticjob.tracing.rdb.listener.RDBTracingListenerFactory" }, { diff --git a/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere.elasticjob/generated-reachability-metadata/resource-config.json b/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere.elasticjob/generated-reachability-metadata/resource-config.json index 101e57e2f..07292ac06 100644 --- a/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere.elasticjob/generated-reachability-metadata/resource-config.json +++ b/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere.elasticjob/generated-reachability-metadata/resource-config.json @@ -1,6 +1,9 @@ { "resources":{ "includes":[{ + "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.spring.boot.tracing.ElasticJobTracingConfiguration$RDBTracingConfiguration"}, + "pattern":"\\QMETA-INF/services/java.sql.Driver\\E" + }, { "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.executor.threadpool.ExecutorServiceReloader"}, "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.elasticjob.kernel.executor.threadpool.JobExecutorThreadPoolSizeProvider\\E" }, { @@ -10,16 +13,16 @@ "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.reg.exception.RegExceptionHandler"}, "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.elasticjob.reg.exception.IgnoredExceptionProvider\\E" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.bootstrap.type.ScheduleJobBootstrap"}, + "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.spring.boot.job.ElasticJobBootstrapConfiguration"}, "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.elasticjob.spi.executor.error.handler.JobErrorHandler\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.executor.item.JobItemExecutorFactory"}, "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.elasticjob.spi.executor.item.type.ClassedJobItemExecutor\\E" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.executor.ElasticJobExecutor"}, + "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.spring.boot.job.ElasticJobBootstrapConfiguration"}, "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.elasticjob.spi.executor.item.type.TypedJobItemExecutor\\E" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.tracing.event.JobTracingEventBus"}, + "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.spring.boot.job.ElasticJobBootstrapConfiguration"}, "pattern":"\\QMETA-INF/services/org.apache.shardingsphere.elasticjob.spi.tracing.listener.TracingListenerFactory\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.kernel.tracing.storage.TracingStorageConverterFactory"}, @@ -34,7 +37,10 @@ "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.tracing.rdb.storage.sql.SQLPropertiesFactory"}, "pattern":"\\QMETA-INF/sql/H2.properties\\E" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.bootstrap.type.ScheduleJobBootstrap"}, + "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.spring.boot.tracing.ElasticJobTracingConfiguration$RDBTracingConfiguration"}, + "pattern":"\\Qorg/h2/util/data.zip\\E" + }, { + "condition":{"typeReachable":"org.apache.shardingsphere.elasticjob.spring.boot.job.ElasticJobBootstrapConfiguration"}, "pattern":"\\Qorg/quartz/core/quartz-build.properties\\E" }]}, "bundles":[] diff --git a/test/native/native-image-filter/extra-filter.json b/test/native/native-image-filter/extra-filter.json index 9e706a39d..fdf91f4da 100644 --- a/test/native/native-image-filter/extra-filter.json +++ b/test/native/native-image-filter/extra-filter.json @@ -2,13 +2,12 @@ "rules": [ {"includeClasses": "**"}, - {"excludeClasses": "com.google.common.util.concurrent.**"}, - {"excludeClasses": "com.zaxxer.hikari.**"}, + {"excludeClasses": "com.**"}, {"excludeClasses": "java.**"}, {"includeClasses": "java.util.Properties"}, - {"excludeClasses": "org.apache.zookeeper.**"}, - {"excludeClasses": "org.quartz.**"}, - {"excludeClasses": "sun.misc.**"}, + {"excludeClasses": "org.**"}, + {"includeClasses": "org.apache.shardingsphere.elasticjob.**"}, + {"excludeClasses": "sun.**"}, {"excludeClasses": "org.apache.shardingsphere.elasticjob.test.natived.**"} ], diff --git a/test/native/pom.xml b/test/native/pom.xml index 459222a52..00cca3bdd 100644 --- a/test/native/pom.xml +++ b/test/native/pom.xml @@ -28,12 +28,15 @@ true + + 2.0.13 + 1.5.6 org.apache.shardingsphere.elasticjob - elasticjob-bootstrap + elasticjob-spring-boot-starter ${project.version} test @@ -53,6 +56,24 @@ curator-test test + + org.springframework.boot + spring-boot-starter-jdbc + ${spring-boot-dependencies.version} + test + + + org.springframework.boot + spring-boot-starter-web + ${spring-boot-dependencies.version} + test + + + org.springframework.boot + spring-boot-starter-test + ${spring-boot-dependencies.version} + test + @@ -62,6 +83,11 @@ native-maven-plugin ${native-maven-plugin.version} + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot-dependencies.version} + diff --git a/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/SpirngBootTest.java b/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/SpirngBootTest.java new file mode 100644 index 000000000..7aab71961 --- /dev/null +++ b/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/SpirngBootTest.java @@ -0,0 +1,110 @@ +/* + * 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.elasticjob.test.natived; + +import org.apache.curator.CuratorZookeeperClient; +import org.apache.curator.retry.ExponentialBackoffRetry; +import org.apache.curator.test.InstanceSpec; +import org.apache.curator.test.TestingServer; +import org.awaitility.Awaitility; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledInNativeImage; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.time.Duration; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +@SpringBootTest( + classes = TestSpringBootApplication.class, + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@TestPropertySource(locations = "classpath:application.yml") +@EnabledInNativeImage +public class SpirngBootTest { + + private static TestingServer testingServer; + + private MockMvc mockMvc; + + @BeforeAll + static void beforeAll() throws Exception { + testingServer = new TestingServer(6181); + try ( + CuratorZookeeperClient client = new CuratorZookeeperClient(testingServer.getConnectString(), + 60 * 1000, 500, null, + new ExponentialBackoffRetry(500, 3, 500 * 3))) { + client.start(); + Awaitility.await().atMost(Duration.ofMillis(500 * 60)).until(client::isConnected); + } + } + + @AfterAll + static void afterAll() throws IOException { + testingServer.close(); + } + + @BeforeEach + void setup(final WebApplicationContext webApplicationContext) { + this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext) + .defaultResponseCharacterEncoding(StandardCharsets.UTF_8) + .build(); + } + + @DynamicPropertySource + static void elasticjobProperties(final DynamicPropertyRegistry registry) { + registry.add("elasticjob.regCenter.serverLists", () -> testingServer.getConnectString()); + registry.add("elasticjob.dump.port", InstanceSpec::getRandomPort); + } + + /** + * ElasticJob Spring Boot Starter requires that all Spring Boot Applications be shut down before shutting down Zookeeper Server. + * That's why this unit test uses {@link DirtiesContext}. + * Refer to spring-projects/spring-framework#26196 . + */ + @DirtiesContext + @Test + public void testOneOffJob() throws Exception { + String contentAsString = mockMvc.perform( + MockMvcRequestBuilders.get("/execute/manualScriptJob") + .characterEncoding(StandardCharsets.UTF_8)) + .andDo(MockMvcResultHandlers.print()) + .andExpectAll( + MockMvcResultMatchers.status().isOk(), + MockMvcResultMatchers.content().encoding(StandardCharsets.UTF_8)) + .andReturn() + .getResponse() + .getContentAsString(); + assertThat(contentAsString, is("{\"msg\":\"OK\"}")); + } +} diff --git a/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/TestSpringBootApplication.java b/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/TestSpringBootApplication.java new file mode 100644 index 000000000..436e4e7c8 --- /dev/null +++ b/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/TestSpringBootApplication.java @@ -0,0 +1,31 @@ +/* + * 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.elasticjob.test.natived; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class TestSpringBootApplication { + + // CHECKSTYLE:OFF + public static void main(final String[] args) { + // CHECKSTYLE:ON + SpringApplication.run(TestSpringBootApplication.class, args); + } +} diff --git a/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/commons/controller/OneOffJobController.java b/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/commons/controller/OneOffJobController.java new file mode 100644 index 000000000..64a6be94e --- /dev/null +++ b/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/commons/controller/OneOffJobController.java @@ -0,0 +1,52 @@ +/* + * 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.elasticjob.test.natived.commons.controller; + +import org.apache.shardingsphere.elasticjob.bootstrap.type.OneOffJobBootstrap; +import org.springframework.beans.factory.ObjectProvider; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Objects; + +@RestController +public class OneOffJobController { + + private static final String RES_TEXT = "{\"msg\":\"OK\"}"; + + @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") + @Autowired + @Qualifier("manualScriptJobBean") + private ObjectProvider manualScriptJobProvider; + + /** + * Execute manual script job. + * + * @return a String + */ + @GetMapping("/execute/manualScriptJob") + public String executeManualScriptJob() { + OneOffJobBootstrap manualScriptJob = manualScriptJobProvider.getIfAvailable(); + Objects.requireNonNull(manualScriptJob); + manualScriptJob.execute(); + manualScriptJob.shutdown(); + return RES_TEXT; + } +} diff --git a/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/commons/job/dataflow/SpringBootDataflowJob.java b/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/commons/job/dataflow/SpringBootDataflowJob.java new file mode 100644 index 000000000..992ca14dc --- /dev/null +++ b/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/commons/job/dataflow/SpringBootDataflowJob.java @@ -0,0 +1,62 @@ +/* + * 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.elasticjob.test.natived.commons.job.dataflow; + +import org.apache.shardingsphere.elasticjob.dataflow.job.DataflowJob; +import org.apache.shardingsphere.elasticjob.spi.executor.item.param.ShardingContext; +import org.apache.shardingsphere.elasticjob.test.natived.commons.entity.Foo; +import org.apache.shardingsphere.elasticjob.test.natived.commons.repository.SpringBootFooRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.lang.invoke.MethodHandles; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; + +@SuppressWarnings("LoggingSimilarMessage") +@Component +public class SpringBootDataflowJob implements DataflowJob { + + private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + @Autowired + private SpringBootFooRepository springBootFooRepository; + + @Override + public List fetchData(final ShardingContext shardingContext) { + logger.info("Item: {} | Time: {} | Thread: {} | {}", + shardingContext.getShardingItem(), + new SimpleDateFormat("HH:mm:ss").format(new Date()), + Thread.currentThread().getId(), + "DATAFLOW FETCH"); + return springBootFooRepository.findTodoData(shardingContext.getShardingParameter(), 10); + } + + @Override + public void processData(final ShardingContext shardingContext, final List data) { + logger.info("Item: {} | Time: {} | Thread: {} | {}", + shardingContext.getShardingItem(), + new SimpleDateFormat("HH:mm:ss").format(new Date()), + Thread.currentThread().getId(), + "DATAFLOW PROCESS"); + data.forEach(each -> springBootFooRepository.setCompleted(each.getId())); + } +} diff --git a/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/commons/job/simple/SpringBootSimpleJob.java b/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/commons/job/simple/SpringBootSimpleJob.java new file mode 100644 index 000000000..1185636d2 --- /dev/null +++ b/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/commons/job/simple/SpringBootSimpleJob.java @@ -0,0 +1,51 @@ +/* + * 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.elasticjob.test.natived.commons.job.simple; + +import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob; +import org.apache.shardingsphere.elasticjob.spi.executor.item.param.ShardingContext; +import org.apache.shardingsphere.elasticjob.test.natived.commons.repository.SpringBootFooRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.lang.invoke.MethodHandles; +import java.text.SimpleDateFormat; +import java.util.Date; + +@Component +public class SpringBootSimpleJob implements SimpleJob { + + private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + @Autowired + private SpringBootFooRepository springBootFooRepository; + + @Override + public void execute(final ShardingContext shardingContext) { + logger.info( + "Item: {} | Time: {} | Thread: {} | {}", + shardingContext.getShardingItem(), + new SimpleDateFormat("HH:mm:ss").format(new Date()), + Thread.currentThread().getId(), + "SIMPLE"); + springBootFooRepository.findTodoData(shardingContext.getShardingParameter(), 10) + .forEach(each -> springBootFooRepository.setCompleted(each.getId())); + } +} diff --git a/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/commons/repository/SpringBootFooRepository.java b/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/commons/repository/SpringBootFooRepository.java new file mode 100644 index 000000000..cafe2bb02 --- /dev/null +++ b/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/commons/repository/SpringBootFooRepository.java @@ -0,0 +1,74 @@ +/* + * 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.elasticjob.test.natived.commons.repository; + +import org.apache.shardingsphere.elasticjob.test.natived.commons.entity.Foo; +import org.springframework.stereotype.Repository; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.LongStream; + +@Repository +public class SpringBootFooRepository { + + private final Map data = new ConcurrentHashMap<>(300, 1); + + public SpringBootFooRepository() { + addData(0L, 100L, "Beijing"); + addData(100L, 200L, "Shanghai"); + addData(200L, 300L, "Guangzhou"); + } + + private void addData(final long idFrom, final long idTo, final String location) { + LongStream.range(idFrom, idTo) + .forEachOrdered(i -> data.put(i, new Foo(i, location, Foo.Status.TODO))); + } + + /** + * Find todoData. + * @param location location + * @param limit limit + * @return An ordered collection, where the user has precise control over where in the list each element is inserted. + */ + public List findTodoData(final String location, final int limit) { + List result = new ArrayList<>(limit); + int count = 0; + for (Map.Entry each : data.entrySet()) { + Foo foo = each.getValue(); + if (foo.getLocation().equals(location) && foo.getStatus() == Foo.Status.TODO) { + result.add(foo); + count++; + if (count == limit) { + break; + } + } + } + return result; + } + + /** + * Set completed. + * @param id id + */ + public void setCompleted(final long id) { + data.get(id).setStatus(Foo.Status.COMPLETED); + } +} diff --git a/test/native/src/test/resources/application.yml b/test/native/src/test/resources/application.yml new file mode 100644 index 000000000..1bc9b28fe --- /dev/null +++ b/test/native/src/test/resources/application.yml @@ -0,0 +1,53 @@ +# +# 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. +# + +spring: + datasource: + url: jdbc:h2:mem:job_event_storage + driver-class-name: org.h2.Driver + username: sa + password: +# `elasticjob.regCenter.serverLists` is dynamically defined in `org.apache.shardingsphere.elasticjob.test.natived.SpirngBootTest` +# `elasticjob.dump.port` is dynamically defined in `org.apache.shardingsphere.elasticjob.test.natived.SpirngBootTest` +elasticjob: + tracing: + type: RDB + regCenter: + namespace: elasticjob-springboot + jobs: + simpleJob: + elasticJobClass: org.apache.shardingsphere.elasticjob.test.natived.commons.job.simple.SpringBootSimpleJob + cron: 0/5 * * * * ? + shardingTotalCount: 3 + shardingItemParameters: 0=Beijing,1=Shanghai,2=Guangzhou + dataflowJob: + elasticJobClass: org.apache.shardingsphere.elasticjob.test.natived.commons.job.dataflow.SpringBootDataflowJob + cron: 0/5 * * * * ? + shardingTotalCount: 3 + shardingItemParameters: 0=Beijing,1=Shanghai,2=Guangzhou + scriptJob: + elasticJobType: SCRIPT + cron: 0/10 * * * * ? + shardingTotalCount: 3 + props: + script.command.line: "echo SCRIPT Job: " + manualScriptJob: + elasticJobType: SCRIPT + jobBootstrapBeanName: manualScriptJobBean + shardingTotalCount: 9 + props: + script.command.line: "echo Manual SCRIPT Job: "