8031766: jstatd nightly tests failing with Expected one jstatd process, got 2. Test will be canceled.
Reviewed-by: jbachorik, sla
--- a/jdk/test/sun/tools/jstatd/JstatdTest.java Mon Apr 07 15:40:05 2014 +0100
+++ b/jdk/test/sun/tools/jstatd/JstatdTest.java Mon Apr 07 16:13:43 2014 +0200
@@ -27,6 +27,7 @@
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Arrays;
+import java.util.regex.Pattern;
import static jdk.testlibrary.Asserts.*;
import jdk.testlibrary.JDKToolLauncher;
@@ -34,6 +35,7 @@
import jdk.testlibrary.ProcessThread;
import jdk.testlibrary.TestThread;
import jdk.testlibrary.Utils;
+import jdk.testlibrary.ProcessTools;
/**
* The base class for tests of jstatd.
@@ -93,8 +95,11 @@
if (tool == "rmiregistry") {
processName = "registryimpl";
}
+
+ Pattern toolInJpsPattern =
+ Pattern.compile("^\\d+\\s{1}" + processName + "\\s{1}.*-dparent\\.pid\\." + ProcessTools.getProcessId() + ".*");
for (String line : lines) {
- if (line.toLowerCase().matches("^\\d+\\s{1}" + processName + "$")) {
+ if (toolInJpsPattern.matcher(line.toLowerCase()).matches()) {
pid = line.split(" ")[0];
count++;
}
@@ -167,6 +172,8 @@
private OutputAnalyzer runJps() throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jps");
launcher.addVMArg("-XX:+UsePerfData");
+ // Run jps with -v flag to obtain -Dparent.pid.<pid>
+ launcher.addToolArg("-v");
launcher.addToolArg(getDestination());
String[] cmd = launcher.getCommand();
@@ -286,7 +293,7 @@
* jstatd -J-XX:+UsePerfData -J-Djava.security.policy=all.policy -n serverName
* jstatd -J-XX:+UsePerfData -J-Djava.security.policy=all.policy -p port -n serverName
*/
- private String[] getJstatdCmd() throws UnknownHostException {
+ private String[] getJstatdCmd() throws Exception {
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstatd");
launcher.addVMArg("-XX:+UsePerfData");
String testSrc = System.getProperty("test.src");
@@ -294,6 +301,8 @@
assertTrue(policy.exists() && policy.isFile(),
"Security policy " + policy.getAbsolutePath() + " does not exist or not a file");
launcher.addVMArg("-Djava.security.policy=" + policy.getAbsolutePath());
+ // -Dparent.pid.<pid> will help to identify jstad process started by this test
+ launcher.addVMArg("-Dparent.pid." + ProcessTools.getProcessId());
if (port != null) {
launcher.addToolArg("-p");
launcher.addToolArg(port);