Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/MBeanServer/MBeanFallbackTest.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.MBeanServer;24import javax.management.MBeanServerFactory;25import javax.management.NotCompliantMBeanException;26import javax.management.ObjectName;2728/*29* @test30* @bug 801028531* @summary Test fallback for private MBean interfaces.32* It needs to be a separate class because the "jdk.jmx.mbeans.allowNonPublic"33* system property must be set before c.s.j.m.MBeanAnalyzer has been loaded.34* @author Jaroslav Bachorik35* @run clean MBeanFallbackTest36* @run build MBeanFallbackTest37* @run main/othervm -Djdk.jmx.mbeans.allowNonPublic=true MBeanFallbackTest38*/39public class MBeanFallbackTest {40private static interface PrivateMBean {41public int[] getInts();42}4344public static class Private implements PrivateMBean {45public int[] getInts() {46return new int[]{1,2,3};47}48}4950private static int failures = 0;5152public static void main(String[] args) throws Exception {53testPrivate(PrivateMBean.class, new Private());5455if (failures == 0)56System.out.println("Test passed");57else58throw new Exception("TEST FAILURES: " + failures);59}6061private static void fail(String msg) {62failures++;63System.out.println("FAIL: " + msg);64}6566private static void success(String msg) {67System.out.println("OK: " + msg);68}6970private static void testPrivate(Class<?> iface, Object bean) throws Exception {71try {72System.out.println("Registering a private MBean " +73iface.getName() + " ...");7475MBeanServer mbs = MBeanServerFactory.newMBeanServer();76ObjectName on = new ObjectName("test:type=Compliant");7778mbs.registerMBean(bean, on);79success("Registered a private MBean - " + iface.getName());80} catch (Exception e) {81Throwable t = e;82while (t != null && !(t instanceof NotCompliantMBeanException)) {83t = t.getCause();84}85if (t != null) {86fail("MBean not registered");87} else {88throw e;89}90}91}92}939495