mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-24 04:54:40 +02:00
8016221: A unit test should not use a fix port to run a jmx connector
Reviewed-by: jbachorik, dfuchs
This commit is contained in:
parent
2f1e08ffec
commit
28502e7c19
3 changed files with 88 additions and 100 deletions
|
@ -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 {
|
||||||
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 @@
|
||||||
* @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 {
|
||||||
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 @@
|
||||||
* @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,36 +45,44 @@ 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\"...");
|
||||||
|
|
||||||
|
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
|
||||||
|
JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
|
||||||
|
JMXConnectorServer cs = null;
|
||||||
|
JMXConnector cc = null;
|
||||||
try {
|
try {
|
||||||
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:8127/jmxrmi");
|
cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
|
||||||
JMXConnector connector = JMXConnectorFactory.connect(url);
|
cs.start();
|
||||||
mbs = connector.getMBeanServerConnection();
|
JMXServiceURL addr = cs.getAddress();
|
||||||
} catch(Throwable t) {
|
cc = JMXConnectorFactory.connect(addr);
|
||||||
t.printStackTrace();
|
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
|
||||||
}
|
ObjectName name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);
|
||||||
ObjectName name;
|
MBeanInfo info = mbsc.getMBeanInfo(name);
|
||||||
try {
|
|
||||||
name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);
|
|
||||||
MBeanInfo info = mbs.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) {
|
||||||
System.out.println("Name: "+info.getName());
|
System.out.println("Name: "+info.getName());
|
||||||
System.out.println("Description: "+info.getDescription());
|
System.out.println("Description: "+info.getDescription());
|
||||||
|
@ -110,4 +111,3 @@ public class DcmdMBeanTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue