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