Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/remote/mandatory/connection/CloseServerTest.java
38867 views
1
/*
2
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
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
*
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.
22
*/
23
24
/*
25
* @test
26
* @bug 4838640
27
* @summary test server close in different conditions.
28
* @author Shanliang JIANG
29
* @run clean CloseServerTest
30
* @run build CloseServerTest
31
* @run main CloseServerTest
32
*/
33
34
import java.net.MalformedURLException;
35
import java.io.IOException;
36
37
import javax.management.*;
38
import javax.management.remote.*;
39
40
public class CloseServerTest {
41
private static final String[] protocols = {"rmi", "iiop", "jmxmp"};
42
private static final MBeanServer mbs = MBeanServerFactory.createMBeanServer();
43
44
public static void main(String[] args) {
45
System.out.println(">>> Tests for closing a server.");
46
47
boolean ok = true;
48
for (int i = 0; i < protocols.length; i++) {
49
try {
50
if (!test(protocols[i])) {
51
System.out.println(">>> Test failed for " + protocols[i]);
52
ok = false;
53
} else {
54
System.out.println(">>> Test successed for " + protocols[i]);
55
}
56
} catch (Exception e) {
57
System.out.println(">>> Test failed for " + protocols[i]);
58
e.printStackTrace(System.out);
59
ok = false;
60
}
61
}
62
63
if (ok) {
64
System.out.println(">>> Test passed");
65
} else {
66
System.out.println(">>> TEST FAILED");
67
System.exit(1);
68
}
69
}
70
71
private static boolean test(String proto)
72
throws Exception {
73
System.out.println(">>> Test for protocol " + proto);
74
JMXServiceURL u = new JMXServiceURL(proto, null, 0);
75
JMXConnectorServer server;
76
JMXServiceURL addr;
77
JMXConnector client;
78
MBeanServerConnection mserver;
79
80
final ObjectName delegateName =
81
new ObjectName("JMImplementation:type=MBeanServerDelegate");
82
final NotificationListener dummyListener = new NotificationListener() {
83
public void handleNotification(Notification n, Object o) {
84
// do nothing
85
return;
86
}
87
};
88
89
try {
90
// open and close
91
System.out.println(">>> Open and close a server.");
92
93
server = JMXConnectorServerFactory.newJMXConnectorServer(u, null, mbs);
94
server.stop();
95
96
// open, start then close
97
System.out.println(">>> Open, start and close a server.");
98
99
server = JMXConnectorServerFactory.newJMXConnectorServer(u, null, mbs);
100
server.start();
101
server.stop();
102
103
// with a client, but close the server first
104
System.out.println(">>> Open, start a server, create a client, close the server then the client.");
105
106
server = JMXConnectorServerFactory.newJMXConnectorServer(u, null, mbs);
107
server.start();
108
109
addr = server.getAddress();
110
client = JMXConnectorFactory.newJMXConnector(addr, null);
111
client.connect(null);
112
113
server.stop();
114
115
try {
116
client.close();
117
} catch (Exception ee) {
118
// OK, the server has been closed
119
}
120
121
// with a client, but close the client first
122
System.out.println(">>> Open, start a server, create a client, close the client then server.");
123
server = JMXConnectorServerFactory.newJMXConnectorServer(u, null, mbs);
124
server.start();
125
126
addr = server.getAddress();
127
client = JMXConnectorFactory.newJMXConnector(addr, null);
128
client.connect(null);
129
130
client.close();
131
132
server.stop();
133
134
// with a client listener, but close the server first
135
System.out.println(">>> Open, start a server, create a client, add a listener, close the server then the client.");
136
server = JMXConnectorServerFactory.newJMXConnectorServer(u, null, mbs);
137
server.start();
138
139
addr = server.getAddress();
140
client = JMXConnectorFactory.newJMXConnector(addr, null);
141
client.connect(null);
142
143
mserver = client.getMBeanServerConnection();
144
mserver.addNotificationListener(delegateName, dummyListener, null, null);
145
146
server.stop();
147
148
try {
149
client.close();
150
} catch (Exception e) {
151
// ok, it is because the server has been closed.
152
}
153
154
// with a client listener, but close the client first
155
System.out.println(">>> Open, start a server, create a client, add a listener, close the client then the server.");
156
server = JMXConnectorServerFactory.newJMXConnectorServer(u, null, mbs);
157
server.start();
158
159
addr = server.getAddress();
160
client = JMXConnectorFactory.newJMXConnector(addr, null);
161
client.connect(null);
162
163
mserver = client.getMBeanServerConnection();
164
mserver.addNotificationListener(delegateName, dummyListener, null, null);
165
166
client.close();
167
server.stop();
168
} catch (MalformedURLException e) {
169
System.out.println(">>> Skipping unsupported URL " + u);
170
return true;
171
}
172
173
return true;
174
}
175
}
176
177