changeset 9605:468b2f4db053

8031766: jstatd nightly tests failing with Expected one jstatd process, got 2. Test will be canceled. Reviewed-by: jbachorik, sla
author ykantser
date Mon, 26 May 2014 11:10:20 +0200
parents 7071909c7964
children c7698d067044
files test/sun/tools/jstatd/JstatdTest.java
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/test/sun/tools/jstatd/JstatdTest.java	Tue May 13 23:18:27 2014 -0700
+++ b/test/sun/tools/jstatd/JstatdTest.java	Mon May 26 11:10:20 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);