Increase testcases' coverage of module elasticjob-lite-spring-boot-starter (#1729)
Co-authored-by: zhouyanjie <zhouyanjie@wakedata.com>
diff --git a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/ElasticJobConfigurationPropertiesTest.java b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/ElasticJobConfigurationPropertiesTest.java
new file mode 100644
index 0000000..5fb9740
--- /dev/null
+++ b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/ElasticJobConfigurationPropertiesTest.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.lite.spring.boot.job;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.Collections;
+import org.apache.shardingsphere.elasticjob.api.ElasticJob;
+import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
+import org.junit.Test;
+
+public final class ElasticJobConfigurationPropertiesTest {
+
+ @Test
+ public void assertToJobConfiguration() {
+ ElasticJobConfigurationProperties properties = new ElasticJobConfigurationProperties();
+ properties.setElasticJobClass(ElasticJob.class);
+ properties.setElasticJobType("jobType");
+ properties.setCron("cron");
+ properties.setJobBootstrapBeanName("beanName");
+ properties.setShardingTotalCount(3);
+ properties.setShardingItemParameters("a=1,b=2");
+ properties.setJobParameter("testParam");
+ properties.setMonitorExecution(true);
+ properties.setFailover(true);
+ properties.setMisfire(true);
+ properties.setMaxTimeDiffSeconds(1);
+ properties.setReconcileIntervalMinutes(2);
+ properties.setJobShardingStrategyType("strategyType");
+ properties.setJobExecutorServiceHandlerType("executorType");
+ properties.setJobErrorHandlerType("errorHandlerType");
+ properties.setJobListenerTypes(Collections.singleton("listenerType"));
+ properties.setDescription("test desc");
+ properties.setDisabled(true);
+ properties.setOverwrite(true);
+ properties.getProps().setProperty("test", "test");
+ JobConfiguration actual = properties.toJobConfiguration("testJob");
+ assertThat(actual.getJobName(), is("testJob"));
+ assertThat(actual.getShardingTotalCount(), is(properties.getShardingTotalCount()));
+ assertThat(actual.getCron(), is(properties.getCron()));
+ assertThat(actual.getShardingItemParameters(), is(properties.getShardingItemParameters()));
+ assertThat(actual.getJobParameter(), is(properties.getJobParameter()));
+ assertThat(actual.getMaxTimeDiffSeconds(), is(properties.getMaxTimeDiffSeconds()));
+ assertThat(actual.getReconcileIntervalMinutes(), is(properties.getReconcileIntervalMinutes()));
+ assertThat(actual.getJobShardingStrategyType(), is(properties.getJobShardingStrategyType()));
+ assertThat(actual.getJobExecutorServiceHandlerType(), is(properties.getJobExecutorServiceHandlerType()));
+ assertThat(actual.getJobErrorHandlerType(), is(properties.getJobErrorHandlerType()));
+ assertThat(actual.getJobListenerTypes().toArray(), is(properties.getJobListenerTypes().toArray()));
+ assertThat(actual.getDescription(), is(properties.getDescription()));
+ assertThat(actual.isDisabled(), is(properties.isDisabled()));
+ assertThat(actual.isOverwrite(), is(properties.isOverwrite()));
+ assertThat(actual.isMisfire(), is(properties.isMisfire()));
+ assertThat(actual.isFailover(), is(properties.isFailover()));
+ assertThat(actual.isMonitorExecution(), is(properties.isMonitorExecution()));
+ assertThat(actual.getProps().size(), is(properties.getProps().size()));
+ assertThat(actual.getProps().getProperty("test"), is(properties.getProps().getProperty("test")));
+ }
+}
diff --git a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/ElasticJobSpringBootTest.java b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/ElasticJobSpringBootTest.java
index 8636370..a2b7236 100644
--- a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/ElasticJobSpringBootTest.java
+++ b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/ElasticJobSpringBootTest.java
@@ -21,6 +21,7 @@
import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
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.spring.boot.job.fixture.EmbedTestingServer;
import org.apache.shardingsphere.elasticjob.lite.spring.boot.job.fixture.job.impl.CustomTestJob;
import org.apache.shardingsphere.elasticjob.lite.spring.boot.reg.ZookeeperProperties;
@@ -90,7 +91,7 @@
ElasticJobProperties elasticJobProperties = applicationContext.getBean(ElasticJobProperties.class);
assertNotNull(elasticJobProperties);
assertNotNull(elasticJobProperties.getJobs());
- assertThat(elasticJobProperties.getJobs().size(), is(2));
+ assertThat(elasticJobProperties.getJobs().size(), is(4));
ElasticJobConfigurationProperties customTestJobProperties = elasticJobProperties.getJobs().get("customTestJob");
assertNotNull(customTestJobProperties);
assertThat(customTestJobProperties.getElasticJobClass(), is(CustomTestJob.class));
@@ -126,4 +127,18 @@
assertNotNull(applicationContext.getBean("customTestJobBean", OneOffJobBootstrap.class));
assertNotNull(applicationContext.getBean("printTestJobBean", OneOffJobBootstrap.class));
}
+
+ @Test
+ public void assertDefaultBeanNameWithClassJob() {
+ assertNotNull(applicationContext);
+ assertNotNull(applicationContext.getBean("defaultBeanNameClassJobScheduleJobBootstrap",
+ ScheduleJobBootstrap.class));
+ }
+
+ @Test
+ public void assertDefaultBeanNameWithTypeJob() {
+ assertNotNull(applicationContext);
+ assertNotNull(applicationContext.getBean("defaultBeanNameTypeJobScheduleJobBootstrap",
+ ScheduleJobBootstrap.class));
+ }
}
diff --git a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/reg/ZookeeperPropertiesTest.java b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/reg/ZookeeperPropertiesTest.java
new file mode 100644
index 0000000..ed02fa0
--- /dev/null
+++ b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/reg/ZookeeperPropertiesTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.spring.boot.reg;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
+import org.junit.Test;
+
+public final class ZookeeperPropertiesTest {
+
+ @Test
+ public void assertToZookeeperConfiguration() {
+ ZookeeperProperties properties = new ZookeeperProperties();
+ properties.setServerLists("localhost:18181");
+ properties.setNamespace("test");
+ properties.setBaseSleepTimeMilliseconds(2000);
+ properties.setMaxSleepTimeMilliseconds(4000);
+ properties.setMaxRetries(5);
+ properties.setSessionTimeoutMilliseconds(5000);
+ properties.setConnectionTimeoutMilliseconds(6000);
+ properties.setDigest("digest");
+ ZookeeperConfiguration actual = properties.toZookeeperConfiguration();
+ assertThat(actual.getServerLists(), is(properties.getServerLists()));
+ assertThat(actual.getNamespace(), is(properties.getNamespace()));
+ assertThat(actual.getBaseSleepTimeMilliseconds(), is(properties.getBaseSleepTimeMilliseconds()));
+ assertThat(actual.getMaxSleepTimeMilliseconds(), is(properties.getMaxSleepTimeMilliseconds()));
+ assertThat(actual.getMaxRetries(), is(properties.getMaxRetries()));
+ assertThat(actual.getSessionTimeoutMilliseconds(), is(properties.getSessionTimeoutMilliseconds()));
+ assertThat(actual.getConnectionTimeoutMilliseconds(), is(properties.getConnectionTimeoutMilliseconds()));
+ assertThat(actual.getDigest(), is(properties.getDigest()));
+ }
+}
diff --git a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/reg/snapshot/ElasticJobSnapshotServiceConfigurationTest.java b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/reg/snapshot/ElasticJobSnapshotServiceConfigurationTest.java
new file mode 100644
index 0000000..547599b
--- /dev/null
+++ b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/reg/snapshot/ElasticJobSnapshotServiceConfigurationTest.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.spring.boot.reg.snapshot;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.shardingsphere.elasticjob.lite.internal.snapshot.SnapshotService;
+import org.apache.shardingsphere.elasticjob.lite.spring.boot.job.fixture.EmbedTestingServer;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+@SpringBootTest
+@SpringBootApplication
+@ActiveProfiles("snapshot")
+public class ElasticJobSnapshotServiceConfigurationTest extends AbstractJUnit4SpringContextTests {
+
+ @BeforeClass
+ public static void init() {
+ EmbedTestingServer.start();
+ }
+
+ @Test
+ public void assertSnapshotServiceConfiguration() {
+ assertNotNull(applicationContext);
+ assertNotNull(applicationContext.getBean(SnapshotService.class));
+ }
+}
diff --git a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/resources/application-elasticjob.yml b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/resources/application-elasticjob.yml
index 1b058a4..e90702f 100644
--- a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/resources/application-elasticjob.yml
+++ b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/resources/application-elasticjob.yml
@@ -42,3 +42,13 @@
shardingTotalCount: 3
props:
print.content: "test print job"
+ defaultBeanNameClassJob:
+ cron: 0/5 * * * * ?
+ elasticJobClass: org.apache.shardingsphere.elasticjob.lite.spring.boot.job.fixture.job.impl.CustomTestJob
+ shardingTotalCount: 3
+ defaultBeanNameTypeJob:
+ cron: 0/5 * * * * ?
+ elasticJobType: PRINT
+ shardingTotalCount: 3
+ props:
+ print.content: "test print job"
diff --git a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/resources/application-snapshot.yml b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/resources/application-snapshot.yml
new file mode 100644
index 0000000..022757b
--- /dev/null
+++ b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/resources/application-snapshot.yml
@@ -0,0 +1,23 @@
+#
+# 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.
+#
+
+elasticjob:
+ dump:
+ port: 8888
+ regCenter:
+ serverLists: localhost:18181
+ namespace: elasticjob-lite-spring-boot-starter