Skip to content
Permalink
Browse files
ARTEMIS-3854: use Process.pid() rather than reflection
  • Loading branch information
gemmellr committed Jun 8, 2022
1 parent 0fab0da commit 0c5e83b76a960edecd6819af3d60829a6cc9ef69
Showing 4 changed files with 7 additions and 13 deletions.
@@ -39,8 +39,8 @@ public void kill() throws InterruptedException {
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 int waitFor() throws InterruptedException {

}

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 {
@@ -134,8 +134,8 @@ public void testDisconnect(boolean pause, boolean startClient) throws Exception
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();
}
@@ -85,7 +85,7 @@ public void stopQpidRouter() throws Exception {
}

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" +
@@ -227,15 +227,15 @@ protected void jstack() throws Exception {
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);
}
try {
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);
}

0 comments on commit 0c5e83b

Please sign in to comment.