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/23 02:20:08 UTC
[shardingsphere-elasticjob] branch master updated: Add test for
CloudJobConfigurationListenerTest (#1208) (#1258)
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.git
The following commit(s) were added to refs/heads/master by this push:
new 89e6729 Add test for CloudJobConfigurationListenerTest (#1208) (#1258)
89e6729 is described below
commit 89e67299d9e9a0dabe2c2177ad0b887f552622f2
Author: luky116 <38...@users.noreply.github.com>
AuthorDate: Thu Jul 23 10:20:01 2020 +0800
Add test for CloudJobConfigurationListenerTest (#1208) (#1258)
* Add test for CloudJobConfigurationListenerTest (#1208)
---
.../job/CloudJobConfigurationListenerTest.java | 35 ++++++++++++++++++++++
.../scheduler/fixture/EmbedTestingServer.java | 9 ++++++
2 files changed, 44 insertions(+)
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/job/CloudJobConfigurationListenerTest.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/job/CloudJobConfigurationListenerTest.java
index e1501fd..2c4d9e8 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/job/CloudJobConfigurationListenerTest.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/job/CloudJobConfigurationListenerTest.java
@@ -22,8 +22,11 @@ import org.apache.curator.framework.recipes.cache.CuratorCacheListener.Type;
import org.apache.shardingsphere.elasticjob.cloud.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.cloud.config.CloudJobExecutionType;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudJsonConstants;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.EmbedTestingServer;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.producer.ProducerManager;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.ready.ReadyService;
+import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
+import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -40,6 +43,8 @@ import static org.mockito.Mockito.verify;
@RunWith(MockitoJUnitRunner.class)
public final class CloudJobConfigurationListenerTest {
+ private static ZookeeperRegistryCenter regCenter;
+
@Mock
private ProducerManager producerManager;
@@ -53,6 +58,18 @@ public final class CloudJobConfigurationListenerTest {
public void setUp() {
ReflectionUtils.setFieldValue(cloudJobConfigurationListener, "producerManager", producerManager);
ReflectionUtils.setFieldValue(cloudJobConfigurationListener, "readyService", readyService);
+ initRegistryCenter();
+ ReflectionUtils.setFieldValue(cloudJobConfigurationListener, "regCenter", regCenter);
+ }
+
+ private void initRegistryCenter() {
+ EmbedTestingServer.start();
+ ZookeeperConfiguration configuration = new ZookeeperConfiguration(EmbedTestingServer.getConnectionString(), CloudJobConfigurationListenerTest.class.getName());
+ configuration.setDigest("digest:password");
+ configuration.setSessionTimeoutMilliseconds(5000);
+ configuration.setConnectionTimeoutMilliseconds(5000);
+ regCenter = new ZookeeperRegistryCenter(configuration);
+ regCenter.init();
}
@Test
@@ -111,4 +128,22 @@ public final class CloudJobConfigurationListenerTest {
cloudJobConfigurationListener.event(Type.NODE_DELETED, null, new ChildData("/config/job/test_job", null, "".getBytes()));
verify(producerManager).unschedule("test_job");
}
+
+ @Test
+ public void assertChildEventWhenStateIsUpdateAndIsConfigPath() {
+ cloudJobConfigurationListener.event(Type.NODE_CHANGED, null, new ChildData("/config/job/test_job", null, "".getBytes()));
+ }
+
+ @Test
+ public void assertStart() {
+ cloudJobConfigurationListener.start();
+ }
+
+ @Test
+ public void assertStop() {
+ regCenter.addCacheData(CloudJobConfigurationNode.ROOT);
+ ReflectionUtils.setFieldValue(cloudJobConfigurationListener, "regCenter", regCenter);
+ cloudJobConfigurationListener.stop();
+ }
+
}
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/fixture/EmbedTestingServer.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/fixture/EmbedTestingServer.java
index 07f1065..f5afa58 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/fixture/EmbedTestingServer.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/fixture/EmbedTestingServer.java
@@ -55,5 +55,14 @@ public final class EmbedTestingServer {
}));
}
}
+
+ /**
+ * Get the connection string.
+ *
+ * @return connection string
+ */
+ public static String getConnectionString() {
+ return "localhost:" + PORT;
+ }
}