author | ykantser |
Wed, 30 Oct 2013 13:44:40 +0100 | |
changeset 21410 | 5f3e83a059c4 |
child 21627 | 5e31d6573ec2 |
permissions | -rw-r--r-- |
21410
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
1 |
/* |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
4 |
* |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
8 |
* |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
13 |
* accompanied this code). |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
14 |
* |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
18 |
* |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
21 |
* questions. |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
22 |
*/ |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
23 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
24 |
import java.io.File; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
25 |
import java.net.UnknownHostException; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
26 |
import java.rmi.RemoteException; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
27 |
import java.rmi.registry.LocateRegistry; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
28 |
import java.rmi.registry.Registry; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
29 |
import java.util.Arrays; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
30 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
31 |
import static jdk.testlibrary.Asserts.*; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
32 |
import jdk.testlibrary.JDKToolLauncher; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
33 |
import jdk.testlibrary.OutputAnalyzer; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
34 |
import jdk.testlibrary.ProcessThread; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
35 |
import jdk.testlibrary.TestThread; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
36 |
import jdk.testlibrary.Utils; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
37 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
38 |
/** |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
39 |
* The base class for tests of jstatd. |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
40 |
* |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
41 |
* The test sequence for TestJstatdDefaults for example is: |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
42 |
* <pre> |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
43 |
* {@code |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
44 |
* // start jstatd process |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
45 |
* jstatd -J-XX:+UsePerfData -J-Djava.security.policy=all.policy |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
46 |
* |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
47 |
* // run jps and verify its output |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
48 |
* jps -J-XX:+UsePerfData hostname |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
49 |
* |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
50 |
* // run jstat and verify its output |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
51 |
* jstat -J-XX:+UsePerfData -J-Duser.language=en -gcutil pid@hostname 250 5 |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
52 |
* |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
53 |
* // stop jstatd process and verify that no unexpected exceptions have been thrown |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
54 |
* } |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
55 |
* </pre> |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
56 |
*/ |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
57 |
public final class JstatdTest { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
58 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
59 |
/** |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
60 |
* jstat gcutil option: takes JSTAT_GCUTIL_SAMPLES samples at |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
61 |
* JSTAT_GCUTIL_INTERVAL_MS millisecond intervals |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
62 |
*/ |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
63 |
private static final int JSTAT_GCUTIL_SAMPLES = 5; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
64 |
private static final int JSTAT_GCUTIL_INTERVAL_MS = 250; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
65 |
private static final String JPS_OUTPUT_REGEX = "^\\d+\\s*.*"; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
66 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
67 |
private boolean useDefaultPort = true; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
68 |
private String port; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
69 |
private String serverName; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
70 |
private String jstatdPid; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
71 |
private boolean withExternalRegistry = false; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
72 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
73 |
public void setServerName(String serverName) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
74 |
this.serverName = serverName; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
75 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
76 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
77 |
public void setUseDefaultPort(boolean useDefaultPort) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
78 |
this.useDefaultPort = useDefaultPort; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
79 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
80 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
81 |
public void setWithExternalRegistry(boolean withExternalRegistry) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
82 |
this.withExternalRegistry = withExternalRegistry; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
83 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
84 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
85 |
/** |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
86 |
* Parse pid from jps output |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
87 |
*/ |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
88 |
private String parsePid(String tool, OutputAnalyzer output) throws Exception { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
89 |
String[] lines = output.getOutput().split(Utils.NEW_LINE); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
90 |
String pid = null; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
91 |
int count = 0; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
92 |
String processName = tool; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
93 |
if (tool == "rmiregistry") { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
94 |
processName = "registryimpl"; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
95 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
96 |
for (String line : lines) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
97 |
if (line.toLowerCase().matches("^\\d+\\s{1}" + processName + "$")) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
98 |
pid = line.split(" ")[0]; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
99 |
count++; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
100 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
101 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
102 |
if (count > 1) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
103 |
throw new Exception("Expected one " + tool |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
104 |
+ " process, got " + count + ". Test will be canceled."); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
105 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
106 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
107 |
return pid; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
108 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
109 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
110 |
private String getToolPid(String tool) |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
111 |
throws Exception { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
112 |
OutputAnalyzer output = runJps(); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
113 |
return parsePid(tool, output); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
114 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
115 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
116 |
private String waitOnTool(String tool, TestThread thread) throws Throwable { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
117 |
while (true) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
118 |
String pid = getToolPid(tool); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
119 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
120 |
if (pid != null) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
121 |
System.out.println(tool + " pid: " + pid); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
122 |
return pid; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
123 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
124 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
125 |
Throwable t = thread.getUncaught(); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
126 |
if (t != null) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
127 |
if (t.getMessage().contains( |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
128 |
"java.rmi.server.ExportException: Port already in use")) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
129 |
System.out.println("Port already in use. Trying to restart with a new one..."); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
130 |
Thread.sleep(100); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
131 |
return null; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
132 |
} else { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
133 |
// Something unexpected has happened |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
134 |
throw new Throwable(t); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
135 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
136 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
137 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
138 |
System.out.println("Waiting until " + tool + " is running..."); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
139 |
Thread.sleep(100); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
140 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
141 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
142 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
143 |
private void log(String caption, String... cmd) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
144 |
System.out.println(Utils.NEW_LINE + caption + ":"); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
145 |
System.out.println(Arrays.toString(cmd).replace(",", "")); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
146 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
147 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
148 |
private String getDestination() throws UnknownHostException { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
149 |
String option = Utils.getHostname(); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
150 |
if (port != null) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
151 |
option += ":" + port; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
152 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
153 |
if (serverName != null) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
154 |
option += "/" + serverName; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
155 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
156 |
return option; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
157 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
158 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
159 |
/** |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
160 |
* Depending on test settings command line can look like: |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
161 |
* |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
162 |
* jps -J-XX:+UsePerfData hostname |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
163 |
* jps -J-XX:+UsePerfData hostname:port |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
164 |
* jps -J-XX:+UsePerfData hostname/serverName |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
165 |
* jps -J-XX:+UsePerfData hostname:port/serverName |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
166 |
*/ |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
167 |
private OutputAnalyzer runJps() throws Exception { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
168 |
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jps"); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
169 |
launcher.addVMArg("-XX:+UsePerfData"); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
170 |
launcher.addToolArg(getDestination()); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
171 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
172 |
String[] cmd = launcher.getCommand(); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
173 |
log("Start jps", cmd); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
174 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
175 |
ProcessBuilder processBuilder = new ProcessBuilder(cmd); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
176 |
OutputAnalyzer output = new OutputAnalyzer(processBuilder.start()); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
177 |
System.out.println(output.getOutput()); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
178 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
179 |
return output; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
180 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
181 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
182 |
/** |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
183 |
* Verifies output form jps contains pids and programs' name information. |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
184 |
* The function will discard any lines that come before the first line with pid. |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
185 |
* This can happen if the JVM outputs a warning message for some reason |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
186 |
* before running jps. |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
187 |
* |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
188 |
* The output can look like: |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
189 |
* 35536 Jstatd |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
190 |
* 35417 Main |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
191 |
* 31103 org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
192 |
*/ |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
193 |
private void verifyJpsOutput(OutputAnalyzer output) throws Exception { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
194 |
output.shouldHaveExitValue(0); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
195 |
assertFalse(output.getOutput().isEmpty(), "Output should not be empty"); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
196 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
197 |
boolean foundFirstLineWithPid = false; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
198 |
String[] lines = output.getOutput().split(Utils.NEW_LINE); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
199 |
for (String line : lines) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
200 |
if (!foundFirstLineWithPid) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
201 |
foundFirstLineWithPid = line.matches(JPS_OUTPUT_REGEX); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
202 |
continue; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
203 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
204 |
assertTrue(line.matches(JPS_OUTPUT_REGEX), |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
205 |
"Output does not match the pattern" + Utils.NEW_LINE + line); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
206 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
207 |
assertTrue(foundFirstLineWithPid, "Invalid output"); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
208 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
209 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
210 |
/** |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
211 |
* Depending on test settings command line can look like: |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
212 |
* |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
213 |
* jstat -J-XX:+UsePerfData -J-Duser.language=en -gcutil pid@hostname 250 5 |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
214 |
* jstat -J-XX:+UsePerfData -J-Duser.language=en -gcutil pid@hostname:port 250 5 |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
215 |
* jstat -J-XX:+UsePerfData -J-Duser.language=en -gcutil pid@hostname/serverName 250 5 |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
216 |
* jstat -J-XX:+UsePerfData -J-Duser.language=en -gcutil pid@hostname:port/serverName 250 5 |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
217 |
*/ |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
218 |
private OutputAnalyzer runJstat() throws Exception { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
219 |
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstat"); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
220 |
launcher.addVMArg("-XX:+UsePerfData"); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
221 |
launcher.addVMArg("-Duser.language=en"); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
222 |
launcher.addToolArg("-gcutil"); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
223 |
launcher.addToolArg(jstatdPid + "@" + getDestination()); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
224 |
launcher.addToolArg(Integer.toString(JSTAT_GCUTIL_INTERVAL_MS)); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
225 |
launcher.addToolArg(Integer.toString(JSTAT_GCUTIL_SAMPLES)); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
226 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
227 |
String[] cmd = launcher.getCommand(); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
228 |
log("Start jstat", cmd); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
229 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
230 |
ProcessBuilder processBuilder = new ProcessBuilder(cmd); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
231 |
OutputAnalyzer output = new OutputAnalyzer(processBuilder.start()); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
232 |
System.out.println(output.getOutput()); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
233 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
234 |
return output; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
235 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
236 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
237 |
private void verifyJstatOutput(OutputAnalyzer output) |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
238 |
throws Exception { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
239 |
output.shouldHaveExitValue(0); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
240 |
assertFalse(output.getOutput().isEmpty(), "Output should not be empty"); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
241 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
242 |
JstatGCUtilParser gcUtilParser = new JstatGCUtilParser( |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
243 |
output.getOutput()); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
244 |
gcUtilParser.parse(JSTAT_GCUTIL_SAMPLES); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
245 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
246 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
247 |
private void runToolsAndVerify() throws Exception { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
248 |
OutputAnalyzer output = runJps(); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
249 |
verifyJpsOutput(output); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
250 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
251 |
output = runJstat(); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
252 |
verifyJstatOutput(output); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
253 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
254 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
255 |
private Registry startRegistry() |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
256 |
throws InterruptedException, RemoteException { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
257 |
Registry registry = null; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
258 |
try { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
259 |
System.out.println("Start rmiregistry on port " + port); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
260 |
registry = LocateRegistry |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
261 |
.createRegistry(Integer.parseInt(port)); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
262 |
} catch (RemoteException e) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
263 |
if (e.getMessage().contains("Port already in use")) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
264 |
System.out.println("Port already in use. Trying to restart with a new one..."); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
265 |
Thread.sleep(100); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
266 |
return null; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
267 |
} else { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
268 |
throw e; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
269 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
270 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
271 |
return registry; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
272 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
273 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
274 |
private void cleanUpThread(ProcessThread thread) throws Throwable { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
275 |
if (thread != null) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
276 |
thread.stopProcess(); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
277 |
thread.joinAndThrow(); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
278 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
279 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
280 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
281 |
/** |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
282 |
* Depending on test settings command line can look like: |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
283 |
* |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
284 |
* jstatd -J-XX:+UsePerfData -J-Djava.security.policy=all.policy |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
285 |
* jstatd -J-XX:+UsePerfData -J-Djava.security.policy=all.policy -p port |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
286 |
* jstatd -J-XX:+UsePerfData -J-Djava.security.policy=all.policy -n serverName |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
287 |
* jstatd -J-XX:+UsePerfData -J-Djava.security.policy=all.policy -p port -n serverName |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
288 |
*/ |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
289 |
private String[] getJstatdCmd() throws UnknownHostException { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
290 |
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstatd"); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
291 |
launcher.addVMArg("-XX:+UsePerfData"); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
292 |
String testSrc = System.getProperty("test.src"); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
293 |
File policy = new File(testSrc, "all.policy"); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
294 |
launcher.addVMArg("-Djava.security.policy=" + policy.getAbsolutePath()); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
295 |
if (port != null) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
296 |
launcher.addToolArg("-p"); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
297 |
launcher.addToolArg(port); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
298 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
299 |
if (serverName != null) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
300 |
launcher.addToolArg("-n"); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
301 |
launcher.addToolArg(serverName); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
302 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
303 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
304 |
String[] cmd = launcher.getCommand(); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
305 |
log("Start jstatd", cmd); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
306 |
return cmd; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
307 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
308 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
309 |
private ProcessThread tryToSetupJstatdProcess() throws Throwable { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
310 |
ProcessThread jstatdThread = new ProcessThread("Jstatd-Thread", |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
311 |
getJstatdCmd()); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
312 |
try { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
313 |
jstatdThread.start(); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
314 |
// Make sure jstatd is up and running |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
315 |
jstatdPid = waitOnTool("jstatd", jstatdThread); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
316 |
if (jstatdPid == null) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
317 |
// The port is already in use. Cancel and try with new one. |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
318 |
jstatdThread.stopProcess(); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
319 |
jstatdThread.join(); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
320 |
return null; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
321 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
322 |
} catch (Throwable t) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
323 |
// Something went wrong in the product - clean up! |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
324 |
cleanUpThread(jstatdThread); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
325 |
throw t; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
326 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
327 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
328 |
return jstatdThread; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
329 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
330 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
331 |
public void doTest() throws Throwable { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
332 |
ProcessThread jstatdThread = null; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
333 |
try { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
334 |
while (jstatdThread == null) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
335 |
if (!useDefaultPort || withExternalRegistry) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
336 |
port = Integer.toString(Utils.getFreePort()); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
337 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
338 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
339 |
if (withExternalRegistry) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
340 |
Registry registry = startRegistry(); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
341 |
if (registry == null) { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
342 |
// The port is already in use. Cancel and try with new one. |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
343 |
continue; |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
344 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
345 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
346 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
347 |
jstatdThread = tryToSetupJstatdProcess(); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
348 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
349 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
350 |
runToolsAndVerify(); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
351 |
} finally { |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
352 |
cleanUpThread(jstatdThread); |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
353 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
354 |
} |
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
355 |
|
5f3e83a059c4
8022229: Intermittent test failures in sun/tools/jstatd
ykantser
parents:
diff
changeset
|
356 |
} |