20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
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)) {
73 log2 = true;
74 System.out.println(" : Found new Logger : " + logger);
75 }
76 }
77 if ( log1 && log2 )
78 System.out.println(" : PASSED." );
79 else {
80 System.out.println(" : FAILED. Could not Detect the new Loggers." );
81 throw new RuntimeException(
82 "Could not Detect the presense of the new Loggers");
83 }
84
85 System.out.println("Test getLoggerLevel");
86 String l1 = mbean.getLoggerLevel(LOGGER_NAME_1);
87 System.out.println(" : Level for Logger " + LOGGER_NAME_1 + " : " + l1);
170 "Expected parent for " + LOGGER_NAME_2 + " = " +
171 LOGGER_NAME_1 + " but got " + p1);
172 }
173 String p2 = mbean.getParentLoggerName("");
174 System.out.println(" : Parent Logger for \"\" : " + p2);
175 if (!p2.equals("")) {
176 throw new RuntimeException(
177 "Expected parent for root logger \"\" = \"\"" +
178 " but got " + p2);
179 }
180 String p3 = mbean.getParentLoggerName(UNKNOWN_LOGGER_NAME);
181 System.out.println(" : Parent Logger for unknown logger : " + p3);
182 if (p3 != null) {
183 throw new RuntimeException(
184 "Expected level for " + UNKNOWN_LOGGER_NAME + " = null" +
185 " but got " + p3);
186 }
187 }
188
189 public static void main(String[] argv) throws Exception {
190 LoggingMXBeanTest2 p = new LoggingMXBeanTest2();
191 }
192 }
|
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
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 static LoggingMXBean mbean = LogManager.getLoggingMXBean();
41 static String LOGGER_NAME_1 = "com.sun.management.Logger";
42 static String LOGGER_NAME_2 = "com.sun.management.Logger.Logger2";
43 static String UNKNOWN_LOGGER_NAME = "com.sun.management.Unknown";
44 static Logger logger1;
45 static Logger logger2;
46
47 public LoggingMXBeanTest2() throws Exception {
48
49 logger1 = Logger.getLogger( LOGGER_NAME_1 );
50 logger1.setLevel(Level.FINE);
51 logger2 = Logger.getLogger( LOGGER_NAME_2 );
52 logger2.setLevel(null);
53
54 /*
55 * Check for the existence of our new Loggers
56 */
57 System.out.println("Test Logger Name retrieval (getLoggerNames)");
58 boolean log1 = false, log2 = false;
59 List<String> loggers = mbean.getLoggerNames();
60 if (loggers == null || loggers.size() < 2) {
61 throw new RuntimeException(
62 "Could not Detect the presense of the new Loggers");
63 }
64
65 for (ListIterator<String> iter = loggers.listIterator(); iter.hasNext(); ) {
66 String logger = iter.next();
67 if (logger.equals(LOGGER_NAME_1)) {
68 log1 = true;
69 System.out.println(" : Found new Logger : " + logger);
70 }
71 if (logger.equals(LOGGER_NAME_2)) {
72 log2 = true;
73 System.out.println(" : Found new Logger : " + logger);
74 }
75 }
76 if ( log1 && log2 )
77 System.out.println(" : PASSED." );
78 else {
79 System.out.println(" : FAILED. Could not Detect the new Loggers." );
80 throw new RuntimeException(
81 "Could not Detect the presense of the new Loggers");
82 }
83
84 System.out.println("Test getLoggerLevel");
85 String l1 = mbean.getLoggerLevel(LOGGER_NAME_1);
86 System.out.println(" : Level for Logger " + LOGGER_NAME_1 + " : " + l1);
169 "Expected parent for " + LOGGER_NAME_2 + " = " +
170 LOGGER_NAME_1 + " but got " + p1);
171 }
172 String p2 = mbean.getParentLoggerName("");
173 System.out.println(" : Parent Logger for \"\" : " + p2);
174 if (!p2.equals("")) {
175 throw new RuntimeException(
176 "Expected parent for root logger \"\" = \"\"" +
177 " but got " + p2);
178 }
179 String p3 = mbean.getParentLoggerName(UNKNOWN_LOGGER_NAME);
180 System.out.println(" : Parent Logger for unknown logger : " + p3);
181 if (p3 != null) {
182 throw new RuntimeException(
183 "Expected level for " + UNKNOWN_LOGGER_NAME + " = null" +
184 " but got " + p3);
185 }
186 }
187
188 public static void main(String[] argv) throws Exception {
189 new LoggingMXBeanTest2();
190 }
191 }
|