Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/mxbean/MXBeanFallbackTest.java
38841 views
/*1* Copyright (c) 2005, 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*/2223/*24* @test25* @bug 801028526* @summary Test for the private MXBean interface fallback.27* It needs to be a separate class because the "jdk.jmx.mbeans.allowNonPublic"28* system property must be set before c.s.j.m.MBeanAnalyzer has been loaded.29* @author Jaroslav Bachorik30* @run clean MXBeanFallbackTest31* @run build MXBeanFallbackTest32* @run main/othervm -Djdk.jmx.mbeans.allowNonPublic=true MXBeanFallbackTest33*/3435import javax.management.MBeanServer;36import javax.management.MBeanServerFactory;37import javax.management.NotCompliantMBeanException;38import javax.management.ObjectName;3940public class MXBeanFallbackTest {41public static void main(String[] args) throws Exception {42testPrivateMXBean("Private", new Private());4344if (failures == 0)45System.out.println("Test passed");46else47throw new Exception("TEST FAILURES: " + failures);48}4950private static int failures = 0;5152private static interface PrivateMXBean {53public int[] getInts();54}5556public static class Private implements PrivateMXBean {57public int[] getInts() {58return new int[]{1,2,3};59}60}6162private static void testPrivateMXBean(String type, Object bean) throws Exception {63System.out.println(type + " MXBean test...");64MBeanServer mbs = MBeanServerFactory.newMBeanServer();65ObjectName on = new ObjectName("test:type=" + type);66try {67mbs.registerMBean(bean, on);68success("Private MXBean registered");69} catch (NotCompliantMBeanException e) {70failure("Failed to register the private MXBean - " +71bean.getClass().getInterfaces()[0].getName());72}73}7475private static void success(String what) {76System.out.println("OK: " + what);77}7879private static void failure(String what) {80System.out.println("FAILED: " + what);81failures++;82}83}848586