You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ke...@apache.org on 2022/01/06 01:56:36 UTC

[dolphinscheduler] branch dev updated: [Bug-7832, Improvement] Add unit test for worker module, fix apache#7832. Optimize HttpUtils and HttpUtilsTest 1. Checking input parameters of getResponseContentString 2. Add unit test (#7798)

This is an automated email from the ASF dual-hosted git repository.

kerwin pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new 0911fd7  [Bug-7832, Improvement] Add unit test for worker module, fix apache#7832. Optimize HttpUtils and HttpUtilsTest 1. Checking input parameters of getResponseContentString 2. Add unit test (#7798)
0911fd7 is described below

commit 0911fd711d84a3aa6febf26246a146ec4af3bfc9
Author: springmonster <ch...@163.com>
AuthorDate: Thu Jan 6 09:56:30 2022 +0800

    [Bug-7832, Improvement] Add unit test for worker module, fix apache#7832. Optimize HttpUtils and HttpUtilsTest 1. Checking input parameters of getResponseContentString 2. Add unit test (#7798)
---
 .../dolphinscheduler/common/utils/HttpUtils.java    |  5 +++++
 .../common/utils/HttpUtilsTest.java                 |  6 ++++++
 .../worker/registry/WorkerRegistryClientTest.java   | 21 ++++++++++++++++-----
 3 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HttpUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HttpUtils.java
index 36b437f..b5168c2 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HttpUtils.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HttpUtils.java
@@ -41,6 +41,7 @@ import java.security.KeyManagementException;
 import java.security.NoSuchAlgorithmException;
 import java.security.cert.X509Certificate;
 import java.util.Arrays;
+import java.util.Objects;
 
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.TrustManager;
@@ -141,6 +142,10 @@ public class HttpUtils {
      * @return http get request response content
      */
     public static String getResponseContentString(HttpGet httpget, CloseableHttpClient httpClient) {
+        if (Objects.isNull(httpget) || Objects.isNull(httpClient)) {
+            logger.error("HttpGet or HttpClient parameter is null");
+            return null;
+        }
         String responseContent = null;
         CloseableHttpResponse response = null;
         try {
diff --git a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HttpUtilsTest.java b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HttpUtilsTest.java
index f9ce989..d97a2ea 100644
--- a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HttpUtilsTest.java
+++ b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HttpUtilsTest.java
@@ -73,6 +73,12 @@ public class HttpUtilsTest {
 	httpget.setConfig(requestConfig);
 	String responseContent = HttpUtils.getResponseContentString(httpget, httpclient);
 	Assert.assertNotNull(responseContent);
+	
+	responseContent = HttpUtils.getResponseContentString(null, httpclient);
+	Assert.assertNull(responseContent);
+	
+	responseContent = HttpUtils.getResponseContentString(httpget, null);
+	Assert.assertNull(responseContent);
     }
 
 
diff --git a/dolphinscheduler-worker/src/test/java/org/apache/dolphinscheduler/server/worker/worker/registry/WorkerRegistryClientTest.java b/dolphinscheduler-worker/src/test/java/org/apache/dolphinscheduler/server/worker/worker/registry/WorkerRegistryClientTest.java
index 245107a..56af82d 100644
--- a/dolphinscheduler-worker/src/test/java/org/apache/dolphinscheduler/server/worker/worker/registry/WorkerRegistryClientTest.java
+++ b/dolphinscheduler-worker/src/test/java/org/apache/dolphinscheduler/server/worker/worker/registry/WorkerRegistryClientTest.java
@@ -19,7 +19,9 @@ package org.apache.dolphinscheduler.server.worker.registry;
 
 import static org.mockito.BDDMockito.given;
 
+import org.apache.dolphinscheduler.common.enums.NodeType;
 import org.apache.dolphinscheduler.server.worker.config.WorkerConfig;
+import org.apache.dolphinscheduler.server.worker.runner.WorkerManagerThread;
 import org.apache.dolphinscheduler.service.registry.RegistryClient;
 
 import java.util.Set;
@@ -63,6 +65,9 @@ public class WorkerRegistryClientTest {
     @Mock
     private ScheduledExecutorService heartBeatExecutor;
 
+    @Mock
+    private WorkerManagerThread workerManagerThread;
+    
     //private static final Set<String> workerGroups;
 
     static {
@@ -80,11 +85,17 @@ public class WorkerRegistryClientTest {
 
     @Test
     public void testRegistry() {
-        //workerRegistryClient.initWorkRegistry();
-        //Set<String> workerGroups = Sets.newHashSet("127.0.0.1");
-        //workerRegistryClient.registry();
-       // workerRegistryClient.handleDeadServer();
-
+        workerRegistryClient.initWorkRegistry();
+    
+        given(workerManagerThread.getThreadPoolQueueSize()).willReturn(1);
+    
+        given(registryClient.checkNodeExists(Mockito.anyString(), Mockito.any(NodeType.class))).willReturn(true);
+    
+        given(workerConfig.getHeartbeatInterval()).willReturn(1);
+    
+        workerRegistryClient.registry();
+    
+        Mockito.verify(registryClient, Mockito.times(1)).handleDeadServer(Mockito.anyCollection(), Mockito.any(NodeType.class), Mockito.anyString());
     }
 
     @Test