Skip to content

Commit

Permalink
Modify OpenJ9DiagnosticMXBean tests to use getDumpOptions
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Shipton <[email protected]>
  • Loading branch information
pshipton committed Nov 20, 2024
1 parent 73d61a8 commit bd7d8bc
Showing 1 changed file with 4 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class TestOpenJ9DiagnosticsMXBean {
private ObjectName mxbeanName = null;
private OpenJ9DiagnosticsMXBean diagBean = null;
private OpenJ9DiagnosticsMXBean diagBeanRemote = null;
List<String> initialDumpOptions = new ArrayList<String>();
String initialDumpOptions = null;
private JMXConnector connector = null;
private static ProcessLocking lock;
private static String tmpFileName;
Expand All @@ -80,31 +80,11 @@ public void setUp() throws Exception {
Assert.fail("MalformedObjectNameException!");
}

initialDumpOptions = getDumpOptions();

getLocalMXBean();

getRemoteMXBean();
}

/**
* Function to get the dump options.
*
*/
private List<String> getDumpOptions() throws IOException {
List<String> list = new ArrayList<String>();
String javaExec = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
ProcessBuilder builder = new ProcessBuilder(javaExec, "-Xdump:what", "-version");
Process process = builder.start();
builder.redirectErrorStream(true);

BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while(null != (line = reader.readLine())) {
logger.info(line);
list.add(line);
}
return list;
initialDumpOptions = diagBean.getDumpOptions();
}

private void getLocalMXBean() {
Expand Down Expand Up @@ -527,10 +507,9 @@ private void resetDumpOptions(OpenJ9DiagnosticsMXBean diagBean) throws IOExcepti
diagBean.setDumpOptions("java+heap+system:events=vmstop");
diagBean.resetDumpOptions();

List<String> newDumpOptions = getDumpOptions();
boolean res = initialDumpOptions.equals(newDumpOptions);
String newDumpOptions = diagBean.getDumpOptions();

Assert.assertTrue(res, "Reset Dump Options failed");
Assert.assertEquals(newDumpOptions, initialDumpOptions, "Reset Dump Options failed");
}

/**
Expand Down

0 comments on commit bd7d8bc

Please sign in to comment.