提交 d09fa405 编写于 作者: A alanb

8001048: JSR-160: Allow IIOP transport to be optional

Reviewed-by: dsamersoff, dfuchs, mchung
上级 397d95ab
...@@ -26,13 +26,8 @@ ...@@ -26,13 +26,8 @@
package com.sun.jmx.remote.internal; package com.sun.jmx.remote.internal;
import java.util.Properties; import java.util.Properties;
import java.io.IOException;
import java.rmi.Remote; import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.NoSuchObjectException;
import java.util.Properties;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.NoSuchObjectException; import java.rmi.NoSuchObjectException;
import java.security.AccessController; import java.security.AccessController;
...@@ -115,9 +110,10 @@ public final class IIOPHelper { ...@@ -115,9 +110,10 @@ public final class IIOPHelper {
* Connects the Stub to the given ORB. * Connects the Stub to the given ORB.
*/ */
public static void connect(Object stub, Object orb) public static void connect(Object stub, Object orb)
throws RemoteException throws IOException
{ {
ensureAvailable(); if (proxy == null)
throw new IOException("Connection to ORB failed, RMI/IIOP not available");
proxy.connect(stub, orb); proxy.connect(stub, orb);
} }
...@@ -125,15 +121,17 @@ public final class IIOPHelper { ...@@ -125,15 +121,17 @@ public final class IIOPHelper {
* Returns true if the given object is an ORB. * Returns true if the given object is an ORB.
*/ */
public static boolean isOrb(Object obj) { public static boolean isOrb(Object obj) {
ensureAvailable(); return (proxy == null) ? false : proxy.isOrb(obj);
return proxy.isOrb(obj);
} }
/** /**
* Creates, and returns, a new ORB instance. * Creates, and returns, a new ORB instance.
*/ */
public static Object createOrb(String[] args, Properties props) { public static Object createOrb(String[] args, Properties props)
ensureAvailable(); throws IOException
{
if (proxy == null)
throw new IOException("ORB initialization failed, RMI/IIOP not available");
return proxy.createOrb(args, props); return proxy.createOrb(args, props);
} }
...@@ -166,24 +164,27 @@ public final class IIOPHelper { ...@@ -166,24 +164,27 @@ public final class IIOPHelper {
/** /**
* Makes a server object ready to receive remote calls * Makes a server object ready to receive remote calls
*/ */
public static void exportObject(Remote obj) throws RemoteException { public static void exportObject(Remote obj) throws IOException {
ensureAvailable(); if (proxy == null)
throw new IOException("RMI object cannot be exported, RMI/IIOP not available");
proxy.exportObject(obj); proxy.exportObject(obj);
} }
/** /**
* Deregisters a server object from the runtime. * Deregisters a server object from the runtime.
*/ */
public static void unexportObject(Remote obj) throws NoSuchObjectException { public static void unexportObject(Remote obj) throws IOException {
ensureAvailable(); if (proxy == null)
throw new NoSuchObjectException("Object not exported");
proxy.unexportObject(obj); proxy.unexportObject(obj);
} }
/** /**
* Returns a stub for the given server object. * Returns a stub for the given server object.
*/ */
public static Remote toStub(Remote obj) throws NoSuchObjectException { public static Remote toStub(Remote obj) throws IOException {
ensureAvailable(); if (proxy == null)
throw new NoSuchObjectException("Object not exported");
return proxy.toStub(obj); return proxy.toStub(obj);
} }
} }
...@@ -137,8 +137,10 @@ import com.sun.jmx.remote.util.EnvHelp; ...@@ -137,8 +137,10 @@ import com.sun.jmx.remote.util.EnvHelp;
* JAR conventions for service providers</a>, where the service * JAR conventions for service providers</a>, where the service
* interface is <code>JMXConnectorProvider</code>.</p> * interface is <code>JMXConnectorProvider</code>.</p>
* *
* <p>Every implementation must support the RMI connector protocols, * <p>Every implementation must support the RMI connector protocol with
* specified with the string <code>rmi</code> or * the default RMI transport, specified with string <code>rmi</code>.
* An implementation may optionally support the RMI connector protocol
* with the RMI/IIOP transport, specified with the string
* <code>iiop</code>.</p> * <code>iiop</code>.</p>
* *
* <p>Once a provider is found, the result of the * <p>Once a provider is found, the result of the
......
...@@ -129,8 +129,10 @@ import javax.management.MBeanServer; ...@@ -129,8 +129,10 @@ import javax.management.MBeanServer;
* JAR conventions for service providers</a>, where the service * JAR conventions for service providers</a>, where the service
* interface is <code>JMXConnectorServerProvider</code>.</p> * interface is <code>JMXConnectorServerProvider</code>.</p>
* *
* <p>Every implementation must support the RMI connector protocols, * <p>Every implementation must support the RMI connector protocol with
* specified with the string <code>rmi</code> or * the default RMI transport, specified with string <code>rmi</code>.
* An implementation may optionally support the RMI connector protocol
* with the RMI/IIOP transport, specified with the string
* <code>iiop</code>.</p> * <code>iiop</code>.</p>
* *
* <p>Once a provider is found, the result of the * <p>Once a provider is found, the result of the
......
...@@ -238,10 +238,21 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable ...@@ -238,10 +238,21 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// implements JMXConnector interface // implements JMXConnector interface
//-------------------------------------------------------------------- //--------------------------------------------------------------------
/**
* @throws IOException if the connection could not be made because of a
* communication problem, or in the case of the {@code iiop} protocol,
* that RMI/IIOP is not supported
*/
public void connect() throws IOException { public void connect() throws IOException {
connect(null); connect(null);
} }
/**
* @throws IOException if the connection could not be made because of a
* communication problem, or in the case of the {@code iiop} protocol,
* that RMI/IIOP is not supported
*/
public synchronized void connect(Map<String,?> environment) public synchronized void connect(Map<String,?> environment)
throws IOException { throws IOException {
final boolean tracing = logger.traceOn(); final boolean tracing = logger.traceOn();
......
...@@ -337,7 +337,8 @@ public class RMIConnectorServer extends JMXConnectorServer { ...@@ -337,7 +337,8 @@ public class RMIConnectorServer extends JMXConnectorServer {
* @exception IllegalStateException if the connector server has * @exception IllegalStateException if the connector server has
* not been attached to an MBean server. * not been attached to an MBean server.
* @exception IOException if the connector server cannot be * @exception IOException if the connector server cannot be
* started. * started, or in the case of the {@code iiop} protocol, that
* RMI/IIOP is not supported.
*/ */
public synchronized void start() throws IOException { public synchronized void start() throws IOException {
final boolean tracing = logger.traceOn(); final boolean tracing = logger.traceOn();
......
...@@ -36,8 +36,8 @@ questions. ...@@ -36,8 +36,8 @@ questions.
that different implementations of the RMI connector can that different implementations of the RMI connector can
interoperate.</p> interoperate.</p>
<p>The RMI connector supports both the JRMP and the IIOP transports <p>The RMI connector supports the JRMP transport for RMI, and
for RMI.</p> optionally the IIOP transport.</p>
<p>Like most connectors in the JMX Remote API, an RMI connector <p>Like most connectors in the JMX Remote API, an RMI connector
usually has an address, which usually has an address, which
......
...@@ -45,19 +45,36 @@ public class AddressableTest { ...@@ -45,19 +45,36 @@ public class AddressableTest {
private static final MBeanServer mbs = MBeanServerFactory.createMBeanServer(); private static final MBeanServer mbs = MBeanServerFactory.createMBeanServer();
private static boolean isProtocolSupported(String protocol) {
if (protocol.equals("rmi"))
return true;
if (protocol.equals("iiop")) {
try {
Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie");
return true;
} catch (ClassNotFoundException x) { }
}
return false;
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
System.out.println(">>> test the new interface Addressable."); System.out.println(">>> test the new interface Addressable.");
boolean ok = true; boolean ok = true;
for (int i = 0; i < protocols.length; i++) { for (int i = 0; i < protocols.length; i++) {
try { String protocol = protocols[i];
test(protocols[i], prefixes[i]); if (isProtocolSupported(protocol)) {
try {
System.out.println(">>> Test successed for "+protocols[i]); test(protocol, prefixes[i]);
} catch (Exception e) { System.out.println(">>> Test successed for "+protocols[i]);
System.out.println(">>> Test failed for "+protocols[i]); } catch (Exception e) {
e.printStackTrace(System.out); System.out.println(">>> Test failed for "+protocols[i]);
ok = false; e.printStackTrace(System.out);
ok = false;
}
} else {
System.out.format(">>> Test skipped for %s, protocol not supported%n",
protocol);
} }
} }
...@@ -65,7 +82,7 @@ public class AddressableTest { ...@@ -65,7 +82,7 @@ public class AddressableTest {
System.out.println(">>> All Test passed."); System.out.println(">>> All Test passed.");
} else { } else {
System.out.println(">>> Some TESTs FAILED"); System.out.println(">>> Some TESTs FAILED");
System.exit(1); throw new RuntimeException("See log for details");
} }
} }
......
...@@ -42,7 +42,6 @@ import javax.management.remote.rmi.RMIConnector; ...@@ -42,7 +42,6 @@ import javax.management.remote.rmi.RMIConnector;
import javax.management.remote.rmi.RMIIIOPServerImpl; import javax.management.remote.rmi.RMIIIOPServerImpl;
import javax.management.remote.rmi.RMIJRMPServerImpl; import javax.management.remote.rmi.RMIJRMPServerImpl;
import javax.management.remote.rmi.RMIServerImpl; import javax.management.remote.rmi.RMIServerImpl;
import org.omg.stub.javax.management.remote.rmi._RMIConnection_Stub;
public class CloseableTest { public class CloseableTest {
private static final Class closeArray[] = { private static final Class closeArray[] = {
...@@ -51,26 +50,43 @@ public class CloseableTest { ...@@ -51,26 +50,43 @@ public class CloseableTest {
RMIConnection.class, RMIConnection.class,
RMIConnectionImpl.class, RMIConnectionImpl.class,
RMIConnectionImpl_Stub.class, RMIConnectionImpl_Stub.class,
_RMIConnection_Stub.class,
RMIServerImpl.class, RMIServerImpl.class,
RMIIIOPServerImpl.class, RMIIIOPServerImpl.class,
RMIJRMPServerImpl.class RMIJRMPServerImpl.class
}; };
static int error;
static void test(Class<?> c) {
System.out.println("\nTest " + c);
if (Closeable.class.isAssignableFrom(c)) {
System.out.println("Test passed!");
} else {
error++;
System.out.println("Test failed!");
}
}
static void test(String cn) {
try {
test(Class.forName(cn));
} catch (ClassNotFoundException ignore) {
System.out.println("\n" + cn + " not tested.");
}
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
System.out.println("Test that all the JMX Remote API classes that " + System.out.println("Test that all the JMX Remote API classes that " +
"define\nthe method \"void close() throws " + "define\nthe method \"void close() throws " +
"IOException;\" extend\nor implement the " + "IOException;\" extend\nor implement the " +
"java.io.Closeable interface."); "java.io.Closeable interface.");
int error = 0; for (Class<?> c : closeArray) {
for (Class c : closeArray) { test(c);
System.out.println("\nTest " + c);
if (Closeable.class.isAssignableFrom(c)) {
System.out.println("Test passed!");
} else {
error++;
System.out.println("Test failed!");
}
} }
// Stub classes not present if RMI-IIOP not supported
test("org.omg.stub.javax.management.remote.rmi._RMIConnection_Stub");
if (error > 0) { if (error > 0) {
final String msg = "\nTest FAILED! Got " + error + " error(s)"; final String msg = "\nTest FAILED! Got " + error + " error(s)";
System.out.println(msg); System.out.println(msg);
......
...@@ -39,33 +39,22 @@ import javax.management.NotificationListener; ...@@ -39,33 +39,22 @@ import javax.management.NotificationListener;
import java.util.Map; import java.util.Map;
public class ConnectionListenerNullTest { public class ConnectionListenerNullTest {
static final boolean optionalFlag; static boolean isPresent(String cn) {
static {
Class genericClass = null;
try { try {
genericClass = Class.forName(cn);
Class.forName("javax.management.remote.generic.GenericConnector"); return true;
} catch (ClassNotFoundException x) { } catch (ClassNotFoundException x) {
// NO optional package return false;
} }
optionalFlag = (genericClass != null);
} }
final static String[] mandatoryList = { public static int test(String... urls) {
"service:jmx:rmi://", "service:jmx:iiop://"
};
final static String[] optionalList = {
"service:jmx:jmxmp://"
};
public static int test(String[] urls) {
int errCount = 0; int errCount = 0;
for (int i=0;i<urls.length;i++) { for (int i=0;i<urls.length;i++) {
try { try {
final JMXServiceURL url = new JMXServiceURL(urls[i]); final JMXServiceURL url = new JMXServiceURL(urls[i]);
final JMXConnector c = final JMXConnector c =
JMXConnectorFactory.newJMXConnector(url,(Map)null); JMXConnectorFactory.newJMXConnector(url,(Map<String,String>)null);
final NotificationListener nl = null; final NotificationListener nl = null;
final NotificationFilter nf = null; final NotificationFilter nf = null;
final Object h = null; final Object h = null;
...@@ -121,12 +110,19 @@ public class ConnectionListenerNullTest { ...@@ -121,12 +110,19 @@ public class ConnectionListenerNullTest {
public static void main(String args[]) { public static void main(String args[]) {
int errCount = 0; int errCount = 0;
errCount += test(mandatoryList);
if (optionalFlag) errCount += test(optionalList); // mandatory
errCount += test("service:jmx:rmi://");
// optional
if (isPresent("javax.management.remote.rmi._RMIConnectionImpl_Tie"))
errCount += test("service:jmx:iiop://");
if (isPresent("javax.management.remote.generic.GenericConnector"))
errCount += test("service:jmx:jmxmp://");
if (errCount > 0) { if (errCount > 0) {
System.err.println("ConnectionListenerNullTest failed: " + throw new RuntimeException("ConnectionListenerNullTest failed: " +
errCount + " error(s) reported."); errCount + " error(s) reported.");
System.exit(1);
} }
System.out.println("ConnectionListenerNullTest passed."); System.out.println("ConnectionListenerNullTest passed.");
} }
......
...@@ -49,17 +49,24 @@ public class IIOPURLTest { ...@@ -49,17 +49,24 @@ public class IIOPURLTest {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
JMXServiceURL inputAddr = JMXServiceURL inputAddr =
new JMXServiceURL("service:jmx:iiop://"); new JMXServiceURL("service:jmx:iiop://");
JMXConnectorServer s = JMXConnectorServer s;
JMXConnectorServerFactory.newJMXConnectorServer(inputAddr, null, try {
null); s = JMXConnectorServerFactory.newJMXConnectorServer(inputAddr, null, null);
} catch (java.net.MalformedURLException x) {
try {
Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie");
throw new RuntimeException("MalformedURLException thrown but iiop appears to be supported");
} catch (ClassNotFoundException expected) { }
System.out.println("IIOP protocol not supported, test skipped");
return;
}
MBeanServer mbs = MBeanServerFactory.createMBeanServer(); MBeanServer mbs = MBeanServerFactory.createMBeanServer();
mbs.registerMBean(s, new ObjectName("a:b=c")); mbs.registerMBean(s, new ObjectName("a:b=c"));
s.start(); s.start();
JMXServiceURL outputAddr = s.getAddress(); JMXServiceURL outputAddr = s.getAddress();
if (!outputAddr.getURLPath().startsWith("/ior/IOR:")) { if (!outputAddr.getURLPath().startsWith("/ior/IOR:")) {
System.out.println("URL path should start with \"/ior/IOR:\": " + throw new RuntimeException("URL path should start with \"/ior/IOR:\": " +
outputAddr); outputAddr);
System.exit(1);
} }
System.out.println("IIOP URL path looks OK: " + outputAddr); System.out.println("IIOP URL path looks OK: " + outputAddr);
JMXConnector c = JMXConnectorFactory.connect(outputAddr); JMXConnector c = JMXConnectorFactory.connect(outputAddr);
......
...@@ -52,21 +52,27 @@ import javax.management.remote.JMXServiceURL; ...@@ -52,21 +52,27 @@ import javax.management.remote.JMXServiceURL;
import com.sun.jmx.remote.util.EnvHelp; import com.sun.jmx.remote.util.EnvHelp;
public class IdleTimeoutTest { public class IdleTimeoutTest {
static boolean isPresent(String cn) {
try {
Class.forName(cn);
return true;
} catch (ClassNotFoundException x) {
return false;
}
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
boolean ok = true; boolean ok = true;
List protos; List protos;
if (args.length > 0) if (args.length > 0)
protos = Arrays.asList(args); protos = Arrays.asList(args);
else { else {
protos = protos = new ArrayList(Arrays.asList(new String[] {"rmi"}));
new ArrayList(Arrays.asList(new String[] {"rmi", "iiop"})); if (isPresent("javax.management.remote.rmi._RMIConnectionImpl_Tie"))
try { protos.add("iiop");
Class.forName("javax.management.remote.jmxmp." + if (isPresent("javax.management.remote.jmxmp.JMXMPConnectorServer"))
"JMXMPConnectorServer");
protos.add("jmxmp"); protos.add("jmxmp");
} catch (ClassNotFoundException e) {
// OK: Optional JMXMP support is not present
}
} }
for (Iterator it = protos.iterator(); it.hasNext(); ) { for (Iterator it = protos.iterator(); it.hasNext(); ) {
String proto = (String) it.next(); String proto = (String) it.next();
...@@ -81,13 +87,13 @@ public class IdleTimeoutTest { ...@@ -81,13 +87,13 @@ public class IdleTimeoutTest {
} }
} }
if (!ok) { if (!ok) {
System.out.println("SOME TESTS FAILED"); throw new RuntimeException("Some tests failed - see log for details");
System.exit(1);
} }
} }
private static long getIdleTimeout(MBeanServer mbs, JMXServiceURL url) private static long getIdleTimeout(MBeanServer mbs, JMXServiceURL url)
throws Exception { throws Exception
{
JMXConnectorServer server = JMXConnectorServer server =
JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
server.start(); server.start();
......
...@@ -253,4 +253,3 @@ public class MultiThreadDeadLockTest { ...@@ -253,4 +253,3 @@ public class MultiThreadDeadLockTest {
System.out.println("===Leave the method: " + m); System.out.println("===Leave the method: " + m);
} }
} }
...@@ -40,27 +40,16 @@ import com.sun.jmx.remote.security.MBeanServerAccessController; ...@@ -40,27 +40,16 @@ import com.sun.jmx.remote.security.MBeanServerAccessController;
public class SetMBeanServerForwarder { public class SetMBeanServerForwarder {
static final boolean optionalFlag; static boolean isPresent(String cn) {
static {
Class genericClass = null;
try { try {
genericClass = Class.forName(cn);
Class.forName("javax.management.remote.generic.GenericConnector"); return true;
} catch (ClassNotFoundException x) { } catch (ClassNotFoundException x) {
// NO optional package return false;
} }
optionalFlag = (genericClass != null);
} }
final static String[] mandatoryList = { public static int test(String... urls) {
"service:jmx:rmi://", "service:jmx:iiop://"
};
final static String[] optionalList = {
"service:jmx:jmxmp://"
};
public static int test(String[] urls) {
int errorCount = 0; int errorCount = 0;
for (int i=0;i<urls.length;i++) { for (int i=0;i<urls.length;i++) {
try { try {
...@@ -241,12 +230,19 @@ public class SetMBeanServerForwarder { ...@@ -241,12 +230,19 @@ public class SetMBeanServerForwarder {
public static void main(String args[]) { public static void main(String args[]) {
int errCount = 0; int errCount = 0;
errCount += test(mandatoryList);
if (optionalFlag) errCount += test(optionalList); // mandatory
errCount += test("service:jmx:rmi://");
// optional
if (isPresent("javax.management.remote.rmi._RMIConnectionImpl_Tie"))
errCount += test("service:jmx:iiop://");
if (isPresent("javax.management.remote.generic.GenericConnector"))
errCount += test("service:jmx:jmxmp://");
if (errCount > 0) { if (errCount > 0) {
System.err.println("SetMBeanServerForwarder failed: " + throw new RuntimeException("SetMBeanServerForwarder failed: " +
errCount + " error(s) reported."); errCount + " error(s) reported.");
System.exit(1);
} }
System.out.println("SetMBeanServerForwarder passed."); System.out.println("SetMBeanServerForwarder passed.");
} }
......
...@@ -70,7 +70,6 @@ import javax.management.remote.JMXConnectorServer; ...@@ -70,7 +70,6 @@ import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory; import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL; import javax.management.remote.JMXServiceURL;
import javax.management.remote.rmi.RMIConnectorServer; import javax.management.remote.rmi.RMIConnectorServer;
import org.omg.CORBA.MARSHAL;
public class MissingClassTest { public class MissingClassTest {
private static final int NNOTIFS = 50; private static final int NNOTIFS = 50;
...@@ -84,6 +83,15 @@ public class MissingClassTest { ...@@ -84,6 +83,15 @@ public class MissingClassTest {
private static final Object unserializableObject = Thread.currentThread(); private static final Object unserializableObject = Thread.currentThread();
private static boolean isInstance(Object o, String cn) {
try {
Class<?> c = Class.forName(cn);
return c.isInstance(o);
} catch (ClassNotFoundException x) {
return false;
}
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
System.out.println("Test that the client or server end of a " + System.out.println("Test that the client or server end of a " +
"connection does not fail if sent an object " + "connection does not fail if sent an object " +
...@@ -118,8 +126,7 @@ public class MissingClassTest { ...@@ -118,8 +126,7 @@ public class MissingClassTest {
if (ok) if (ok)
System.out.println("Test passed"); System.out.println("Test passed");
else { else {
System.out.println("TEST FAILED"); throw new RuntimeException("TEST FAILED");
System.exit(1);
} }
} }
...@@ -133,7 +140,7 @@ public class MissingClassTest { ...@@ -133,7 +140,7 @@ public class MissingClassTest {
JMXConnectorServer cs; JMXConnectorServer cs;
JMXServiceURL url = new JMXServiceURL(proto, null, 0); JMXServiceURL url = new JMXServiceURL(proto, null, 0);
Map serverMap = new HashMap(); Map<String,Object> serverMap = new HashMap<>();
serverMap.put(JMXConnectorServerFactory.DEFAULT_CLASS_LOADER, serverMap.put(JMXConnectorServerFactory.DEFAULT_CLASS_LOADER,
serverLoader); serverLoader);
...@@ -151,7 +158,7 @@ public class MissingClassTest { ...@@ -151,7 +158,7 @@ public class MissingClassTest {
} }
cs.start(); cs.start();
JMXServiceURL addr = cs.getAddress(); JMXServiceURL addr = cs.getAddress();
Map clientMap = new HashMap(); Map<String,Object> clientMap = new HashMap<>();
clientMap.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER, clientMap.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER,
clientLoader); clientLoader);
...@@ -174,7 +181,7 @@ public class MissingClassTest { ...@@ -174,7 +181,7 @@ public class MissingClassTest {
ok = false; ok = false;
} catch (IOException e) { } catch (IOException e) {
Throwable cause = e.getCause(); Throwable cause = e.getCause();
if (cause instanceof MARSHAL) // see CR 4935098 if (isInstance(cause, "org.omg.CORBA.MARSHAL")) // see CR 4935098
cause = cause.getCause(); cause = cause.getCause();
if (cause instanceof ClassNotFoundException) { if (cause instanceof ClassNotFoundException) {
System.out.println("Success: got an IOException wrapping " + System.out.println("Success: got an IOException wrapping " +
...@@ -188,7 +195,7 @@ public class MissingClassTest { ...@@ -188,7 +195,7 @@ public class MissingClassTest {
} }
System.out.println("Doing queryNames to ensure connection alive"); System.out.println("Doing queryNames to ensure connection alive");
Set names = mbsc.queryNames(null, null); Set<ObjectName> names = mbsc.queryNames(null, null);
System.out.println("queryNames returned " + names); System.out.println("queryNames returned " + names);
System.out.println("Provoke exception of unknown class"); System.out.println("Provoke exception of unknown class");
...@@ -198,7 +205,7 @@ public class MissingClassTest { ...@@ -198,7 +205,7 @@ public class MissingClassTest {
ok = false; ok = false;
} catch (IOException e) { } catch (IOException e) {
Throwable wrapped = e.getCause(); Throwable wrapped = e.getCause();
if (wrapped instanceof MARSHAL) // see CR 4935098 if (isInstance(wrapped, "org.omg.CORBA.MARSHAL")) // see CR 4935098
wrapped = wrapped.getCause(); wrapped = wrapped.getCause();
if (wrapped instanceof ClassNotFoundException) { if (wrapped instanceof ClassNotFoundException) {
System.out.println("Success: got an IOException wrapping " + System.out.println("Success: got an IOException wrapping " +
...@@ -251,7 +258,7 @@ public class MissingClassTest { ...@@ -251,7 +258,7 @@ public class MissingClassTest {
ok = false; ok = false;
} catch (IOException e) { } catch (IOException e) {
Throwable cause = e.getCause(); Throwable cause = e.getCause();
if (cause instanceof MARSHAL) // see CR 4935098 if (isInstance(cause, "org.omg.CORBA.MARSHAL")) // see CR 4935098
cause = cause.getCause(); cause = cause.getCause();
if (cause instanceof ClassNotFoundException) { if (cause instanceof ClassNotFoundException) {
System.out.println("Success: got an IOException " + System.out.println("Success: got an IOException " +
...@@ -584,15 +591,13 @@ public class MissingClassTest { ...@@ -584,15 +591,13 @@ public class MissingClassTest {
try { try {
new ObjectOutputStream(new ByteArrayOutputStream()) new ObjectOutputStream(new ByteArrayOutputStream())
.writeObject(tricky); .writeObject(tricky);
System.out.println("TEST INCORRECT: tricky notif is " + throw new RuntimeException("TEST INCORRECT: tricky notif is " +
"serializable"); "serializable");
System.exit(1);
} catch (NotSerializableException e) { } catch (NotSerializableException e) {
// OK: tricky notif is not serializable // OK: tricky notif is not serializable
} catch (IOException e) { } catch (IOException e) {
System.out.println("TEST INCORRECT: tricky notif " + throw new RuntimeException("TEST INCORRECT: tricky notif " +
"serialization check failed"); "serialization check failed");
System.exit(1);
} }
/* Now shuffle an imaginary deck of cards where K, U, T, and /* Now shuffle an imaginary deck of cards where K, U, T, and
...@@ -629,12 +634,11 @@ public class MissingClassTest { ...@@ -629,12 +634,11 @@ public class MissingClassTest {
} }
if (knownCount != 0 || unknownCount != 0 if (knownCount != 0 || unknownCount != 0
|| trickyCount != 0 || boringCount != 0) { || trickyCount != 0 || boringCount != 0) {
System.out.println("TEST INCORRECT: Shuffle failed: " + throw new RuntimeException("TEST INCORRECT: Shuffle failed: " +
"known=" + knownCount +" unknown=" + "known=" + knownCount +" unknown=" +
unknownCount + " tricky=" + trickyCount + unknownCount + " tricky=" + trickyCount +
" boring=" + boringCount + " boring=" + boringCount +
" deal=" + notifList); " deal=" + notifList);
System.exit(1);
} }
String notifs = notifList.toString(); String notifs = notifList.toString();
System.out.println("Shuffle: " + notifs); System.out.println("Shuffle: " + notifs);
...@@ -646,10 +650,8 @@ public class MissingClassTest { ...@@ -646,10 +650,8 @@ public class MissingClassTest {
case 't': n = tricky; break; case 't': n = tricky; break;
case 'b': n = boring; break; case 'b': n = boring; break;
default: default:
System.out.println("TEST INCORRECT: Bad shuffle char: " + throw new RuntimeException("TEST INCORRECT: Bad shuffle char: " +
notifs.charAt(i)); notifs.charAt(i));
System.exit(1);
throw new Error();
} }
sendNotification(n); sendNotification(n);
} }
......
...@@ -49,13 +49,13 @@ import javax.management.MBeanServer; ...@@ -49,13 +49,13 @@ import javax.management.MBeanServer;
import provider.JMXConnectorProviderImpl; import provider.JMXConnectorProviderImpl;
import provider.JMXConnectorServerProviderImpl; import provider.JMXConnectorServerProviderImpl;
public class ProviderTest { public class ProviderTest {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
System.out.println("Starting ProviderTest"); System.out.println("Starting ProviderTest");
MBeanServer mbs = MBeanServerFactory.newMBeanServer(); MBeanServer mbs = MBeanServerFactory.newMBeanServer();
//First do the test with a protocol handled by Service providers
JMXServiceURL url =
new JMXServiceURL("service:jmx:rmi://");
// First do the test with a protocol handled by Service providers
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
dotest(url, mbs); dotest(url, mbs);
boolean clientCalled = provider.JMXConnectorProviderImpl.called(); boolean clientCalled = provider.JMXConnectorProviderImpl.called();
...@@ -66,16 +66,22 @@ public class ProviderTest { ...@@ -66,16 +66,22 @@ public class ProviderTest {
System.out.println("Client provider not called"); System.out.println("Client provider not called");
if (!serverCalled) if (!serverCalled)
System.out.println("Server provider not called"); System.out.println("Server provider not called");
System.out.println("Test Failed"); throw new RuntimeException("Test failed - see log for details");
System.exit(1);
} }
//The Service Provider doesn't handle IIOP. Default providers MUST // The Service Provider doesn't handle IIOP. Default providers MUST
//be called. // be called, which may or may not support IIOP.
url = url = new JMXServiceURL("service:jmx:iiop://");
new JMXServiceURL("service:jmx:iiop://"); try {
dotest(url, mbs);
dotest(url, mbs); } catch (MalformedURLException e) {
try {
Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie");
e.printStackTrace(System.out);
throw new RuntimeException("MalformedURLException throw but IIOP appears to be supported");
} catch (ClassNotFoundException expected) { }
System.out.println("MalformedURLException thrown, IIOP transport not supported");
}
// Unsupported protocol. // Unsupported protocol.
JMXConnectorServer server = null; JMXConnectorServer server = null;
...@@ -87,31 +93,19 @@ public class ProviderTest { ...@@ -87,31 +93,19 @@ public class ProviderTest {
JMXConnectorServerFactory.newJMXConnectorServer(url, JMXConnectorServerFactory.newJMXConnectorServer(url,
null, null,
mbs); mbs);
System.out.println("Exception not thrown."); throw new RuntimeException("Exception not thrown.");
System.exit(1); } catch (MalformedURLException e) {
}catch(MalformedURLException e) {
System.out.println("Expected MalformedURLException thrown."); System.out.println("Expected MalformedURLException thrown.");
} }
catch(Exception e) {
e.printStackTrace();
System.out.println("Exception thrown : " + e);
System.exit(1);
}
try { try {
client = client =
JMXConnectorFactory.newJMXConnector(url, JMXConnectorFactory.newJMXConnector(url,
null); null);
System.out.println("Exception not thrown."); throw new RuntimeException("Exception not thrown.");
System.exit(1); } catch (MalformedURLException e) {
}catch(MalformedURLException e) {
System.out.println("Expected MalformedURLException thrown."); System.out.println("Expected MalformedURLException thrown.");
} }
catch(Exception e) {
e.printStackTrace();
System.out.println("Exception thrown : " + e);
System.exit(1);
}
//JMXConnectorProviderException //JMXConnectorProviderException
url = url =
...@@ -121,60 +115,34 @@ public class ProviderTest { ...@@ -121,60 +115,34 @@ public class ProviderTest {
JMXConnectorServerFactory.newJMXConnectorServer(url, JMXConnectorServerFactory.newJMXConnectorServer(url,
null, null,
mbs); mbs);
System.out.println("Exception not thrown."); throw new RuntimeException("Exception not thrown.");
System.exit(1); } catch(JMXProviderException e) {
}catch(JMXProviderException e) {
System.out.println("Expected JMXProviderException thrown."); System.out.println("Expected JMXProviderException thrown.");
} }
catch(Exception e) {
e.printStackTrace();
System.out.println("Exception thrown : " + e);
System.exit(1);
}
try { try {
client = client =
JMXConnectorFactory.newJMXConnector(url, JMXConnectorFactory.newJMXConnector(url,
null); null);
System.out.println("Exception not thrown."); throw new RuntimeException("Exception not thrown.");
System.exit(1);
}catch(JMXProviderException e) { }catch(JMXProviderException e) {
System.out.println("Expected JMXProviderException thrown."); System.out.println("Expected JMXProviderException thrown.");
} }
catch(Exception e) {
e.printStackTrace();
System.out.println("Exception thrown : " + e);
System.exit(1);
}
System.out.println("Test OK"); System.out.println("Test OK");
return;
} }
private static void dotest(JMXServiceURL url, MBeanServer mbs) private static void dotest(JMXServiceURL url, MBeanServer mbs)
throws Exception { throws Exception {
JMXConnectorServer server = null; JMXConnectorServer server = null;
JMXConnector client = null; JMXConnector client = null;
try {
server = server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
JMXConnectorServerFactory.newJMXConnectorServer(url,
null,
mbs);
}catch(IllegalArgumentException e) {
e.printStackTrace();
System.exit(1);
}
server.start(); server.start();
JMXServiceURL outputAddr = server.getAddress(); JMXServiceURL outputAddr = server.getAddress();
System.out.println("Server started ["+ outputAddr+ "]"); System.out.println("Server started ["+ outputAddr+ "]");
try { client = JMXConnectorFactory.newJMXConnector(outputAddr, null);
client =
JMXConnectorFactory.newJMXConnector(outputAddr, null);
}catch(IllegalArgumentException e) {
e.printStackTrace();
System.exit(1);
}
client.connect(); client.connect();
System.out.println("Client connected"); System.out.println("Client connected");
......
...@@ -120,7 +120,7 @@ public class JMXServerErrorTest { ...@@ -120,7 +120,7 @@ public class JMXServerErrorTest {
try { try {
cs=JMXConnectorServerFactory.newJMXConnectorServer(jurl,null,kbs); cs=JMXConnectorServerFactory.newJMXConnectorServer(jurl,null,kbs);
} catch (MalformedURLException m) { } catch (MalformedURLException m) {
if ("jmxmp".equals(jurl.getProtocol())) { if ("jmxmp".equals(jurl.getProtocol()) || "iiop".equals(jurl.getProtocol())) {
// OK, we may not have this in the classpath... // OK, we may not have this in the classpath...
System.out.println("WARNING: Skipping protocol: " + jurl); System.out.println("WARNING: Skipping protocol: " + jurl);
return; return;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册