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