author | dbuck |
Tue, 18 Aug 2015 04:29:28 -0700 | |
changeset 32417 | 6859107fc6c3 |
parent 30376 | 2ccf2cf7ea48 |
child 43503 | bc7f8619ab70 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
30376
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
||
25 |
/* |
|
26 |
* @test |
|
27 |
* @bug 4917237 |
|
28 |
* @summary test that process exit immediately after stop() / close() called |
|
29 |
* @author Jean Francois Denise |
|
30376
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
5506
diff
changeset
|
30 |
* @modules java.management |
2 | 31 |
* @run clean RMIExitTest |
32 |
* @run build RMIExitTest |
|
33 |
* @run main RMIExitTest |
|
34 |
*/ |
|
35 |
||
36 |
import java.net.MalformedURLException; |
|
37 |
import java.io.IOException; |
|
38 |
||
39 |
import javax.management.MBeanServerFactory; |
|
40 |
import javax.management.MBeanServer; |
|
41 |
import javax.management.ObjectName; |
|
42 |
import javax.management.MBeanServerConnection; |
|
43 |
import javax.management.NotificationListener; |
|
44 |
import javax.management.Notification; |
|
45 |
||
46 |
import javax.management.remote.JMXServiceURL; |
|
47 |
import javax.management.remote.JMXConnectorServer; |
|
48 |
import javax.management.remote.JMXConnector; |
|
49 |
import javax.management.remote.JMXConnectorServerFactory; |
|
50 |
import javax.management.remote.JMXConnectorFactory; |
|
51 |
||
52 |
/** |
|
53 |
* VM shutdown hook. Test that the hook is called less than 5 secs |
|
54 |
* after expected exit. |
|
55 |
*/ |
|
56 |
class TimeChecker extends Thread { |
|
1004 | 57 |
@Override |
2 | 58 |
public void run() { |
59 |
System.out.println("shutdown hook called"); |
|
60 |
long elapsedTime = |
|
61 |
System.currentTimeMillis() - RMIExitTest.exitStartTime; |
|
62 |
if(elapsedTime >= 5000) { |
|
63 |
System.out.println("BUG 4917237 not Fixed."); |
|
64 |
// Once in hook, to provide an exit status != 0, halt must |
|
65 |
// be called. Hooks are not called when halt is called. |
|
66 |
Runtime.getRuntime().halt(1); |
|
67 |
} else { |
|
68 |
System.out.println("BUG 4917237 Fixed"); |
|
69 |
} |
|
70 |
} |
|
71 |
} |
|
72 |
||
73 |
/** |
|
74 |
* Start a server, connect a client, add/remove listeners, close client, |
|
75 |
* stop server. Check that VM exits in less than 5 secs. |
|
76 |
* |
|
77 |
*/ |
|
78 |
public class RMIExitTest { |
|
79 |
private static final MBeanServer mbs = |
|
80 |
MBeanServerFactory.createMBeanServer(); |
|
81 |
public static long exitStartTime = 0; |
|
82 |
||
83 |
public static void main(String[] args) { |
|
84 |
System.out.println("Start test"); |
|
85 |
Runtime.getRuntime().addShutdownHook(new TimeChecker()); |
|
4156 | 86 |
test(); |
2 | 87 |
exitStartTime = System.currentTimeMillis(); |
88 |
System.out.println("End test"); |
|
89 |
} |
|
90 |
||
4156 | 91 |
private static void test() { |
2 | 92 |
try { |
93 |
JMXServiceURL u = new JMXServiceURL("rmi", null, 0); |
|
94 |
JMXConnectorServer server; |
|
95 |
JMXServiceURL addr; |
|
96 |
JMXConnector client; |
|
97 |
MBeanServerConnection mserver; |
|
98 |
||
99 |
final ObjectName delegateName = |
|
100 |
new ObjectName("JMImplementation:type=MBeanServerDelegate"); |
|
101 |
final NotificationListener dummyListener = |
|
102 |
new NotificationListener() { |
|
103 |
public void handleNotification(Notification n, |
|
104 |
Object o) { |
|
105 |
// do nothing |
|
106 |
return; |
|
107 |
} |
|
108 |
}; |
|
109 |
||
110 |
server = JMXConnectorServerFactory.newJMXConnectorServer(u, |
|
4156 | 111 |
null, |
2 | 112 |
mbs); |
113 |
server.start(); |
|
114 |
||
115 |
addr = server.getAddress(); |
|
116 |
client = JMXConnectorFactory.newJMXConnector(addr, null); |
|
117 |
client.connect(null); |
|
118 |
||
119 |
mserver = client.getMBeanServerConnection(); |
|
120 |
String s1 = "1"; |
|
121 |
String s2 = "2"; |
|
122 |
String s3 = "3"; |
|
123 |
||
124 |
mserver.addNotificationListener(delegateName, |
|
125 |
dummyListener, null, s1); |
|
126 |
mserver.addNotificationListener(delegateName, |
|
127 |
dummyListener, null, s2); |
|
128 |
mserver.addNotificationListener(delegateName, |
|
129 |
dummyListener, null, s3); |
|
130 |
||
131 |
mserver.removeNotificationListener(delegateName, |
|
132 |
dummyListener, null, s3); |
|
133 |
mserver.removeNotificationListener(delegateName, |
|
134 |
dummyListener, null, s2); |
|
135 |
mserver.removeNotificationListener(delegateName, |
|
136 |
dummyListener, null, s1); |
|
137 |
client.close(); |
|
138 |
||
139 |
server.stop(); |
|
140 |
} catch (Exception e) { |
|
141 |
System.out.println(e); |
|
142 |
e.printStackTrace(); |
|
143 |
System.exit(1); |
|
144 |
} |
|
145 |
} |
|
146 |
} |