author | mikael |
Mon, 29 Jul 2019 09:59:04 -0700 | |
changeset 57584 | 9d82a35b6ff7 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
18595
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
1 |
/* |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
4 |
* |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
8 |
* |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
13 |
* accompanied this code). |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
14 |
* |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
18 |
* |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
21 |
* questions. |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
22 |
*/ |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
23 |
import java.util.Arrays; |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
24 |
import java.util.List; |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
25 |
import java.util.logging.Logger; |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
26 |
|
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
27 |
/** |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
28 |
* @test |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
29 |
* @bug 7184195 |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
30 |
* @summary checks that java.util.logging.Logger.getGlobal().info() logs without configuration |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
31 |
* @build TestGetGlobal testgetglobal.HandlerImpl testgetglobal.LogManagerImpl1 testgetglobal.LogManagerImpl2 testgetglobal.LogManagerImpl3 testgetglobal.BadLogManagerImpl testgetglobal.DummyLogManagerImpl |
20195
fcd61ec8fff6
8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents:
19825
diff
changeset
|
32 |
* @run main/othervm TestGetGlobal |
fcd61ec8fff6
8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents:
19825
diff
changeset
|
33 |
* @run main/othervm/policy=policy -Djava.security.manager TestGetGlobal |
fcd61ec8fff6
8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents:
19825
diff
changeset
|
34 |
* @run main/othervm -Djava.util.logging.manager=testgetglobal.LogManagerImpl1 TestGetGlobal |
fcd61ec8fff6
8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents:
19825
diff
changeset
|
35 |
* @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl1 TestGetGlobal |
fcd61ec8fff6
8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents:
19825
diff
changeset
|
36 |
* @run main/othervm -Djava.util.logging.manager=testgetglobal.LogManagerImpl2 TestGetGlobal |
fcd61ec8fff6
8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents:
19825
diff
changeset
|
37 |
* @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl2 TestGetGlobal |
fcd61ec8fff6
8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents:
19825
diff
changeset
|
38 |
* @run main/othervm -Djava.util.logging.manager=testgetglobal.LogManagerImpl3 TestGetGlobal |
fcd61ec8fff6
8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents:
19825
diff
changeset
|
39 |
* @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl3 TestGetGlobal |
fcd61ec8fff6
8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents:
19825
diff
changeset
|
40 |
* @run main/othervm -Djava.util.logging.manager=testgetglobal.BadLogManagerImpl TestGetGlobal |
fcd61ec8fff6
8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents:
19825
diff
changeset
|
41 |
* @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.BadLogManagerImpl TestGetGlobal |
fcd61ec8fff6
8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents:
19825
diff
changeset
|
42 |
* @run main/othervm -Djava.util.logging.manager=testgetglobal.DummyLogManagerImpl TestGetGlobal |
fcd61ec8fff6
8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents:
19825
diff
changeset
|
43 |
* @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.DummyLogManagerImpl TestGetGlobal |
18595
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
44 |
* @author danielfuchs |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
45 |
*/ |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
46 |
public class TestGetGlobal { |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
47 |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
20195
diff
changeset
|
48 |
static final String[] messages = { |
18595
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
49 |
"1. This message should not appear on the console.", |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
50 |
"2. This message should appear on the console.", |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
51 |
"3. This message should now appear on the console too." |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
52 |
}; |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
53 |
|
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
54 |
static { |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
55 |
System.setProperty("java.util.logging.config.file", |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
56 |
System.getProperty("test.src", ".") + java.io.File.separator + "logging.properties"); |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
57 |
} |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
58 |
|
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
59 |
public static void main(String... args) { |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
18595
diff
changeset
|
60 |
final String manager = System.getProperty("java.util.logging.manager", null); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
18595
diff
changeset
|
61 |
|
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
18595
diff
changeset
|
62 |
final String description = "TestGetGlobal" |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
18595
diff
changeset
|
63 |
+ (System.getSecurityManager() == null ? " " : |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
18595
diff
changeset
|
64 |
" -Djava.security.manager ") |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
18595
diff
changeset
|
65 |
+ (manager == null ? "" : "-Djava.util.logging.manager=" + manager); |
18595
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
66 |
|
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
67 |
Logger.global.info(messages[0]); // at this point LogManager is not |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
68 |
// initialized yet, so this message should not appear. |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
69 |
Logger.getGlobal().info(messages[1]); // calling getGlobal() will |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
70 |
// initialize the LogManager - and thus this message should appear. |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
71 |
Logger.global.info(messages[2]); // Now that the LogManager is |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
72 |
// initialized, this message should appear too. |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
73 |
|
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
74 |
final List<String> expected = Arrays.asList(Arrays.copyOfRange(messages, 1, messages.length)); |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
75 |
if (!testgetglobal.HandlerImpl.received.equals(expected)) { |
19825
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
18595
diff
changeset
|
76 |
System.err.println("Test case failed: " + description); |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
18595
diff
changeset
|
77 |
throw new Error("Unexpected message list: "+testgetglobal.HandlerImpl.received+" vs "+ expected |
a7e79bc2e437
8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents:
18595
diff
changeset
|
78 |
+ "\n\t"+description); |
18595
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
79 |
} |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
80 |
} |
c6f81d76027a
7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff
changeset
|
81 |
} |