Path: blob/master/test/jdk/com/sun/management/DiagnosticCommandMBean/DcmdMBeanTest.java
41155 views
/*1* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 715025626* @summary Basic Test for the DiagnosticCommandMBean27* @author Frederic Parain, Shanliang JIANG28*29* @run main/othervm DcmdMBeanTest30*/313233import java.lang.management.ManagementFactory;34import javax.management.Descriptor;35import javax.management.MBeanInfo;36import javax.management.MBeanOperationInfo;37import javax.management.MBeanServer;38import javax.management.ObjectName;39import javax.management.*;40import javax.management.remote.*;4142public class DcmdMBeanTest {4344private static String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME =45"com.sun.management:type=DiagnosticCommand";4647public static void main(String[] args) throws Exception {48System.out.println("--->JRCMD MBean Test: invocation on \"operation info\"...");4950MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();51JMXServiceURL url = new JMXServiceURL("rmi", null, 0);52JMXConnectorServer cs = null;53JMXConnector cc = null;54try {55cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);56cs.start();57JMXServiceURL addr = cs.getAddress();58cc = JMXConnectorFactory.connect(addr);59MBeanServerConnection mbsc = cc.getMBeanServerConnection();60ObjectName name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);61MBeanInfo info = mbsc.getMBeanInfo(name);6263// the test should check that the MBean doesn't have any64// Attribute, notification or constructor. Current version only65// check operations66System.out.println("Class Name:" + info.getClassName());67System.out.println("Description:" + info.getDescription());68MBeanOperationInfo[] opInfo = info.getOperations();69System.out.println("Operations:");70for (int i = 0; i < opInfo.length; i++) {71printOperation(opInfo[i]);72System.out.println("\n@@@@@@\n");73}74} finally {75try {76cc.close();77cs.stop();78} catch (Exception e) {79}80}8182System.out.println("Test passed");83}8485static void printOperation(MBeanOperationInfo info) {86System.out.println("Name: "+info.getName());87System.out.println("Description: "+info.getDescription());88System.out.println("Return Type: "+info.getReturnType());89System.out.println("Impact: "+info.getImpact());90Descriptor desc = info.getDescriptor();91System.out.println("Descriptor");92for(int i=0; i<desc.getFieldNames().length; i++) {93if(desc.getFieldNames()[i].compareTo("dcmd.arguments") == 0) {94System.out.println("\t"+desc.getFieldNames()[i]+":");95Descriptor desc2 =96(Descriptor)desc.getFieldValue(desc.getFieldNames()[i]);97for(int j=0; j<desc2.getFieldNames().length; j++) {98System.out.println("\t\t"+desc2.getFieldNames()[j]+"=");99Descriptor desc3 =100(Descriptor)desc2.getFieldValue(desc2.getFieldNames()[j]);101for(int k=0; k<desc3.getFieldNames().length; k++) {102System.out.println("\t\t\t"+desc3.getFieldNames()[k]+"="103+desc3.getFieldValue(desc3.getFieldNames()[k]));104}105}106} else {107System.out.println("\t"+desc.getFieldNames()[i]+"="108+desc.getFieldValue(desc.getFieldNames()[i]));109}110}111}112}113114115