You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/07/05 06:17:27 UTC
[shardingsphere-elasticjob-lite] branch master updated: Fixes #950
(#951)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob-lite.git
The following commit(s) were added to refs/heads/master by this push:
new bcd1552 Fixes #950 (#951)
bcd1552 is described below
commit bcd1552b805d12d21b97640ede2a3dcdd950c1d1
Author: Liang Zhang <te...@163.com>
AuthorDate: Sun Jul 5 14:17:20 2020 +0800
Fixes #950 (#951)
* Refactor DisabledJobIntegrateTest
* Refactor EnabledJobIntegrateTest
---
.../lite/integrate/BaseIntegrateTest.java | 54 ++--------------------
.../lite/integrate/DisabledJobIntegrateTest.java | 42 ++++++++++++++++-
.../lite/integrate/EnabledJobIntegrateTest.java | 30 +++++++++++-
3 files changed, 73 insertions(+), 53 deletions(-)
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/BaseIntegrateTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/BaseIntegrateTest.java
index 58ff84a..c902bf8 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/BaseIntegrateTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/BaseIntegrateTest.java
@@ -19,53 +19,41 @@ package org.apache.shardingsphere.elasticjob.lite.integrate;
import lombok.AccessLevel;
import lombok.Getter;
-import org.apache.shardingsphere.elasticjob.lite.api.job.ElasticJob;
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.api.job.ElasticJob;
+import org.apache.shardingsphere.elasticjob.lite.api.job.config.JobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.api.listener.AbstractDistributeOnceElasticJobListener;
import org.apache.shardingsphere.elasticjob.lite.api.listener.ElasticJobListener;
-import org.apache.shardingsphere.elasticjob.lite.api.job.config.JobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.executor.ShardingContexts;
import org.apache.shardingsphere.elasticjob.lite.fixture.EmbedTestingServer;
-import org.apache.shardingsphere.elasticjob.lite.internal.config.yaml.YamlJobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.internal.election.LeaderService;
import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
-import org.apache.shardingsphere.elasticjob.lite.internal.server.ServerStatus;
import org.apache.shardingsphere.elasticjob.lite.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.lite.reg.zookeeper.ZookeeperConfiguration;
import org.apache.shardingsphere.elasticjob.lite.reg.zookeeper.ZookeeperRegistryCenter;
import org.apache.shardingsphere.elasticjob.lite.util.ReflectionUtils;
-import org.apache.shardingsphere.elasticjob.lite.util.concurrent.BlockUtils;
-import org.apache.shardingsphere.elasticjob.lite.util.env.IpUtils;
-import org.apache.shardingsphere.elasticjob.lite.util.yaml.YamlEngine;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
+@Getter(AccessLevel.PROTECTED)
public abstract class BaseIntegrateTest {
private static ZookeeperConfiguration zkConfig = new ZookeeperConfiguration(EmbedTestingServer.getConnectionString(), "zkRegTestCenter");
- @Getter(value = AccessLevel.PROTECTED)
+ @Getter(AccessLevel.PROTECTED)
private static CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(zkConfig);
- @Getter(value = AccessLevel.PROTECTED)
private final ElasticJob elasticJob;
- @Getter(AccessLevel.PROTECTED)
private final JobConfiguration jobConfiguration;
private final JobBootstrap jobBootstrap;
private final LeaderService leaderService;
- @Getter(AccessLevel.PROTECTED)
private final String jobName = System.nanoTime() + "_test_job";
protected BaseIntegrateTest(final TestType type, final ElasticJob elasticJob) {
@@ -128,40 +116,6 @@ public abstract class BaseIntegrateTest {
ReflectionUtils.setFieldValue(JobRegistry.getInstance(), "instance", null);
}
- protected final void assertRegCenterCommonInfoWithEnabled() {
- assertRegCenterCommonInfo();
- assertTrue(leaderService.isLeaderUntilBlock());
- }
-
- protected final void assertRegCenterCommonInfoWithDisabled() {
- assertRegCenterCommonInfo();
- }
-
- private void assertRegCenterCommonInfo() {
- assertThat(JobRegistry.getInstance().getCurrentShardingTotalCount(jobName), is(3));
- assertThat(JobRegistry.getInstance().getJobInstance(jobName).getIp(), is(IpUtils.getIp()));
- JobConfiguration jobConfig = YamlEngine.unmarshal(regCenter.get("/" + jobName + "/config"), YamlJobConfiguration.class).toJobConfiguration();
- assertThat(jobConfig.getShardingTotalCount(), is(3));
- if (jobBootstrap instanceof ScheduleJobBootstrap) {
- assertThat(jobConfig.getCron(), is("0/1 * * * * ?"));
- } else {
- assertNull(jobConfig.getCron());
- }
- assertThat(jobConfig.getShardingItemParameters(), is("0=A,1=B,2=C"));
- if (jobConfiguration.isDisabled()) {
- assertThat(regCenter.get("/" + jobName + "/servers/" + JobRegistry.getInstance().getJobInstance(jobName).getIp()), is(ServerStatus.DISABLED.name()));
- while (null != regCenter.get("/" + jobName + "/leader/election/instance")) {
- BlockUtils.waitingShortTime();
- }
- regCenter.persist("/" + jobName + "/servers/" + JobRegistry.getInstance().getJobInstance(jobName).getIp(), "");
- } else {
- assertThat(regCenter.get("/" + jobName + "/servers/" + JobRegistry.getInstance().getJobInstance(jobName).getIp()), is(ServerStatus.ENABLED.name()));
- assertThat(regCenter.get("/" + jobName + "/leader/election/instance"), is(JobRegistry.getInstance().getJobInstance(jobName).getJobInstanceId()));
- }
- assertTrue(regCenter.isExisted("/" + jobName + "/instances/" + JobRegistry.getInstance().getJobInstance(jobName).getJobInstanceId()));
- regCenter.remove("/" + jobName + "/leader/election");
- }
-
public enum TestType {
SCHEDULE, ONE_OFF
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/DisabledJobIntegrateTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/DisabledJobIntegrateTest.java
index 0d1f695..ec419ff 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/DisabledJobIntegrateTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/DisabledJobIntegrateTest.java
@@ -17,10 +17,22 @@
package org.apache.shardingsphere.elasticjob.lite.integrate;
+import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap;
+import org.apache.shardingsphere.elasticjob.lite.api.job.config.JobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.executor.fixture.job.DetailedFooJob;
+import org.apache.shardingsphere.elasticjob.lite.internal.config.yaml.YamlJobConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
+import org.apache.shardingsphere.elasticjob.lite.internal.server.ServerStatus;
import org.apache.shardingsphere.elasticjob.lite.util.concurrent.BlockUtils;
+import org.apache.shardingsphere.elasticjob.lite.util.env.IpUtils;
+import org.apache.shardingsphere.elasticjob.lite.util.yaml.YamlEngine;
import org.junit.Test;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
public abstract class DisabledJobIntegrateTest extends BaseIntegrateTest {
public DisabledJobIntegrateTest(final TestType type) {
@@ -30,6 +42,34 @@ public abstract class DisabledJobIntegrateTest extends BaseIntegrateTest {
@Test
public final void assertJobRunning() {
BlockUtils.waitingShortTime();
- assertRegCenterCommonInfoWithDisabled();
+ assertDisabledRegCenterInfo();
+ setJobEnable();
+ assertEnabledRegCenterInfo();
+ }
+
+ private void assertDisabledRegCenterInfo() {
+ assertThat(JobRegistry.getInstance().getCurrentShardingTotalCount(getJobName()), is(3));
+ assertThat(JobRegistry.getInstance().getJobInstance(getJobName()).getIp(), is(IpUtils.getIp()));
+ JobConfiguration jobConfig = YamlEngine.unmarshal(getRegCenter().get("/" + getJobName() + "/config"), YamlJobConfiguration.class).toJobConfiguration();
+ assertThat(jobConfig.getShardingTotalCount(), is(3));
+ if (getJobBootstrap() instanceof ScheduleJobBootstrap) {
+ assertThat(jobConfig.getCron(), is("0/1 * * * * ?"));
+ } else {
+ assertNull(jobConfig.getCron());
+ }
+ assertThat(jobConfig.getShardingItemParameters(), is("0=A,1=B,2=C"));
+ assertThat(getRegCenter().get("/" + getJobName() + "/servers/" + JobRegistry.getInstance().getJobInstance(getJobName()).getIp()), is(ServerStatus.DISABLED.name()));
+ while (null != getRegCenter().get("/" + getJobName() + "/leader/election/instance")) {
+ BlockUtils.waitingShortTime();
+ }
+ }
+
+ private void setJobEnable() {
+ getRegCenter().persist("/" + getJobName() + "/servers/" + JobRegistry.getInstance().getJobInstance(getJobName()).getIp(), ServerStatus.ENABLED.name());
+ }
+
+ private void assertEnabledRegCenterInfo() {
+ assertTrue(getRegCenter().isExisted("/" + getJobName() + "/instances/" + JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId()));
+ getRegCenter().remove("/" + getJobName() + "/leader/election");
}
}
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/EnabledJobIntegrateTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/EnabledJobIntegrateTest.java
index 28e99c6..4bf8ec0 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/EnabledJobIntegrateTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/EnabledJobIntegrateTest.java
@@ -17,9 +17,21 @@
package org.apache.shardingsphere.elasticjob.lite.integrate;
+import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap;
import org.apache.shardingsphere.elasticjob.lite.api.job.ElasticJob;
+import org.apache.shardingsphere.elasticjob.lite.api.job.config.JobConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.internal.config.yaml.YamlJobConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
+import org.apache.shardingsphere.elasticjob.lite.internal.server.ServerStatus;
+import org.apache.shardingsphere.elasticjob.lite.util.env.IpUtils;
+import org.apache.shardingsphere.elasticjob.lite.util.yaml.YamlEngine;
import org.junit.Before;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
public abstract class EnabledJobIntegrateTest extends BaseIntegrateTest {
protected EnabledJobIntegrateTest(final TestType type, final ElasticJob elasticJob) {
@@ -31,7 +43,21 @@ public abstract class EnabledJobIntegrateTest extends BaseIntegrateTest {
}
@Before
- public final void autoSchedule() {
- assertRegCenterCommonInfoWithEnabled();
+ public final void assertEnabledRegCenterInfo() {
+ assertThat(JobRegistry.getInstance().getCurrentShardingTotalCount(getJobName()), is(3));
+ assertThat(JobRegistry.getInstance().getJobInstance(getJobName()).getIp(), is(IpUtils.getIp()));
+ JobConfiguration jobConfig = YamlEngine.unmarshal(getRegCenter().get("/" + getJobName() + "/config"), YamlJobConfiguration.class).toJobConfiguration();
+ assertThat(jobConfig.getShardingTotalCount(), is(3));
+ if (getJobBootstrap() instanceof ScheduleJobBootstrap) {
+ assertThat(jobConfig.getCron(), is("0/1 * * * * ?"));
+ } else {
+ assertNull(jobConfig.getCron());
+ }
+ assertThat(jobConfig.getShardingItemParameters(), is("0=A,1=B,2=C"));
+ assertThat(getRegCenter().get("/" + getJobName() + "/servers/" + JobRegistry.getInstance().getJobInstance(getJobName()).getIp()), is(ServerStatus.ENABLED.name()));
+ assertThat(getRegCenter().get("/" + getJobName() + "/leader/election/instance"), is(JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId()));
+ assertTrue(getRegCenter().isExisted("/" + getJobName() + "/instances/" + JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId()));
+ getRegCenter().remove("/" + getJobName() + "/leader/election");
+ assertTrue(getLeaderService().isLeaderUntilBlock());
}
}