use of javax.management.remote.JMXConnector in project jdk8u_jdk by JetBrains.
the class IdleTimeoutTest method test.
private static boolean test(String proto, int opCount, int liCount) throws Exception {
System.out.println("Idle timeout test for protocol " + proto);
ObjectName delegateName = ObjectName.getInstance("JMImplementation:" + "type=MBeanServerDelegate");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
JMXServiceURL url = new JMXServiceURL("service:jmx:" + proto + "://");
final long timeout = getIdleTimeout(mbs, url);
System.out.println("Timeout for " + proto + " is: " + timeout + " ms");
Map idleMap = new HashMap();
idleMap.put(EnvHelp.SERVER_CONNECTION_TIMEOUT, new Long(timeout));
JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(url, idleMap, mbs);
final int[] listenerCount = new int[1];
final NotificationListener[] countListeners = new NotificationListener[liCount];
int i;
for (i = 0; i < countListeners.length; i++) {
countListeners[i] = new NotificationCounter(listenerCount, "Listener" + i);
}
server.start();
try {
url = server.getAddress();
final long firstTime = System.currentTimeMillis();
JMXConnector client = JMXConnectorFactory.connect(url);
long elapsed, startIdle = 0;
try {
String connId = client.getConnectionId();
MBeanServerConnection conn = client.getMBeanServerConnection();
elapsed = System.currentTimeMillis() - firstTime;
System.out.println("Idle Time: " + elapsed + "ms");
for (i = 0; i < countListeners.length; i++) {
System.out.println("add " + countListeners[i] + ": starting at " + elapsed + "ms");
conn.addNotificationListener(delegateName, countListeners[i], null, null);
}
System.out.println("connId=" + connId);
for (i = 0; i < opCount; i++) {
elapsed = System.currentTimeMillis() - firstTime;
System.out.println("Operation[" + (i + 1) + "]: starting at " + elapsed + "ms");
final String name = "d:type=mlet,instance=" + i;
mbs.createMBean("javax.management.loading.MLet", new ObjectName(name));
if (i == (opCount - 1))
startIdle = System.currentTimeMillis();
Thread.sleep(2);
}
// Wait for notifs to arrive before doing removeNListener
long startTime = System.currentTimeMillis();
long deadline = startTime + 10000;
System.out.println("Waiting for notifs: starting at " + (startTime - firstTime) + "ms");
final int expectedCount = opCount * countListeners.length;
while (System.currentTimeMillis() < deadline) {
synchronized (listenerCount) {
if (listenerCount[0] >= expectedCount)
break;
listenerCount.wait();
}
}
long elapsedWait = System.currentTimeMillis() - startTime;
System.out.println("Waited " + elapsedWait + "ms for notifs to arrive");
if (listenerCount[0] != expectedCount) {
System.out.println("Did not get expected " + expectedCount + " notifications: " + listenerCount[0]);
return false;
}
elapsed = System.currentTimeMillis() - firstTime;
System.out.println("idle time since last operation: " + (elapsed + firstTime - startIdle) + "ms");
System.out.println("Requesting conn id at: " + elapsed + "ms");
final String cid = client.getConnectionId();
elapsed = System.currentTimeMillis() - firstTime;
System.out.println("Got conn id <" + cid + "> at: " + elapsed + "ms");
if (!connId.equals(cid)) {
System.out.println("Client id changed: <" + connId + "> -> <" + cid + ">");
return false;
}
List ids = Arrays.asList(server.getConnectionIds());
if (!ids.contains(connId)) {
System.out.println("Server ids don't contain our id: " + ids + " - " + connId);
return false;
}
for (i = 0; i < countListeners.length; i++) {
System.out.println("Removing notification listener: " + countListeners[i]);
conn.removeNotificationListener(delegateName, countListeners[i]);
}
System.out.println("Waiting for id list to drop ours");
// pass or timed out by test harness - see 8025204
do {
Thread.sleep(100);
ids = Arrays.asList(server.getConnectionIds());
} while (ids.contains(connId));
conn.getDefaultDomain();
if (connId.equals(client.getConnectionId())) {
System.out.println("Client id did not change: <" + connId + ">: idle timeout did not happen?");
return false;
} else {
System.out.println("Client id changed as expected: <" + connId + "> -> <" + client.getConnectionId() + ">");
}
} finally {
client.close();
System.out.println("Connection id list on server after " + "client close: " + Arrays.asList(server.getConnectionIds()));
}
} finally {
server.stop();
}
System.out.println("*** ------------------------------------------");
System.out.println("*** Test passed for " + proto);
System.out.println("*** ------------------------------------------");
return true;
}
use of javax.management.remote.JMXConnector in project jdk8u_jdk by JetBrains.
the class ConnectionListenerNullTest method test.
public static int test(String... urls) {
int errCount = 0;
for (int i = 0; i < urls.length; i++) {
try {
final JMXServiceURL url = new JMXServiceURL(urls[i]);
final JMXConnector c = JMXConnectorFactory.newJMXConnector(url, (Map<String, String>) null);
final NotificationListener nl = null;
final NotificationFilter nf = null;
final Object h = null;
System.out.println("Testing " + c.getClass().getName());
try {
System.out.println("addConnectionNotificationListener(null,null,null)");
c.addConnectionNotificationListener(nl, nf, h);
throw new AssertionError("No exception raised");
} catch (NullPointerException npe) {
// OK.
}
final NotificationListener listener = new NotificationListener() {
public void handleNotification(Notification notification, Object handback) {
}
};
c.addConnectionNotificationListener(listener, nf, h);
try {
System.out.println("removeConnectionNotificationListener(null)");
c.removeConnectionNotificationListener(nl);
throw new AssertionError("No exception raised");
} catch (NullPointerException npe) {
// OK.
}
try {
System.out.println("removeConnectionNotificationListener(null,null,null)");
c.removeConnectionNotificationListener(nl, nf, h);
throw new AssertionError("No exception raised");
} catch (NullPointerException npe) {
// OK.
}
c.removeConnectionNotificationListener(listener);
System.out.println(c.getClass().getName() + " successfully tested.");
} catch (Exception x) {
System.err.println("Unexpected exception for " + urls[i] + ": " + x);
x.printStackTrace();
errCount++;
} catch (AssertionError e) {
System.err.println("Unexpected assertion error for " + urls[i] + ": " + e);
e.printStackTrace();
errCount++;
}
}
return errCount;
}
use of javax.management.remote.JMXConnector in project jdk8u_jdk by JetBrains.
the class DaemonRMIExporterTest method main.
public static void main(String[] args) throws Exception {
Set<Thread> initialNonDaemonThreads = getNonDaemonThreads();
JMXServiceURL addr = new JMXServiceURL("rmi", null, 0);
System.out.println("DaemonRMIExporterTest: Creating a RMIConnectorServer on " + addr);
Map<String, ?> env = Collections.singletonMap("jmx.remote.x.daemon", "true");
JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(addr, env, MBeanServerFactory.createMBeanServer());
server.start();
System.out.println("DaemonRMIExporterTest: Started the server on " + server.getAddress());
System.out.println("DaemonRMIExporterTest: Connecting a client to the server ...");
final JMXConnector conn = JMXConnectorFactory.connect(server.getAddress());
conn.getMBeanServerConnection().getDefaultDomain();
System.out.println("DaemonRMIExporterTest: Closing the client ...");
conn.close();
System.out.println("DaemonRMIExporterTest No more user code to execute, the VM should " + "exit normally, otherwise will be blocked forever if the bug is not fixed.");
long deadline = System.currentTimeMillis() + 10000;
ok: {
while (System.currentTimeMillis() < deadline) {
Set<Thread> nonDaemonThreads = getNonDaemonThreads();
nonDaemonThreads.removeAll(initialNonDaemonThreads);
if (nonDaemonThreads.isEmpty())
break ok;
System.out.println("Non-daemon threads: " + nonDaemonThreads);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
throw new AssertionError(e);
}
}
throw new Exception("TEST FAILED: non-daemon threads remain");
}
System.out.println("TEST PASSED");
}
use of javax.management.remote.JMXConnector in project jdk8u_jdk by JetBrains.
the class GetConnectionTest method test.
private static boolean test(String proto) throws Exception {
JMXConnector client;
try {
JMXServiceURL url = new JMXServiceURL(proto, null, 0);
client = JMXConnectorFactory.newJMXConnector(url, null);
} catch (MalformedURLException e) {
System.out.println("Protocol " + proto + " not supported, ignoring");
return true;
}
// IOException is expected
try {
MBeanServerConnection connection = client.getMBeanServerConnection();
System.out.println("FAILED: Expected IOException is not thrown.");
return false;
} catch (IOException e) {
System.out.println("PASSED");
return true;
}
}
use of javax.management.remote.JMXConnector in project jdk8u_jdk by JetBrains.
the class RMIExitTest method test.
private static void test() {
try {
JMXServiceURL u = new JMXServiceURL("rmi", null, 0);
JMXConnectorServer server;
JMXServiceURL addr;
JMXConnector client;
MBeanServerConnection mserver;
final ObjectName delegateName = new ObjectName("JMImplementation:type=MBeanServerDelegate");
final NotificationListener dummyListener = new NotificationListener() {
public void handleNotification(Notification n, Object o) {
// do nothing
return;
}
};
server = JMXConnectorServerFactory.newJMXConnectorServer(u, null, mbs);
server.start();
addr = server.getAddress();
client = JMXConnectorFactory.newJMXConnector(addr, null);
client.connect(null);
mserver = client.getMBeanServerConnection();
String s1 = "1";
String s2 = "2";
String s3 = "3";
mserver.addNotificationListener(delegateName, dummyListener, null, s1);
mserver.addNotificationListener(delegateName, dummyListener, null, s2);
mserver.addNotificationListener(delegateName, dummyListener, null, s3);
mserver.removeNotificationListener(delegateName, dummyListener, null, s3);
mserver.removeNotificationListener(delegateName, dummyListener, null, s2);
mserver.removeNotificationListener(delegateName, dummyListener, null, s1);
client.close();
server.stop();
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
System.exit(1);
}
}
Aggregations