1 /*
2 * Copyright (c) 2004, 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 */
25 * @test
26 * @bug 5007165
27 * @summary Basic Test for LoggingMXBean (direct access to MXBean)
28 * @author Mandy Chung
29 *
30 * @build LoggingMXBeanTest2
31 * @run main LoggingMXBeanTest2
32 */
33
34 import java.util.logging.*;
35 import java.util.List;
36 import java.util.ListIterator;
37
38 public class LoggingMXBeanTest2
39 {
40
41 static LoggingMXBean mbean = LogManager.getLoggingMXBean();
42 static String LOGGER_NAME_1 = "com.sun.management.Logger";
43 static String LOGGER_NAME_2 = "com.sun.management.Logger.Logger2";
44 static String UNKNOWN_LOGGER_NAME = "com.sun.management.Unknown";
45
46 public LoggingMXBeanTest2() throws Exception {
47
48 Logger logger1 = Logger.getLogger( LOGGER_NAME_1 );
49 logger1.setLevel(Level.FINE);
50 Logger logger2 = Logger.getLogger( LOGGER_NAME_2 );
51 logger2.setLevel(null);
52
53 /*
54 * Check for the existence of our new Loggers
55 */
56 System.out.println("Test Logger Name retrieval (getLoggerNames)");
57 boolean log1 = false, log2 = false;
58 List loggers = mbean.getLoggerNames();
59 if (loggers == null || loggers.size() < 2) {
60 throw new RuntimeException(
61 "Could not Detect the presense of the new Loggers");
62 }
63
64 for (ListIterator iter = loggers.listIterator(); iter.hasNext(); ) {
65 String logger = (String) iter.next();
66 if (logger.equals(LOGGER_NAME_1)) {
67 log1 = true;
68 System.out.println(" : Found new Logger : " + logger);
69 }
70 if (logger.equals(LOGGER_NAME_2)) {
|
1 /*
2 * Copyright (c) 2004, 2012, 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 */
25 * @test
26 * @bug 5007165
27 * @summary Basic Test for LoggingMXBean (direct access to MXBean)
28 * @author Mandy Chung
29 *
30 * @build LoggingMXBeanTest2
31 * @run main LoggingMXBeanTest2
32 */
33
34 import java.util.logging.*;
35 import java.util.List;
36 import java.util.ListIterator;
37
38 public class LoggingMXBeanTest2
39 {
40
41 static LoggingMXBean mbean = LogManager.getLoggingMXBean();
42 static String LOGGER_NAME_1 = "com.sun.management.Logger";
43 static String LOGGER_NAME_2 = "com.sun.management.Logger.Logger2";
44 static String UNKNOWN_LOGGER_NAME = "com.sun.management.Unknown";
45 static Logger logger1;
46 static Logger logger2;
47
48 public LoggingMXBeanTest2() throws Exception {
49
50 logger1 = Logger.getLogger( LOGGER_NAME_1 );
51 logger1.setLevel(Level.FINE);
52 logger2 = Logger.getLogger( LOGGER_NAME_2 );
53 logger2.setLevel(null);
54
55 /*
56 * Check for the existence of our new Loggers
57 */
58 System.out.println("Test Logger Name retrieval (getLoggerNames)");
59 boolean log1 = false, log2 = false;
60 List loggers = mbean.getLoggerNames();
61 if (loggers == null || loggers.size() < 2) {
62 throw new RuntimeException(
63 "Could not Detect the presense of the new Loggers");
64 }
65
66 for (ListIterator iter = loggers.listIterator(); iter.hasNext(); ) {
67 String logger = (String) iter.next();
68 if (logger.equals(LOGGER_NAME_1)) {
69 log1 = true;
70 System.out.println(" : Found new Logger : " + logger);
71 }
72 if (logger.equals(LOGGER_NAME_2)) {
|