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 36b437f31..b5168c263 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 f9ce989f7..d97a2ea45 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 245107a78..56af82d9d 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 workerGroups; static { @@ -80,11 +85,17 @@ public class WorkerRegistryClientTest { @Test public void testRegistry() { - //workerRegistryClient.initWorkRegistry(); - //Set 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