Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/proxy/JMXProxyFallbackTest.java
38838 views
/*1* Copyright (c) 2013, 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*/2223import javax.management.JMX;24import javax.management.MBeanServer;25import javax.management.MBeanServerFactory;26import javax.management.NotCompliantMBeanException;27import javax.management.ObjectName;2829/*30* @test31* @bug 801028532* @summary Tests the fallback for creating JMX proxies for private interfaces33* It needs to be a separate class because the "jdk.jmx.mbeans.allowNonPublic"34* system property must be set before c.s.j.m.MBeanAnalyzer has been loaded.35* @author Jaroslav Bachorik36* @run clean JMXProxyFallbackTest37* @run build JMXProxyFallbackTest38* @run main/othervm -Djdk.jmx.mbeans.allowNonPublic=true JMXProxyFallbackTest39*/40public class JMXProxyFallbackTest {41private static interface PrivateMBean {42public int[] getInts();43}4445private static interface PrivateMXBean {46public int[] getInts();47}4849public static class Private implements PrivateMXBean, PrivateMBean {50public int[] getInts() {51return new int[]{1,2,3};52}53}5455private static int failures = 0;5657public static void main(String[] args) throws Exception {58testPrivate(PrivateMBean.class);59testPrivate(PrivateMXBean.class);6061if (failures == 0)62System.out.println("Test passed");63else64throw new Exception("TEST FAILURES: " + failures);65}6667private static void fail(String msg) {68failures++;69System.out.println("FAIL: " + msg);70}7172private static void success(String msg) {73System.out.println("OK: " + msg);74}7576private static void testPrivate(Class<?> iface) throws Exception {77try {78System.out.println("Creating a proxy for private M(X)Bean " +79iface.getName() + " ...");8081MBeanServer mbs = MBeanServerFactory.newMBeanServer();82ObjectName on = new ObjectName("test:type=Proxy");8384JMX.newMBeanProxy(mbs, on, iface);85success("Created a proxy for private M(X)Bean - " + iface.getName());86} catch (Exception e) {87Throwable t = e;88while (t != null && !(t instanceof NotCompliantMBeanException)) {89t = t.getCause();90}91if (t != null) {92fail("Proxy not created");93} else {94throw e;95}96}97}98}99100101