Path: blob/master/test/jdk/javax/management/mxbean/OverloadTest.java
41149 views
/*1* Copyright (c) 2005, 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 617551726* @summary Test that MXBean interfaces can contain overloaded methods27* @author Eamonn McManus28*29* @run clean OverloadTest30* @run build OverloadTest31* @run main OverloadTest32*/3334import java.lang.management.*;35import javax.management.*;3637public class OverloadTest {38public static void main(String[] args) throws Exception {39MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();40ObjectName on = new ObjectName("a:b=c");41OverloadMXBean overloadImpl = new OverloadImpl();42mbs.registerMBean(overloadImpl, on);43OverloadMXBean p = JMX.newMXBeanProxy(mbs, on, OverloadMXBean.class);44check(p.notOverloaded(5), "notOverloaded");45check(p.overloaded(), "overloaded()");46check(p.overloaded(5), "overloaded(int)");47check(p.overloaded("x"), "overloaded(String)");48check(p.overloaded(36, 64), "overloaded(int, int)");4950// ObjectName threadingName = new ObjectName("java.lang:type=Threading");51// ThreadMXBean t =52// JMX.newMXBeanProxy(mbs, threadingName, ThreadMXBean.class);53// long[] ids = t.getAllThreadIds();54// ThreadInfo ti = t.getThreadInfo(ids[0]);5556if (failure != null)57throw new Exception(failure);5859}6061private static void check(String got, String expect) {62if (!expect.equals(got)) {63failure = "FAILED: got \"" + got + "\", expected \"" + expect + "\"";64System.out.println(failure);65}66}6768public static interface OverloadMXBean {69String notOverloaded(int x);70String overloaded();71String overloaded(int x);72String overloaded(String x);73String overloaded(int x, int y);74}7576public static class OverloadImpl implements OverloadMXBean {77public String notOverloaded(int x) {78return "notOverloaded";79}8081public String overloaded() {82return "overloaded()";83}8485public String overloaded(int x) {86return "overloaded(int)";87}8889public String overloaded(String x) {90return "overloaded(String)";91}9293public String overloaded(int x, int y) {94return "overloaded(int, int)";95}96}9798private static String failure;99}100101102