0N/A/*
2362N/A * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 6359948
0N/A * @summary Check that MXBean operations have the expected ReturnType in MBeanOperationInfo
0N/A * @author Luis-Miguel Alventosa
0N/A * @run clean MBeanOperationInfoTest
0N/A * @run build MBeanOperationInfoTest
0N/A * @run main MBeanOperationInfoTest
0N/A */
0N/A
0N/Aimport java.lang.management.*;
0N/Aimport javax.management.*;
0N/Aimport javax.management.openmbean.*;
0N/A
0N/Apublic class MBeanOperationInfoTest {
0N/A private static final String[][] returnTypes = {
0N/A { "dumpAllThreads(boolean,boolean)", "[Ljavax.management.openmbean.CompositeData;" },
0N/A { "findDeadlockedThreads()", "[J" },
0N/A { "findMonitorDeadlockedThreads()", "[J" },
0N/A { "getThreadInfo(long)","javax.management.openmbean.CompositeData"},
0N/A { "getThreadInfo(long,int)","javax.management.openmbean.CompositeData"},
0N/A { "getThreadInfo([J)","[Ljavax.management.openmbean.CompositeData;"},
0N/A { "getThreadInfo([J,int)","[Ljavax.management.openmbean.CompositeData;"},
0N/A { "getThreadInfo([J,boolean,boolean)","[Ljavax.management.openmbean.CompositeData;"},
0N/A { "getThreadCpuTime(long)","long"},
0N/A { "getThreadUserTime(long)","long"},
0N/A { "resetPeakThreadCount()","void"},
0N/A };
0N/A public static void main(String[] args) throws Exception {
0N/A int error = 0;
0N/A int tested = 0;
0N/A MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
0N/A ObjectName on = new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME);
0N/A MBeanInfo mbi = mbs.getMBeanInfo(on);
0N/A MBeanOperationInfo[] ops = mbi.getOperations();
0N/A for (MBeanOperationInfo op : ops) {
0N/A String name = op.getName();
0N/A String rt = op.getReturnType();
0N/A StringBuilder sb = new StringBuilder();
0N/A sb.append(name + "(");
0N/A for (MBeanParameterInfo param : op.getSignature()) {
0N/A sb.append(param.getType() + ",");
0N/A }
0N/A int comma = sb.lastIndexOf(",");
0N/A if (comma == -1) {
0N/A sb.append(")");
0N/A } else {
0N/A sb.replace(comma, comma + 1, ")");
0N/A }
0N/A System.out.println("\nNAME = " + sb.toString() + "\nRETURN TYPE = " + rt);
0N/A for (String[] rts : returnTypes) {
0N/A if (sb.toString().equals(rts[0])) {
0N/A if (rt.equals(rts[1])) {
0N/A System.out.println("OK");
0N/A tested++;
0N/A } else {
0N/A System.out.println("KO: EXPECTED RETURN TYPE = " + rts[1]);
0N/A error++;
0N/A }
0N/A }
0N/A }
0N/A }
0N/A if (error > 0) {
0N/A System.out.println("\nTEST FAILED");
0N/A throw new Exception("TEST FAILED: " + error + " wrong return types");
469N/A } else if (tested != returnTypes.length &&
469N/A !System.getProperty("java.specification.version").equals("1.5")) {
0N/A System.out.println("\nTEST FAILED");
0N/A throw new Exception("TEST FAILED: " + tested + " cases tested, " +
0N/A returnTypes.length + " expected");
0N/A } else {
0N/A System.out.println("\nTEST PASSED");
0N/A }
0N/A }
0N/A}