author | jbachorik |
Mon, 18 Nov 2013 15:25:15 +0100 | |
changeset 21802 | b36494ddf19e |
parent 21408 | 6468b29c9877 |
child 23031 | 995cf5c2eb55 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
21408
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2003, 2013, 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 |
import sun.management.jmxremote.ConnectorBootstrap; |
|
24 |
||
25 |
import java.io.File; |
|
26 |
import java.io.FileInputStream; |
|
27 |
import java.io.FilenameFilter; |
|
28 |
import java.io.IOException; |
|
21408
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
29 |
import java.net.BindException; |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
30 |
import java.net.ServerSocket; |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
31 |
import java.rmi.server.ExportException; |
2 | 32 |
|
33 |
import java.util.Properties; |
|
34 |
import java.util.Iterator; |
|
35 |
import java.util.Set; |
|
36 |
import java.util.ArrayList; |
|
37 |
import java.util.HashMap; |
|
38 |
import java.util.Map; |
|
39 |
import java.util.Enumeration; |
|
40 |
||
41 |
import javax.management.remote.*; |
|
42 |
import javax.management.*; |
|
43 |
||
44 |
import sun.management.AgentConfigurationError; |
|
45 |
||
46 |
import util.TestLogger; |
|
47 |
||
48 |
/** |
|
49 |
* <p>This class implements unit test for RMI Bootstrap. |
|
50 |
* When called with no arguments main() looks in the directory indicated |
|
51 |
* by the "test.src" system property for files called management*ok.properties |
|
52 |
* or management*ko.properties. The *ok.properties files are assumed to be |
|
53 |
* valid Java M&M config files for which the bootstrap should succeed. |
|
54 |
* The *ko.properties files are assumed to be configurations for which the |
|
55 |
* bootstrap & connection test will fail.</p> |
|
56 |
* |
|
57 |
* <p>The rmi port number can be specified with the "rmi.port" system property. |
|
21408
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
58 |
* If not, this test will use the first available port</p> |
2 | 59 |
* |
60 |
* <p>When called with some argument, the main() will interprete its args to |
|
61 |
* be Java M&M configuration file names. The filenames are expected to end |
|
62 |
* with ok.properties or ko.properties - and are interpreted as above.</p> |
|
63 |
* |
|
64 |
* <p>Note that a limitation of the RMI registry (bug 4267864) prevent |
|
65 |
* this test from succeeding if more than 1 configuration is used. |
|
66 |
* As long as 4267864 isn't fix, this test must be called as many times |
|
67 |
* as needed but with a single argument (no arguments, or several arguments |
|
68 |
* will fail).</p> |
|
69 |
* |
|
70 |
* <p>Debug traces are logged in "sun.management.test"</p> |
|
71 |
**/ |
|
72 |
public class RmiBootstrapTest { |
|
21408
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
73 |
// the number of consecutive ports to test for availability |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
74 |
private static final int PORT_TEST_LEN = 800; |
2 | 75 |
static TestLogger log = |
76 |
new TestLogger("RmiBootstrapTest"); |
|
77 |
||
78 |
/** |
|
79 |
* When launching several registries, we increment the port number |
|
80 |
* to avoid falling into "port number already in use" problems. |
|
81 |
**/ |
|
82 |
static int testPort = 0; |
|
21408
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
83 |
static int basePort = 0; |
2 | 84 |
|
85 |
/** |
|
86 |
* Default values for RMI configuration properties. |
|
87 |
**/ |
|
88 |
public static interface DefaultValues { |
|
89 |
public static final String PORT="0"; |
|
90 |
public static final String CONFIG_FILE_NAME="management.properties"; |
|
91 |
public static final String USE_SSL="true"; |
|
92 |
public static final String USE_AUTHENTICATION="true"; |
|
93 |
public static final String PASSWORD_FILE_NAME="jmxremote.password"; |
|
94 |
public static final String ACCESS_FILE_NAME="jmxremote.access"; |
|
95 |
public static final String KEYSTORE="keystore"; |
|
96 |
public static final String KEYSTORE_PASSWD="password"; |
|
97 |
public static final String TRUSTSTORE="truststore"; |
|
98 |
public static final String TRUSTSTORE_PASSWD="trustword"; |
|
99 |
public static final String SSL_NEED_CLIENT_AUTH="false"; |
|
100 |
} |
|
101 |
||
102 |
/** |
|
103 |
* Names of RMI configuration properties. |
|
104 |
**/ |
|
105 |
public static interface PropertyNames { |
|
106 |
public static final String PORT= |
|
107 |
"com.sun.management.jmxremote.port"; |
|
108 |
public static final String CONFIG_FILE_NAME= |
|
109 |
"com.sun.management.config.file"; |
|
110 |
public static final String USE_SSL= |
|
111 |
"com.sun.management.jmxremote.ssl"; |
|
112 |
public static final String USE_AUTHENTICATION= |
|
113 |
"com.sun.management.jmxremote.authenticate"; |
|
114 |
public static final String PASSWORD_FILE_NAME= |
|
115 |
"com.sun.management.jmxremote.password.file"; |
|
116 |
public static final String ACCESS_FILE_NAME= |
|
117 |
"com.sun.management.jmxremote.access.file"; |
|
118 |
public static final String INSTRUMENT_ALL= |
|
119 |
"com.sun.management.instrumentall"; |
|
120 |
public static final String CREDENTIALS = |
|
121 |
"jmx.remote.credentials"; |
|
122 |
public static final String KEYSTORE= |
|
123 |
"javax.net.ssl.keyStore"; |
|
124 |
public static final String KEYSTORE_PASSWD= |
|
125 |
"javax.net.ssl.keyStorePassword"; |
|
126 |
public static final String TRUSTSTORE= |
|
127 |
"javax.net.ssl.trustStore"; |
|
128 |
public static final String TRUSTSTORE_PASSWD= |
|
129 |
"javax.net.ssl.trustStorePassword"; |
|
130 |
public static final String SSL_ENABLED_CIPHER_SUITES = |
|
131 |
"com.sun.management.jmxremote.ssl.enabled.cipher.suites"; |
|
132 |
public static final String SSL_ENABLED_PROTOCOLS = |
|
133 |
"com.sun.management.jmxremote.ssl.enabled.protocols"; |
|
134 |
public static final String SSL_NEED_CLIENT_AUTH = |
|
135 |
"com.sun.management.jmxremote.ssl.need.client.auth"; |
|
136 |
} |
|
137 |
||
138 |
/** |
|
139 |
* A filter to find all filenames who match <prefix>*<suffix>. |
|
140 |
* Note that <prefix> and <suffix> can overlap. |
|
141 |
**/ |
|
142 |
private static class ConfigFilenameFilter implements FilenameFilter { |
|
143 |
final String suffix; |
|
144 |
final String prefix; |
|
145 |
ConfigFilenameFilter(String prefix, String suffix) { |
|
146 |
this.suffix=suffix; |
|
147 |
this.prefix=prefix; |
|
148 |
} |
|
149 |
public boolean accept(File dir, String name) { |
|
150 |
return (name.startsWith(prefix) && name.endsWith(suffix)); |
|
151 |
} |
|
152 |
} |
|
153 |
||
154 |
/** |
|
155 |
* Get all "management*ok.properties" files in the directory |
|
156 |
* indicated by the "test.src" management property. |
|
157 |
**/ |
|
158 |
private static File[] findConfigurationFilesOk() { |
|
159 |
final String testSrc = System.getProperty("test.src"); |
|
160 |
final File dir = new File(testSrc); |
|
161 |
final FilenameFilter filter = |
|
162 |
new ConfigFilenameFilter("management_test","ok.properties"); |
|
163 |
return dir.listFiles(filter); |
|
164 |
} |
|
165 |
||
166 |
/** |
|
167 |
* Get all "management*ko.properties" files in the directory |
|
168 |
* indicated by the "test.src" management property. |
|
169 |
**/ |
|
170 |
private static File[] findConfigurationFilesKo() { |
|
171 |
final String testSrc = System.getProperty("test.src"); |
|
172 |
final File dir = new File(testSrc); |
|
173 |
final FilenameFilter filter = |
|
174 |
new ConfigFilenameFilter("management_test","ko.properties"); |
|
175 |
return dir.listFiles(filter); |
|
176 |
} |
|
177 |
||
178 |
/** |
|
179 |
* List all MBeans and their attributes. Used to test communication |
|
180 |
* with the Java M&M MBean Server. |
|
181 |
* @return the number of queried MBeans. |
|
182 |
*/ |
|
183 |
public static int listMBeans(MBeanServerConnection server) |
|
184 |
throws IOException { |
|
185 |
return listMBeans(server,null,null); |
|
186 |
} |
|
187 |
||
188 |
/** |
|
189 |
* List all matching MBeans and their attributes. |
|
190 |
* Used to test communication with the Java M&M MBean Server. |
|
191 |
* @return the number of matching MBeans. |
|
192 |
*/ |
|
193 |
public static int listMBeans(MBeanServerConnection server, |
|
194 |
ObjectName pattern, QueryExp query) |
|
195 |
throws IOException { |
|
196 |
||
197 |
final Set names = server.queryNames(pattern,query); |
|
198 |
for (final Iterator i=names.iterator(); i.hasNext(); ) { |
|
199 |
ObjectName name = (ObjectName)i.next(); |
|
200 |
log.trace("listMBeans","Got MBean: "+name); |
|
201 |
try { |
|
202 |
MBeanInfo info = |
|
203 |
server.getMBeanInfo((ObjectName)name); |
|
204 |
MBeanAttributeInfo[] attrs = info.getAttributes(); |
|
205 |
if (attrs == null) continue; |
|
206 |
for (int j=0; j<attrs.length; j++) { |
|
207 |
if (attrs[j].isReadable()) { |
|
208 |
try { |
|
209 |
Object o = |
|
210 |
server.getAttribute(name,attrs[j].getName()); |
|
211 |
if (log.isDebugOn()) |
|
212 |
log.debug("listMBeans","\t\t" + |
|
213 |
attrs[j].getName() + |
|
214 |
" = "+o); |
|
215 |
} catch (Exception x) { |
|
216 |
log.trace("listMBeans","JmxClient failed to get " + |
|
217 |
attrs[j].getName() + ": " + x); |
|
218 |
final IOException io = |
|
219 |
new IOException("JmxClient failed to get " + |
|
220 |
attrs[j].getName()); |
|
221 |
io.initCause(x); |
|
222 |
throw io; |
|
223 |
} |
|
224 |
} |
|
225 |
} |
|
226 |
} catch (Exception x) { |
|
227 |
log.trace("listMBeans", |
|
228 |
"JmxClient failed to get MBeanInfo: " + x); |
|
229 |
final IOException io = |
|
230 |
new IOException("JmxClient failed to get MBeanInfo: "+x); |
|
231 |
io.initCause(x); |
|
232 |
throw io; |
|
233 |
} |
|
234 |
} |
|
235 |
return names.size(); |
|
236 |
} |
|
237 |
||
238 |
/** |
|
239 |
* Compute the full path name for a default file. |
|
240 |
* @param basename basename (with extension) of the default file. |
|
241 |
* @return ${JRE}/lib/management/${basename} |
|
242 |
**/ |
|
243 |
private static String getDefaultFileName(String basename) { |
|
244 |
final String fileSeparator = File.separator; |
|
245 |
final StringBuffer defaultFileName = |
|
246 |
new StringBuffer(System.getProperty("java.home")). |
|
247 |
append(fileSeparator).append("lib").append(fileSeparator). |
|
248 |
append("management").append(fileSeparator). |
|
249 |
append(basename); |
|
250 |
return defaultFileName.toString(); |
|
251 |
} |
|
252 |
||
253 |
/** |
|
254 |
* Compute the full path name for a default file. |
|
255 |
* @param basename basename (with extension) of the default file. |
|
256 |
* @return ${JRE}/lib/management/${basename} |
|
257 |
**/ |
|
258 |
private static String getDefaultStoreName(String basename) { |
|
259 |
final String fileSeparator = File.separator; |
|
260 |
final StringBuffer defaultFileName = |
|
261 |
new StringBuffer(System.getProperty("test.src")). |
|
262 |
append(fileSeparator).append("ssl").append(fileSeparator). |
|
263 |
append(basename); |
|
264 |
return defaultFileName.toString(); |
|
265 |
} |
|
266 |
||
267 |
||
268 |
/** |
|
269 |
* Parses the password file to read the credentials. |
|
270 |
* Returns an ArrayList of arrays of 2 string: |
|
271 |
* {<subject>, <password>}. |
|
272 |
* If the password file does not exists, return an empty list. |
|
273 |
* (File not found = empty file). |
|
274 |
**/ |
|
275 |
private ArrayList readCredentials(String passwordFileName) |
|
276 |
throws IOException { |
|
277 |
final Properties pws = new Properties(); |
|
278 |
final ArrayList result = new ArrayList(); |
|
279 |
final File f = new File(passwordFileName); |
|
280 |
if (!f.exists()) return result; |
|
281 |
FileInputStream fin = new FileInputStream(passwordFileName); |
|
282 |
try {pws.load(fin);}finally{fin.close();} |
|
283 |
for (Enumeration en=pws.propertyNames();en.hasMoreElements();) { |
|
284 |
final String[] cred = new String[2]; |
|
285 |
cred[0]=(String)en.nextElement(); |
|
286 |
cred[1]=pws.getProperty(cred[0]); |
|
287 |
result.add(cred); |
|
288 |
} |
|
289 |
return result; |
|
290 |
} |
|
291 |
||
292 |
||
293 |
/** |
|
294 |
* Connect with the given url, using all given credentials in turn. |
|
295 |
* A null entry in the useCredentials arrays indicate a connection |
|
296 |
* where no credentials are used. |
|
297 |
* @param url JMXServiceURL of the server. |
|
298 |
* @param useCredentials An array of credentials (a credential |
|
299 |
* is a two String array, so this is an array of arrays |
|
300 |
* of strings: |
|
301 |
* useCredentials[i][0]=subject |
|
302 |
* useCredentials[i][1]=password |
|
303 |
* if useCredentials[i] == null means no credentials. |
|
304 |
* @param expectConnectOk true if connection is expected to succeed |
|
305 |
* Note: if expectConnectOk=false and the test fails to connect |
|
306 |
* the number of failure is not incremented. Conversely, |
|
307 |
* if expectConnectOk=false and the test does not fail to |
|
308 |
* connect the number of failure is incremented. |
|
309 |
* @param expectReadOk true if communication (listMBeans) is expected |
|
310 |
* to succeed. |
|
311 |
* Note: if expectReadOk=false and the test fails to read MBeans |
|
312 |
* the number of failure is not incremented. Conversely, |
|
313 |
* if expectReadOk=false and the test does not fail to |
|
314 |
* read MBeans the number of failure is incremented. |
|
315 |
* @return number of failure. |
|
316 |
**/ |
|
317 |
public int connectAndRead(JMXServiceURL url, |
|
318 |
Object[] useCredentials, |
|
319 |
boolean expectConnectOk, |
|
320 |
boolean expectReadOk) |
|
321 |
throws IOException { |
|
322 |
||
323 |
int errorCount = 0; |
|
324 |
||
325 |
for (int i=0 ; i<useCredentials.length ; i++) { |
|
326 |
final Map m = new HashMap(); |
|
327 |
final String[] credentials = (String[])useCredentials[i]; |
|
328 |
final String crinfo; |
|
329 |
if (credentials != null) { |
|
330 |
crinfo = "{"+credentials[0] + ", " + credentials[1] + "}"; |
|
331 |
m.put(PropertyNames.CREDENTIALS,credentials); |
|
332 |
} else { |
|
333 |
crinfo="no credentials"; |
|
334 |
} |
|
335 |
log.trace("testCommunication","using credentials: " + crinfo); |
|
336 |
||
337 |
final JMXConnector c; |
|
338 |
try { |
|
339 |
c = JMXConnectorFactory.connect(url,m); |
|
340 |
} catch (IOException x ) { |
|
341 |
if (expectConnectOk) { |
|
342 |
final String err = "Connection failed for " + crinfo + |
|
343 |
": " + x; |
|
344 |
System.out.println(err); |
|
345 |
log.trace("testCommunication",err); |
|
346 |
log.debug("testCommunication",x); |
|
347 |
errorCount++; |
|
348 |
continue; |
|
349 |
} else { |
|
350 |
System.out.println("Connection failed as expected for " + |
|
351 |
crinfo + ": " + x); |
|
352 |
continue; |
|
353 |
} |
|
354 |
} catch (RuntimeException x ) { |
|
355 |
if (expectConnectOk) { |
|
356 |
final String err = "Connection failed for " + crinfo + |
|
357 |
": " + x; |
|
358 |
System.out.println(err); |
|
359 |
log.trace("testCommunication",err); |
|
360 |
log.debug("testCommunication",x); |
|
361 |
errorCount++; |
|
362 |
continue; |
|
363 |
} else { |
|
364 |
System.out.println("Connection failed as expected for " + |
|
365 |
crinfo + ": " + x); |
|
366 |
continue; |
|
367 |
} |
|
368 |
} |
|
369 |
try { |
|
370 |
MBeanServerConnection conn = |
|
371 |
c.getMBeanServerConnection(); |
|
372 |
if (log.isDebugOn()) { |
|
373 |
log.debug("testCommunication","Connection is:" + conn); |
|
374 |
log.debug("testCommunication","Server domain is: " + |
|
375 |
conn.getDefaultDomain()); |
|
376 |
} |
|
377 |
final ObjectName pattern = |
|
378 |
new ObjectName("java.lang:type=Memory,*"); |
|
379 |
final int count = listMBeans(conn,pattern,null); |
|
380 |
if (count == 0) |
|
381 |
throw new Exception("Expected at least one matching "+ |
|
382 |
"MBean for "+pattern); |
|
383 |
if (expectReadOk) { |
|
384 |
System.out.println("Communication succeeded " + |
|
385 |
"as expected for "+ |
|
386 |
crinfo + ": found " + count |
|
387 |
+ ((count<2)?"MBean":"MBeans")); |
|
388 |
} else { |
|
389 |
final String err = "Expected failure didn't occur for " + |
|
390 |
crinfo; |
|
391 |
System.out.println(err); |
|
392 |
errorCount++; |
|
393 |
} |
|
394 |
} catch (IOException x ) { |
|
395 |
if (expectReadOk) { |
|
396 |
final String err = "Communication failed with " + crinfo + |
|
397 |
": " + x; |
|
398 |
System.out.println(err); |
|
399 |
log.trace("testCommunication",err); |
|
400 |
log.debug("testCommunication",x); |
|
401 |
errorCount++; |
|
402 |
continue; |
|
403 |
} else { |
|
404 |
System.out.println("Communication failed as expected for "+ |
|
405 |
crinfo + ": " + x); |
|
406 |
continue; |
|
407 |
} |
|
408 |
} catch (RuntimeException x ) { |
|
409 |
if (expectReadOk) { |
|
410 |
final String err = "Communication failed with " + crinfo + |
|
411 |
": " + x; |
|
412 |
System.out.println(err); |
|
413 |
log.trace("testCommunication",err); |
|
414 |
log.debug("testCommunication",x); |
|
415 |
errorCount++; |
|
416 |
continue; |
|
417 |
} else { |
|
418 |
System.out.println("Communication failed as expected for "+ |
|
419 |
crinfo + ": " + x); |
|
420 |
} |
|
421 |
} catch (Exception x) { |
|
422 |
final String err = "Failed to read MBeans with " + crinfo + |
|
423 |
": " + x; |
|
424 |
System.out.println(err); |
|
425 |
log.trace("testCommunication",err); |
|
426 |
log.debug("testCommunication",x); |
|
427 |
errorCount++; |
|
428 |
continue; |
|
429 |
} finally { |
|
430 |
c.close(); |
|
431 |
} |
|
432 |
} |
|
433 |
return errorCount; |
|
434 |
} |
|
435 |
||
436 |
||
437 |
private void setSslProperties() { |
|
438 |
final String defaultKeyStore = |
|
439 |
getDefaultStoreName(DefaultValues.KEYSTORE); |
|
440 |
final String defaultTrustStore = |
|
441 |
getDefaultStoreName(DefaultValues.TRUSTSTORE); |
|
442 |
||
443 |
final String keyStore = |
|
444 |
System.getProperty(PropertyNames.KEYSTORE, defaultKeyStore); |
|
445 |
System.setProperty(PropertyNames.KEYSTORE,keyStore); |
|
446 |
log.trace("setSslProperties",PropertyNames.KEYSTORE+"="+keyStore); |
|
447 |
||
448 |
final String password = |
|
449 |
System.getProperty(PropertyNames.KEYSTORE_PASSWD, |
|
450 |
DefaultValues.KEYSTORE_PASSWD); |
|
451 |
System.setProperty(PropertyNames.KEYSTORE_PASSWD,password); |
|
452 |
log.trace("setSslProperties", |
|
453 |
PropertyNames.KEYSTORE_PASSWD+"="+password); |
|
454 |
||
455 |
final String trustStore = |
|
456 |
System.getProperty(PropertyNames.TRUSTSTORE, |
|
457 |
defaultTrustStore); |
|
458 |
System.setProperty(PropertyNames.TRUSTSTORE,trustStore); |
|
459 |
log.trace("setSslProperties", |
|
460 |
PropertyNames.TRUSTSTORE+"="+trustStore); |
|
461 |
||
462 |
final String trustword = |
|
463 |
System.getProperty(PropertyNames.TRUSTSTORE_PASSWD, |
|
464 |
DefaultValues.TRUSTSTORE_PASSWD); |
|
465 |
System.setProperty(PropertyNames.TRUSTSTORE_PASSWD,trustword); |
|
466 |
log.trace("setSslProperties", |
|
467 |
PropertyNames.TRUSTSTORE_PASSWD+"="+trustword); |
|
468 |
} |
|
469 |
||
470 |
private void checkSslConfiguration() { |
|
471 |
try { |
|
472 |
final String defaultConf = |
|
473 |
getDefaultFileName(DefaultValues.CONFIG_FILE_NAME); |
|
474 |
final String confname = |
|
475 |
System.getProperty(PropertyNames.CONFIG_FILE_NAME,defaultConf); |
|
476 |
||
477 |
final Properties props = new Properties(); |
|
478 |
final File conf = new File(confname); |
|
479 |
if (conf.exists()) { |
|
480 |
FileInputStream fin = new FileInputStream(conf); |
|
481 |
try {props.load(fin);} finally {fin.close();} |
|
482 |
} |
|
483 |
||
484 |
// Do we use SSL? |
|
485 |
final String useSslStr = |
|
486 |
props.getProperty(PropertyNames.USE_SSL, |
|
487 |
DefaultValues.USE_SSL); |
|
488 |
final boolean useSsl = |
|
489 |
Boolean.valueOf(useSslStr).booleanValue(); |
|
490 |
||
491 |
log.debug("checkSslConfiguration", |
|
492 |
PropertyNames.USE_SSL+"="+useSsl+ |
|
493 |
": setting SSL"); |
|
494 |
// Do we use SSL client authentication? |
|
495 |
final String useSslClientAuthStr = |
|
496 |
props.getProperty(PropertyNames.SSL_NEED_CLIENT_AUTH, |
|
497 |
DefaultValues.SSL_NEED_CLIENT_AUTH); |
|
498 |
final boolean useSslClientAuth = |
|
499 |
Boolean.valueOf(useSslClientAuthStr).booleanValue(); |
|
500 |
||
501 |
log.debug("checkSslConfiguration", |
|
502 |
PropertyNames.SSL_NEED_CLIENT_AUTH+"="+useSslClientAuth); |
|
503 |
||
504 |
// Do we use customized SSL cipher suites? |
|
505 |
final String sslCipherSuites = |
|
506 |
props.getProperty(PropertyNames.SSL_ENABLED_CIPHER_SUITES); |
|
507 |
||
508 |
log.debug("checkSslConfiguration", |
|
509 |
PropertyNames.SSL_ENABLED_CIPHER_SUITES + "=" + |
|
510 |
sslCipherSuites); |
|
511 |
||
512 |
// Do we use customized SSL protocols? |
|
513 |
final String sslProtocols = |
|
514 |
props.getProperty(PropertyNames.SSL_ENABLED_PROTOCOLS); |
|
515 |
||
516 |
log.debug("checkSslConfiguration", |
|
517 |
PropertyNames.SSL_ENABLED_PROTOCOLS + "=" + |
|
518 |
sslProtocols); |
|
519 |
||
520 |
if (useSsl) setSslProperties(); |
|
521 |
} catch (Exception x) { |
|
522 |
System.out.println("Failed to setup SSL configuration: " + x); |
|
523 |
log.debug("checkSslConfiguration",x); |
|
524 |
} |
|
525 |
} |
|
526 |
||
527 |
/** |
|
528 |
* Tests the server bootstraped at the given URL. |
|
529 |
* Uses the system properties to determine which config file is used. |
|
530 |
* Loads the config file to determine which password file is used. |
|
531 |
* Loads the password file to find out wich credentials to use. |
|
532 |
* Also checks that unregistered user/passwords are not allowed to |
|
533 |
* connect when a password file is used. |
|
534 |
* |
|
535 |
* This method calls connectAndRead(). |
|
536 |
**/ |
|
537 |
public void testCommunication(JMXServiceURL url) |
|
538 |
throws IOException { |
|
539 |
||
540 |
final String defaultConf = |
|
541 |
getDefaultFileName(DefaultValues.CONFIG_FILE_NAME); |
|
542 |
final String confname = |
|
543 |
System.getProperty(PropertyNames.CONFIG_FILE_NAME,defaultConf); |
|
544 |
||
545 |
final Properties props = new Properties(); |
|
546 |
final File conf = new File(confname); |
|
547 |
if (conf.exists()) { |
|
548 |
FileInputStream fin = new FileInputStream(conf); |
|
549 |
try {props.load(fin);} finally {fin.close();} |
|
550 |
} |
|
551 |
||
552 |
// Do we use authentication? |
|
553 |
final String useAuthenticationStr = |
|
554 |
props.getProperty(PropertyNames.USE_AUTHENTICATION, |
|
555 |
DefaultValues.USE_AUTHENTICATION); |
|
556 |
final boolean useAuthentication = |
|
557 |
Boolean.valueOf(useAuthenticationStr).booleanValue(); |
|
558 |
||
559 |
// Get Password File |
|
560 |
final String defaultPasswordFileName = Utils.convertPath( |
|
561 |
getDefaultFileName(DefaultValues.PASSWORD_FILE_NAME)); |
|
562 |
final String passwordFileName = Utils.convertPath( |
|
563 |
props.getProperty(PropertyNames.PASSWORD_FILE_NAME, |
|
564 |
defaultPasswordFileName)); |
|
565 |
||
566 |
// Get Access File |
|
567 |
final String defaultAccessFileName = Utils.convertPath( |
|
568 |
getDefaultFileName(DefaultValues.ACCESS_FILE_NAME)); |
|
569 |
final String accessFileName = Utils.convertPath( |
|
570 |
props.getProperty(PropertyNames.ACCESS_FILE_NAME, |
|
571 |
defaultAccessFileName)); |
|
572 |
||
573 |
if (useAuthentication) { |
|
574 |
System.out.println("PasswordFileName: " + passwordFileName); |
|
575 |
System.out.println("accessFileName: " + accessFileName); |
|
576 |
} |
|
577 |
||
578 |
final Object[] allCredentials; |
|
579 |
final Object[] noCredentials = { null }; |
|
580 |
if (useAuthentication) { |
|
581 |
final ArrayList l = readCredentials(passwordFileName); |
|
582 |
if (l.size() == 0) allCredentials = null; |
|
583 |
else allCredentials = l.toArray(); |
|
584 |
} else allCredentials = noCredentials; |
|
585 |
||
586 |
int errorCount = 0; |
|
587 |
if (allCredentials!=null) { |
|
588 |
// Tests that the registered user/passwords are allowed to |
|
589 |
// connect & read |
|
590 |
// |
|
591 |
errorCount += connectAndRead(url,allCredentials,true,true); |
|
592 |
} else { |
|
593 |
// Tests that no one is allowed |
|
594 |
// connect & read |
|
595 |
// |
|
596 |
final String[][] someCredentials = { |
|
597 |
null, |
|
598 |
{ "modify", "R&D" }, |
|
599 |
{ "measure", "QED" } |
|
600 |
}; |
|
601 |
errorCount += connectAndRead(url,someCredentials,false,false); |
|
602 |
} |
|
603 |
||
604 |
if (useAuthentication && allCredentials != noCredentials) { |
|
605 |
// Tests that the registered user/passwords are not allowed to |
|
606 |
// connect & read |
|
607 |
// |
|
608 |
final String[][] badCredentials = { |
|
609 |
{ "bad.user", "R&D" }, |
|
610 |
{ "measure", "bad.password" } |
|
611 |
}; |
|
612 |
errorCount += connectAndRead(url,badCredentials,false,false); |
|
613 |
} |
|
614 |
if (errorCount > 0) { |
|
615 |
final String err = "Test " + confname + " failed with " + |
|
616 |
errorCount + " error(s)"; |
|
617 |
log.debug("testCommunication",err); |
|
618 |
throw new RuntimeException(err); |
|
619 |
} |
|
620 |
} |
|
621 |
||
622 |
||
623 |
/** |
|
624 |
* Test the configuration indicated by `file'. |
|
625 |
* Sets the appropriate System properties for config file and |
|
626 |
* port and then calls ConnectorBootstrap.initialize(). |
|
627 |
* eventually cleans up by calling ConnectorBootstrap.terminate(). |
|
628 |
* @return null if the test succeeds, an error message otherwise. |
|
629 |
**/ |
|
21408
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
630 |
private String testConfiguration(File file,int port) throws BindException { |
2 | 631 |
|
632 |
final String path; |
|
633 |
try { |
|
634 |
path=(file==null)?null:file.getCanonicalPath(); |
|
635 |
} catch(IOException x) { |
|
636 |
final String err = "Failed to test configuration " + file + |
|
637 |
": " + x; |
|
638 |
log.trace("testConfiguration",err); |
|
639 |
log.debug("testConfiguration",x); |
|
640 |
return err; |
|
641 |
} |
|
642 |
final String config = (path==null)?"Default config file":path; |
|
643 |
||
644 |
System.out.println("***"); |
|
645 |
System.out.println("*** Testing configuration (port=" + port + "): " |
|
646 |
+ path); |
|
647 |
System.out.println("***"); |
|
648 |
||
649 |
System.setProperty("com.sun.management.jmxremote.port", |
|
21408
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
650 |
Integer.toString(port)); |
2 | 651 |
if (path != null) |
652 |
System.setProperty("com.sun.management.config.file", path); |
|
653 |
else |
|
654 |
System.getProperties().remove("com.sun.management.config.file"); |
|
655 |
||
656 |
log.trace("testConfiguration","com.sun.management.jmxremote.port="+port); |
|
657 |
if (path != null && log.isDebugOn()) |
|
658 |
log.trace("testConfiguration", |
|
659 |
"com.sun.management.config.file="+path); |
|
660 |
||
661 |
checkSslConfiguration(); |
|
662 |
||
663 |
final JMXConnectorServer cs; |
|
664 |
try { |
|
665 |
cs = ConnectorBootstrap.initialize(); |
|
666 |
} catch (AgentConfigurationError x) { |
|
21408
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
667 |
if (x.getCause() instanceof ExportException) { |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
668 |
if (x.getCause().getCause() instanceof BindException) { |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
669 |
throw (BindException)x.getCause().getCause(); |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
670 |
} |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
671 |
} |
2 | 672 |
final String err = "Failed to initialize connector:" + |
673 |
"\n\tcom.sun.management.jmxremote.port=" + port + |
|
674 |
((path!=null)?"\n\tcom.sun.management.config.file="+path: |
|
675 |
"\n\t"+config) + |
|
676 |
"\n\tError is: " + x; |
|
677 |
log.trace("testConfiguration",err); |
|
678 |
log.debug("testConfiguration",x); |
|
679 |
return err; |
|
680 |
} catch (Exception x) { |
|
681 |
log.debug("testConfiguration",x); |
|
682 |
return x.toString(); |
|
683 |
} |
|
684 |
||
685 |
try { |
|
686 |
JMXServiceURL url = |
|
687 |
new JMXServiceURL("rmi",null,0,"/jndi/rmi://localhost:"+ |
|
688 |
port+"/jmxrmi"); |
|
689 |
||
690 |
try { |
|
691 |
testCommunication(url); |
|
692 |
} catch (Exception x) { |
|
693 |
final String err = "Failed to connect to agent {url="+url+ |
|
694 |
"}: " + x; |
|
695 |
log.trace("testConfiguration",err); |
|
696 |
log.debug("testConfiguration",x); |
|
697 |
return err; |
|
698 |
} |
|
699 |
} catch (Exception x) { |
|
700 |
final String err = "Failed to test configuration "+config+ |
|
701 |
": "+x; |
|
702 |
log.trace("testConfiguration",err); |
|
703 |
log.debug("testConfiguration",x); |
|
704 |
return err; |
|
705 |
} finally { |
|
706 |
try { |
|
707 |
cs.stop(); |
|
708 |
} catch (Exception x) { |
|
709 |
final String err = "Failed to terminate: "+x; |
|
710 |
log.trace("testConfiguration",err); |
|
711 |
log.debug("testConfiguration",x); |
|
712 |
} |
|
713 |
} |
|
714 |
System.out.println("Configuration " + config + " successfully tested"); |
|
715 |
return null; |
|
716 |
} |
|
717 |
||
718 |
/** |
|
719 |
* Test a configuration file which should make the bootstrap fail. |
|
720 |
* The test is assumed to have succeeded if the bootstrap fails. |
|
721 |
* @return null if the test succeeds, an error message otherwise. |
|
722 |
**/ |
|
723 |
private String testConfigurationKo(File conf,int port) { |
|
21408
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
724 |
String errStr = null; |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
725 |
for (int i = 0; i < PORT_TEST_LEN; i++) { |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
726 |
try { |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
727 |
errStr = testConfiguration(conf,port+testPort++); |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
728 |
break; |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
729 |
} catch (BindException e) { |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
730 |
// port conflict; try another port |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
731 |
} |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
732 |
} |
2 | 733 |
if (errStr == null) { |
734 |
return "Configuration " + |
|
735 |
conf + " should have failed!"; |
|
736 |
} |
|
737 |
System.out.println("Configuration " + |
|
738 |
conf + " failed as expected"); |
|
739 |
log.debug("runko","Error was: " + errStr); |
|
740 |
return null; |
|
741 |
} |
|
742 |
||
743 |
/** |
|
744 |
* Test a configuration file. Determines whether the bootstrap |
|
745 |
* should succeed or fail depending on the file name: |
|
746 |
* *ok.properties: bootstrap should succeed. |
|
747 |
* *ko.properties: bootstrap or connection should fail. |
|
748 |
* @return null if the test succeeds, an error message otherwise. |
|
749 |
**/ |
|
750 |
private String testConfigurationFile(String fileName) { |
|
751 |
File file = new File(fileName); |
|
21408
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
752 |
final String portStr = System.getProperty("rmi.port",null); |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
753 |
final int port = portStr != null ? |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
754 |
Integer.parseInt(portStr) : basePort; |
2 | 755 |
|
756 |
if (fileName.endsWith("ok.properties")) { |
|
21408
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
757 |
String errStr = null; |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
758 |
for (int i = 0; i < PORT_TEST_LEN; i++) { |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
759 |
try { |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
760 |
errStr = testConfiguration(file,port+testPort++); |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
761 |
return errStr; |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
762 |
} catch (BindException e) { |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
763 |
// port conflict; try another port |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
764 |
} |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
765 |
} |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
766 |
return "Can not locate available port"; |
2 | 767 |
} |
768 |
if (fileName.endsWith("ko.properties")) { |
|
769 |
return testConfigurationKo(file,port+testPort++); |
|
770 |
} |
|
771 |
return fileName + |
|
772 |
": test file suffix must be one of [ko|ok].properties"; |
|
773 |
} |
|
774 |
||
775 |
/** |
|
776 |
* Find all *ko.property files and test them. |
|
777 |
* (see findConfigurationFilesKo() and testConfigurationKo()) |
|
778 |
* @throws RuntimeException if the test fails. |
|
779 |
**/ |
|
780 |
public void runko() { |
|
21408
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
781 |
final String portStr = System.getProperty("rmi.port",null); |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
782 |
final int port = portStr != null ? |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
783 |
Integer.parseInt(portStr) : basePort; |
2 | 784 |
final File[] conf = findConfigurationFilesKo(); |
785 |
if ((conf == null)||(conf.length == 0)) |
|
786 |
throw new RuntimeException("No configuration found"); |
|
787 |
||
788 |
String errStr; |
|
789 |
for (int i=0;i<conf.length;i++) { |
|
790 |
errStr = testConfigurationKo(conf[i],port+testPort++); |
|
791 |
if (errStr != null) { |
|
792 |
throw new RuntimeException(errStr); |
|
793 |
} |
|
794 |
} |
|
795 |
||
796 |
} |
|
797 |
||
798 |
/** |
|
799 |
* Find all *ok.property files and test them. |
|
800 |
* (see findConfigurationFilesOk() and testConfiguration()) |
|
801 |
* @throws RuntimeException if the test fails. |
|
802 |
**/ |
|
803 |
public void runok() { |
|
21408
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
804 |
final String portStr = System.getProperty("rmi.port",null); |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
805 |
final int port = portStr != null ? |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
806 |
Integer.parseInt(portStr) : basePort; |
2 | 807 |
final File[] conf = findConfigurationFilesOk(); |
808 |
if ((conf == null)||(conf.length == 0)) |
|
809 |
throw new RuntimeException("No configuration found"); |
|
810 |
||
21408
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
811 |
String errStr = null; |
2 | 812 |
for (int i=0;i<conf.length;i++) { |
21408
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
813 |
for (int j = 0; j < PORT_TEST_LEN; i++) { |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
814 |
try { |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
815 |
errStr = testConfiguration(conf[i],port+testPort++); |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
816 |
break; |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
817 |
} catch (BindException e) { |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
818 |
// port conflict; try another port |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
819 |
} |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
820 |
} |
2 | 821 |
if (errStr != null) { |
822 |
throw new RuntimeException(errStr); |
|
823 |
} |
|
824 |
} |
|
825 |
||
826 |
// FIXME: No jmxremote.password is not installed in JRE by default. |
|
827 |
// - disable the following test case. |
|
828 |
// |
|
829 |
// Test default config |
|
830 |
// |
|
831 |
// errStr = testConfiguration(null,port+testPort++); |
|
832 |
// if (errStr != null) { |
|
833 |
// throw new RuntimeException(errStr); |
|
834 |
// } |
|
835 |
} |
|
836 |
||
837 |
/** |
|
838 |
* Finds all configuration files (*ok.properties and *ko.properties) |
|
839 |
* and tests them. |
|
840 |
* (see runko() and runok()). |
|
841 |
* @throws RuntimeException if the test fails. |
|
842 |
**/ |
|
843 |
public void run() { |
|
844 |
runok(); |
|
845 |
runko(); |
|
846 |
} |
|
847 |
||
848 |
/** |
|
849 |
* Tests the specified configuration files. |
|
850 |
* If args[] is not empty, each element in args[] is expected to be |
|
851 |
* a filename ending either by ok.properties or ko.properties. |
|
852 |
* Otherwise, the configuration files will be automatically determined |
|
853 |
* by looking at all *.properties files located in the directory |
|
854 |
* indicated by the System property "test.src". |
|
855 |
* @throws RuntimeException if the test fails. |
|
856 |
**/ |
|
857 |
public void run(String args[]) { |
|
858 |
if (args.length == 0) { |
|
859 |
run() ; return; |
|
860 |
} |
|
861 |
for (int i=0; i<args.length; i++) { |
|
862 |
final String errStr =testConfigurationFile(args[i]); |
|
863 |
if (errStr != null) { |
|
864 |
throw new RuntimeException(errStr); |
|
865 |
} |
|
866 |
} |
|
867 |
} |
|
868 |
||
869 |
/** |
|
870 |
* Calls run(args[]). |
|
871 |
* exit(1) if the test fails. |
|
872 |
**/ |
|
21408
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
873 |
public static void main(String args[]) throws Exception { |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
874 |
setupBasePort(); |
2 | 875 |
RmiBootstrapTest manager = new RmiBootstrapTest(); |
876 |
try { |
|
877 |
manager.run(args); |
|
878 |
} catch (RuntimeException r) { |
|
879 |
System.out.println("Test Failed: "+ r.getMessage()); |
|
880 |
System.exit(1); |
|
881 |
} catch (Throwable t) { |
|
882 |
System.out.println("Test Failed: "+ t); |
|
883 |
t.printStackTrace(); |
|
884 |
System.exit(2); |
|
885 |
} |
|
886 |
System.out.println("**** Test RmiBootstrap Passed ****"); |
|
887 |
} |
|
888 |
||
21408
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
889 |
private static void setupBasePort() throws IOException { |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
890 |
try (ServerSocket s = new ServerSocket(0)) { |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
891 |
basePort = s.getLocalPort() + 1; |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
892 |
} |
6468b29c9877
8027058: sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh Failed to initialize connector
jbachorik
parents:
5506
diff
changeset
|
893 |
} |
2 | 894 |
} |