1 /*
2 * @test
3 * @bug 6498300
4 *
5 * @summary regression: parent loggers are not properly registered
6 * @author ss45998
7 *
8 * @build ParentLoggersTest
9 * @run main/othervm ParentLoggersTest
10 */
11
12 /*
13 * There are several original tests which were failed when
14 * this regression was introduced. This is an extra test
15 * to ensure that the parent loggers with the defined
16 * .level property are implicitly registered.
17 */
18
19 import java.util.*;
20 import java.io.*;
21 import java.util.logging.*;
69 }
70
71 public static List<String> getDefaultLoggerNames() {
72 List<String> expectedLoggerNames = new ArrayList<String>();
73
74 // LogManager always creates two loggers:
75 expectedLoggerNames.add(""); // root logger: ""
76 expectedLoggerNames.add("global"); // global logger: "global"
77 return expectedLoggerNames;
78 }
79
80 /* Check: getLoggerNames() must return correct names
81 * for registered loggers and their parents.
82 * Returns boolean values: PASSED or FAILED
83 */
84 public static boolean checkLoggers() {
85 String failMsg = "# checkLoggers: getLoggerNames() returned unexpected loggers";
86 Vector<String> expectedLoggerNames = new Vector<String>(getDefaultLoggerNames());
87
88 // Create the logger LOGGER_NAME_1
89 Logger logger1 = Logger.getLogger(LOGGER_NAME_1);
90 expectedLoggerNames.addElement(PARENT_NAME_1);
91 expectedLoggerNames.addElement(LOGGER_NAME_1);
92
93 // Create the logger LOGGER_NAME_2
94 Logger logger2 = Logger.getLogger(LOGGER_NAME_2);
95 expectedLoggerNames.addElement(PARENT_NAME_2);
96 expectedLoggerNames.addElement(LOGGER_NAME_2);
97
98 Enumeration<String> returnedLoggersEnum = logMgr.getLoggerNames();
99 Vector<String> returnedLoggerNames = new Vector<String>(0);
100 while (returnedLoggersEnum.hasMoreElements()) {
101 String logger = returnedLoggersEnum.nextElement();
102 if (!initialLoggerNames.contains(logger)) {
103 // filter out the loggers that have been added before this test runs
104 returnedLoggerNames.addElement(logger);
105 }
106
107 };
108
109 return checkNames(expectedLoggerNames, returnedLoggerNames, failMsg);
110 }
111
112 // Returns boolean values: PASSED or FAILED
113 private static boolean checkNames(Vector<String> expNames,
114 Vector<String> retNames,
|
1 /*
2 * Copyright (c) 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 */
23
24 /*
25 * @test
26 * @bug 6498300
27 *
28 * @summary regression: parent loggers are not properly registered
29 * @author ss45998
30 *
31 * @build ParentLoggersTest
32 * @run main/othervm ParentLoggersTest
33 */
34
35 /*
36 * There are several original tests which were failed when
37 * this regression was introduced. This is an extra test
38 * to ensure that the parent loggers with the defined
39 * .level property are implicitly registered.
40 */
41
42 import java.util.*;
43 import java.io.*;
44 import java.util.logging.*;
92 }
93
94 public static List<String> getDefaultLoggerNames() {
95 List<String> expectedLoggerNames = new ArrayList<String>();
96
97 // LogManager always creates two loggers:
98 expectedLoggerNames.add(""); // root logger: ""
99 expectedLoggerNames.add("global"); // global logger: "global"
100 return expectedLoggerNames;
101 }
102
103 /* Check: getLoggerNames() must return correct names
104 * for registered loggers and their parents.
105 * Returns boolean values: PASSED or FAILED
106 */
107 public static boolean checkLoggers() {
108 String failMsg = "# checkLoggers: getLoggerNames() returned unexpected loggers";
109 Vector<String> expectedLoggerNames = new Vector<String>(getDefaultLoggerNames());
110
111 // Create the logger LOGGER_NAME_1
112 Logger.getLogger(LOGGER_NAME_1);
113 expectedLoggerNames.addElement(PARENT_NAME_1);
114 expectedLoggerNames.addElement(LOGGER_NAME_1);
115
116 // Create the logger LOGGER_NAME_2
117 Logger.getLogger(LOGGER_NAME_2);
118 expectedLoggerNames.addElement(PARENT_NAME_2);
119 expectedLoggerNames.addElement(LOGGER_NAME_2);
120
121 Enumeration<String> returnedLoggersEnum = logMgr.getLoggerNames();
122 Vector<String> returnedLoggerNames = new Vector<String>(0);
123 while (returnedLoggersEnum.hasMoreElements()) {
124 String logger = returnedLoggersEnum.nextElement();
125 if (!initialLoggerNames.contains(logger)) {
126 // filter out the loggers that have been added before this test runs
127 returnedLoggerNames.addElement(logger);
128 }
129
130 };
131
132 return checkNames(expectedLoggerNames, returnedLoggerNames, failMsg);
133 }
134
135 // Returns boolean values: PASSED or FAILED
136 private static boolean checkNames(Vector<String> expNames,
137 Vector<String> retNames,
|