use of javax.management.remote.JMXConnectorServer in project jdk8u_jdk by JetBrains.
the class RMIConnectorNullSubjectConnTest method main.
public static void main(String[] args) throws Exception {
System.out.println("---RMIConnectorNullSubjectConnTest starting...");
JMXConnectorServer connectorServer = null;
JMXConnector connectorClient = null;
try {
MBeanServer mserver = ManagementFactory.getPlatformMBeanServer();
JMXServiceURL serverURL = new JMXServiceURL("rmi", "localhost", 0);
connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(serverURL, null, mserver);
connectorServer.start();
JMXServiceURL serverAddr = connectorServer.getAddress();
connectorClient = JMXConnectorFactory.connect(serverAddr, null);
connectorClient.connect();
Field nullSubjectConnField = RMIConnector.class.getDeclaredField("nullSubjectConnRef");
nullSubjectConnField.setAccessible(true);
WeakReference<MBeanServerConnection> weak = (WeakReference<MBeanServerConnection>) nullSubjectConnField.get(connectorClient);
if (weak != null && weak.get() != null) {
throw new RuntimeException("nullSubjectConnRef must be null at initial time.");
}
MBeanServerConnection conn1 = connectorClient.getMBeanServerConnection(null);
MBeanServerConnection conn2 = connectorClient.getMBeanServerConnection(null);
if (conn1 == null) {
throw new RuntimeException("A connection with null subject should not be null.");
} else if (conn1 != conn2) {
throw new RuntimeException("The 2 connections with null subject are not equal.");
}
conn1 = null;
conn2 = null;
int i = 1;
do {
System.gc();
Thread.sleep(100);
weak = (WeakReference<MBeanServerConnection>) nullSubjectConnField.get(connectorClient);
} while ((weak != null && weak.get() != null) && i++ < 60);
System.out.println("---GC times: " + i);
if (weak != null && weak.get() != null) {
throw new RuntimeException("Failed to clean RMIConnector's nullSubjectConn");
} else {
System.out.println("---RMIConnectorNullSubjectConnTest: PASSED!");
}
} finally {
try {
connectorClient.close();
connectorServer.stop();
} catch (Exception e) {
}
}
}
use of javax.management.remote.JMXConnectorServer in project jdk8u_jdk by JetBrains.
the class MapNullValuesTest method nullKeyFactoryTests.
private int nullKeyFactoryTests() {
int errorCount = 0;
echo("");
echo(dashedMessage("Run Null Key Factory Tests"));
echo("\tMap = " + map3);
try {
String urlStr = "service:jmx:rmi:///jndi/rmi://:" + port + "/NullKeyFactory";
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
JMXServiceURL url = null;
JMXConnectorServer jmxcs = null;
JMXConnector jmxc = null;
echo("\tJMXConnectorServerFactory.newJMXConnectorServer()");
try {
url = new JMXServiceURL(urlStr + "1");
jmxcs = JMXConnectorServerFactory.newJMXConnectorServer(url, map3, mbs);
errorCount++;
echo("\tTest FAILED!");
} catch (Exception e) {
echo("\tException Message: " + e.getMessage());
echo("\tTest PASSED!");
}
echo("\tJMXConnectorServerFactory.toJMXConnector()");
try {
url = new JMXServiceURL(urlStr + "2");
jmxcs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
jmxcs.start();
jmxcs.toJMXConnector(map3);
errorCount++;
echo("\tTest FAILED!");
} catch (Exception e) {
echo("\tException Message: " + e.getMessage());
echo("\tTest PASSED!");
} finally {
jmxcs.stop();
}
echo("\tJMXConnectorFactory.newJMXConnector()");
try {
url = new JMXServiceURL(urlStr + "3");
jmxcs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
jmxcs.start();
jmxc = JMXConnectorFactory.newJMXConnector(jmxcs.getAddress(), map3);
errorCount++;
echo("\tTest FAILED!");
} catch (Exception e) {
echo("\tException Message: " + e.getMessage());
echo("\tTest PASSED!");
} finally {
jmxcs.stop();
}
echo("\tJMXConnectorFactory.connect()");
try {
url = new JMXServiceURL(urlStr + "4");
jmxcs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
jmxcs.start();
jmxc = JMXConnectorFactory.connect(jmxcs.getAddress(), map3);
errorCount++;
echo("\tTest FAILED!");
} catch (Exception e) {
echo("\tException Message: " + e.getMessage());
echo("\tTest PASSED!");
} finally {
jmxcs.stop();
}
echo("\tJMXConnector.connect()");
try {
url = new JMXServiceURL(urlStr + "5");
jmxcs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
jmxcs.start();
jmxc = JMXConnectorFactory.newJMXConnector(jmxcs.getAddress(), null);
jmxc.connect(map3);
errorCount++;
echo("\tTest FAILED!");
} catch (Exception e) {
echo("\tException Message: " + e.getMessage());
echo("\tTest PASSED!");
} finally {
jmxcs.stop();
}
} catch (Exception e) {
echo("\tGot unexpected exception!");
e.printStackTrace(System.out);
errorCount = 1;
}
if (errorCount == 0) {
echo("");
echo(dashedMessage("Null Key Factory Tests PASSED!"));
} else {
echo("");
echo(dashedMessage("Null Key Factory Tests FAILED!"));
}
return errorCount;
}
use of javax.management.remote.JMXConnectorServer in project jdk8u_jdk by JetBrains.
the class MapNullValuesTest method jmxConnectorFactoryTests.
private int jmxConnectorFactoryTests() {
int errorCount = 0;
echo("");
echo(dashedMessage("Run JMXConnectorFactory Tests"));
for (int i = 0; i < maps.length - 1; i++) {
echo("\n>>> JMXConnectorFactory Test [" + i + "]");
try {
echo("\tMap = " + maps[i]);
echo("\tCreate the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
echo("\tCreate the RMI connector server");
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:" + port + "/JMXConnectorFactory" + i);
JMXConnectorServer jmxcs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
echo("\tStart the RMI connector server");
jmxcs.start();
echo("\tCreate and connect the RMI connector");
JMXConnector jmxc = JMXConnectorFactory.connect(jmxcs.getAddress(), maps[i]);
echo("\tClose the RMI connector");
jmxc.close();
echo("\tTest [" + i + "] PASSED!");
} catch (Exception e) {
errorCount++;
echo("\tTest [" + i + "] FAILED!");
e.printStackTrace(System.out);
}
}
if (errorCount == 0) {
echo("");
echo(dashedMessage("JMXConnectorFactory Tests PASSED!"));
} else {
echo("");
echo(dashedMessage("JMXConnectorFactory Tests FAILED!"));
}
return errorCount;
}
Aggregations