From 4d6af516b9bbc1587318f9a305d82b461c124a30 Mon Sep 17 00:00:00 2001 From: dada Sun <707509803@qq.com> Date: Mon, 5 Feb 2024 11:41:21 +0800 Subject: [PATCH] [Bug][Task Api] fix 'MACPATTERN' in ProcessUtils and cover all cases on MacOS in ProcessUtilsTest (#15480) (#15529) Co-authored-by: Rick Cheng --- .../dolphinscheduler/plugin/task/api/utils/ProcessUtils.java | 2 +- .../plugin/task/api/utils/ProcessUtilsTest.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java index 46b8ff4c7b..7b61a1eaec 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java @@ -71,7 +71,7 @@ public final class ProcessUtils { * Initialization regularization, solve the problem of pre-compilation performance, * avoid the thread safety problem of multi-thread operation */ - private static final Pattern MACPATTERN = Pattern.compile("-[+|-]-\\s(\\d+)"); + private static final Pattern MACPATTERN = Pattern.compile("-[+|-][-|=]\\s(\\d+)"); /** * Expression of PID recognition in Windows scene diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtilsTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtilsTest.java index ef10e73325..14caf470d7 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtilsTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtilsTest.java @@ -38,6 +38,7 @@ public class ProcessUtilsTest { String command; MockedStatic osUtilsMockedStatic = Mockito.mockStatic(OSUtils.class); if (SystemUtils.IS_OS_MAC) { + pids = "-+= 6279 sudo -+- 6282 558_1497.sh --- 6354 sleep"; command = String.format("%s -sp %d", TaskConstants.PSTREE, processId); } else if (SystemUtils.IS_OS_LINUX) { command = String.format("%s -p %d", TaskConstants.PSTREE, processId); @@ -54,6 +55,7 @@ public class ProcessUtilsTest { String exceptPidsStr2 = "2000 2100 2101"; String command2; if (SystemUtils.IS_OS_MAC) { + pids2 = "-+= 2000 apache2 -+- 2100 222332-apache2-submit_task.py --- 2101 apache2"; command2 = String.format("%s -sp %d", TaskConstants.PSTREE, processId2); } else if (SystemUtils.IS_OS_LINUX) { command2 = String.format("%s -p %d", TaskConstants.PSTREE, processId2); @@ -70,6 +72,7 @@ public class ProcessUtilsTest { String exceptPidsStr3 = "5000 6000 7000 7100"; String command3; if (SystemUtils.IS_OS_MAC) { + pids3 = "-+= 5000 sshd -+- 6000 sshd --= 7000 bash --- 7100 python"; command3 = String.format("%s -sp %d", TaskConstants.PSTREE, processId3); } else if (SystemUtils.IS_OS_LINUX) { command3 = String.format("%s -p %d", TaskConstants.PSTREE, processId3);