Path: blob/master/test/jdk/javax/management/mxbean/MBeanOperationInfoTest.java
41149 views
/*1* Copyright (c) 2006, 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 635994826* @summary Check that MXBean operations have the expected ReturnType in MBeanOperationInfo27* @author Luis-Miguel Alventosa28*29* @run clean MBeanOperationInfoTest30* @run build MBeanOperationInfoTest31* @run main MBeanOperationInfoTest32*/3334import java.lang.management.*;35import javax.management.*;36import javax.management.openmbean.*;3738public class MBeanOperationInfoTest {39private static final String[][] returnTypes = {40{ "dumpAllThreads(boolean,boolean)", "[Ljavax.management.openmbean.CompositeData;" },41{ "findDeadlockedThreads()", "[J" },42{ "findMonitorDeadlockedThreads()", "[J" },43{ "getThreadInfo(long)","javax.management.openmbean.CompositeData"},44{ "getThreadInfo(long,int)","javax.management.openmbean.CompositeData"},45{ "getThreadInfo([J)","[Ljavax.management.openmbean.CompositeData;"},46{ "getThreadInfo([J,int)","[Ljavax.management.openmbean.CompositeData;"},47{ "getThreadInfo([J,boolean,boolean)","[Ljavax.management.openmbean.CompositeData;"},48{ "getThreadCpuTime(long)","long"},49{ "getThreadUserTime(long)","long"},50{ "resetPeakThreadCount()","void"},51};52public static void main(String[] args) throws Exception {53int error = 0;54int tested = 0;55MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();56ObjectName on = new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME);57MBeanInfo mbi = mbs.getMBeanInfo(on);58MBeanOperationInfo[] ops = mbi.getOperations();59for (MBeanOperationInfo op : ops) {60String name = op.getName();61String rt = op.getReturnType();62StringBuilder sb = new StringBuilder();63sb.append(name + "(");64for (MBeanParameterInfo param : op.getSignature()) {65sb.append(param.getType() + ",");66}67int comma = sb.lastIndexOf(",");68if (comma == -1) {69sb.append(")");70} else {71sb.replace(comma, comma + 1, ")");72}73System.out.println("\nNAME = " + sb.toString() + "\nRETURN TYPE = " + rt);74for (String[] rts : returnTypes) {75if (sb.toString().equals(rts[0])) {76if (rt.equals(rts[1])) {77System.out.println("OK");78tested++;79} else {80System.out.println("KO: EXPECTED RETURN TYPE = " + rts[1]);81error++;82}83}84}85}86if (error > 0) {87System.out.println("\nTEST FAILED");88throw new Exception("TEST FAILED: " + error + " wrong return types");89} else if (tested != returnTypes.length &&90!System.getProperty("java.specification.version").equals("1.5")) {91System.out.println("\nTEST FAILED");92throw new Exception("TEST FAILED: " + tested + " cases tested, " +93returnTypes.length + " expected");94} else {95System.out.println("\nTEST PASSED");96}97}98}99100101