jdk/test/java/util/logging/Logger/getGlobal/TestGetGlobalConcurrent.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 20195 fcd61ec8fff6
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 18595
diff changeset
    25
import java.util.logging.Level;
18595
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    26
import java.util.logging.Logger;
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
/**
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    29
 * @test
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 18595
diff changeset
    30
 * @bug 7184195 8021003
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 18595
diff changeset
    31
 * @summary Test that the global logger can log with no configuration when accessed from multiple threads.
18595
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    32
 * @build TestGetGlobalConcurrent 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
    33
 * @run main/othervm TestGetGlobalConcurrent
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 19825
diff changeset
    34
 * @run main/othervm/policy=policy -Djava.security.manager TestGetGlobalConcurrent
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 19825
diff changeset
    35
 * @run main/othervm -Djava.util.logging.manager=testgetglobal.LogManagerImpl1 TestGetGlobalConcurrent
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 19825
diff changeset
    36
 * @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl1 TestGetGlobalConcurrent
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 19825
diff changeset
    37
 * @run main/othervm -Djava.util.logging.manager=testgetglobal.LogManagerImpl2 TestGetGlobalConcurrent
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 19825
diff changeset
    38
 * @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl2 TestGetGlobalConcurrent
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 19825
diff changeset
    39
 * @run main/othervm -Djava.util.logging.manager=testgetglobal.LogManagerImpl3 TestGetGlobalConcurrent
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 19825
diff changeset
    40
 * @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl3 TestGetGlobalConcurrent
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 19825
diff changeset
    41
 * @run main/othervm -Djava.util.logging.manager=testgetglobal.BadLogManagerImpl TestGetGlobalConcurrent
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 19825
diff changeset
    42
 * @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.BadLogManagerImpl TestGetGlobalConcurrent
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 19825
diff changeset
    43
 * @run main/othervm -Djava.util.logging.manager=testgetglobal.DummyLogManagerImpl TestGetGlobalConcurrent
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 19825
diff changeset
    44
 * @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.DummyLogManagerImpl TestGetGlobalConcurrent
18595
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    45
 * @author danielfuchs
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    46
 */
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    47
public class TestGetGlobalConcurrent {
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    48
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 20195
diff changeset
    49
    static final String[] messages = {
18595
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    50
        "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
    51
        "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
    52
        "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
    53
        "4. This message should appear on the console.",
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    54
        "5. 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
    55
        "6. This message should appear on the console.",
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    56
        "7. 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
    57
        "8. This message should appear on the console.",
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    58
        "9. 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
    59
    };
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    60
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    61
    static {
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    62
        System.setProperty("java.util.logging.config.file",
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    63
            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
    64
    }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    65
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    66
    public static void test1() {
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    67
        final int nb = 1;
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    68
        final int i = 2*nb + 1;
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    69
        Logger.getGlobal().info(messages[i]); // 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[i+1]); // 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
        final List<String> expected = Arrays.asList(Arrays.copyOfRange(messages, i, i+2));
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    74
        if (!testgetglobal.HandlerImpl.received.containsAll(expected)) {
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    75
            fail(new Error("Unexpected message list: "+testgetglobal.HandlerImpl.received+" vs "+ expected));
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    76
        }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    77
    }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    78
    public static void test2() {
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    79
        final int nb = 2;
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    80
        final int i = 2*nb + 1;
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    81
        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(messages[i]); // calling getGlobal() will
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    82
             // 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
    83
        Logger.global.info(messages[i+1]); // Now that the LogManager is
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    84
             // initialized, this message should appear too.
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    85
        final List<String> expected = Arrays.asList(Arrays.copyOfRange(messages, i, i+2));
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    86
        if (!testgetglobal.HandlerImpl.received.containsAll(expected)) {
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    87
            fail(new Error("Unexpected message list: "+testgetglobal.HandlerImpl.received+" vs "+ expected));
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    88
        }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    89
    }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    90
    public static void test3() {
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    91
        final int nb = 3;
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    92
        final int i = 2*nb + 1;
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    93
        java.util.logging.LogManager.getLogManager();
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    94
        Logger.getGlobal().info(messages[i]); // calling getGlobal() will
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    95
             // 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
    96
        Logger.global.info(messages[i+1]); // Now that the LogManager is
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    97
             // initialized, this message should appear too.
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    98
        final List<String> expected = Arrays.asList(Arrays.copyOfRange(messages, i, i+2));
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    99
        if (!testgetglobal.HandlerImpl.received.containsAll(expected)) {
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   100
            fail(new Error("Unexpected message list: "+testgetglobal.HandlerImpl.received+" vs "+ expected));
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   101
        }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   102
    }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   103
    public static void test4() {
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   104
        log = new MyLogger("foo.bar");
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   105
        java.util.logging.LogManager.getLogManager().addLogger(log);
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   106
    }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   107
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   108
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   109
    private static volatile Throwable failed = null;
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   110
    private static volatile Logger log = null;
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   111
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   112
    public static class MyLogger extends Logger {
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   113
        public MyLogger(String name) {
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   114
            super(name, null);
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   115
        }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   116
    }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   117
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   118
    public static void fail(Throwable failure) {
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   119
        failure.printStackTrace();
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   120
        if (failed == null) failed = failure;
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   121
    }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   122
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   123
    public static class WaitAndRun implements Runnable {
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   124
          private final Runnable run;
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   125
          public WaitAndRun(Runnable run) {
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   126
              this.run = run;
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   127
          }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   128
          public void run() {
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   129
              try {
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   130
                 Thread.sleep(10);
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   131
                 run.run();
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   132
              } catch (Exception | Error x) {
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   133
                 fail(x);
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   134
              }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   135
          }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   136
    }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   137
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 20195
diff changeset
   138
    static final class Run1 implements Runnable {
18595
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   139
        public void run() { test1(); }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   140
    }
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 20195
diff changeset
   141
    static final class Run2 implements Runnable {
18595
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   142
        public void run() { test2(); }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   143
    }
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 20195
diff changeset
   144
    static final class Run3 implements Runnable {
18595
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   145
        public void run() { test3(); }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   146
    }
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 20195
diff changeset
   147
    static final class Run4 implements Runnable {
18595
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   148
        public void run() { test4(); }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   149
    }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   150
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 18595
diff changeset
   151
    static String description = "Unknown";
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 18595
diff changeset
   152
18595
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   153
    public static void main(String... args) throws Exception {
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   154
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 18595
diff changeset
   155
        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
   156
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 18595
diff changeset
   157
        description = "TestGetGlobalConcurrent"
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 18595
diff changeset
   158
            + (System.getSecurityManager() == null ? " " :
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 18595
diff changeset
   159
               " -Djava.security.manager ")
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 18595
diff changeset
   160
            + (manager == null ? "" : "-Djava.util.logging.manager=" + manager);
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 18595
diff changeset
   161
18595
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   162
        final Thread t1 = new Thread(new WaitAndRun(new Run1()), "test1");
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   163
        final Thread t2 = new Thread(new WaitAndRun(new Run2()), "test2");
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   164
        final Thread t3 = new Thread(new WaitAndRun(new Run3()), "test3");
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   165
        final Thread t4 = new Thread(new WaitAndRun(new Run4()), "test4");
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   166
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   167
        t1.setDaemon(true); t2.setDaemon(true); t3.setDaemon(true); t4.setDaemon(true);
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   168
        t1.start(); t2.start(); t3.start(); t4.start();
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   169
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   170
        Thread.sleep(10);
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   171
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   172
        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
   173
             // 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
   174
        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
   175
             // initialized, this message should appear too.
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   176
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   177
        final List<String> expected = Arrays.asList(Arrays.copyOfRange(messages, 1, 3));
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   178
        if (!testgetglobal.HandlerImpl.received.containsAll(expected)) {
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 18595
diff changeset
   179
            fail(new Error("Unexpected message list: "+testgetglobal.HandlerImpl.received+" vs "+ expected));
18595
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   180
        }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   181
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   182
        t1.join(); t2.join(); t3.join(); t4.join();
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   183
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   184
        if (failed != null) {
19825
a7e79bc2e437 8023168: Cleanup LogManager class initialization and LogManager/LoggerContext relationship
dfuchs
parents: 18595
diff changeset
   185
             throw new Error("Test failed: "+description, failed);
18595
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   186
        }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   187
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   188
        System.out.println("Test passed");
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   189
    }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
   190
}