/* * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * The base class for tests of jstatd. * * The test sequence for TestJstatdDefaults for example is: * <pre> * {@code * // start jstatd process * jstatd -J-XX:+UsePerfData * * // run jps and verify its output * jps -J-XX:+UsePerfData hostname * * // run jstat and verify its output * jstat -J-XX:+UsePerfData -gcutil pid@hostname 250 5 * * // stop jstatd process and verify that no unexpected exceptions have been thrown * } * </pre>
*/ publicfinalclass JstatdTest {
ProcessBuilder processBuilder = new ProcessBuilder(cmd);
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
System.out.println(output.getOutput());
return output;
}
/** * Verifies output form jps contains pids and programs' name information. * The function will discard any lines that come before the first line with pid. * This can happen if the JVM outputs a warning message for some reason * before running jps. * * The output can look like: * 35536 Jstatd * 35417 Main * 31103 org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
*/ privatevoid verifyJpsOutput(OutputAnalyzer output) throws Exception {
output.shouldHaveExitValue(0);
assertFalse(output.getOutput().isEmpty(), "Output should not be empty");
boolean foundFirstLineWithPid = false;
List<String> lines = output.asLinesWithoutVMWarnings(); for (String line : lines) { if (!foundFirstLineWithPid) {
foundFirstLineWithPid = line.matches(JPS_OUTPUT_REGEX); continue;
}
assertTrue(line.matches(JPS_OUTPUT_REGEX), "Output does not match the pattern" + Utils.NEW_LINE + line);
}
assertTrue(foundFirstLineWithPid, "Invalid output");
}
ProcessBuilder processBuilder = new ProcessBuilder(cmd);
OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
System.out.println(output.getOutput());
return output;
}
privatevoid verifyJstatOutput(OutputAnalyzer output) throws Exception {
output.shouldHaveExitValue(0);
assertFalse(output.getOutput().isEmpty(), "Output should not be empty");
JstatGCUtilParser gcUtilParser = new JstatGCUtilParser(
output.getOutput());
gcUtilParser.parse(JSTAT_GCUTIL_SAMPLES);
}
private ProcessThread tryToSetupJstatdProcess() throws Throwable {
portInUse = false;
ProcessThread jstatdThread = new ProcessThread("Jstatd-Thread",
JstatdTest::isJstadReady, getJstatdCmd()); try {
jstatdThread.start(); // Make sure jstatd is up and running
jstatdPid = waitOnTool(jstatdThread); if (jstatdPid == null) { // The port is already in use. Cancel and try with new one.
jstatdThread.stopProcess();
jstatdThread.join(); returnnull;
}
} catch (Throwable t) { // Something went wrong in the product - clean up!
cleanUpThread(jstatdThread); throw t;
}
return jstatdThread;
}
privatestaticboolean isJstadReady(String line) { if (line.contains("Port already in use")) {
portInUse = true; returntrue;
} return line.startsWith("jstatd started (bound to ");
}
ProcessThread jstatdThread = null; try { while (jstatdThread == null) { if (!useDefaultPort) {
port = String.valueOf(Utils.getFreePort());
}
if (!useDefaultRmiPort) {
rmiPort = String.valueOf(Utils.getFreePort());
}
if (withExternalRegistry) {
Registry registry = startRegistry(); if (registry == null) { // The port is already in use. Cancel and try with a new one. continue;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.