|
| 1 | +/* |
| 2 | + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +/* |
| 25 | + * @test |
| 26 | + * @bug 8338139 |
| 27 | + * @summary Basic unit test of ClassLoadingMXBean.set/isVerbose() when |
| 28 | + * related unified logging is enabled. |
| 29 | + * |
| 30 | + * @run main/othervm -Xlog:class+load=trace:file=vm.log TestVerboseClassLoading false |
| 31 | + * @run main/othervm -Xlog:class+load=debug:file=vm.log TestVerboseClassLoading false |
| 32 | + * @run main/othervm -Xlog:class+load=info:file=vm.log TestVerboseClassLoading false |
| 33 | + * |
| 34 | + * @run main/othervm -Xlog:class+load=trace TestVerboseClassLoading false |
| 35 | + * @run main/othervm -Xlog:class+load=debug TestVerboseClassLoading false |
| 36 | + * @run main/othervm -Xlog:class+load=info TestVerboseClassLoading false |
| 37 | + * @run main/othervm -Xlog:class+load=warning TestVerboseClassLoading false |
| 38 | + * @run main/othervm -Xlog:class+load=error TestVerboseClassLoading false |
| 39 | + * @run main/othervm -Xlog:class+load=off TestVerboseClassLoading false |
| 40 | + * |
| 41 | + * @run main/othervm -Xlog:class+load*=trace TestVerboseClassLoading true |
| 42 | + * @run main/othervm -Xlog:class+load*=debug TestVerboseClassLoading true |
| 43 | + * @run main/othervm -Xlog:class+load*=info TestVerboseClassLoading true |
| 44 | + * @run main/othervm -Xlog:class+load*=warning TestVerboseClassLoading false |
| 45 | + * @run main/othervm -Xlog:class+load*=error TestVerboseClassLoading false |
| 46 | + * @run main/othervm -Xlog:class+load*=off TestVerboseClassLoading false |
| 47 | + * |
| 48 | + * @run main/othervm -Xlog:class+load*=info,class+load=trace TestVerboseClassLoading true |
| 49 | + * @run main/othervm -Xlog:class+load*=info,class+load=debug TestVerboseClassLoading true |
| 50 | + * @run main/othervm -Xlog:class+load*=info,class+load=info TestVerboseClassLoading true |
| 51 | + * @run main/othervm -Xlog:class+load*=info,class+load=warning TestVerboseClassLoading false |
| 52 | + * @run main/othervm -Xlog:class+load*=info,class+load=error TestVerboseClassLoading false |
| 53 | + * @run main/othervm -Xlog:class+load*=info,class+load=off TestVerboseClassLoading false |
| 54 | + * |
| 55 | + * @run main/othervm -Xlog:all=trace:file=vm.log TestVerboseClassLoading false |
| 56 | + */ |
| 57 | + |
| 58 | +import java.lang.management.ManagementFactory; |
| 59 | +import java.lang.management.ClassLoadingMXBean; |
| 60 | + |
| 61 | +public class TestVerboseClassLoading { |
| 62 | + |
| 63 | + public static void main(String[] args) throws Exception { |
| 64 | + ClassLoadingMXBean mxBean = ManagementFactory.getClassLoadingMXBean(); |
| 65 | + boolean expected = Boolean.parseBoolean(args[0]); |
| 66 | + boolean initial = mxBean.isVerbose(); |
| 67 | + if (expected != initial) { |
| 68 | + throw new Error("Initial verbosity setting was unexpectedly " + initial); |
| 69 | + } |
| 70 | + mxBean.setVerbose(false); |
| 71 | + if (mxBean.isVerbose()) { |
| 72 | + throw new Error("Verbosity was still enabled"); |
| 73 | + } |
| 74 | + mxBean.setVerbose(true); |
| 75 | + if (!mxBean.isVerbose()) { |
| 76 | + throw new Error("Verbosity was still disabled"); |
| 77 | + } |
| 78 | + // Turn off again as a double-check and also to avoid excessive logging |
| 79 | + mxBean.setVerbose(false); |
| 80 | + if (mxBean.isVerbose()) { |
| 81 | + throw new Error("Verbosity was still enabled"); |
| 82 | + } |
| 83 | + } |
| 84 | +} |
0 commit comments