Path: blob/master/test/jdk/javax/management/mxbean/MXBeanFallbackTest.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 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*31* @run clean MXBeanFallbackTest32* @run build MXBeanFallbackTest33* @run main/othervm -Djdk.jmx.mbeans.allowNonPublic=true MXBeanFallbackTest34*/3536import javax.management.MBeanServer;37import javax.management.MBeanServerFactory;38import javax.management.NotCompliantMBeanException;39import javax.management.ObjectName;4041public class MXBeanFallbackTest {42public static void main(String[] args) throws Exception {43testPrivateMXBean("Private", new Private());4445if (failures == 0)46System.out.println("Test passed");47else48throw new Exception("TEST FAILURES: " + failures);49}5051private static int failures = 0;5253private static interface PrivateMXBean {54public int[] getInts();55}5657public static class Private implements PrivateMXBean {58public int[] getInts() {59return new int[]{1,2,3};60}61}6263private static void testPrivateMXBean(String type, Object bean) throws Exception {64System.out.println(type + " MXBean test...");65MBeanServer mbs = MBeanServerFactory.newMBeanServer();66ObjectName on = new ObjectName("test:type=" + type);67try {68mbs.registerMBean(bean, on);69success("Private MXBean registered");70} catch (NotCompliantMBeanException e) {71failure("Failed to register the private MXBean - " +72bean.getClass().getInterfaces()[0].getName());73}74}7576private static void success(String what) {77System.out.println("OK: " + what);78}7980private static void failure(String what) {81System.out.println("FAILED: " + what);82failures++;83}84}858687