You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ch...@apache.org on 2022/10/10 02:43:46 UTC

[dolphinscheduler] branch dev updated: [Improvement][Test] Fully remove the usage of powermock from the whole project (#12244)

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

chufenggao 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 9ab79e064c [Improvement][Test] Fully remove the usage of powermock from the whole project (#12244)
9ab79e064c is described below

commit 9ab79e064cce90d02adf18343a14d8f7cddc3fae
Author: Eric Gao <er...@gmail.com>
AuthorDate: Mon Oct 10 10:43:38 2022 +0800

    [Improvement][Test] Fully remove the usage of powermock from the whole project (#12244)
    
    * Fully remove the usage of powermock from the whole project
    
    * Upgrade org.reflections to 0.10.12
---
 .../apache/dolphinscheduler/alert/AlertServer.java | 12 ++--
 .../dolphinscheduler/alert/AlertServerTest.java    | 47 ++++++++++++----
 dolphinscheduler-bom/pom.xml                       |  8 ++-
 dolphinscheduler-common/pom.xml                    |  7 +++
 .../apache/dolphinscheduler/common/Constants.java  |  4 --
 .../common/utils/KubernetesUtils.java              | 20 +++----
 .../dolphinscheduler/common/utils/NetUtils.java    | 15 +++--
 .../common/utils/CommonUtilsTest.java              | 13 ++---
 .../common/utils/FileUtilsTest.java                | 24 ++++----
 .../common/utils/HadoopUtilsTest.java              | 24 ++++----
 .../common/utils/NetUtilsTest.java                 | 64 ++++++++++++----------
 .../factory/NettyRemotingClientFactory.java        |  2 +-
 .../remote/factory/NettyRemotingServerFactory.java | 21 +++----
 .../dolphinscheduler/rpc/config/ServiceBean.java   |  2 +-
 .../service/alert/AlertClientService.java          |  2 +-
 .../dolphinscheduler/service/log/LogClient.java    |  2 +-
 .../service/alert/AlertClientServiceTest.java      |  2 +-
 .../service/log/LogClientTest.java                 |  2 +-
 .../dolphinscheduler/spi/utils/DateUtils.java      |  8 +--
 .../processor/TaskDispatchProcessorTest.java       | 21 +++----
 pom.xml                                            | 19 -------
 tools/dependencies/known-dependencies.txt          |  4 +-
 22 files changed, 158 insertions(+), 165 deletions(-)

diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java
index 8f27dcb3e4..b40830be26 100644
--- a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java
+++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java
@@ -23,7 +23,7 @@ import org.apache.dolphinscheduler.common.thread.ThreadUtils;
 import org.apache.dolphinscheduler.dao.PluginDao;
 import org.apache.dolphinscheduler.remote.NettyRemotingServer;
 import org.apache.dolphinscheduler.remote.command.CommandType;
-import org.apache.dolphinscheduler.remote.config.NettyServerConfig;
+import org.apache.dolphinscheduler.remote.factory.NettyRemotingServerFactory;
 
 import java.io.Closeable;
 
@@ -108,20 +108,16 @@ public class AlertServer implements Closeable {
         }
     }
 
-    private void checkTable() {
+    protected void checkTable() {
         if (!pluginDao.checkPluginDefineTableExist()) {
             logger.error("Plugin Define Table t_ds_plugin_define Not Exist . Please Create it First !");
             System.exit(1);
         }
     }
 
-    private void startServer() {
-        NettyServerConfig serverConfig = new NettyServerConfig();
-        serverConfig.setListenPort(alertConfig.getPort());
-
-        nettyRemotingServer = new NettyRemotingServer(serverConfig);
+    protected void startServer() {
+        nettyRemotingServer = NettyRemotingServerFactory.buildNettyRemotingServer(alertConfig.getPort());
         nettyRemotingServer.registerProcessor(CommandType.ALERT_SEND_REQUEST, alertRequestProcessor);
         nettyRemotingServer.start();
     }
-
 }
diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java
index 63381a2619..171c8ccbc4 100644
--- a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java
+++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java
@@ -17,18 +17,26 @@
 
 package org.apache.dolphinscheduler.alert;
 
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
 import org.apache.dolphinscheduler.dao.PluginDao;
 import org.apache.dolphinscheduler.remote.NettyRemotingServer;
-import org.apache.dolphinscheduler.remote.config.NettyServerConfig;
-import org.junit.jupiter.api.Assertions;
+import org.apache.dolphinscheduler.remote.factory.NettyRemotingServerFactory;
+
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
+import org.mockito.MockedStatic;
 import org.mockito.Mockito;
+import org.mockito.Spy;
 import org.mockito.junit.jupiter.MockitoExtension;
-import org.powermock.reflect.Whitebox;
 
 @ExtendWith(MockitoExtension.class)
 public class AlertServerTest {
@@ -42,7 +50,11 @@ public class AlertServerTest {
     @Mock
     private AlertSenderService alertSenderService;
 
+    @Mock
+    private NettyRemotingServer nettyRemotingServer;
+
     @InjectMocks
+    @Spy
     private AlertServer alertServer;
 
     @BeforeEach
@@ -50,20 +62,31 @@ public class AlertServerTest {
         Mockito.lenient().when(pluginDao.checkPluginDefineTableExist()).thenReturn(true);
 
         Mockito.lenient().when(alertConfig.getPort()).thenReturn(50052);
-
-        Mockito.doNothing().when(alertSenderService).start();
-
     }
+
     @Test
-    public void alertServerStartSuccessfully() {
+    public void alertServerRunSuccessfully() {
+        doNothing().when(alertServer).checkTable();
+        doNothing().when(alertServer).startServer();
 
         alertServer.run(null);
 
-        NettyRemotingServer nettyRemotingServer = Whitebox.getInternalState(alertServer, "nettyRemotingServer");
-
-        NettyServerConfig nettyServerConfig = Whitebox.getInternalState(nettyRemotingServer, "serverConfig");
-
-        Assertions.assertEquals(50052, nettyServerConfig.getListenPort());
+        Mockito.verify(alertServer, times(1)).checkTable();
+        Mockito.verify(alertServer, times(1)).startServer();
+        Mockito.verify(alertSenderService, times(1)).start();
+    }
 
+    @Test
+    public void alertServerServerStartWithExpectedListeningPort() {
+        try (
+                MockedStatic<NettyRemotingServerFactory> mockedNettyRemotingServerFactory =
+                        mockStatic(NettyRemotingServerFactory.class)) {
+            mockedNettyRemotingServerFactory.when(() -> NettyRemotingServerFactory.buildNettyRemotingServer(anyInt()))
+                    .thenReturn(nettyRemotingServer);
+            alertServer.startServer();
+            mockedNettyRemotingServerFactory.verify(() -> NettyRemotingServerFactory.buildNettyRemotingServer(50052));
+            verify(nettyRemotingServer, times(1)).registerProcessor(any(), any());
+            verify(nettyRemotingServer, times(1)).start();
+        }
     }
 }
diff --git a/dolphinscheduler-bom/pom.xml b/dolphinscheduler-bom/pom.xml
index 95b8c848b6..3267ad3578 100644
--- a/dolphinscheduler-bom/pom.xml
+++ b/dolphinscheduler-bom/pom.xml
@@ -77,7 +77,7 @@
         <servlet-api.version>2.5</servlet-api.version>
         <springfox.version>3.0.0</springfox.version>
         <guava-retry.version>2.0.0</guava-retry.version>
-        <reflections.version>0.9.12</reflections.version>
+        <reflections.version>0.10.2</reflections.version>
         <py4j.version>0.10.9</py4j.version>
         <jsr305.version>3.0.0</jsr305.version>
         <commons-compress.version>1.21</commons-compress.version>
@@ -162,6 +162,12 @@
                 <groupId>com.cronutils</groupId>
                 <artifactId>cron-utils</artifactId>
                 <version>${cron-utils.version}</version>
+                <exclusions>
+                    <exclusion>
+                        <groupId>org.javassist</groupId>
+                        <artifactId>javassist</artifactId>
+                    </exclusion>
+                </exclusions>
             </dependency>
 
             <dependency>
diff --git a/dolphinscheduler-common/pom.xml b/dolphinscheduler-common/pom.xml
index ea698aeecd..00806f5298 100644
--- a/dolphinscheduler-common/pom.xml
+++ b/dolphinscheduler-common/pom.xml
@@ -65,6 +65,13 @@
             <artifactId>mockito-core</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-inline</artifactId>
+            <version>3.12.4</version>
+            <!-- TODO: move this dependency to root pom after removing powermock in the whole project -->
+            <scope>test</scope>
+        </dependency>
 
         <dependency>
             <groupId>org.springframework</groupId>
diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java
index 042b28a980..81a0272e4d 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java
@@ -20,7 +20,6 @@ package org.apache.dolphinscheduler.common;
 import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus;
 import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
 
-import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.SystemUtils;
 
 import java.time.Duration;
@@ -797,9 +796,6 @@ public final class Constants {
      */
     public static final String PSTREE = "pstree";
 
-    public static final boolean KUBERNETES_MODE = !StringUtils.isEmpty(System.getenv("KUBERNETES_SERVICE_HOST"))
-            && !StringUtils.isEmpty(System.getenv("KUBERNETES_SERVICE_PORT"));
-
     /**
      * dry run flag
      */
diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/factory/NettyRemotingClientFactory.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/KubernetesUtils.java
similarity index 56%
copy from dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/factory/NettyRemotingClientFactory.java
copy to dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/KubernetesUtils.java
index 450b052be4..cb5616181f 100644
--- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/factory/NettyRemotingClientFactory.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/KubernetesUtils.java
@@ -15,24 +15,18 @@
  * limitations under the License.
  */
 
-package org.apache.dolphinscheduler.service.factory;
+package org.apache.dolphinscheduler.common.utils;
 
-import org.apache.dolphinscheduler.remote.NettyRemotingClient;
-import org.apache.dolphinscheduler.remote.config.NettyClientConfig;
+import org.apache.commons.lang3.StringUtils;
 
 import lombok.experimental.UtilityClass;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 @UtilityClass
-public class NettyRemotingClientFactory {
-
-    private final Logger logger = LoggerFactory.getLogger(NettyRemotingClientFactory.class);
+public class KubernetesUtils {
 
-    public NettyRemotingClient buildNettyRemotingClient() {
-        NettyClientConfig nettyClientConfig = new NettyClientConfig();
-        logger.info("NettyRemotingClient initialized with config: {}", nettyClientConfig);
-        return new NettyRemotingClient(nettyClientConfig);
+    public boolean isKubernetesMode() {
+        return !StringUtils.isEmpty(System.getenv("KUBERNETES_SERVICE_HOST"))
+                && !StringUtils.isEmpty(System.getenv("KUBERNETES_SERVICE_PORT"));
     }
+
 }
diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/NetUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/NetUtils.java
index f7027cf78b..39796d5d40 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/NetUtils.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/NetUtils.java
@@ -21,6 +21,8 @@ import static java.util.Collections.emptyList;
 
 import org.apache.dolphinscheduler.common.Constants;
 
+import org.apache.http.conn.util.InetAddressUtils;
+
 import java.io.IOException;
 import java.net.Inet6Address;
 import java.net.InetAddress;
@@ -33,7 +35,6 @@ import java.util.List;
 import java.util.Objects;
 import java.util.Optional;
 
-import org.apache.http.conn.util.InetAddressUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -75,7 +76,7 @@ public class NetUtils {
      */
     public static String getHost(InetAddress inetAddress) {
         if (inetAddress != null) {
-            if (Constants.KUBERNETES_MODE) {
+            if (KubernetesUtils.isKubernetesMode()) {
                 String canonicalHost = inetAddress.getCanonicalHostName();
                 String[] items = canonicalHost.split("\\.");
                 if (items.length == 6 && "svc".equals(items[3])) {
@@ -98,7 +99,7 @@ public class NetUtils {
             HOST_ADDRESS = getHost(address);
             return HOST_ADDRESS;
         }
-        return Constants.KUBERNETES_MODE ? "localhost" : "127.0.0.1";
+        return KubernetesUtils.isKubernetesMode() ? "localhost" : "127.0.0.1";
     }
 
     private static InetAddress getLocalAddress() {
@@ -258,8 +259,9 @@ public class NetUtils {
     }
 
     private static boolean isSpecifyNetworkInterface(NetworkInterface networkInterface) {
-        String preferredNetworkInterface = PropertyUtils.getString(Constants.DOLPHIN_SCHEDULER_NETWORK_INTERFACE_PREFERRED,
-                System.getProperty(Constants.DOLPHIN_SCHEDULER_NETWORK_INTERFACE_PREFERRED));
+        String preferredNetworkInterface =
+                PropertyUtils.getString(Constants.DOLPHIN_SCHEDULER_NETWORK_INTERFACE_PREFERRED,
+                        System.getProperty(Constants.DOLPHIN_SCHEDULER_NETWORK_INTERFACE_PREFERRED));
         return Objects.equals(networkInterface.getDisplayName(), preferredNetworkInterface);
     }
 
@@ -267,7 +269,8 @@ public class NetUtils {
         if (validNetworkInterfaces.isEmpty()) {
             return null;
         }
-        String networkPriority = PropertyUtils.getString(Constants.DOLPHIN_SCHEDULER_NETWORK_PRIORITY_STRATEGY, NETWORK_PRIORITY_DEFAULT);
+        String networkPriority = PropertyUtils.getString(Constants.DOLPHIN_SCHEDULER_NETWORK_PRIORITY_STRATEGY,
+                NETWORK_PRIORITY_DEFAULT);
         if (NETWORK_PRIORITY_DEFAULT.equalsIgnoreCase(networkPriority)) {
             return findAddressByDefaultPolicy(validNetworkInterfaces);
         } else if (NETWORK_PRIORITY_INNER.equalsIgnoreCase(networkPriority)) {
diff --git a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/CommonUtilsTest.java b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/CommonUtilsTest.java
index 8123da3690..8bb962107e 100644
--- a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/CommonUtilsTest.java
+++ b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/CommonUtilsTest.java
@@ -17,27 +17,22 @@
 
 package org.apache.dolphinscheduler.common.utils;
 
-import org.apache.dolphinscheduler.spi.utils.PropertyUtils;
-
-import org.apache.hadoop.security.UserGroupInformation;
-
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * configuration test
  */
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(value = {PropertyUtils.class, UserGroupInformation.class})
+@RunWith(MockitoJUnitRunner.class)
 public class CommonUtilsTest {
+
     private static final Logger logger = LoggerFactory.getLogger(CommonUtilsTest.class);
 
     @Test
@@ -89,4 +84,4 @@ public class CommonUtilsTest {
         Assert.assertTrue(true);
     }
 
-}
\ No newline at end of file
+}
diff --git a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/FileUtilsTest.java b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/FileUtilsTest.java
index fdcaccd697..ec8c9c425e 100644
--- a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/FileUtilsTest.java
+++ b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/FileUtilsTest.java
@@ -27,26 +27,26 @@ import java.io.FileNotFoundException;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
 
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(DateUtils.class)
+@RunWith(MockitoJUnitRunner.class)
 public class FileUtilsTest {
 
     @Test
     public void testGetDownloadFilename() {
-        PowerMockito.mockStatic(DateUtils.class);
-        PowerMockito.when(DateUtils.getCurrentTime(YYYYMMDDHHMMSS)).thenReturn("20190101101059");
-        Assert.assertEquals("/tmp/dolphinscheduler/download/20190101101059/test",
-                FileUtils.getDownloadFilename("test"));
+        try (MockedStatic<DateUtils> mockedDateUtils = Mockito.mockStatic(DateUtils.class)) {
+            mockedDateUtils.when(() -> DateUtils.getCurrentTime(YYYYMMDDHHMMSS)).thenReturn("20190101101059");
+            Assert.assertEquals("/tmp/dolphinscheduler/download/20190101101059/test",
+                    FileUtils.getDownloadFilename("test"));
+        }
     }
 
     @Test
     public void testGetUploadFilename() {
         Assert.assertEquals("/tmp/dolphinscheduler/aaa/resources/bbb",
-                FileUtils.getUploadFilename("aaa","bbb"));
+                FileUtils.getUploadFilename("aaa", "bbb"));
     }
 
     @Test
@@ -68,9 +68,9 @@ public class FileUtilsTest {
     @Test
     public void testSetValue() {
         try {
-            PropertyUtils.setValue(Constants.DATASOURCE_ENCRYPTION_ENABLE,"true");
+            PropertyUtils.setValue(Constants.DATASOURCE_ENCRYPTION_ENABLE, "true");
             Assert.assertTrue(PropertyUtils.getBoolean(Constants.DATASOURCE_ENCRYPTION_ENABLE));
-            PropertyUtils.setValue(Constants.DATASOURCE_ENCRYPTION_ENABLE,"false");
+            PropertyUtils.setValue(Constants.DATASOURCE_ENCRYPTION_ENABLE, "false");
             Assert.assertFalse(PropertyUtils.getBoolean(Constants.DATASOURCE_ENCRYPTION_ENABLE));
         } catch (Exception e) {
             Assert.assertTrue(false);
diff --git a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HadoopUtilsTest.java b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HadoopUtilsTest.java
index d2b29254b9..ecdc557e58 100644
--- a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HadoopUtilsTest.java
+++ b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HadoopUtilsTest.java
@@ -22,20 +22,18 @@ import org.apache.dolphinscheduler.spi.enums.ResourceType;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
-import org.powermock.modules.junit4.PowerMockRunner;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * hadoop utils test
  */
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(value = {HadoopUtils.class})
-@SuppressStaticInitializationFor("org.apache.dolphinscheduler.common.utils.HttpUtils")
+@RunWith(MockitoJUnitRunner.class)
 public class HadoopUtilsTest {
+
     private static final Logger logger = LoggerFactory.getLogger(HadoopUtilsTest.class);
 
     @Test
@@ -64,10 +62,12 @@ public class HadoopUtilsTest {
 
     @Test
     public void getAppAddress() {
-        PowerMockito.mockStatic(HttpUtils.class);
-        PowerMockito.when(HttpUtils.get("http://ds1:8088/ws/v1/cluster/info")).thenReturn("{\"clusterInfo\":{\"state\":\"STARTED\",\"haState\":\"ACTIVE\"}}");
-        logger.info(HadoopUtils.getAppAddress("http://ds1:8088/ws/v1/cluster/apps/%s", "ds1,ds2"));
-        Assert.assertTrue(true);
+        try (MockedStatic<HttpUtils> mockedHttpUtils = Mockito.mockStatic(HttpUtils.class)) {
+            mockedHttpUtils.when(() -> HttpUtils.get("http://ds1:8088/ws/v1/cluster/info"))
+                    .thenReturn("{\"clusterInfo\":{\"state\":\"STARTED\",\"haState\":\"ACTIVE\"}}");
+            logger.info(HadoopUtils.getAppAddress("http://ds1:8088/ws/v1/cluster/apps/%s", "ds1,ds2"));
+            Assert.assertTrue(true);
+        }
     }
 
-}
\ No newline at end of file
+}
diff --git a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/NetUtilsTest.java b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/NetUtilsTest.java
index 1da8ffdb1b..7e0a8f3603 100644
--- a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/NetUtilsTest.java
+++ b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/NetUtilsTest.java
@@ -22,21 +22,15 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
 import static org.mockito.Mockito.when;
 
-import org.apache.dolphinscheduler.common.Constants;
-
 import java.net.InetAddress;
 
-import org.junit.After;
 import org.junit.Test;
-import org.powermock.reflect.Whitebox;
+import org.mockito.MockedStatic;
 
 public class NetUtilsTest {
-    @After
-    public void reset() {
-        Whitebox.setInternalState(Constants.class, "KUBERNETES_MODE", false);
-    }
 
     @Test
     public void testGetAddr() {
@@ -46,32 +40,42 @@ public class NetUtilsTest {
     }
 
     @Test
-    public void testGetHost() {
-        InetAddress address = mock(InetAddress.class);
-        when(address.getCanonicalHostName()).thenReturn("dolphinscheduler-worker-0.dolphinscheduler-worker-headless.default.svc.cluster.local");
-        when(address.getHostName()).thenReturn("dolphinscheduler-worker-0");
-        when(address.getHostAddress()).thenReturn("172.17.0.15");
-        assertEquals("172.17.0.15", NetUtils.getHost(address));
-        Whitebox.setInternalState(Constants.class, "KUBERNETES_MODE", true);
-        assertEquals("dolphinscheduler-worker-0.dolphinscheduler-worker-headless", NetUtils.getHost(address));
+    public void testGetHostInKubernetesMode() {
+        try (MockedStatic<KubernetesUtils> mockedKubernetesUtils = mockStatic(KubernetesUtils.class)) {
+            mockedKubernetesUtils.when(() -> KubernetesUtils.isKubernetesMode()).thenReturn(true);
 
-        address = mock(InetAddress.class);
-        when(address.getCanonicalHostName()).thenReturn("busybox-1.default-subdomain.my-namespace.svc.cluster-domain.example");
-        when(address.getHostName()).thenReturn("busybox-1");
-        Whitebox.setInternalState(Constants.class, "KUBERNETES_MODE", true);
-        assertEquals("busybox-1.default-subdomain", NetUtils.getHost(address));
+            InetAddress address = mock(InetAddress.class);
+            when(address.getCanonicalHostName())
+                    .thenReturn("dolphinscheduler-worker-0.dolphinscheduler-worker-headless.default.svc.cluster.local");
+            when(address.getHostName()).thenReturn("dolphinscheduler-worker-0");
+            assertEquals("dolphinscheduler-worker-0.dolphinscheduler-worker-headless", NetUtils.getHost(address));
 
-        address = mock(InetAddress.class);
-        when(address.getCanonicalHostName()).thenReturn("dolphinscheduler.cluster-domain.example");
-        when(address.getHostName()).thenReturn("dolphinscheduler");
-        Whitebox.setInternalState(Constants.class, "KUBERNETES_MODE", true);
-        assertEquals("dolphinscheduler.cluster-domain.example", NetUtils.getHost(address));
+            address = mock(InetAddress.class);
+            when(address.getCanonicalHostName())
+                    .thenReturn("busybox-1.default-subdomain.my-namespace.svc.cluster-domain.example");
+            when(address.getHostName()).thenReturn("busybox-1");
+            assertEquals("busybox-1.default-subdomain", NetUtils.getHost(address));
 
-        address = mock(InetAddress.class);
-        when(address.getCanonicalHostName()).thenReturn("dolphinscheduler-worker-0");
+            address = mock(InetAddress.class);
+            when(address.getCanonicalHostName()).thenReturn("dolphinscheduler.cluster-domain.example");
+            when(address.getHostName()).thenReturn("dolphinscheduler");
+            assertEquals("dolphinscheduler.cluster-domain.example", NetUtils.getHost(address));
+
+            address = mock(InetAddress.class);
+            when(address.getCanonicalHostName()).thenReturn("dolphinscheduler-worker-0");
+            when(address.getHostName()).thenReturn("dolphinscheduler-worker-0");
+            assertEquals("dolphinscheduler-worker-0", NetUtils.getHost(address));
+        }
+    }
+
+    @Test
+    public void testGetHostInNonKubernetesMode() {
+        InetAddress address = mock(InetAddress.class);
+        when(address.getCanonicalHostName())
+                .thenReturn("dolphinscheduler-worker-0.dolphinscheduler-worker-headless.default.svc.cluster.local");
         when(address.getHostName()).thenReturn("dolphinscheduler-worker-0");
-        Whitebox.setInternalState(Constants.class, "KUBERNETES_MODE", true);
-        assertEquals("dolphinscheduler-worker-0", NetUtils.getHost(address));
+        when(address.getHostAddress()).thenReturn("172.17.0.15");
+        assertEquals("172.17.0.15", NetUtils.getHost(address));
     }
 
     @Test
diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/factory/NettyRemotingClientFactory.java b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/factory/NettyRemotingClientFactory.java
similarity index 96%
copy from dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/factory/NettyRemotingClientFactory.java
copy to dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/factory/NettyRemotingClientFactory.java
index 450b052be4..122979cb30 100644
--- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/factory/NettyRemotingClientFactory.java
+++ b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/factory/NettyRemotingClientFactory.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.dolphinscheduler.service.factory;
+package org.apache.dolphinscheduler.remote.factory;
 
 import org.apache.dolphinscheduler.remote.NettyRemotingClient;
 import org.apache.dolphinscheduler.remote.config.NettyClientConfig;
diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/factory/NettyRemotingClientFactory.java b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/factory/NettyRemotingServerFactory.java
similarity index 57%
rename from dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/factory/NettyRemotingClientFactory.java
rename to dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/factory/NettyRemotingServerFactory.java
index 450b052be4..9669795b77 100644
--- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/factory/NettyRemotingClientFactory.java
+++ b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/factory/NettyRemotingServerFactory.java
@@ -15,24 +15,19 @@
  * limitations under the License.
  */
 
-package org.apache.dolphinscheduler.service.factory;
+package org.apache.dolphinscheduler.remote.factory;
 
-import org.apache.dolphinscheduler.remote.NettyRemotingClient;
-import org.apache.dolphinscheduler.remote.config.NettyClientConfig;
+import org.apache.dolphinscheduler.remote.NettyRemotingServer;
+import org.apache.dolphinscheduler.remote.config.NettyServerConfig;
 
 import lombok.experimental.UtilityClass;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 @UtilityClass
-public class NettyRemotingClientFactory {
-
-    private final Logger logger = LoggerFactory.getLogger(NettyRemotingClientFactory.class);
+public class NettyRemotingServerFactory {
 
-    public NettyRemotingClient buildNettyRemotingClient() {
-        NettyClientConfig nettyClientConfig = new NettyClientConfig();
-        logger.info("NettyRemotingClient initialized with config: {}", nettyClientConfig);
-        return new NettyRemotingClient(nettyClientConfig);
+    public NettyRemotingServer buildNettyRemotingServer(int listenPort) {
+        NettyServerConfig serverConfig = new NettyServerConfig();
+        serverConfig.setListenPort(listenPort);
+        return new NettyRemotingServer(serverConfig);
     }
 }
diff --git a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/config/ServiceBean.java b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/config/ServiceBean.java
index a51281d8d8..9cfc189eb3 100644
--- a/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/config/ServiceBean.java
+++ b/dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/config/ServiceBean.java
@@ -49,7 +49,7 @@ public class ServiceBean {
         if (initialized.get()) {
             return;
         }
-        Reflections f = new Reflections("org/apache/dolphinscheduler/");
+        Reflections f = new Reflections("org.apache.dolphinscheduler.");
         List<Class<?>> list = new ArrayList<>(f.getTypesAnnotatedWith(RpcService.class));
         list.forEach(rpcClass -> {
             RpcService rpcService = rpcClass.getAnnotation(RpcService.class);
diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/AlertClientService.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/AlertClientService.java
index 178cd6b2cc..4f915a97fd 100644
--- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/AlertClientService.java
+++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/AlertClientService.java
@@ -21,9 +21,9 @@ import org.apache.dolphinscheduler.remote.NettyRemotingClient;
 import org.apache.dolphinscheduler.remote.command.Command;
 import org.apache.dolphinscheduler.remote.command.alert.AlertSendRequestCommand;
 import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseCommand;
+import org.apache.dolphinscheduler.remote.factory.NettyRemotingClientFactory;
 import org.apache.dolphinscheduler.remote.utils.Host;
 import org.apache.dolphinscheduler.remote.utils.JsonSerializer;
-import org.apache.dolphinscheduler.service.factory.NettyRemotingClientFactory;
 
 import java.util.concurrent.atomic.AtomicBoolean;
 
diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/log/LogClient.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/log/LogClient.java
index d72dfeba13..45fbe6f374 100644
--- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/log/LogClient.java
+++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/log/LogClient.java
@@ -34,8 +34,8 @@ import org.apache.dolphinscheduler.remote.command.log.RollViewLogResponseCommand
 import org.apache.dolphinscheduler.remote.command.log.ViewLogRequestCommand;
 import org.apache.dolphinscheduler.remote.command.log.ViewLogResponseCommand;
 import org.apache.dolphinscheduler.remote.exceptions.RemotingException;
+import org.apache.dolphinscheduler.remote.factory.NettyRemotingClientFactory;
 import org.apache.dolphinscheduler.remote.utils.Host;
-import org.apache.dolphinscheduler.service.factory.NettyRemotingClientFactory;
 
 import java.util.List;
 
diff --git a/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java b/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java
index 0140f6e770..686888face 100644
--- a/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java
+++ b/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/alert/AlertClientServiceTest.java
@@ -23,7 +23,7 @@ import org.apache.dolphinscheduler.remote.command.Command;
 import org.apache.dolphinscheduler.remote.command.alert.AlertSendRequestCommand;
 import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseCommand;
 import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseResult;
-import org.apache.dolphinscheduler.service.factory.NettyRemotingClientFactory;
+import org.apache.dolphinscheduler.remote.factory.NettyRemotingClientFactory;
 
 import java.util.ArrayList;
 import java.util.List;
diff --git a/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/log/LogClientTest.java b/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/log/LogClientTest.java
index 449cbc5a3c..c62748e27c 100644
--- a/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/log/LogClientTest.java
+++ b/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/log/LogClientTest.java
@@ -26,8 +26,8 @@ import org.apache.dolphinscheduler.remote.command.log.GetLogBytesResponseCommand
 import org.apache.dolphinscheduler.remote.command.log.RemoveTaskLogResponseCommand;
 import org.apache.dolphinscheduler.remote.command.log.RollViewLogResponseCommand;
 import org.apache.dolphinscheduler.remote.command.log.ViewLogResponseCommand;
+import org.apache.dolphinscheduler.remote.factory.NettyRemotingClientFactory;
 import org.apache.dolphinscheduler.remote.utils.Host;
-import org.apache.dolphinscheduler.service.factory.NettyRemotingClientFactory;
 
 import java.nio.charset.StandardCharsets;
 
diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/utils/DateUtils.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/utils/DateUtils.java
index 3f187f92a6..4bc9504693 100644
--- a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/utils/DateUtils.java
+++ b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/utils/DateUtils.java
@@ -45,7 +45,8 @@ public class DateUtils {
     /**
      * a default datetime formatter for the timestamp
      */
-    private static final DateTimeFormatter DEFAULT_DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+    private static final DateTimeFormatter DEFAULT_DATETIME_FORMATTER =
+            DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
 
     private static final Logger logger = LoggerFactory.getLogger(DateUtils.class);
 
@@ -193,7 +194,6 @@ public class DateUtils {
         return calendar.get(Calendar.HOUR_OF_DAY);
     }
 
-
     /**
      * compare two dates
      *
@@ -431,10 +431,6 @@ public class DateUtils {
         return TimeZone.getTimeZone(timezoneId);
     }
 
-    /**
-     * get timestamp in String
-     * PowerMock 2.0.9 fails to mock System.currentTimeMillis(), this method helps in UT
-     */
     public static String getTimestampString() {
         return String.valueOf(System.currentTimeMillis());
     }
diff --git a/dolphinscheduler-worker/src/test/java/org/apache/dolphinscheduler/server/worker/processor/TaskDispatchProcessorTest.java b/dolphinscheduler-worker/src/test/java/org/apache/dolphinscheduler/server/worker/processor/TaskDispatchProcessorTest.java
index d88a589a85..66ae632288 100644
--- a/dolphinscheduler-worker/src/test/java/org/apache/dolphinscheduler/server/worker/processor/TaskDispatchProcessorTest.java
+++ b/dolphinscheduler-worker/src/test/java/org/apache/dolphinscheduler/server/worker/processor/TaskDispatchProcessorTest.java
@@ -17,9 +17,7 @@
 
 package org.apache.dolphinscheduler.server.worker.processor;
 
-import io.netty.channel.Channel;
 import org.apache.dolphinscheduler.common.storage.StorageOperate;
-import org.apache.dolphinscheduler.plugin.task.api.TaskChannel;
 import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
 import org.apache.dolphinscheduler.remote.command.Command;
 import org.apache.dolphinscheduler.remote.command.CommandType;
@@ -29,19 +27,22 @@ import org.apache.dolphinscheduler.server.worker.rpc.WorkerMessageSender;
 import org.apache.dolphinscheduler.server.worker.runner.WorkerManagerThread;
 import org.apache.dolphinscheduler.service.alert.AlertClientService;
 import org.apache.dolphinscheduler.service.task.TaskPluginManager;
+
+import java.util.Date;
+
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.powermock.modules.junit4.PowerMockRunner;
+import org.mockito.junit.MockitoJUnitRunner;
 
-import java.util.Date;
+import io.netty.channel.Channel;
 
 /**
  * test task execute processor
  */
-@RunWith(PowerMockRunner.class)
+@RunWith(MockitoJUnitRunner.class)
 public class TaskDispatchProcessorTest {
 
     @InjectMocks
@@ -68,25 +69,21 @@ public class TaskDispatchProcessorTest {
     @Test
     public void process() {
         Channel channel = Mockito.mock(Channel.class);
-        TaskChannel taskChannel = Mockito.mock(TaskChannel.class);
-        Mockito.when(taskPluginManager.getTaskChannel(Mockito.anyString())).thenReturn(taskChannel);
-
         TaskExecutionContext taskExecutionContext = getTaskExecutionContext();
         Command dispatchCommand = createDispatchCommand(taskExecutionContext);
         taskDispatchProcessor.process(channel, dispatchCommand);
 
         Mockito.verify(workerManagerThread, Mockito.atMostOnce()).offer(Mockito.any());
-        Mockito.verify(workerMessageSender, Mockito.never()).sendMessageWithRetry(taskExecutionContext, "localhost:5678", CommandType.TASK_REJECT);
+        Mockito.verify(workerMessageSender, Mockito.never()).sendMessageWithRetry(taskExecutionContext,
+                "localhost:5678", CommandType.TASK_REJECT);
     }
 
-
     public Command createDispatchCommand(TaskExecutionContext taskExecutionContext) {
         return new TaskDispatchCommand(
                 taskExecutionContext,
                 "localhost:5678",
                 "localhost:1234",
-                System.currentTimeMillis()
-        ).convert2Command();
+                System.currentTimeMillis()).convert2Command();
     }
 
     public TaskExecutionContext getTaskExecutionContext() {
diff --git a/pom.xml b/pom.xml
index 2bd06eb2aa..6b956b8b54 100644
--- a/pom.xml
+++ b/pom.xml
@@ -81,7 +81,6 @@
         <auto-service.version>1.0.1</auto-service.version>
         <jacoco.skip>false</jacoco.skip>
         <maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
-        <powermock.version>2.0.9</powermock.version>
         <exec-maven-plugin.version>3.0.0</exec-maven-plugin.version>
         <owasp-dependency-check-maven.version>7.1.2</owasp-dependency-check-maven.version>
         <lombok.version>1.18.20</lombok.version>
@@ -363,24 +362,6 @@
             <version>${lombok.version}</version>
             <scope>provided</scope>
         </dependency>
-        <dependency>
-            <groupId>org.powermock</groupId>
-            <artifactId>powermock-api-mockito2</artifactId>
-            <version>${powermock.version}</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.powermock</groupId>
-            <artifactId>powermock-module-junit4</artifactId>
-            <version>${powermock.version}</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.powermock</groupId>
-            <artifactId>powermock-core</artifactId>
-            <version>${powermock.version}</version>
-            <scope>test</scope>
-        </dependency>
     </dependencies>
 
     <build>
diff --git a/tools/dependencies/known-dependencies.txt b/tools/dependencies/known-dependencies.txt
index 06ec6d81c1..9a6c44d584 100644
--- a/tools/dependencies/known-dependencies.txt
+++ b/tools/dependencies/known-dependencies.txt
@@ -124,7 +124,7 @@ jakarta.websocket-api-1.1.2.jar
 jakarta.xml.bind-api-2.3.3.jar
 jamon-runtime-2.3.1.jar
 janino-3.0.16.jar
-javassist-3.27.0-GA.jar
+javassist-3.28.0-GA.jar
 javax.activation-api-1.2.0.jar
 javax.annotation-api-1.3.2.jar
 javax.el-3.0.0.jar
@@ -266,7 +266,7 @@ py4j-0.10.9.jar
 quartz-2.3.2.jar
 re2j-1.1.jar
 reactive-streams-1.0.4.jar
-reflections-0.9.12.jar
+reflections-0.10.2.jar
 regions-2.17.282.jar
 reload4j-1.2.18.3.jar
 sdk-core-2.17.282.jar