Path: blob/master/test/jdk/java/lang/management/ManagementFactory/GetPlatformManagementInterfaces.java
41152 views
/*1* Copyright (c) 2012, 2016, 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 707461626* @summary Basic unit test of the27* ManagementFactory.getPlatformManagementInterfaces() method28* @author Frederic Parain29*30* @run main GetPlatformManagementInterfaces31*/3233import java.lang.management.*;34import java.io.IOException;35import java.util.*;36import javax.management.*;3738import static java.lang.management.ManagementFactory.*;3940public class GetPlatformManagementInterfaces {4142private static enum ManagementInterfaces {43CLASS_LOADING_MXBEAN(ClassLoadingMXBean.class),44COMPILATION_MXBEAN(CompilationMXBean.class),45MEMORY_MXBEAN(MemoryMXBean.class),46OPERATING_SYSTEM_MXBEAN(OperatingSystemMXBean.class),47RUNTIME_MXBEAN(RuntimeMXBean.class),48THREAD_MXBEAN(ThreadMXBean.class),49GARBAGE_COLLECTOR_MXBEAN(GarbageCollectorMXBean.class),50MEMORY_MANAGER_MXBEAN(MemoryManagerMXBean.class),51MEMORY_POOL_MXBEAN(MemoryPoolMXBean.class);5253private final Class<? extends PlatformManagedObject> managementInterface;54private ManagementInterfaces(Class<? extends PlatformManagedObject> minterface) {55managementInterface = minterface;56}57public Class<? extends PlatformManagedObject> getManagementInterface() {58return managementInterface;59}60};6162public static void main(String[] args) {63Set<Class<? extends PlatformManagedObject>> interfaces =64ManagementFactory.getPlatformManagementInterfaces();65for(Class<? extends PlatformManagedObject> pom : interfaces) {66List<? extends PlatformManagedObject> list =67ManagementFactory.getPlatformMXBeans(pom);68}69for(ManagementInterfaces mi : ManagementInterfaces.values()) {70if(!interfaces.contains(mi.getManagementInterface())) {71throw new RuntimeException(mi.getManagementInterface() + " not in ManagementInterfaces set");72}73}74}75}767778