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 03:04:22 UTC

[shardingsphere-elasticjob-lite] branch master updated: Decouple simple job and monitor service test (#945)

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 ca73e42  Decouple simple job and monitor service test (#945)
ca73e42 is described below

commit ca73e424d007a418d6713b741b071d45fc587f33
Author: Liang Zhang <te...@163.com>
AuthorDate: Sun Jul 5 11:04:12 2020 +0800

    Decouple simple job and monitor service test (#945)
    
    * Rename FooSimpleJob
    
    * Decouple simple job and monitor service test
---
 .../lite/integrate/DisabledJobIntegrateTest.java          |  8 ++++----
 .../enable/oneoff/simple/SimpleElasticJobTest.java        |  8 ++++----
 .../enable/schedule/simple/SimpleElasticJobTest.java      |  8 ++++----
 .../{FooSimpleElasticJob.java => FooSimpleJob.java}       |  2 +-
 .../lite/internal/monitor/BaseMonitorServiceTest.java     | 15 ++++++---------
 .../lite/internal/monitor/MonitorServiceDisableTest.java  |  6 +++---
 .../lite/internal/monitor/MonitorServiceEnableTest.java   | 11 ++++-------
 7 files changed, 26 insertions(+), 32 deletions(-)

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 92cbd06..b5d3fb7 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,7 +17,7 @@
 
 package org.apache.shardingsphere.elasticjob.lite.integrate;
 
-import org.apache.shardingsphere.elasticjob.lite.integrate.fixture.simple.FooSimpleElasticJob;
+import org.apache.shardingsphere.elasticjob.lite.integrate.fixture.simple.FooSimpleJob;
 import org.apache.shardingsphere.elasticjob.lite.util.concurrent.BlockUtils;
 import org.junit.After;
 import org.junit.Before;
@@ -26,19 +26,19 @@ import org.junit.Test;
 public abstract class DisabledJobIntegrateTest extends BaseIntegrateTest {
     
     public DisabledJobIntegrateTest(final TestType type) {
-        super(type, new FooSimpleElasticJob());
+        super(type, new FooSimpleJob());
     }
     
     @Before
     @After
     public void reset() {
-        FooSimpleElasticJob.reset();
+        FooSimpleJob.reset();
     }
     
     @Test
     public final void assertJobRunning() {
         assertRegCenterCommonInfoWithDisabled();
-        while (!FooSimpleElasticJob.isCompleted()) {
+        while (!FooSimpleJob.isCompleted()) {
             BlockUtils.waitingShortTime();
         }
     }
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/assertion/enable/oneoff/simple/SimpleElasticJobTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/assertion/enable/oneoff/simple/SimpleElasticJobTest.java
index ce83c0f..ee18942 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/assertion/enable/oneoff/simple/SimpleElasticJobTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/assertion/enable/oneoff/simple/SimpleElasticJobTest.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.elasticjob.lite.integrate.assertion.enable.one
 
 import org.apache.shardingsphere.elasticjob.lite.api.job.config.JobConfiguration;
 import org.apache.shardingsphere.elasticjob.lite.integrate.EnabledJobIntegrateTest;
-import org.apache.shardingsphere.elasticjob.lite.integrate.fixture.simple.FooSimpleElasticJob;
+import org.apache.shardingsphere.elasticjob.lite.integrate.fixture.simple.FooSimpleJob;
 import org.apache.shardingsphere.elasticjob.lite.util.concurrent.BlockUtils;
 import org.junit.After;
 import org.junit.Before;
@@ -30,13 +30,13 @@ import static org.junit.Assert.assertTrue;
 public final class SimpleElasticJobTest extends EnabledJobIntegrateTest {
     
     public SimpleElasticJobTest() {
-        super(TestType.ONE_OFF, new FooSimpleElasticJob());
+        super(TestType.ONE_OFF, new FooSimpleJob());
     }
     
     @Before
     @After
     public void reset() {
-        FooSimpleElasticJob.reset();
+        FooSimpleJob.reset();
     }
     
     @Override
@@ -46,7 +46,7 @@ public final class SimpleElasticJobTest extends EnabledJobIntegrateTest {
     
     @Test
     public void assertJobInit() {
-        while (!FooSimpleElasticJob.isCompleted()) {
+        while (!FooSimpleJob.isCompleted()) {
             BlockUtils.waitingShortTime();
         }
         assertTrue(getRegCenter().isExisted("/" + getJobName() + "/sharding"));
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/assertion/enable/schedule/simple/SimpleElasticJobTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/assertion/enable/schedule/simple/SimpleElasticJobTest.java
index 27af8af..bb83486 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/assertion/enable/schedule/simple/SimpleElasticJobTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/assertion/enable/schedule/simple/SimpleElasticJobTest.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.elasticjob.lite.integrate.assertion.enable.sch
 
 import org.apache.shardingsphere.elasticjob.lite.api.job.config.JobConfiguration;
 import org.apache.shardingsphere.elasticjob.lite.integrate.EnabledJobIntegrateTest;
-import org.apache.shardingsphere.elasticjob.lite.integrate.fixture.simple.FooSimpleElasticJob;
+import org.apache.shardingsphere.elasticjob.lite.integrate.fixture.simple.FooSimpleJob;
 import org.apache.shardingsphere.elasticjob.lite.util.concurrent.BlockUtils;
 import org.junit.After;
 import org.junit.Before;
@@ -30,13 +30,13 @@ import static org.junit.Assert.assertTrue;
 public final class SimpleElasticJobTest extends EnabledJobIntegrateTest {
     
     public SimpleElasticJobTest() {
-        super(TestType.SCHEDULE, new FooSimpleElasticJob());
+        super(TestType.SCHEDULE, new FooSimpleJob());
     }
     
     @Before
     @After
     public void reset() {
-        FooSimpleElasticJob.reset();
+        FooSimpleJob.reset();
     }
     
     @Override
@@ -46,7 +46,7 @@ public final class SimpleElasticJobTest extends EnabledJobIntegrateTest {
     
     @Test
     public void assertJobInit() {
-        while (!FooSimpleElasticJob.isCompleted()) {
+        while (!FooSimpleJob.isCompleted()) {
             BlockUtils.waitingShortTime();
         }
         assertTrue(getRegCenter().isExisted("/" + getJobName() + "/sharding"));
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/fixture/simple/FooSimpleElasticJob.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/fixture/simple/FooSimpleJob.java
similarity index 95%
rename from elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/fixture/simple/FooSimpleElasticJob.java
rename to elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/fixture/simple/FooSimpleJob.java
index 485984c..e8264a2 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/fixture/simple/FooSimpleElasticJob.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/fixture/simple/FooSimpleJob.java
@@ -21,7 +21,7 @@ import lombok.Getter;
 import org.apache.shardingsphere.elasticjob.lite.api.job.ShardingContext;
 import org.apache.shardingsphere.elasticjob.lite.api.job.type.SimpleJob;
 
-public final class FooSimpleElasticJob implements SimpleJob {
+public final class FooSimpleJob implements SimpleJob {
     
     @Getter
     private static volatile boolean completed;
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/monitor/BaseMonitorServiceTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/monitor/BaseMonitorServiceTest.java
index 7a80cb1..1bdf904 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/monitor/BaseMonitorServiceTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/monitor/BaseMonitorServiceTest.java
@@ -19,8 +19,8 @@ package org.apache.shardingsphere.elasticjob.lite.internal.monitor;
 
 import lombok.AccessLevel;
 import lombok.Getter;
-import org.apache.shardingsphere.elasticjob.lite.api.job.ElasticJob;
 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.fixture.EmbedTestingServer;
 import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
@@ -34,12 +34,12 @@ import org.junit.BeforeClass;
 
 public abstract class BaseMonitorServiceTest {
     
-    protected static final int MONITOR_PORT = 9000;
+    static final int MONITOR_PORT = 9000;
     
     private static ZookeeperConfiguration zkConfig = new ZookeeperConfiguration(EmbedTestingServer.getConnectionString(), "zkRegTestCenter");
     
     private static CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(zkConfig);
-
+    
     @Getter(value = AccessLevel.PROTECTED)
     private static MonitorService monitorService = new MonitorService(regCenter, MONITOR_PORT);
     
@@ -60,17 +60,14 @@ public abstract class BaseMonitorServiceTest {
     }
     
     @Before
-    public void setUp() {
+    public final void setUp() {
         regCenter.init();
+        bootstrap.schedule();
     }
     
     @After
-    public void tearDown() {
+    public final void tearDown() {
         bootstrap.shutdown();
         ReflectionUtils.setFieldValue(JobRegistry.getInstance(), "instance", null);
     }
-    
-    protected final void scheduleJob() {
-        bootstrap.schedule();
-    }
 }
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/monitor/MonitorServiceDisableTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/monitor/MonitorServiceDisableTest.java
index 31037e1..8b59773 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/monitor/MonitorServiceDisableTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/monitor/MonitorServiceDisableTest.java
@@ -17,7 +17,7 @@
 
 package org.apache.shardingsphere.elasticjob.lite.internal.monitor;
 
-import org.apache.shardingsphere.elasticjob.lite.integrate.fixture.simple.FooSimpleElasticJob;
+import org.apache.shardingsphere.elasticjob.lite.executor.fixture.job.DetailedFooJob;
 import org.junit.Test;
 
 import java.io.IOException;
@@ -25,11 +25,11 @@ import java.io.IOException;
 public final class MonitorServiceDisableTest extends BaseMonitorServiceTest {
     
     public MonitorServiceDisableTest() {
-        super(new FooSimpleElasticJob());
+        super(new DetailedFooJob());
     }
     
     @Test(expected = IOException.class)
     public void assertMonitorWithDumpCommand() throws IOException {
-        SocketUtils.sendCommand(MonitorService.DUMP_COMMAND, 9000 - 1);
+        SocketUtils.sendCommand(MonitorService.DUMP_COMMAND, MONITOR_PORT - 1);
     }
 }
diff --git a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/monitor/MonitorServiceEnableTest.java b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/monitor/MonitorServiceEnableTest.java
index 142746b..7222e0a 100644
--- a/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/monitor/MonitorServiceEnableTest.java
+++ b/elastic-job-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/monitor/MonitorServiceEnableTest.java
@@ -17,7 +17,7 @@
 
 package org.apache.shardingsphere.elasticjob.lite.internal.monitor;
 
-import org.apache.shardingsphere.elasticjob.lite.integrate.fixture.simple.FooSimpleElasticJob;
+import org.apache.shardingsphere.elasticjob.lite.executor.fixture.job.DetailedFooJob;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -30,24 +30,21 @@ import static org.junit.Assert.assertNull;
 public final class MonitorServiceEnableTest extends BaseMonitorServiceTest {
     
     public MonitorServiceEnableTest() {
-        super(new FooSimpleElasticJob());
+        super(new DetailedFooJob());
     }
     
     @Before
-    public void setUp() {
-        super.setUp();
+    public void listenMonitor() {
         getMonitorService().listen();
     }
     
     @After
-    public void tearDown() {
-        super.tearDown();
+    public void closeMonitor() {
         getMonitorService().close();
     }
     
     @Test
     public void assertMonitorWithCommand() throws IOException {
-        scheduleJob();
         assertNotNull(SocketUtils.sendCommand(MonitorService.DUMP_COMMAND + getJobName(), MONITOR_PORT));
         assertNull(SocketUtils.sendCommand("unknown_command", MONITOR_PORT));
     }