From 341481f4ae59d4e739d75aef8674d5dff81781bf Mon Sep 17 00:00:00 2001 From: linghengqian Date: Sun, 29 Sep 2024 18:29:40 +0800 Subject: [PATCH] Support building and using ElasticJob with JDK23 --- .github/workflows/maven.yml | 2 +- .../usage/operation-api/_index.cn.md | 38 +++++++++--------- .../usage/operation-api/_index.en.md | 38 +++++++++--------- examples/pom.xml | 2 +- pom.xml | 11 ++++- .../test/natived/it/operation/JavaTest.java | 40 +++++++++---------- 6 files changed, 67 insertions(+), 64 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 9f1c5bbfb..2984015ca 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -29,7 +29,7 @@ jobs: if: github.repository == 'apache/shardingsphere-elasticjob' strategy: matrix: - java: [ 8, 17, 21, 22 ] + java: [ 8, 17, 21, 23 ] os: [ 'windows-latest', 'macos-latest', 'ubuntu-latest' ] runs-on: ${{ matrix.os }} steps: diff --git a/docs/content/user-manual/usage/operation-api/_index.cn.md b/docs/content/user-manual/usage/operation-api/_index.cn.md index c74e94b3d..b8b4fb201 100644 --- a/docs/content/user-manual/usage/operation-api/_index.cn.md +++ b/docs/content/user-manual/usage/operation-api/_index.cn.md @@ -22,7 +22,7 @@ ElasticJob 提供了 Java API,可以通过直接对注册中心进行操作的 ### 获取作业配置 -方法签名:YamlJobConfiguration getJobConfiguration(String jobName) +方法签名:`JobConfigurationPOJO getJobConfiguration(String jobName)` * **Parameters:** * jobName — 作业名称 @@ -31,14 +31,14 @@ ElasticJob 提供了 Java API,可以通过直接对注册中心进行操作的 ### 更新作业配置 -方法签名:void updateJobConfiguration(YamlJobConfiguration yamlJobConfiguration) +方法签名:`void updateJobConfiguration(JobConfigurationPOJO jobConfig)` * **Parameters:** - * jobConfiguration — 作业配置对象 + * jobConfig — 作业配置对象 ### 删除作业设置 -方法签名:void removeJobConfiguration(String jobName) +方法签名:`void removeJobConfiguration(String jobName)` * **Parameters:** * jobName — 作业名称 @@ -51,7 +51,7 @@ ElasticJob 提供了 Java API,可以通过直接对注册中心进行操作的 作业在不与当前运行中作业冲突的情况下才会触发执行,并在启动后自动清理此标记。 -方法签名:void trigger(Optional jobName) +方法签名:`void trigger(String jobName)` * **Parameters:** * jobName — 作业名称 @@ -60,7 +60,7 @@ ElasticJob 提供了 Java API,可以通过直接对注册中心进行操作的 禁用作业将会导致分布式的其他作业触发重新分片。 -方法签名:void disable(Optional jobName, Optional serverIp) +方法签名:`void disable(String jobName, String serverIp)` * **Parameters:** * jobName — 作业名称 @@ -68,7 +68,7 @@ ElasticJob 提供了 Java API,可以通过直接对注册中心进行操作的 ### 启用作业 -方法签名:void enable(Optional jobName, Optional serverIp) +方法签名:`void enable(String jobName, String serverIp)` * **Parameters:** * jobName — 作业名称 @@ -76,7 +76,7 @@ ElasticJob 提供了 Java API,可以通过直接对注册中心进行操作的 ### 停止调度作业 -方法签名:void shutdown(Optional jobName, Optional serverIp) +方法签名:`void shutdown(String jobName, String serverIp)` * **Parameters:** * jobName — 作业名称 @@ -84,7 +84,7 @@ ElasticJob 提供了 Java API,可以通过直接对注册中心进行操作的 ### 删除作业 -方法签名:void remove(Optional jobName, Optional serverIp) +方法签名:`void remove(String jobName, String serverIp)` * **Parameters:** * jobName — 作业名称 @@ -92,7 +92,7 @@ ElasticJob 提供了 Java API,可以通过直接对注册中心进行操作的 ### Dump 作业 -方法签名:String dump(String jobName, String instanceIp, int dumpPort) +方法签名:`String dump(String jobName, String instanceIp, int dumpPort) throws IOException` * **Parameters:** * jobName — 作业名称 @@ -105,7 +105,7 @@ ElasticJob 提供了 Java API,可以通过直接对注册中心进行操作的 ### 禁用作业分片 -方法签名:void disable(String jobName, String item) +方法签名:`void disable(String jobName, String item)` * **Parameters:** * jobName — 作业名称 @@ -113,7 +113,7 @@ ElasticJob 提供了 Java API,可以通过直接对注册中心进行操作的 ### 启用作业分片 -方法签名:void enable(String jobName, String item) +方法签名:`void enable(String jobName, String item)` * **Parameters:** * jobName — 作业名称 @@ -125,13 +125,13 @@ ElasticJob 提供了 Java API,可以通过直接对注册中心进行操作的 ### 获取作业总数 -方法签名:int getJobsTotalCount() +方法签名:`int getJobsTotalCount()` * **Returns:** 作业总数 ### 获取作业简明信息 -方法签名:JobBriefInfo getJobBriefInfo(String jobName) +方法签名:`JobBriefInfo getJobBriefInfo(String jobName)` * **Parameters:** * jobName — 作业名称 @@ -140,13 +140,13 @@ ElasticJob 提供了 Java API,可以通过直接对注册中心进行操作的 ### 获取所有作业简明信息 -方法签名:Collection getAllJobsBriefInfo() +方法签名:`Collection getAllJobsBriefInfo()` * **Returns:** 作业简明信息集合 ### 获取该 IP 下所有作业简明信息 -方法签名:Collection getJobsBriefInfo(String ip) +方法签名:`Collection getJobsBriefInfo(String ip)` * **Parameters:** * ip — 服务器 IP @@ -159,13 +159,13 @@ ElasticJob 提供了 Java API,可以通过直接对注册中心进行操作的 ### 获取作业服务器总数 -方法签名:int getServersTotalCount() +方法签名:`int getServersTotalCount()` * **Returns:** 作业服务器总数 ### 获取所有作业服务器简明信息 -方法签名:Collection getAllServersBriefInfo() +方法签名:`Collection getAllServersBriefInfo()` * **Returns:** 作业服务器简明信息集合 @@ -175,7 +175,7 @@ ElasticJob 提供了 Java API,可以通过直接对注册中心进行操作的 ### 获取作业分片信息集合 -方法签名:Collection getShardingInfo(String jobName) +方法签名:`Collection getShardingInfo(String jobName)` * **Parameters:** * jobName — 作业名称 diff --git a/docs/content/user-manual/usage/operation-api/_index.en.md b/docs/content/user-manual/usage/operation-api/_index.en.md index 3919ac9bb..7507bcc0d 100644 --- a/docs/content/user-manual/usage/operation-api/_index.en.md +++ b/docs/content/user-manual/usage/operation-api/_index.en.md @@ -22,7 +22,7 @@ Class name: `org.apache.shardingsphere.elasticjob.lifecycle.api.JobConfiguration ### Get job configuration -Method signature:YamlJobConfiguration getJobConfiguration(String jobName) +Method signature:`JobConfigurationPOJO getJobConfiguration(String jobName)` * **Parameters:** * jobName — Job name @@ -31,14 +31,14 @@ Method signature:YamlJobConfiguration getJobConfiguration(String jobName) ### Update job configuration -Method signature:void updateJobConfiguration(YamlJobConfiguration yamlJobConfiguration) +Method signature:`void updateJobConfiguration(JobConfigurationPOJO jobConfig)` * **Parameters:** - * jobConfiguration — Job configuration object + * jobConfig — Job configuration object ### Remove job configuration -Method signature:void removeJobConfiguration(String jobName) +Method signature:`void removeJobConfiguration(String jobName)` * **Parameters:** * jobName — Job name @@ -51,7 +51,7 @@ Class name:`org.apache.shardingsphere.elasticjob.lifecycle.api.JobOperateAPI` The job will only trigger execution if it does not conflict with the currently running job, and this flag will be automatically cleared after it is started. -Method signature:void trigger(Optional jobName) +Method signature:`void trigger(String jobName)` * **Parameters:** * jobName — Job name @@ -60,7 +60,7 @@ Method signature:void trigger(Optional jobName) Disabling a job will cause other distributed jobs to trigger resharding. -Method signature:void disable(Optional jobName, Optional serverIp) +Method signature:`void disable(String jobName, String serverIp)` * **Parameters:** * jobName — Job name @@ -68,7 +68,7 @@ Method signature:void disable(Optional jobName, Optional serve ### Enable job -Method signature:void enable(Optional jobName, Optional serverIp) +Method signature:`void enable(String jobName, String serverIp)` * **Parameters:** * jobName — Job name @@ -76,7 +76,7 @@ Method signature:void enable(Optional jobName, Optional server ### Shutdown scheduling job -Method signature:void shutdown(Optional jobName, Optional serverIp) +Method signature:`void shutdown(String jobName, String serverIp)` * **Parameters:** * jobName — Job name @@ -84,7 +84,7 @@ Method signature:void shutdown(Optional jobName, Optional serv ### Remove job -Method signature:void remove(Optional jobName, Optional serverIp) +Method signature:`void remove(String jobName, String serverIp)` * **Parameters:** * jobName — Job name @@ -92,7 +92,7 @@ Method signature:void remove(Optional jobName, Optional server ### Dump job -Method signature:String dump(String jobName, String instanceIp, int dumpPort) +Method signature:`String dump(String jobName, String instanceIp, int dumpPort) throws IOException` * **Parameters:** * jobName — Job name @@ -105,7 +105,7 @@ Class name:`org.apache.shardingsphere.elasticjob.lifecycle.api.ShardingOperate ### Disable job sharding -Method signature:void disable(String jobName, String item) +Method signature:`void disable(String jobName, String item)` * **Parameters:** * jobName — Job name @@ -113,7 +113,7 @@ Method signature:void disable(String jobName, String item) ### Enable job sharding -Method signature:void enable(String jobName, String item) +Method signature:`void enable(String jobName, String item)` * **Parameters:** * jobName — Job name @@ -125,13 +125,13 @@ Class name:`org.apache.shardingsphere.elasticjob.lifecycle.api.JobStatisticsAP ### Get the total count of jobs -Method signature:int getJobsTotalCount() +Method signature:`int getJobsTotalCount()` * **Returns:** the total count of jobs ### Get brief job information -Method signature:JobBriefInfo getJobBriefInfo(String jobName) +Method signature:`JobBriefInfo getJobBriefInfo(String jobName)` * **Parameters:** * jobName — Job name @@ -140,13 +140,13 @@ Method signature:JobBriefInfo getJobBriefInfo(String jobName) ### Get brief information about all jobs. -Method signature:Collection getAllJobsBriefInfo() +Method signature:`Collection getAllJobsBriefInfo()` * **Returns:** Brief collection of all job information ### Get brief information of all jobs under this IP -Method signature:Collection getJobsBriefInfo(String ip) +Method signature:`Collection getJobsBriefInfo(String ip)` * **Parameters:** * ip — server IP @@ -159,13 +159,13 @@ Class name:`org.apache.shardingsphere.elasticjob.lifecycle.api.ServerStatistic ### Total count of job servers -Method signature:int getServersTotalCount() +Method signature:`int getServersTotalCount()` * **Returns:** Get the total count of job servers ### Get brief information about all job servers -Method signature:Collection getAllServersBriefInfo() +Method signature:`Collection getAllServersBriefInfo()` * **Returns:** Brief collection of job information @@ -175,7 +175,7 @@ Class name:`org.apache.shardingsphere.elasticjob.lifecycle.api.ShardingStatist ### Get job sharding information collection -Method signature:Collection getShardingInfo(String jobName) +Method signature:`Collection getShardingInfo(String jobName)` * **Parameters:** * jobName — Job name diff --git a/examples/pom.xml b/examples/pom.xml index e9371acfb..d9a111f15 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -50,7 +50,7 @@ 4.0.3 - 3.3 + 3.13.0 1.2.5 diff --git a/pom.xml b/pom.xml index 399162a31..560d19570 100644 --- a/pom.xml +++ b/pom.xml @@ -69,7 +69,7 @@ 2.3.2 3.9.2 - 5.7.0 + 5.7.1 1.6.0 1.16.0 @@ -97,7 +97,7 @@ 3.2.1 - 3.11.0 + 3.13.0 3.3.1 3.1.2 3.3.0 @@ -433,6 +433,13 @@ ${java.version} ${java.version} ${java.version} + + + org.projectlombok + lombok + ${lombok.version} + + diff --git a/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/it/operation/JavaTest.java b/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/it/operation/JavaTest.java index 1ea2421c7..939866716 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/it/operation/JavaTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/elasticjob/test/natived/it/operation/JavaTest.java @@ -46,11 +46,10 @@ import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter; import org.apache.shardingsphere.elasticjob.test.natived.commons.job.simple.JavaSimpleJob; import org.awaitility.Awaitility; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledInNativeImage; -import org.junit.jupiter.api.function.Executable; import javax.sql.DataSource; import java.io.IOException; @@ -81,8 +80,8 @@ class JavaTest { private static TracingConfiguration tracingConfig; - @BeforeAll - static void beforeAll() throws Exception { + @BeforeEach + void beforeEach() throws Exception { testingServer = new TestingServer(); try ( CuratorZookeeperClient client = new CuratorZookeeperClient(testingServer.getConnectString(), @@ -103,8 +102,8 @@ static void beforeAll() throws Exception { tracingConfig = new TracingConfiguration<>("RDB", new HikariDataSource(config)); } - @AfterAll - static void afterAll() throws IOException { + @AfterEach + void afterEach() throws IOException { firstRegCenter.close(); secondRegCenter.close(); testingServer.close(); @@ -112,9 +111,18 @@ static void afterAll() throws IOException { /** * TODO Executing {@link JobConfigurationAPI#removeJobConfiguration(String)} will always cause the listener - * to throw an exception similar to {@code Caused by: java.lang.IllegalStateException: Expected state [STARTED] was [STOPPED]} . - * This is not acceptable behavior. - * The logic inside {@link org.junit.jupiter.api.Assertions#assertDoesNotThrow(Executable)} should be removed. + * to throw an exception. This is not acceptable behavior. + *
+     *   
+     *  Caused by: java.lang.IllegalStateException: Expected state [STARTED] was [STOPPED]
+     *  at org.apache.curator.shaded.com.google.common.base.Preconditions.checkState(Preconditions.java:835)
+     *  at org.apache.curator.framework.imps.CuratorFrameworkImpl.checkState(CuratorFrameworkImpl.java:465)
+     *  at org.apache.curator.framework.imps.CuratorFrameworkImpl.getData(CuratorFrameworkImpl.java:498)
+     *  at org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter.getDirectly(ZookeeperRegistryCenter.java:179)
+     *  ... 12 common frames omitted
+     *   
+     *  
+ * */ @Test void testJobConfigurationAPI() { @@ -142,11 +150,6 @@ void testJobConfigurationAPI() { JobConfigurationPOJO newTestJavaSimpleJob = jobConfigAPI.getJobConfiguration(jobName); assertThat(newTestJavaSimpleJob, notNullValue()); assertThat(newTestJavaSimpleJob.getCron(), is("0/10 * * * * ?")); - assertDoesNotThrow(() -> { - List ipList = secondRegCenter.getChildrenKeys("/" + jobName + "/servers"); - assertThat(ipList.size(), is(1)); - secondRegCenter.remove("/" + jobName + "/servers/" + ipList.get(0)); - }); jobConfigAPI.removeJobConfiguration(jobName); assertThat(jobConfigAPI.getJobConfiguration(jobName), nullValue()); job.shutdown(); @@ -244,9 +247,6 @@ void testJobStatisticsAPI() { job.shutdown(); } - /** - * TODO The logic inside {@link org.junit.jupiter.api.Assertions#assertDoesNotThrow(Executable)} should be removed. - */ @Test void testServerStatisticsAPI() { String jobName = "testServerStatisticsAPI"; @@ -277,10 +277,6 @@ void testServerStatisticsAPI() { assertThat(serverBriefInfo.getDisabledJobsNum().intValue(), is(0)); }); job.shutdown(); - assertDoesNotThrow(() -> { - JobConfigurationAPI jobConfigAPI = new JobConfigurationAPIImpl(secondRegCenter); - jobConfigAPI.removeJobConfiguration(jobName); - }); } @Test