You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2021/09/27 03:51:52 UTC
[shardingsphere-elasticjob] branch feature-annotation updated:
Support annotation job java (#1982)
This is an automated email from the ASF dual-hosted git repository.
wuweijie pushed a commit to branch feature-annotation
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob.git
The following commit(s) were added to refs/heads/feature-annotation by this push:
new 761fd30 Support annotation job java (#1982)
761fd30 is described below
commit 761fd30d680b283cabd40701d379a5e4380b1dae
Author: skai <su...@gmail.com>
AuthorDate: Mon Sep 27 11:51:46 2021 +0800
Support annotation job java (#1982)
* add annotation interface
* add test
* add JobAnnotationBuilder
* complete JobAnntotationBuilder
* Bootstarp support annotation job && add test
* add License
* fix bug
* fix review problem
* import `Optional`
* fix bug
Co-authored-by: 蔡顺铠 <sk...@gmail.com>
---
.../annotation/ElasticJobConfiguration.java | 155 +++++++++++++++++++++
.../elasticjob/annotation/ElasticJobProp.java | 42 ++++++
.../api/JobExtraConfigurationFactory.java | 32 +++++
.../annotation/ElasticJobConfigurationTest.java | 51 +++++++
.../SimpleTracingConfigurationFactory.java | 30 ++++
.../elasticjob/annotation/job/CustomJob.java | 31 +++++
.../annotation/job/impl/SimpleTestJob.java | 44 ++++++
.../api/bootstrap/impl/OneOffJobBootstrap.java | 7 +
.../api/bootstrap/impl/ScheduleJobBootstrap.java | 6 +
.../internal/annotation/JobAnnotationBuilder.java | 71 ++++++++++
.../lite/fixture/job/AnnotationSimpleJob.java | 46 ++++++
.../lite/fixture/job/AnnotationUnShardingJob.java | 39 ++++++
.../annotation/JobAnnotationBuilderTest.java | 54 +++++++
.../annotation/integrate/BaseAnnotationTest.java | 102 ++++++++++++++
.../annotation/integrate/OneOffEnabledJobTest.java | 64 +++++++++
.../integrate/ScheduleEnabledJobTest.java | 66 +++++++++
16 files changed, 840 insertions(+)
diff --git a/elasticjob-api/src/main/java/org/apache/shardingsphere/elasticjob/annotation/ElasticJobConfiguration.java b/elasticjob-api/src/main/java/org/apache/shardingsphere/elasticjob/annotation/ElasticJobConfiguration.java
new file mode 100644
index 0000000..39cd0d9
--- /dev/null
+++ b/elasticjob-api/src/main/java/org/apache/shardingsphere/elasticjob/annotation/ElasticJobConfiguration.java
@@ -0,0 +1,155 @@
+/*
+ * 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.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.apache.shardingsphere.elasticjob.api.JobExtraConfigurationFactory;
+
+/**
+ * The annotation that specify a job of elastic.
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface ElasticJobConfiguration {
+
+ /**
+ * Job name.
+ * @return jobName
+ */
+ String jobName();
+
+ /**
+ * CRON expression, control the job trigger time.
+ * @return cron
+ */
+ String cron() default "";
+
+ /**
+ * Time zone of CRON.
+ * @return timeZone
+ */
+ String timeZone() default "";
+
+ /**
+ * Sharding total count.
+ * @return shardingTotalCount
+ */
+ int shardingTotalCount();
+
+ /**
+ * Sharding item parameters.
+ * @return shardingItemParameters
+ */
+ String shardingItemParameters() default "";
+
+ /**
+ * Job parameter.
+ * @return jobParameter
+ */
+ String jobParameter() default "";
+
+ /**
+ * Monitor job execution status.
+ * @return monitorExecution
+ */
+ boolean monitorExecution() default true;
+
+ /**
+ * Enable or disable job failover.
+ * @return failover
+ */
+ boolean failover() default false;
+
+ /**
+ * Enable or disable the missed task to re-execute.
+ * @return misfire
+ */
+ boolean misfire() default true;
+
+ /**
+ * The maximum value for time difference between server and registry center in seconds.
+ * @return maxTimeDiffSeconds
+ */
+ int maxTimeDiffSeconds() default -1;
+
+ /**
+ * Service scheduling interval in minutes for repairing job server inconsistent state.
+ * @return reconcileIntervalMinutes
+ */
+ int reconcileIntervalMinutes() default 10;
+
+ /**
+ * Job sharding strategy type.
+ * @return jobShardingStrategyType
+ */
+ String jobShardingStrategyType() default "";
+
+ /**
+ * Job thread pool handler type.
+ * @return jobExecutorServiceHandlerType
+ */
+ String jobExecutorServiceHandlerType() default "";
+
+ /**
+ * Job thread pool handler type.
+ * @return jobErrorHandlerType
+ */
+ String jobErrorHandlerType() default "";
+
+ /**
+ * Job listener types.
+ * @return jobListenerTypes
+ */
+ String[] jobListenerTypes() default {};
+
+ /**
+ * extra configurations.
+ * @return extraConfigurations
+ */
+ Class<? extends JobExtraConfigurationFactory>[] extraConfigurations() default {};
+
+ /**
+ * Job description.
+ * @return description
+ */
+ String description() default "";
+
+ /**
+ * Job properties.
+ * @return props
+ */
+ ElasticJobProp[] props() default {};
+
+ /**
+ * Enable or disable start the job.
+ * @return disabled
+ */
+ boolean disabled() default false;
+
+ /**
+ * Enable or disable local configuration override registry center configuration.
+ * @return overwrite
+ */
+ boolean overwrite() default false;
+
+}
diff --git a/elasticjob-api/src/main/java/org/apache/shardingsphere/elasticjob/annotation/ElasticJobProp.java b/elasticjob-api/src/main/java/org/apache/shardingsphere/elasticjob/annotation/ElasticJobProp.java
new file mode 100644
index 0000000..aa0d790
--- /dev/null
+++ b/elasticjob-api/src/main/java/org/apache/shardingsphere/elasticjob/annotation/ElasticJobProp.java
@@ -0,0 +1,42 @@
+/*
+ * 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.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * The annotation that specify elastic-job prop.
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ElasticJobProp {
+
+ /**
+ * Prop key.
+ * @return key
+ */
+ String key();
+
+ /**
+ * Prop value.
+ * @return value
+ */
+ String value() default "";
+}
diff --git a/elasticjob-api/src/main/java/org/apache/shardingsphere/elasticjob/api/JobExtraConfigurationFactory.java b/elasticjob-api/src/main/java/org/apache/shardingsphere/elasticjob/api/JobExtraConfigurationFactory.java
new file mode 100644
index 0000000..8670ed9
--- /dev/null
+++ b/elasticjob-api/src/main/java/org/apache/shardingsphere/elasticjob/api/JobExtraConfigurationFactory.java
@@ -0,0 +1,32 @@
+/*
+ * 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.api;
+
+import java.util.Optional;
+
+/**
+ * Job extra configuration factory.
+ */
+public interface JobExtraConfigurationFactory {
+
+ /**
+ * Get JobExtraConfiguration.
+ * @return JobExtraConfiguration
+ */
+ Optional<JobExtraConfiguration> getJobExtraConfiguration();
+}
diff --git a/elasticjob-api/src/test/java/org/apache/shardingsphere/elasticjob/annotation/ElasticJobConfigurationTest.java b/elasticjob-api/src/test/java/org/apache/shardingsphere/elasticjob/annotation/ElasticJobConfigurationTest.java
new file mode 100644
index 0000000..3a3562f
--- /dev/null
+++ b/elasticjob-api/src/test/java/org/apache/shardingsphere/elasticjob/annotation/ElasticJobConfigurationTest.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.annotation;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertThat;
+
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.Queue;
+import org.apache.shardingsphere.elasticjob.annotation.job.impl.SimpleTestJob;
+import org.apache.shardingsphere.elasticjob.api.JobExtraConfigurationFactory;
+import org.junit.Test;
+
+public class ElasticJobConfigurationTest {
+
+ @Test
+ public void assertAnnotationJob() {
+ ElasticJobConfiguration annotation = SimpleTestJob.class.getAnnotation(ElasticJobConfiguration.class);
+ assertThat(annotation.jobName(), is("SimpleTestJob"));
+ assertThat(annotation.cron(), is("0/5 * * * * ?"));
+ assertThat(annotation.shardingTotalCount(), is(3));
+ assertThat(annotation.shardingItemParameters(), is("0=Beijing,1=Shanghai,2=Guangzhou"));
+ for (Class<? extends JobExtraConfigurationFactory> factory :annotation.extraConfigurations()) {
+ assertThat(factory, is(SimpleTracingConfigurationFactory.class));
+ }
+ assertArrayEquals(annotation.jobListenerTypes(), new String[] {"NOOP", "LOG"});
+ Queue<String> propsKey = new LinkedList<>(Arrays.asList("print.title", "print.content"));
+ Queue<String> propsValue = new LinkedList<>(Arrays.asList("test title", "test content"));
+ for (ElasticJobProp prop :annotation.props()) {
+ assertThat(prop.key(), is(propsKey.poll()));
+ assertThat(prop.value(), is(propsValue.poll()));
+ }
+ }
+}
diff --git a/elasticjob-api/src/test/java/org/apache/shardingsphere/elasticjob/annotation/SimpleTracingConfigurationFactory.java b/elasticjob-api/src/test/java/org/apache/shardingsphere/elasticjob/annotation/SimpleTracingConfigurationFactory.java
new file mode 100644
index 0000000..095081c
--- /dev/null
+++ b/elasticjob-api/src/test/java/org/apache/shardingsphere/elasticjob/annotation/SimpleTracingConfigurationFactory.java
@@ -0,0 +1,30 @@
+/*
+ * 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.annotation;
+
+import java.util.Optional;
+import org.apache.shardingsphere.elasticjob.api.JobExtraConfiguration;
+import org.apache.shardingsphere.elasticjob.api.JobExtraConfigurationFactory;
+
+public class SimpleTracingConfigurationFactory implements JobExtraConfigurationFactory {
+
+ @Override
+ public Optional<JobExtraConfiguration> getJobExtraConfiguration() {
+ return Optional.empty();
+ }
+}
diff --git a/elasticjob-api/src/test/java/org/apache/shardingsphere/elasticjob/annotation/job/CustomJob.java b/elasticjob-api/src/test/java/org/apache/shardingsphere/elasticjob/annotation/job/CustomJob.java
new file mode 100644
index 0000000..fbad39c
--- /dev/null
+++ b/elasticjob-api/src/test/java/org/apache/shardingsphere/elasticjob/annotation/job/CustomJob.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.annotation.job;
+
+import org.apache.shardingsphere.elasticjob.api.ElasticJob;
+import org.apache.shardingsphere.elasticjob.api.ShardingContext;
+
+public interface CustomJob extends ElasticJob {
+
+ /**
+ * Execute custom job.
+ *
+ * @param shardingContext sharding context
+ */
+ void execute(ShardingContext shardingContext);
+}
diff --git a/elasticjob-api/src/test/java/org/apache/shardingsphere/elasticjob/annotation/job/impl/SimpleTestJob.java b/elasticjob-api/src/test/java/org/apache/shardingsphere/elasticjob/annotation/job/impl/SimpleTestJob.java
new file mode 100644
index 0000000..48f4fab
--- /dev/null
+++ b/elasticjob-api/src/test/java/org/apache/shardingsphere/elasticjob/annotation/job/impl/SimpleTestJob.java
@@ -0,0 +1,44 @@
+/*
+ * 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.annotation.job.impl;
+
+import org.apache.shardingsphere.elasticjob.annotation.ElasticJobConfiguration;
+import org.apache.shardingsphere.elasticjob.annotation.ElasticJobProp;
+import org.apache.shardingsphere.elasticjob.annotation.SimpleTracingConfigurationFactory;
+import org.apache.shardingsphere.elasticjob.annotation.job.CustomJob;
+import org.apache.shardingsphere.elasticjob.api.ShardingContext;
+
+@ElasticJobConfiguration(
+ cron = "0/5 * * * * ?",
+ jobName = "SimpleTestJob",
+ shardingTotalCount = 3,
+ shardingItemParameters = "0=Beijing,1=Shanghai,2=Guangzhou",
+ jobListenerTypes = {"NOOP", "LOG"},
+ extraConfigurations = {SimpleTracingConfigurationFactory.class},
+ props = {
+ @ElasticJobProp(key = "print.title", value = "test title"),
+ @ElasticJobProp(key = "print.content", value = "test content")
+ }
+)
+public class SimpleTestJob implements CustomJob {
+
+ @Override
+ public void execute(final ShardingContext shardingContext) {
+ }
+
+}
diff --git a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/api/bootstrap/impl/OneOffJobBootstrap.java b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/api/bootstrap/impl/OneOffJobBootstrap.java
index a98a33e..3423f24 100644
--- a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/api/bootstrap/impl/OneOffJobBootstrap.java
+++ b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/api/bootstrap/impl/OneOffJobBootstrap.java
@@ -22,6 +22,7 @@ import com.google.common.base.Strings;
import org.apache.shardingsphere.elasticjob.api.ElasticJob;
import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.JobBootstrap;
+import org.apache.shardingsphere.elasticjob.lite.internal.annotation.JobAnnotationBuilder;
import org.apache.shardingsphere.elasticjob.lite.internal.instance.InstanceService;
import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobScheduler;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
@@ -47,6 +48,12 @@ public final class OneOffJobBootstrap implements JobBootstrap {
instanceService = new InstanceService(regCenter, jobConfig.getJobName());
}
+ public OneOffJobBootstrap(final CoordinatorRegistryCenter regCenter, final ElasticJob elasticJob) {
+ JobConfiguration jobConfig = JobAnnotationBuilder.generateJobConfiguration(elasticJob.getClass());
+ jobScheduler = new JobScheduler(regCenter, elasticJob, jobConfig);
+ instanceService = new InstanceService(regCenter, jobConfig.getJobName());
+ }
+
/**
* Execute job.
*/
diff --git a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/api/bootstrap/impl/ScheduleJobBootstrap.java b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/api/bootstrap/impl/ScheduleJobBootstrap.java
index bb49199..8d1f6ce 100644
--- a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/api/bootstrap/impl/ScheduleJobBootstrap.java
+++ b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/api/bootstrap/impl/ScheduleJobBootstrap.java
@@ -22,6 +22,7 @@ import com.google.common.base.Strings;
import org.apache.shardingsphere.elasticjob.api.ElasticJob;
import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.JobBootstrap;
+import org.apache.shardingsphere.elasticjob.lite.internal.annotation.JobAnnotationBuilder;
import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobScheduler;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
@@ -40,6 +41,11 @@ public final class ScheduleJobBootstrap implements JobBootstrap {
jobScheduler = new JobScheduler(regCenter, elasticJobType, jobConfig);
}
+ public ScheduleJobBootstrap(final CoordinatorRegistryCenter regCenter, final ElasticJob elasticJob) {
+ JobConfiguration jobConfig = JobAnnotationBuilder.generateJobConfiguration(elasticJob.getClass());
+ jobScheduler = new JobScheduler(regCenter, elasticJob, jobConfig);
+ }
+
/**
* Schedule job.
*/
diff --git a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/JobAnnotationBuilder.java b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/JobAnnotationBuilder.java
new file mode 100644
index 0000000..be3c1fb
--- /dev/null
+++ b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/JobAnnotationBuilder.java
@@ -0,0 +1,71 @@
+/*
+ * 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.lite.internal.annotation;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import java.util.Optional;
+import org.apache.shardingsphere.elasticjob.annotation.ElasticJobConfiguration;
+import org.apache.shardingsphere.elasticjob.annotation.ElasticJobProp;
+import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
+import org.apache.shardingsphere.elasticjob.api.JobExtraConfiguration;
+import org.apache.shardingsphere.elasticjob.api.JobExtraConfigurationFactory;
+import org.apache.shardingsphere.elasticjob.infra.exception.JobConfigurationException;
+
+public class JobAnnotationBuilder {
+
+ /**
+ * generate JobConfiguration from @ElasticJobConfiguration.
+ * @param type The job of @ElasticJobConfiguration annotation class
+ * @return JobConfiguration
+ */
+ public static JobConfiguration generateJobConfiguration(final Class<?> type) {
+ ElasticJobConfiguration annotation = type.getAnnotation(ElasticJobConfiguration.class);
+ Preconditions.checkArgument(null != annotation, "@ElasticJobConfiguration not found by class '%s'.", type);
+ Preconditions.checkArgument(!Strings.isNullOrEmpty(annotation.jobName()), "@ElasticJobConfiguration jobName not be empty by class '%s'.", type);
+ JobConfiguration.Builder jobConfigurationBuilder = JobConfiguration.newBuilder(annotation.jobName(), annotation.shardingTotalCount())
+ .shardingItemParameters(annotation.shardingItemParameters())
+ .cron(Strings.isNullOrEmpty(annotation.cron()) ? null : annotation.cron())
+ .timeZone(Strings.isNullOrEmpty(annotation.timeZone()) ? null : annotation.timeZone())
+ .jobParameter(annotation.jobParameter())
+ .monitorExecution(annotation.monitorExecution())
+ .failover(annotation.failover())
+ .misfire(annotation.misfire())
+ .maxTimeDiffSeconds(annotation.maxTimeDiffSeconds())
+ .reconcileIntervalMinutes(annotation.reconcileIntervalMinutes())
+ .jobShardingStrategyType(Strings.isNullOrEmpty(annotation.jobShardingStrategyType()) ? null : annotation.jobShardingStrategyType())
+ .jobExecutorServiceHandlerType(Strings.isNullOrEmpty(annotation.jobExecutorServiceHandlerType()) ? null : annotation.jobExecutorServiceHandlerType())
+ .jobErrorHandlerType(Strings.isNullOrEmpty(annotation.jobErrorHandlerType()) ? null : annotation.jobErrorHandlerType())
+ .jobListenerTypes(annotation.jobListenerTypes())
+ .description(annotation.description())
+ .disabled(annotation.disabled())
+ .overwrite(annotation.overwrite());
+ for (Class<? extends JobExtraConfigurationFactory> clazz : annotation.extraConfigurations()) {
+ try {
+ Optional<JobExtraConfiguration> jobExtraConfiguration = clazz.newInstance().getJobExtraConfiguration();
+ jobExtraConfiguration.ifPresent(jobConfigurationBuilder::addExtraConfigurations);
+ } catch (IllegalAccessException | InstantiationException exception) {
+ throw (JobConfigurationException) new JobConfigurationException("new JobExtraConfigurationFactory instance by class '%s' failure", clazz).initCause(exception);
+ }
+ }
+ for (ElasticJobProp prop :annotation.props()) {
+ jobConfigurationBuilder.setProperty(prop.key(), prop.value());
+ }
+ return jobConfigurationBuilder.build();
+ }
+}
diff --git a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/fixture/job/AnnotationSimpleJob.java b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/fixture/job/AnnotationSimpleJob.java
new file mode 100644
index 0000000..6d33915
--- /dev/null
+++ b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/fixture/job/AnnotationSimpleJob.java
@@ -0,0 +1,46 @@
+/*
+ * 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.lite.fixture.job;
+
+import lombok.Getter;
+import org.apache.shardingsphere.elasticjob.annotation.ElasticJobConfiguration;
+import org.apache.shardingsphere.elasticjob.annotation.ElasticJobProp;
+import org.apache.shardingsphere.elasticjob.api.ShardingContext;
+import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
+
+@Getter
+@ElasticJobConfiguration(
+ jobName = "AnnotationSimpleJob",
+ description = "desc",
+ shardingTotalCount = 3,
+ shardingItemParameters = "0=a,1=b,2=c",
+ cron = "*/10 * * * * ?",
+ props = {
+ @ElasticJobProp(key = "print.title", value = "test title"),
+ @ElasticJobProp(key = "print.content", value = "test content")
+ }
+)
+public class AnnotationSimpleJob implements SimpleJob {
+
+ private volatile boolean completed;
+
+ @Override
+ public void execute(final ShardingContext shardingContext) {
+ completed = true;
+ }
+}
diff --git a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/fixture/job/AnnotationUnShardingJob.java b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/fixture/job/AnnotationUnShardingJob.java
new file mode 100644
index 0000000..5268bac
--- /dev/null
+++ b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/fixture/job/AnnotationUnShardingJob.java
@@ -0,0 +1,39 @@
+/*
+ * 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.lite.fixture.job;
+
+import lombok.Getter;
+import org.apache.shardingsphere.elasticjob.annotation.ElasticJobConfiguration;
+import org.apache.shardingsphere.elasticjob.api.ShardingContext;
+import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
+
+@Getter
+@ElasticJobConfiguration(
+ jobName = "AnnotationUnShardingJob",
+ description = "desc",
+ shardingTotalCount = 1
+)
+public class AnnotationUnShardingJob implements SimpleJob {
+
+ private volatile boolean completed;
+
+ @Override
+ public void execute(final ShardingContext shardingContext) {
+ completed = true;
+ }
+}
diff --git a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/JobAnnotationBuilderTest.java b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/JobAnnotationBuilderTest.java
new file mode 100644
index 0000000..25b73e5
--- /dev/null
+++ b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/JobAnnotationBuilderTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.lite.internal.annotation;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.fixture.job.AnnotationSimpleJob;
+import org.junit.Test;
+
+public final class JobAnnotationBuilderTest {
+
+ @Test
+ public void assertGenerateJobConfiguration() {
+ JobConfiguration jobConfiguration = JobAnnotationBuilder.generateJobConfiguration(AnnotationSimpleJob.class);
+ assertThat(jobConfiguration.getJobName(), is("AnnotationSimpleJob"));
+ assertThat(jobConfiguration.getShardingTotalCount(), is(3));
+ assertThat(jobConfiguration.getShardingItemParameters(), is("0=a,1=b,2=c"));
+ assertThat(jobConfiguration.getCron(), is("*/10 * * * * ?"));
+ assertTrue(jobConfiguration.isMonitorExecution());
+ assertFalse(jobConfiguration.isFailover());
+ assertTrue(jobConfiguration.isMisfire());
+ assertThat(jobConfiguration.getMaxTimeDiffSeconds(), is(-1));
+ assertThat(jobConfiguration.getReconcileIntervalMinutes(), is(10));
+ assertNull(jobConfiguration.getJobShardingStrategyType());
+ assertNull(jobConfiguration.getJobExecutorServiceHandlerType());
+ assertNull(jobConfiguration.getJobErrorHandlerType());
+ assertThat(jobConfiguration.getDescription(), is("desc"));
+ assertThat(jobConfiguration.getProps().getProperty("print.title"), is("test title"));
+ assertThat(jobConfiguration.getProps().getProperty("print.content"), is("test content"));
+ assertFalse(jobConfiguration.isDisabled());
+ assertFalse(jobConfiguration.isOverwrite());
+ }
+
+}
diff --git a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/integrate/BaseAnnotationTest.java b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/integrate/BaseAnnotationTest.java
new file mode 100644
index 0000000..bbc3e46
--- /dev/null
+++ b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/integrate/BaseAnnotationTest.java
@@ -0,0 +1,102 @@
+/*
+ * 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.lite.internal.annotation.integrate;
+
+import lombok.AccessLevel;
+import lombok.Getter;
+import org.apache.shardingsphere.elasticjob.api.ElasticJob;
+import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.JobBootstrap;
+import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.OneOffJobBootstrap;
+import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap;
+import org.apache.shardingsphere.elasticjob.lite.fixture.EmbedTestingServer;
+import org.apache.shardingsphere.elasticjob.lite.internal.annotation.JobAnnotationBuilder;
+import org.apache.shardingsphere.elasticjob.lite.internal.election.LeaderService;
+import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
+import org.apache.shardingsphere.elasticjob.lite.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
+import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
+import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+
+@Getter(AccessLevel.PROTECTED)
+public abstract class BaseAnnotationTest {
+
+ private static final ZookeeperConfiguration ZOOKEEPER_CONFIG = new ZookeeperConfiguration(EmbedTestingServer.getConnectionString(), "zkRegTestCenter");
+
+ @Getter(AccessLevel.PROTECTED)
+ private static final CoordinatorRegistryCenter REGISTRY_CENTER = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIG);
+
+ private final ElasticJob elasticJob;
+
+ private final JobConfiguration jobConfiguration;
+
+ private final JobBootstrap jobBootstrap;
+
+ private final LeaderService leaderService;
+
+ private final String jobName;
+
+ protected BaseAnnotationTest(final TestType type, final ElasticJob elasticJob) {
+ this.elasticJob = elasticJob;
+ jobConfiguration = JobAnnotationBuilder.generateJobConfiguration(elasticJob.getClass());
+ jobName = jobConfiguration.getJobName();
+ jobBootstrap = createJobBootstrap(type, elasticJob);
+ leaderService = new LeaderService(REGISTRY_CENTER, jobName);
+ }
+
+ private JobBootstrap createJobBootstrap(final TestType type, final ElasticJob elasticJob) {
+ switch (type) {
+ case SCHEDULE:
+ return new ScheduleJobBootstrap(REGISTRY_CENTER, elasticJob);
+ case ONE_OFF:
+ return new OneOffJobBootstrap(REGISTRY_CENTER, elasticJob);
+ default:
+ throw new RuntimeException(String.format("Cannot support `%s`", type));
+ }
+ }
+
+ @BeforeClass
+ public static void init() {
+ EmbedTestingServer.start();
+ ZOOKEEPER_CONFIG.setConnectionTimeoutMilliseconds(30000);
+ REGISTRY_CENTER.init();
+ }
+
+ @Before
+ public void setUp() {
+ if (jobBootstrap instanceof ScheduleJobBootstrap) {
+ ((ScheduleJobBootstrap) jobBootstrap).schedule();
+ } else {
+ ((OneOffJobBootstrap) jobBootstrap).execute();
+ }
+ }
+
+ @After
+ public void tearDown() {
+ jobBootstrap.shutdown();
+ ReflectionUtils.setFieldValue(JobRegistry.getInstance(), "instance", null);
+ }
+
+ public enum TestType {
+
+ SCHEDULE, ONE_OFF
+ }
+}
diff --git a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/integrate/OneOffEnabledJobTest.java b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/integrate/OneOffEnabledJobTest.java
new file mode 100644
index 0000000..33bf40e
--- /dev/null
+++ b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/integrate/OneOffEnabledJobTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.lite.internal.annotation.integrate;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
+import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
+import org.apache.shardingsphere.elasticjob.infra.env.IpUtils;
+import org.apache.shardingsphere.elasticjob.infra.pojo.JobConfigurationPOJO;
+import org.apache.shardingsphere.elasticjob.infra.yaml.YamlEngine;
+import org.apache.shardingsphere.elasticjob.lite.fixture.job.AnnotationUnShardingJob;
+import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
+import org.apache.shardingsphere.elasticjob.lite.internal.server.ServerStatus;
+import org.junit.Before;
+import org.junit.Test;
+
+public final class OneOffEnabledJobTest extends BaseAnnotationTest {
+
+ public OneOffEnabledJobTest() {
+ super(TestType.ONE_OFF, new AnnotationUnShardingJob());
+ }
+
+ @Before
+ public void assertEnabledRegCenterInfo() {
+ assertThat(JobRegistry.getInstance().getCurrentShardingTotalCount(getJobName()), is(1));
+ assertThat(JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp(), is(IpUtils.getIp()));
+ JobConfiguration jobConfig = YamlEngine.unmarshal(getREGISTRY_CENTER().get("/" + getJobName() + "/config"), JobConfigurationPOJO.class).toJobConfiguration();
+ assertThat(jobConfig.getShardingTotalCount(), is(1));
+ assertNull(jobConfig.getCron());
+ assertThat(getREGISTRY_CENTER().get("/" + getJobName() + "/servers/" + JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp()), is(ServerStatus.ENABLED.name()));
+ assertThat(getREGISTRY_CENTER().get("/" + getJobName() + "/leader/election/instance"), is(JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId()));
+ assertTrue(getREGISTRY_CENTER().isExisted("/" + getJobName() + "/instances/" + JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId()));
+ getREGISTRY_CENTER().remove("/" + getJobName() + "/leader/election");
+ assertTrue(getLeaderService().isLeaderUntilBlock());
+ }
+
+ @Test
+ public void assertJobInit() {
+ while (!((AnnotationUnShardingJob) getElasticJob()).isCompleted()) {
+ BlockUtils.waitingShortTime();
+ }
+ assertTrue(getREGISTRY_CENTER().isExisted("/" + getJobName() + "/sharding"));
+ }
+
+}
diff --git a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/integrate/ScheduleEnabledJobTest.java b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/integrate/ScheduleEnabledJobTest.java
new file mode 100644
index 0000000..d250341
--- /dev/null
+++ b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/integrate/ScheduleEnabledJobTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.lite.internal.annotation.integrate;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
+import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
+import org.apache.shardingsphere.elasticjob.infra.env.IpUtils;
+import org.apache.shardingsphere.elasticjob.infra.pojo.JobConfigurationPOJO;
+import org.apache.shardingsphere.elasticjob.infra.yaml.YamlEngine;
+import org.apache.shardingsphere.elasticjob.lite.fixture.job.AnnotationSimpleJob;
+import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
+import org.apache.shardingsphere.elasticjob.lite.internal.server.ServerStatus;
+import org.junit.Before;
+import org.junit.Test;
+
+public final class ScheduleEnabledJobTest extends BaseAnnotationTest {
+
+ public ScheduleEnabledJobTest() {
+ super(TestType.SCHEDULE, new AnnotationSimpleJob());
+ }
+
+ @Before
+ public void assertEnabledRegCenterInfo() {
+ assertThat(JobRegistry.getInstance().getCurrentShardingTotalCount(getJobName()), is(3));
+ assertThat(JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp(), is(IpUtils.getIp()));
+ JobConfiguration jobConfig = YamlEngine.unmarshal(getREGISTRY_CENTER().get("/" + getJobName() + "/config"), JobConfigurationPOJO.class).toJobConfiguration();
+ assertThat(jobConfig.getShardingTotalCount(), is(3));
+ assertThat(jobConfig.getCron(), is("*/10 * * * * ?"));
+ assertNull(jobConfig.getTimeZone());
+ assertThat(jobConfig.getShardingItemParameters(), is("0=a,1=b,2=c"));
+ assertThat(getREGISTRY_CENTER().get("/" + getJobName() + "/servers/" + JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp()), is(ServerStatus.ENABLED.name()));
+ assertThat(getREGISTRY_CENTER().get("/" + getJobName() + "/leader/election/instance"), is(JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId()));
+ assertTrue(getREGISTRY_CENTER().isExisted("/" + getJobName() + "/instances/" + JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId()));
+ getREGISTRY_CENTER().remove("/" + getJobName() + "/leader/election");
+ assertTrue(getLeaderService().isLeaderUntilBlock());
+ }
+
+ @Test
+ public void assertJobInit() {
+ while (!((AnnotationSimpleJob) getElasticJob()).isCompleted()) {
+ BlockUtils.waitingShortTime();
+ }
+ assertTrue(getREGISTRY_CENTER().isExisted("/" + getJobName() + "/sharding"));
+ }
+
+}