Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/mxbean/OverloadTest.java
38840 views
/*1* Copyright (c) 2005, 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* @run clean OverloadTest29* @run build OverloadTest30* @run main OverloadTest31*/3233import java.lang.management.*;34import javax.management.*;3536public class OverloadTest {37public static void main(String[] args) throws Exception {38MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();39ObjectName on = new ObjectName("a:b=c");40OverloadMXBean overloadImpl = new OverloadImpl();41mbs.registerMBean(overloadImpl, on);42OverloadMXBean p = JMX.newMXBeanProxy(mbs, on, OverloadMXBean.class);43check(p.notOverloaded(5), "notOverloaded");44check(p.overloaded(), "overloaded()");45check(p.overloaded(5), "overloaded(int)");46check(p.overloaded("x"), "overloaded(String)");47check(p.overloaded(36, 64), "overloaded(int, int)");4849// ObjectName threadingName = new ObjectName("java.lang:type=Threading");50// ThreadMXBean t =51// JMX.newMXBeanProxy(mbs, threadingName, ThreadMXBean.class);52// long[] ids = t.getAllThreadIds();53// ThreadInfo ti = t.getThreadInfo(ids[0]);5455if (failure != null)56throw new Exception(failure);5758}5960private static void check(String got, String expect) {61if (!expect.equals(got)) {62failure = "FAILED: got \"" + got + "\", expected \"" + expect + "\"";63System.out.println(failure);64}65}6667public static interface OverloadMXBean {68String notOverloaded(int x);69String overloaded();70String overloaded(int x);71String overloaded(String x);72String overloaded(int x, int y);73}7475public static class OverloadImpl implements OverloadMXBean {76public String notOverloaded(int x) {77return "notOverloaded";78}7980public String overloaded() {81return "overloaded()";82}8384public String overloaded(int x) {85return "overloaded(int)";86}8788public String overloaded(String x) {89return "overloaded(String)";90}9192public String overloaded(int x, int y) {93return "overloaded(int, int)";94}95}9697private static String failure;98}99100101