Path: blob/master/test/jdk/com/sun/management/DiagnosticCommandMBean/DcmdMBeanDoubleInvocationTest.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 DcmdMBeanDoubleInvocationTest30*/313233import java.lang.management.ManagementFactory;34import javax.management.MBeanServer;35import javax.management.ObjectName;36import javax.management.*;37import javax.management.remote.*;3839public class DcmdMBeanDoubleInvocationTest {4041private static String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME =42"com.sun.management:type=DiagnosticCommand";4344public static void main(String[] args) throws Exception {45System.out.println("--->JRCMD MBean Test: invocation on \"help VM.version\" ...");4647ObjectName name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);48String[] helpArgs = {"-all", "\n", "VM.version"};49Object[] dcmdArgs = {helpArgs};50String[] signature = {String[].class.getName()};5152MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();53JMXServiceURL url = new JMXServiceURL("rmi", null, 0);54JMXConnectorServer cs = null;55JMXConnector cc = null;56try {57cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);58cs.start();59JMXServiceURL addr = cs.getAddress();60cc = JMXConnectorFactory.connect(addr);61MBeanServerConnection mbsc = cc.getMBeanServerConnection();6263String result = (String) mbsc.invoke(name, "help", dcmdArgs, signature);64System.out.println(result);6566throw new Error("Test failed: Double commands have not been detected");67} catch (RuntimeMBeanException ex) {68if (ex.getCause() instanceof IllegalArgumentException) {69System.out.println("JTest passed: Double commands have been detected");70} else {71ex.printStackTrace();72throw new Error("TEST FAILED: got unknown exception "+ex);73}74} finally {75try {76cc.close();77cs.stop();78} catch (Exception e) {79}80}81}82}838485