You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ro...@apache.org on 2022/06/08 14:07:34 UTC

[activemq-artemis] branch main updated: ARTEMIS-3854: use Process.pid() rather than reflection

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

robbie pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/main by this push:
     new 0c5e83b76a ARTEMIS-3854: use Process.pid() rather than reflection
0c5e83b76a is described below

commit 0c5e83b76a960edecd6819af3d60829a6cc9ef69
Author: Robbie Gemmell <ro...@apache.org>
AuthorDate: Wed Jun 8 15:06:04 2022 +0100

    ARTEMIS-3854: use Process.pid() rather than reflection
---
 .../java/org/apache/activemq/artemis/utils/ExecuteUtil.java    | 10 ++--------
 .../integration/amqp/connect/AMQPBridgeDisconnectTest.java     |  4 ++--
 .../tests/integration/amqp/connect/QpidDispatchPeerTest.java   |  2 +-
 .../artemis/tests/smoke/replicationflow/SoakPagingTest.java    |  4 ++--
 4 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/ExecuteUtil.java b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/ExecuteUtil.java
index 921b5ab82d..14456c87ef 100644
--- a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/ExecuteUtil.java
+++ b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/ExecuteUtil.java
@@ -39,8 +39,8 @@ public class ExecuteUtil {
          inputStreamReader.join();
       }
 
-      public int pid() throws Exception {
-         return getPID(process);
+      public long pid() throws Exception {
+         return process.pid();
       }
 
       public int waitFor(long timeout, TimeUnit unit) throws InterruptedException {
@@ -66,12 +66,6 @@ public class ExecuteUtil {
 
    }
 
-   public static int getPID(Process process) throws Exception {
-      Field pidField = process.getClass().getDeclaredField("pid");
-      pidField.setAccessible(true);
-      return (int)pidField.get(process);
-   }
-
    private static final Logger logger = Logger.getLogger(ExecuteUtil.class);
 
    public static int runCommand(boolean logOutput, String... command) throws Exception {
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/connect/AMQPBridgeDisconnectTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/connect/AMQPBridgeDisconnectTest.java
index 2123aae169..606a8228e3 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/connect/AMQPBridgeDisconnectTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/connect/AMQPBridgeDisconnectTest.java
@@ -134,8 +134,8 @@ public class AMQPBridgeDisconnectTest extends AmqpClientTestSupport {
             return this.server.getRemotingService().getConnections().size();
          });
          if (pause) {
-            int pid = ExecuteUtil.getPID(process);
-            ExecuteUtil.runCommand(true, new String[]{"kill", "-STOP", Integer.toString(pid)});
+            long pid = process.pid();
+            ExecuteUtil.runCommand(true, new String[]{"kill", "-STOP", Long.toString(pid)});
          } else {
             process.destroy();
          }
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/connect/QpidDispatchPeerTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/connect/QpidDispatchPeerTest.java
index 6e39d63275..fc8630b365 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/connect/QpidDispatchPeerTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/connect/QpidDispatchPeerTest.java
@@ -85,7 +85,7 @@ public class QpidDispatchPeerTest extends AmqpClientTestSupport {
    }
 
    public void pauseThenKill(int timeToWait) throws Exception {
-      int pid = qpidProcess.pid();
+      long pid = qpidProcess.pid();
       int result = ExecuteUtil.runCommand(true, "kill", "-STOP", Long.toString(pid));
       Assert.assertEquals(0, result);
       logger.info("\n*******************************************************************************************************************************\n" +
diff --git a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/replicationflow/SoakPagingTest.java b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/replicationflow/SoakPagingTest.java
index 2294d45253..f37fb374a9 100644
--- a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/replicationflow/SoakPagingTest.java
+++ b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/replicationflow/SoakPagingTest.java
@@ -227,7 +227,7 @@ public class SoakPagingTest extends SmokeTestBase {
          System.out.println("*******************************************************************************************************************************");
          System.out.println("SERVER 0 jstack");
          System.out.println("*******************************************************************************************************************************");
-         ExecuteUtil.runCommand(true, 1, TimeUnit.MINUTES, "jstack", "" + ExecuteUtil.getPID(server0));
+         ExecuteUtil.runCommand(true, 1, TimeUnit.MINUTES, "jstack", "" + server0.pid());
       } catch (Throwable e) {
          log.warn("Error executing jstack on Server 0", e);
       }
@@ -235,7 +235,7 @@ public class SoakPagingTest extends SmokeTestBase {
          System.out.println("*******************************************************************************************************************************");
          System.out.println("SERVER 1 jstack");
          System.out.println("*******************************************************************************************************************************");
-         ExecuteUtil.runCommand(true, 1, TimeUnit.MINUTES, "jstack", "" + ExecuteUtil.getPID(server1));
+         ExecuteUtil.runCommand(true, 1, TimeUnit.MINUTES, "jstack", "" + server1.pid());
       } catch (Throwable e) {
          log.warn("Error executing jstack on Server 1", e);
       }