6744132: Spurious failures from test/javax/management/MBeanInfo/NotificationInfoTest.java
Reviewed-by: dfuchs
This commit is contained in:
parent
fdfb7acee2
commit
ab464bccd1
@ -33,14 +33,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.lang.management.*;
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.security.CodeSource;
|
import java.security.CodeSource;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.jar.*;
|
import java.util.jar.*;
|
||||||
import javax.management.*;
|
import javax.management.*;
|
||||||
import javax.management.modelmbean.*;
|
|
||||||
import javax.management.relation.*;
|
import javax.management.relation.*;
|
||||||
|
import javax.management.remote.*;
|
||||||
|
import javax.management.remote.rmi.*;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This test finds all classes in the same code-base as the JMX
|
* This test finds all classes in the same code-base as the JMX
|
||||||
@ -68,10 +70,10 @@ import javax.management.relation.*;
|
|||||||
*/
|
*/
|
||||||
public class NotificationInfoTest {
|
public class NotificationInfoTest {
|
||||||
// class or object names where the test failed
|
// class or object names where the test failed
|
||||||
private static final Set/*<String>*/ failed = new TreeSet();
|
private static final Set<String> failed = new TreeSet<String>();
|
||||||
|
|
||||||
// class or object names where there were no MBeanNotificationInfo entries
|
// class or object names where there were no MBeanNotificationInfo entries
|
||||||
private static final Set/*<String>*/ suspicious = new TreeSet();
|
private static final Set<String> suspicious = new TreeSet<String>();
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
System.out.println("Checking that all known MBeans that are " +
|
System.out.println("Checking that all known MBeans that are " +
|
||||||
@ -86,8 +88,20 @@ public class NotificationInfoTest {
|
|||||||
.getCodeSource();
|
.getCodeSource();
|
||||||
URL codeBase;
|
URL codeBase;
|
||||||
if (cs == null) {
|
if (cs == null) {
|
||||||
codeBase = new URL("file:" + System.getProperty("java.home") +
|
String javaHome = System.getProperty("java.home");
|
||||||
"/lib/rt.jar");
|
String[] candidates = {"/lib/rt.jar", "/classes/"};
|
||||||
|
codeBase = null;
|
||||||
|
for (String candidate : candidates) {
|
||||||
|
File file = new File(javaHome + candidate);
|
||||||
|
if (file.exists()) {
|
||||||
|
codeBase = file.toURI().toURL();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (codeBase == null) {
|
||||||
|
throw new Exception(
|
||||||
|
"Could not determine codeBase for java.home=" + javaHome);
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
codeBase = cs.getLocation();
|
codeBase = cs.getLocation();
|
||||||
|
|
||||||
@ -98,7 +112,7 @@ public class NotificationInfoTest {
|
|||||||
System.out.println("Testing standard MBeans...");
|
System.out.println("Testing standard MBeans...");
|
||||||
for (int i = 0; i < classes.length; i++) {
|
for (int i = 0; i < classes.length; i++) {
|
||||||
String name = classes[i];
|
String name = classes[i];
|
||||||
Class c;
|
Class<?> c;
|
||||||
try {
|
try {
|
||||||
c = Class.forName(name);
|
c = Class.forName(name);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@ -109,18 +123,22 @@ public class NotificationInfoTest {
|
|||||||
System.out.println(name + ": not a NotificationBroadcaster");
|
System.out.println(name + ": not a NotificationBroadcaster");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (Modifier.isAbstract(c.getModifiers())) {
|
||||||
|
System.out.println(name + ": abstract class");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
NotificationBroadcaster mbean;
|
NotificationBroadcaster mbean;
|
||||||
Constructor constr;
|
Constructor<?> constr;
|
||||||
try {
|
try {
|
||||||
constr = c.getConstructor(null);
|
constr = c.getConstructor();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println(name + ": no public no-arg constructor: "
|
System.out.println(name + ": no public no-arg constructor: "
|
||||||
+ e);
|
+ e);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
mbean = (NotificationBroadcaster) constr.newInstance(null);
|
mbean = (NotificationBroadcaster) constr.newInstance();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println(name + ": no-arg constructor failed: " + e);
|
System.out.println(name + ": no-arg constructor failed: " + e);
|
||||||
continue;
|
continue;
|
||||||
@ -161,22 +179,9 @@ public class NotificationInfoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void checkPlatformMBeans() throws Exception {
|
private static void checkPlatformMBeans() throws Exception {
|
||||||
Class managementFactory;
|
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
|
||||||
try {
|
Set<ObjectName> mbeanNames = mbs.queryNames(null, null);
|
||||||
managementFactory =
|
for (ObjectName name : mbeanNames) {
|
||||||
Class.forName("java.lang.management.ManagementFactory");
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println("...no ManagementFactory, assuming pre-Tiger: "
|
|
||||||
+ e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Method getPlatformMBeanServer =
|
|
||||||
managementFactory.getMethod("getPlatformMBeanServer", null);
|
|
||||||
MBeanServer mbs = (MBeanServer)
|
|
||||||
getPlatformMBeanServer.invoke(null, null);
|
|
||||||
Set mbeanNames = mbs.queryNames(null, null);
|
|
||||||
for (Iterator it = mbeanNames.iterator(); it.hasNext(); ) {
|
|
||||||
ObjectName name = (ObjectName) it.next();
|
|
||||||
if (!mbs.isInstanceOf(name,
|
if (!mbs.isInstanceOf(name,
|
||||||
NotificationBroadcaster.class.getName())) {
|
NotificationBroadcaster.class.getName())) {
|
||||||
System.out.println(name + ": not a NotificationBroadcaster");
|
System.out.println(name + ": not a NotificationBroadcaster");
|
||||||
@ -188,31 +193,9 @@ public class NotificationInfoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void checkRMIConnectorServer() throws Exception {
|
private static void checkRMIConnectorServer() throws Exception {
|
||||||
Class rmiConnectorServer;
|
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
|
||||||
try {
|
RMIConnectorServer connector = new RMIConnectorServer(url, null);
|
||||||
rmiConnectorServer =
|
check(connector);
|
||||||
Class.forName("javax.management.remote.rmi.RMIConnectorServer");
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println("No RMIConnectorServer class, skipping: " + e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Class jmxServiceURL =
|
|
||||||
Class.forName("javax.management.remote.JMXServiceURL");
|
|
||||||
Constructor jmxServiceURLConstructor =
|
|
||||||
jmxServiceURL.getConstructor(new Class[] {String.class});
|
|
||||||
Object url =
|
|
||||||
jmxServiceURLConstructor.newInstance(new Object[] {
|
|
||||||
"service:jmx:rmi://"
|
|
||||||
});
|
|
||||||
Constructor rmiConnectorServerConstructor =
|
|
||||||
rmiConnectorServer.getConstructor(new Class[] {
|
|
||||||
jmxServiceURL, Map.class
|
|
||||||
});
|
|
||||||
Object connector =
|
|
||||||
rmiConnectorServerConstructor.newInstance(new Object[] {
|
|
||||||
url, null
|
|
||||||
});
|
|
||||||
check((NotificationBroadcaster) connector);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void check(String what, MBeanNotificationInfo[] mbnis) {
|
private static void check(String what, MBeanNotificationInfo[] mbnis) {
|
||||||
@ -250,30 +233,29 @@ public class NotificationInfoTest {
|
|||||||
|
|
||||||
private static String[] findStandardMBeans(URL codeBase)
|
private static String[] findStandardMBeans(URL codeBase)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
Set names;
|
Set<String> names;
|
||||||
if (codeBase.getProtocol().equalsIgnoreCase("file")
|
if (codeBase.getProtocol().equalsIgnoreCase("file")
|
||||||
&& codeBase.toString().endsWith("/"))
|
&& codeBase.toString().endsWith("/"))
|
||||||
names = findStandardMBeansFromDir(codeBase);
|
names = findStandardMBeansFromDir(codeBase);
|
||||||
else
|
else
|
||||||
names = findStandardMBeansFromJar(codeBase);
|
names = findStandardMBeansFromJar(codeBase);
|
||||||
|
|
||||||
Set standardMBeanNames = new TreeSet();
|
Set<String> standardMBeanNames = new TreeSet<String>();
|
||||||
for (Iterator it = names.iterator(); it.hasNext(); ) {
|
for (String name : names) {
|
||||||
String name = (String) it.next();
|
|
||||||
if (name.endsWith("MBean")) {
|
if (name.endsWith("MBean")) {
|
||||||
String prefix = name.substring(0, name.length() - 5);
|
String prefix = name.substring(0, name.length() - 5);
|
||||||
if (names.contains(prefix))
|
if (names.contains(prefix))
|
||||||
standardMBeanNames.add(prefix);
|
standardMBeanNames.add(prefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (String[]) standardMBeanNames.toArray(new String[0]);
|
return standardMBeanNames.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set findStandardMBeansFromJar(URL codeBase)
|
private static Set<String> findStandardMBeansFromJar(URL codeBase)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
InputStream is = codeBase.openStream();
|
InputStream is = codeBase.openStream();
|
||||||
JarInputStream jis = new JarInputStream(is);
|
JarInputStream jis = new JarInputStream(is);
|
||||||
Set names = new TreeSet();
|
Set<String> names = new TreeSet<String>();
|
||||||
JarEntry entry;
|
JarEntry entry;
|
||||||
while ((entry = jis.getNextJarEntry()) != null) {
|
while ((entry = jis.getNextJarEntry()) != null) {
|
||||||
String name = entry.getName();
|
String name = entry.getName();
|
||||||
@ -286,15 +268,15 @@ public class NotificationInfoTest {
|
|||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set findStandardMBeansFromDir(URL codeBase)
|
private static Set<String> findStandardMBeansFromDir(URL codeBase)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
File dir = new File(new URI(codeBase.toString()));
|
File dir = new File(new URI(codeBase.toString()));
|
||||||
Set names = new TreeSet();
|
Set<String> names = new TreeSet<String>();
|
||||||
scanDir(dir, "", names);
|
scanDir(dir, "", names);
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void scanDir(File dir, String prefix, Set names)
|
private static void scanDir(File dir, String prefix, Set<String> names)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
File[] files = dir.listFiles();
|
File[] files = dir.listFiles();
|
||||||
if (files == null)
|
if (files == null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user