Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/management/jmxremote/bootstrap/JvmstatCountersTest.java
38867 views
1
/*
2
* Copyright (c) 2008, 2014, 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 4981215
27
* @summary Tests that the jvmstat counters published by the out-of-the-box
28
* management agent for the JMX connection details are correct.
29
* @author Luis-Miguel Alventosa
30
* @run clean JvmstatCountersTest
31
* @run build JvmstatCountersTest
32
* @run main/othervm/timeout=600 JvmstatCountersTest 1
33
* @run main/othervm/timeout=600 -Dcom.sun.management.jmxremote JvmstatCountersTest 2
34
* @run main/othervm/timeout=600 -Dcom.sun.management.jmxremote.port=0 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false JvmstatCountersTest 3
35
* @run main/othervm/timeout=600 JvmstatCountersTest 4
36
*/
37
38
import java.io.*;
39
import java.lang.management.*;
40
import java.util.*;
41
import javax.management.*;
42
import javax.management.remote.*;
43
import com.sun.tools.attach.*;
44
import sun.management.ConnectorAddressLink;
45
46
public class JvmstatCountersTest {
47
48
public static void checkAddress(String address) throws IOException {
49
System.out.println("Address = " + address);
50
JMXServiceURL url = new JMXServiceURL(address);
51
JMXConnector jmxc = JMXConnectorFactory.connect(url);
52
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
53
System.out.println("MBean Count = " + mbsc.getMBeanCount());
54
}
55
56
public static void checkKey(Map<String, String> data, int index,
57
String key, String expectedValue) throws Exception {
58
String counter = "sun.management.JMXConnectorServer." + index + "." + key;
59
if (!data.containsKey(counter)) {
60
System.out.println("Test FAILED! Missing counter " + counter);
61
throw new IllegalArgumentException("Test case failed");
62
}
63
String value = data.get(counter);
64
if (key.equals("remoteAddress")) {
65
checkAddress(value);
66
} else if (!expectedValue.equals(value)) {
67
System.out.println("Test FAILED! Invalid counter " +
68
counter + "=" + value);
69
throw new IllegalArgumentException("Test case failed");
70
}
71
System.out.println("OK: " + counter + "=" + value);
72
}
73
74
public static void main(String args[]) throws Exception {
75
String localAddress = ConnectorAddressLink.importFrom(0);
76
Map<String, String> remoteData = ConnectorAddressLink.importRemoteFrom(0);
77
final int testCase = Integer.parseInt(args[0]);
78
switch (testCase) {
79
case 1:
80
if (localAddress == null && remoteData.isEmpty()) {
81
System.out.println("Test PASSED! The OOTB management " +
82
"agent didn't publish any jvmstat counter.");
83
} else {
84
System.out.println("Test FAILED! The OOTB management " +
85
"agent unexpectedly published jvmstat counters.");
86
throw new IllegalArgumentException("Test case 1 failed");
87
}
88
break;
89
case 2:
90
if (localAddress == null) {
91
System.out.println("Test FAILED! The OOTB management " +
92
"agent didn't publish the local connector.");
93
throw new IllegalArgumentException("Test case 2 failed");
94
}
95
checkAddress(localAddress);
96
if (!remoteData.isEmpty()) {
97
System.out.println("Test FAILED! The OOTB management " +
98
"agent shouldn't publish the remote connector.");
99
throw new IllegalArgumentException("Test case 2 failed");
100
}
101
System.out.println("Test PASSED! The OOTB management " +
102
"agent only publishes the local connector through " +
103
"a jvmstat counter.");
104
break;
105
case 3:
106
if (localAddress == null) {
107
System.out.println("Test FAILED! The OOTB management " +
108
"agent didn't publish the local connector.");
109
throw new IllegalArgumentException("Test case 3 failed");
110
}
111
checkAddress(localAddress);
112
if (remoteData.isEmpty()) {
113
System.out.println("Test FAILED! The OOTB management " +
114
"agent didnn't publish the remote connector.");
115
throw new IllegalArgumentException("Test case 3 failed");
116
}
117
for (String key : remoteData.keySet()) {
118
if (!key.startsWith("sun.management.JMXConnectorServer.0.")) {
119
System.out.println("Test FAILED! The OOTB management " +
120
"agent shouldn't publish anything which isn't " +
121
"related to the remote connector.");
122
throw new IllegalArgumentException("Test case 3 failed");
123
}
124
}
125
checkKey(remoteData, 0, "remoteAddress", null);
126
checkKey(remoteData, 0, "authenticate", "false");
127
checkKey(remoteData, 0, "ssl", "false");
128
checkKey(remoteData, 0, "sslRegistry", "false");
129
checkKey(remoteData, 0, "sslNeedClientAuth", "false");
130
System.out.println("Test PASSED! The OOTB management " +
131
"agent publishes both the local and remote " +
132
"connector info through jvmstat counters.");
133
break;
134
case 4:
135
if (localAddress != null || !remoteData.isEmpty()) {
136
System.out.println("Test FAILED! The OOTB management " +
137
"agent unexpectedly published jvmstat counters.");
138
throw new IllegalArgumentException("Test case 4 failed");
139
}
140
RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean();
141
String name = rt.getName();
142
System.out.println("name = " + name);
143
String vmid = name.substring(0, name.indexOf("@"));
144
System.out.println("vmid = " + vmid);
145
VirtualMachine vm = VirtualMachine.attach(vmid);
146
Properties p = new Properties();
147
p.put("com.sun.management.jmxremote.port", "0");
148
p.put("com.sun.management.jmxremote.authenticate", "false");
149
p.put("com.sun.management.jmxremote.ssl", "false");
150
vm.startManagementAgent(p);
151
vm.startLocalManagementAgent();
152
vm.detach();
153
String localAddress2 = ConnectorAddressLink.importFrom(0);
154
if (localAddress2 == null) {
155
System.out.println("Test FAILED! The OOTB management " +
156
"agent didn't publish the local connector.");
157
throw new IllegalArgumentException("Test case 4 failed");
158
}
159
checkAddress(localAddress2);
160
Map<String, String> remoteData2 = ConnectorAddressLink.importRemoteFrom(0);
161
if (remoteData2.isEmpty()) {
162
System.out.println("Test FAILED! The OOTB management " +
163
"agent didnn't publish the remote connector.");
164
throw new IllegalArgumentException("Test case 4 failed");
165
}
166
for (String key : remoteData2.keySet()) {
167
if (!key.startsWith("sun.management.JMXConnectorServer.0.")) {
168
System.out.println("Test FAILED! The OOTB management " +
169
"agent shouldn't publish anything which isn't " +
170
"related to the remote connector.");
171
throw new IllegalArgumentException("Test case 4 failed");
172
}
173
}
174
checkKey(remoteData2, 0, "remoteAddress", null);
175
checkKey(remoteData2, 0, "authenticate", "false");
176
checkKey(remoteData2, 0, "ssl", "false");
177
checkKey(remoteData2, 0, "sslRegistry", "false");
178
checkKey(remoteData2, 0, "sslNeedClientAuth", "false");
179
System.out.println("Test PASSED! The OOTB management agent " +
180
"publishes both the local and remote connector " +
181
"info through jvmstat counters when the agent is " +
182
"loaded through the Attach API.");
183
}
184
System.out.println("Bye! Bye!");
185
}
186
}
187
188