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/LocalManagementTest.java
38867 views
1
/*
2
* Copyright (c) 2013, 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
import java.io.File;
25
import java.lang.reflect.Method;
26
import java.lang.reflect.Modifier;
27
import java.nio.file.FileSystem;
28
import java.nio.file.FileSystems;
29
import java.nio.file.Files;
30
import java.nio.file.Path;
31
import java.util.ArrayList;
32
import java.util.List;
33
import java.util.concurrent.TimeUnit;
34
import java.util.concurrent.atomic.AtomicReference;
35
import jdk.testlibrary.ProcessTools;
36
37
/**
38
* @test
39
* @library /lib/testlibrary
40
* @bug 5016507 6173612 6319776 6342019 6484550 8004926
41
* @summary Start a managed VM and test that a management tool can connect
42
* without connection or username/password details.
43
* TestManager will attempt a connection to the address obtained from
44
* both agent properties and jvmstat buffer.
45
* @build jdk.testlibrary.* TestManager TestApplication
46
* @run main/othervm/timeout=300 -XX:+UsePerfData LocalManagementTest
47
*/
48
49
public class LocalManagementTest {
50
private static final String TEST_CLASSPATH = System.getProperty("test.class.path");
51
private static final String TEST_JDK = System.getProperty("test.jdk");
52
53
public static void main(String[] args) throws Exception {
54
int failures = 0;
55
for(Method m : LocalManagementTest.class.getDeclaredMethods()) {
56
if (Modifier.isStatic(m.getModifiers()) &&
57
m.getName().startsWith("test")) {
58
m.setAccessible(true);
59
try {
60
System.out.println(m.getName());
61
System.out.println("==========");
62
Boolean rslt = (Boolean)m.invoke(null);
63
if (!rslt) {
64
System.err.println(m.getName() + " failed");
65
failures++;
66
}
67
} catch (Exception e) {
68
e.printStackTrace();
69
failures++;
70
}
71
}
72
}
73
if (failures > 0) {
74
throw new Error("Test failed");
75
}
76
}
77
78
private static boolean test1() throws Exception {
79
return doTest("1", "-Dcom.sun.management.jmxremote");
80
}
81
82
/**
83
* no args (blank) - manager should attach and start agent
84
*/
85
private static boolean test3() throws Exception {
86
return doTest("3", null);
87
}
88
89
/**
90
* use DNS-only name service
91
*/
92
private static boolean test5() throws Exception {
93
return doTest("5", "-Dsun.net.spi.namservice.provider.1=\"dns,sun\"");
94
}
95
96
private static boolean doTest(String testId, String arg) throws Exception {
97
List<String> args = new ArrayList<>();
98
args.add("-cp");
99
args.add(TEST_CLASSPATH);
100
101
if (arg != null) {
102
args.add(arg);
103
}
104
args.add("TestApplication");
105
ProcessBuilder server = ProcessTools.createJavaProcessBuilder(
106
args.toArray(new String[args.size()])
107
);
108
109
Process serverPrc = null, clientPrc = null;
110
try {
111
final AtomicReference<String> port = new AtomicReference<>();
112
final AtomicReference<String> pid = new AtomicReference<>();
113
114
serverPrc = ProcessTools.startProcess(
115
"TestApplication(" + testId + ")",
116
server,
117
(String line) -> {
118
if (line.startsWith("port:")) {
119
port.set(line.split("\\:")[1]);
120
} else if (line.startsWith("pid:")) {
121
pid.set(line.split("\\:")[1]);
122
} else if (line.startsWith("waiting")) {
123
return true;
124
}
125
return false;
126
},
127
5,
128
TimeUnit.SECONDS
129
);
130
131
System.out.println("Attaching test manager:");
132
System.out.println("=========================");
133
System.out.println(" PID : " + pid.get());
134
System.out.println(" shutdown port : " + port.get());
135
136
ProcessBuilder client = ProcessTools.createJavaProcessBuilder(
137
"-cp",
138
TEST_CLASSPATH +
139
File.pathSeparator +
140
TEST_JDK +
141
File.separator +
142
"lib" +
143
File.separator +
144
"tools.jar",
145
"TestManager",
146
pid.get(),
147
port.get(),
148
"true"
149
);
150
151
clientPrc = ProcessTools.startProcess(
152
"TestManager",
153
client,
154
(String line) -> line.startsWith("Starting TestManager for PID"),
155
10,
156
TimeUnit.SECONDS
157
);
158
159
int clientExitCode = clientPrc.waitFor();
160
int serverExitCode = serverPrc.waitFor();
161
return clientExitCode == 0 && serverExitCode == 0;
162
} finally {
163
if (clientPrc != null) {
164
System.out.println("Stopping process " + clientPrc);
165
clientPrc.destroy();
166
clientPrc.waitFor();
167
}
168
if (serverPrc != null) {
169
System.out.println("Stopping process " + serverPrc);
170
serverPrc.destroy();
171
serverPrc.waitFor();
172
}
173
}
174
}
175
}
176
177