Path: blob/master/test/jdk/java/lang/management/ManagementFactory/ProxyExceptions.java
41152 views
/*1* Copyright (c) 2004, 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 502453126* @summary Test type mapping of the platform MXBean proxy27* returned from Management.newPlatformMXBeanProxy().28* @author Mandy Chung29*/30import java.lang.management.*;31import javax.management.*;32import static java.lang.management.ManagementFactory.*;33import java.util.List;34import java.util.Map;35import java.util.Properties;36import com.sun.management.GcInfo;3738public class ProxyExceptions {39private static MBeanServer server =40ManagementFactory.getPlatformMBeanServer();41private static MemoryPoolMXBean heapPool = null;42private static MemoryPoolMXBean nonHeapPool = null;43public static void main(String[] argv) throws Exception {44List<MemoryPoolMXBean> pools = getMemoryPoolMXBeans();45for (MemoryPoolMXBean p : pools) {46MemoryPoolMXBean proxy = newPlatformMXBeanProxy(server,47MEMORY_POOL_MXBEAN_DOMAIN_TYPE + ",name=" + p.getName(),48MemoryPoolMXBean.class);49boolean uoeCaught;50if (!p.isUsageThresholdSupported()) {51try {52proxy.getUsageThreshold();53uoeCaught = false;54} catch (UnsupportedOperationException e) {55uoeCaught = true;56}57if (!uoeCaught) {58throw new RuntimeException("TEST FAILED: " +59"UnsupportedOperationException not thrown " +60"when calling getUsageThreshold on " + p.getName());61}62try {63proxy.setUsageThreshold(100);64uoeCaught = false;65} catch (UnsupportedOperationException e) {66uoeCaught = true;67}68if (!uoeCaught) {69throw new RuntimeException("TEST FAILED: " +70"UnsupportedOperationException not thrown " +71"when calling setUsageThreshold on " + p.getName());72}73}74if (!p.isCollectionUsageThresholdSupported()) {75try {76proxy.getCollectionUsageThreshold();77uoeCaught = false;78} catch (UnsupportedOperationException e) {79uoeCaught = true;80}81if (!uoeCaught) {82throw new RuntimeException("TEST FAILED: " +83"UnsupportedOperationException not thrown " +84"when calling getCollectionUsageThreshold on " +85p.getName());86}87try {88proxy.setCollectionUsageThreshold(100);89uoeCaught = false;90} catch (UnsupportedOperationException e) {91uoeCaught = true;92}93if (!uoeCaught) {94throw new RuntimeException("TEST FAILED: " +95"UnsupportedOperationException not thrown " +96"when calling getCollectionUsageThreshold on " +97p.getName());98}99}100}101102ThreadMXBean thread = newPlatformMXBeanProxy(server,103THREAD_MXBEAN_NAME,104ThreadMXBean.class);105boolean iaeCaught = false;106try {107thread.getThreadInfo(-1);108} catch (IllegalArgumentException e) {109iaeCaught = true;110}111if (!iaeCaught) {112throw new RuntimeException("TEST FAILED: " +113"IllegalArgumentException not thrown " +114"when calling getThreadInfo(-1)");115}116117System.out.println("Test passed.");118}119}120121122