Browse Source

[Bug][Task Api] fix 'MACPATTERN' in ProcessUtils and cover all cases on MacOS in ProcessUtilsTest (#15480) (#15529)

Co-authored-by: Rick Cheng <rickchengx@gmail.com>
3.2.2-prepare
dada Sun 11 months ago committed by GitHub
parent
commit
4d6af516b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java
  2. 3
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtilsTest.java

2
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

3
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<OSUtils> 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);

Loading…
Cancel
Save