提交 ffac7c43 编写于 作者: S sjiang

8016221: A unit test should not use a fix port to run a jmx connector

Reviewed-by: jbachorik, dfuchs
上级 2890559e
...@@ -25,25 +25,15 @@ ...@@ -25,25 +25,15 @@
* @test * @test
* @bug 7150256 * @bug 7150256
* @summary Basic Test for the DiagnosticCommandMBean * @summary Basic Test for the DiagnosticCommandMBean
* @author Frederic Parain * @author Frederic Parain, Shanliang JIANG
* *
* @run main/othervm -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=8125 DcmdMBeanDoubleInvocationTest * @run main/othervm DcmdMBeanDoubleInvocationTest
*/ */
import java.io.IOException;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.management.Descriptor;
import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanServer; import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName; import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.*; import javax.management.*;
import javax.management.remote.*; import javax.management.remote.*;
...@@ -52,39 +42,42 @@ public class DcmdMBeanDoubleInvocationTest { ...@@ -52,39 +42,42 @@ public class DcmdMBeanDoubleInvocationTest {
private static String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME = private static String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME =
"com.sun.management:type=DiagnosticCommand"; "com.sun.management:type=DiagnosticCommand";
public static void main(String[] args) { public static void main(String[] args) throws Exception {
MBeanServerConnection mbs = null; System.out.println("--->JRCMD MBean Test: invocation on \"help VM.version\" ...");
try {
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:8125/jmxrmi"); ObjectName name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);
JMXConnector connector = JMXConnectorFactory.connect(url);
mbs = connector.getMBeanServerConnection();
} catch(Throwable t) {
t.printStackTrace();
}
ObjectName name;
try {
name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);
MBeanInfo info = mbs.getMBeanInfo(name);
String[] helpArgs = {"-all", "\n", "VM.version"}; String[] helpArgs = {"-all", "\n", "VM.version"};
Object[] dcmdArgs = {helpArgs}; Object[] dcmdArgs = {helpArgs};
String[] signature = {String[].class.getName()}; String[] signature = {String[].class.getName()};
String result = (String) mbs.invoke(name, "help", dcmdArgs, signature);
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
JMXConnectorServer cs = null;
JMXConnector cc = null;
try {
cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
cs.start();
JMXServiceURL addr = cs.getAddress();
cc = JMXConnectorFactory.connect(addr);
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
String result = (String) mbsc.invoke(name, "help", dcmdArgs, signature);
System.out.println(result); System.out.println(result);
throw new Error("Test failed: Double commands have not been detected");
} catch (RuntimeMBeanException ex) { } catch (RuntimeMBeanException ex) {
if (ex.getCause() instanceof IllegalArgumentException) { if (ex.getCause() instanceof IllegalArgumentException) {
System.out.println("Test passed"); System.out.println("JTest passed: Double commands have been detected");
return;
} else { } else {
ex.printStackTrace(); ex.printStackTrace();
throw new RuntimeException("TEST FAILED"); throw new Error("TEST FAILED: got unknown exception "+ex);
}
} finally {
try {
cc.close();
cs.stop();
} catch (Exception e) {
} }
} catch (InstanceNotFoundException | IntrospectionException
| ReflectionException | MalformedObjectNameException
| MBeanException|IOException ex) {
ex.printStackTrace();
throw new RuntimeException("TEST FAILED");
} }
System.out.println("Double commands have not been detected");
throw new RuntimeException("TEST FAILED");
} }
} }
...@@ -25,25 +25,15 @@ ...@@ -25,25 +25,15 @@
* @test * @test
* @bug 7150256 * @bug 7150256
* @summary Basic Test for the DiagnosticCommandMBean * @summary Basic Test for the DiagnosticCommandMBean
* @author Frederic Parain * @author Frederic Parain, Shanliang JIANG
* *
* @run main/othervm -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=8129 DcmdMBeanInvocationTest * @run main/othervm DcmdMBeanInvocationTest
*/ */
import java.io.IOException;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.management.Descriptor;
import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanServer; import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName; import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.*; import javax.management.*;
import javax.management.remote.*; import javax.management.remote.*;
...@@ -52,30 +42,35 @@ public class DcmdMBeanInvocationTest { ...@@ -52,30 +42,35 @@ public class DcmdMBeanInvocationTest {
private static String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME = private static String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME =
"com.sun.management:type=DiagnosticCommand"; "com.sun.management:type=DiagnosticCommand";
public static void main(String[] args) { public static void main(String[] args) throws Exception {
MBeanServerConnection mbs = null; System.out.println("--->JRCMD MBean Test: invocation on \"help -all\" ...");
try {
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:8129/jmxrmi"); ObjectName name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);
JMXConnector connector = JMXConnectorFactory.connect(url);
mbs = connector.getMBeanServerConnection();
} catch(Throwable t) {
t.printStackTrace();
}
ObjectName name;
try {
name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);
MBeanInfo info = mbs.getMBeanInfo(name);
String[] helpArgs = {"-all"}; String[] helpArgs = {"-all"};
Object[] dcmdArgs = {helpArgs}; Object[] dcmdArgs = {helpArgs};
String[] signature = {String[].class.getName()}; String[] signature = {String[].class.getName()};
String result = (String) mbs.invoke(name, "help", dcmdArgs, signature);
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
JMXConnectorServer cs = null;
JMXConnector cc = null;
try {
cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
cs.start();
JMXServiceURL addr = cs.getAddress();
cc = JMXConnectorFactory.connect(addr);
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
String result = (String) mbsc.invoke(name, "help", dcmdArgs, signature);
System.out.println(result); System.out.println(result);
} catch (InstanceNotFoundException | IntrospectionException } finally {
| ReflectionException | MalformedObjectNameException try {
| MBeanException|IOException ex) { cc.close();
ex.printStackTrace(); cs.stop();
throw new RuntimeException("TEST FAILED"); } catch (Exception e) {
} }
}
System.out.println("Test passed"); System.out.println("Test passed");
} }
} }
...@@ -25,25 +25,18 @@ ...@@ -25,25 +25,18 @@
* @test * @test
* @bug 7150256 * @bug 7150256
* @summary Basic Test for the DiagnosticCommandMBean * @summary Basic Test for the DiagnosticCommandMBean
* @author Frederic Parain * @author Frederic Parain, Shanliang JIANG
* *
* @run main/othervm -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=8127 DcmdMBeanTest * @run main/othervm DcmdMBeanTest
*/ */
import java.io.IOException;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.management.Descriptor; import javax.management.Descriptor;
import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.MBeanInfo; import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo; import javax.management.MBeanOperationInfo;
import javax.management.MBeanServer; import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName; import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.*; import javax.management.*;
import javax.management.remote.*; import javax.management.remote.*;
...@@ -52,34 +45,42 @@ public class DcmdMBeanTest { ...@@ -52,34 +45,42 @@ public class DcmdMBeanTest {
private static String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME = private static String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME =
"com.sun.management:type=DiagnosticCommand"; "com.sun.management:type=DiagnosticCommand";
public static void main(String[] args) { public static void main(String[] args) throws Exception {
MBeanServerConnection mbs = null; System.out.println("--->JRCMD MBean Test: invocation on \"operation info\"...");
try {
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:8127/jmxrmi"); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
JMXConnector connector = JMXConnectorFactory.connect(url); JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
mbs = connector.getMBeanServerConnection(); JMXConnectorServer cs = null;
} catch(Throwable t) { JMXConnector cc = null;
t.printStackTrace();
}
ObjectName name;
try { try {
name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME); cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
MBeanInfo info = mbs.getMBeanInfo(name); cs.start();
JMXServiceURL addr = cs.getAddress();
cc = JMXConnectorFactory.connect(addr);
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
ObjectName name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);
MBeanInfo info = mbsc.getMBeanInfo(name);
// the test should check that the MBean doesn't have any // the test should check that the MBean doesn't have any
// Attribute, notification or constructor. Current version only // Attribute, notification or constructor. Current version only
// check operations // check operations
System.out.println("Class Name:"+info.getClassName()); System.out.println("Class Name:" + info.getClassName());
System.out.println("Description:"+info.getDescription()); System.out.println("Description:" + info.getDescription());
MBeanOperationInfo[] opInfo = info.getOperations(); MBeanOperationInfo[] opInfo = info.getOperations();
System.out.println("Operations:"); System.out.println("Operations:");
for(int i=0; i<opInfo.length; i++) { for (int i = 0; i < opInfo.length; i++) {
printOperation(opInfo[i]); printOperation(opInfo[i]);
System.out.println("\n@@@@@@\n"); System.out.println("\n@@@@@@\n");
} }
} catch (InstanceNotFoundException|IntrospectionException|ReflectionException } finally {
|MalformedObjectNameException|IOException ex) { try {
Logger.getLogger(DcmdMBeanTest.class.getName()).log(Level.SEVERE, null, ex); cc.close();
cs.stop();
} catch (Exception e) {
}
} }
System.out.println("Test passed");
} }
static void printOperation(MBeanOperationInfo info) { static void printOperation(MBeanOperationInfo info) {
...@@ -110,4 +111,3 @@ public class DcmdMBeanTest { ...@@ -110,4 +111,3 @@ public class DcmdMBeanTest {
} }
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册