author | ykantser |
Thu, 07 May 2015 09:11:49 +0200 | |
changeset 30376 | 2ccf2cf7ea48 |
parent 25182 | 1f6766bac82c |
child 44640 | 590dec7cadb4 |
permissions | -rw-r--r-- |
23032
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
1 |
/* |
30376
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
25182
diff
changeset
|
2 |
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
23032
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
4 |
* |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
8 |
* |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
13 |
* accompanied this code). |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
14 |
* |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
18 |
* |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
21 |
* questions. |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
22 |
*/ |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
23 |
|
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
24 |
/** |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
25 |
* @test |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
26 |
* @bug 8035668 |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
27 |
* @library /lib/testlibrary |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
28 |
* @summary Test checks case when target application finishes execution and jstat didn't complete work. |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
29 |
jstat is started with interval = 100 (jstat -compiler 100) and monitored application finishes |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
30 |
after 500ms. This shouldn't cause crash or hang in target application or in jstat. |
30376
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
25182
diff
changeset
|
31 |
* @modules java.management |
24509
5d02a6d25f78
8043520: Serviceability tests using @library failing with java.lang.NoClassDefFoundError
ykantser
parents:
23032
diff
changeset
|
32 |
* @build jdk.testlibrary.* JStatInterval |
23032
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
33 |
* @run main JStatInterval |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
34 |
*/ |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
35 |
|
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
36 |
import jdk.testlibrary.ProcessTools; |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
37 |
import jdk.testlibrary.JDKToolLauncher; |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
38 |
|
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
39 |
import java.io.BufferedReader; |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
40 |
import java.io.InputStreamReader; |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
41 |
import java.util.concurrent.TimeUnit; |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
42 |
import java.util.concurrent.atomic.AtomicBoolean; |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
43 |
import java.util.concurrent.atomic.AtomicInteger; |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
44 |
|
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
45 |
public class JStatInterval { |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
46 |
private static final String READY = "READY"; |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
47 |
private static final String ERROR = "!ERROR"; |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
48 |
|
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
49 |
public static class Application { |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
50 |
public static void main(String[] args) { |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
51 |
try { |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
52 |
System.out.println(READY); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
53 |
System.out.flush(); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
54 |
int exitCode = System.in.read(); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
55 |
Thread.sleep(500); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
56 |
System.exit(exitCode); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
57 |
} catch (Exception e) { |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
58 |
System.out.println(ERROR); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
59 |
System.out.flush(); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
60 |
throw new Error(e); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
61 |
} |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
62 |
} |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
63 |
} |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
64 |
public static void main(String[] args) throws Exception { |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
65 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
66 |
"-cp", |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
67 |
System.getProperty("test.class.path"), |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
68 |
"-XX:+UsePerfData", |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
69 |
Application.class.getName() |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
70 |
); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
71 |
AtomicBoolean error = new AtomicBoolean(false); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
72 |
Process app = ProcessTools.startProcess( |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
73 |
"application", |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
74 |
pb, |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
75 |
line -> { |
25182
1f6766bac82c
8048193: [tests] Replace JPS and stdout based PID retrieval by Process.getPid()
jbachorik
parents:
24509
diff
changeset
|
76 |
if (line.equals(READY)) { |
23032
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
77 |
return true; |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
78 |
} else if (line.equals(ERROR)) { |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
79 |
error.set(true); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
80 |
return true; |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
81 |
} |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
82 |
return false; |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
83 |
}, |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
84 |
10, |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
85 |
TimeUnit.SECONDS |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
86 |
); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
87 |
if (error.get()) { |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
88 |
throw new Error("Unable to start the monitored application."); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
89 |
} |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
90 |
|
25182
1f6766bac82c
8048193: [tests] Replace JPS and stdout based PID retrieval by Process.getPid()
jbachorik
parents:
24509
diff
changeset
|
91 |
String pidStr = String.valueOf(app.getPid()); |
23032
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
92 |
JDKToolLauncher l = JDKToolLauncher.createUsingTestJDK("jstat"); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
93 |
l.addToolArg("-compiler"); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
94 |
l.addToolArg(pidStr); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
95 |
l.addToolArg("100"); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
96 |
|
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
97 |
ProcessBuilder jstatDef = new ProcessBuilder(l.getCommand()); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
98 |
Process jstat = ProcessTools.startProcess( |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
99 |
"jstat", |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
100 |
jstatDef, |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
101 |
line -> { |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
102 |
if (line.trim().toLowerCase().startsWith("compiled")) { |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
103 |
return true; |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
104 |
} |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
105 |
return false; |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
106 |
}, |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
107 |
10, |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
108 |
TimeUnit.SECONDS |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
109 |
); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
110 |
|
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
111 |
app.getOutputStream().write(0); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
112 |
app.getOutputStream().flush(); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
113 |
|
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
114 |
if (app.waitFor() != 0) { |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
115 |
throw new Error("Error detected upon exiting the monitored application with active jstat"); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
116 |
} |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
117 |
if (jstat.waitFor() != 0) { |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
118 |
throw new Error("Error detected in jstat when monitored application has exited prematurely"); |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
119 |
} |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
120 |
} |
97414b5605ab
8035668: [test] Check that jstat does not cause problems when monitored application exits before jstat finishes its work
jbachorik
parents:
diff
changeset
|
121 |
} |