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