Path: blob/master/test/jdk/com/sun/management/CheckSomeMXBeanImplPackage.java
41149 views
/*1* Copyright (c) 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*/2223import java.lang.management.ManagementFactory;24import java.lang.management.PlatformManagedObject;2526/*27* @test28* @bug 804290129* @summary If jdk.management is present, GarbageCollectorMXBean and ThreadMXBean30* must be from com.sun.management.internal31* @author Shanliang Jiang32*/33public class CheckSomeMXBeanImplPackage {34private static String implPackageName = "com.sun.management.internal";3536public static void main(String[] args) throws Exception {37boolean present = false;38try {39Class.forName("com.sun.management.GarbageCollectorMXBean");40present = true;41} catch (ClassNotFoundException cnfe) {}4243if (present) {44Class <? extends PlatformManagedObject> klazz =45java.lang.management.GarbageCollectorMXBean.class;46for (Object obj :47ManagementFactory.getPlatformMXBeans(klazz)) {48check(klazz.getName(), obj);49}5051klazz = com.sun.management.GarbageCollectorMXBean.class;52for (Object obj :53ManagementFactory.getPlatformMXBeans(klazz)) {54check(klazz.getName(), obj);55}5657klazz = java.lang.management.ThreadMXBean.class;58check(klazz.getName(),59ManagementFactory.getPlatformMXBean(klazz));6061klazz = com.sun.management.ThreadMXBean.class;62check(klazz.getName(),63ManagementFactory.getPlatformMXBean(klazz));6465System.out.println("--- PASSED!");66} else {67System.out.println("--- Skip the test, jdk.management module is not present!");68}69}7071private static void check(String mbeanName, Object impl) {72if (!impl.getClass().getName().startsWith(implPackageName)) {73throw new RuntimeException(mbeanName+" implementation package "74+ "should be: " + implPackageName75+ ", but got: " + impl.getClass());76} else {77System.out.println("--- Good, "+mbeanName+" got right implementation: " + impl);78}79}80}818283