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/notif/AddRemoveTest.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
/*
26
* @test
27
* @bug 4838640 4917194
28
* @summary test on add/remove NotificationListener
29
* @author Shanliang JIANG
30
* @run clean AddRemoveTest
31
* @run build AddRemoveTest
32
* @run main AddRemoveTest
33
*/
34
35
import java.net.MalformedURLException;
36
import java.io.IOException;
37
38
import javax.management.*;
39
import javax.management.remote.*;
40
41
public class AddRemoveTest {
42
private static final String[] protocols = {"rmi", "iiop", "jmxmp"};
43
private static final MBeanServer mbs = MBeanServerFactory.createMBeanServer();
44
45
public static void main(String[] args) {
46
System.out.println(">>> test on add/remove NotificationListener.");
47
48
boolean ok = true;
49
for (int i = 0; i < protocols.length; i++) {
50
try {
51
if (!test(protocols[i])) {
52
System.out.println(">>> Test failed for " + protocols[i]);
53
ok = false;
54
} else {
55
System.out.println(">>> Test successed for " + protocols[i]);
56
}
57
} catch (Exception e) {
58
System.out.println(">>> Test failed for " + protocols[i]);
59
e.printStackTrace(System.out);
60
ok = false;
61
}
62
}
63
64
if (ok) {
65
System.out.println(">>> Test passed");
66
} else {
67
System.out.println(">>> TEST FAILED");
68
System.exit(1);
69
}
70
}
71
72
private static boolean test(String proto)
73
throws Exception {
74
System.out.println(">>> Test for protocol " + proto);
75
JMXServiceURL u = new JMXServiceURL(proto, null, 0);
76
JMXConnectorServer server;
77
JMXServiceURL addr;
78
JMXConnector client;
79
MBeanServerConnection mserver;
80
81
final ObjectName delegateName =
82
new ObjectName("JMImplementation:type=MBeanServerDelegate");
83
final NotificationListener dummyListener = new NotificationListener() {
84
public void handleNotification(Notification n, Object o) {
85
// do nothing
86
return;
87
}
88
};
89
90
try {
91
// with a client listener, but close the server first
92
server = JMXConnectorServerFactory.newJMXConnectorServer(u, null, mbs);
93
server.start();
94
95
addr = server.getAddress();
96
client = JMXConnectorFactory.newJMXConnector(addr, null);
97
client.connect(null);
98
99
mserver = client.getMBeanServerConnection();
100
String s1 = "1";
101
String s2 = "2";
102
String s3 = "3";
103
104
for (int i=0; i<3; i++) {
105
mserver.addNotificationListener(delegateName, dummyListener, null, s1);
106
mserver.addNotificationListener(delegateName, dummyListener, null, s2);
107
mserver.addNotificationListener(delegateName, dummyListener, null, s3);
108
109
mserver.removeNotificationListener(delegateName, dummyListener, null, s3);
110
mserver.removeNotificationListener(delegateName, dummyListener, null, s2);
111
mserver.removeNotificationListener(delegateName, dummyListener, null, s1);
112
}
113
114
for (int i=0; i<3; i++) {
115
mserver.addNotificationListener(delegateName, dummyListener, null, s1);
116
mserver.addNotificationListener(delegateName, dummyListener, null, s2);
117
mserver.addNotificationListener(delegateName, dummyListener, null, s3);
118
119
mserver.removeNotificationListener(delegateName, dummyListener);
120
121
try {
122
mserver.removeNotificationListener(delegateName, dummyListener, null, s1);
123
System.out.println("Failed to remove a listener.");
124
125
// no expected exception
126
return false;
127
} catch (ListenerNotFoundException lne) {
128
// As expected.
129
}
130
}
131
client.close();
132
133
server.stop();
134
135
} catch (MalformedURLException e) {
136
System.out.println(">>> Skipping unsupported URL " + u);
137
return true;
138
}
139
140
return true;
141
}
142
}
143
144