jdk/test/java/util/logging/Logger/getGlobal/TestGetGlobalByName.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;
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.getLogger(Logger.GLOBAL_LOGGER_NAME).info() logs without configuration
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    31
 * @build TestGetGlobalByName 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: 18595
diff changeset
    32
 * @run main/othervm TestGetGlobalByName
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 18595
diff changeset
    33
 * @run main/othervm/policy=policy -Djava.security.manager TestGetGlobalByName
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 18595
diff changeset
    34
 * @run main/othervm -Djava.util.logging.manager=testgetglobal.LogManagerImpl1 TestGetGlobalByName
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 18595
diff changeset
    35
 * @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl TestGetGlobalByName
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 18595
diff changeset
    36
 * @run main/othervm -Djava.util.logging.manager=testgetglobal.LogManagerImpl2 TestGetGlobalByName
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 18595
diff changeset
    37
 * @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl2 TestGetGlobalByName
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 18595
diff changeset
    38
 * @run main/othervm -Djava.util.logging.manager=testgetglobal.LogManagerImpl3 TestGetGlobalByName
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 18595
diff changeset
    39
 * @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.LogManagerImpl3 TestGetGlobalByName
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 18595
diff changeset
    40
 * @run main/othervm -Djava.util.logging.manager=testgetglobal.BadLogManagerImpl TestGetGlobalByName
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 18595
diff changeset
    41
 * @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.BadLogManagerImpl TestGetGlobalByName
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 18595
diff changeset
    42
 * @run main/othervm -Djava.util.logging.manager=testgetglobal.DummyLogManagerImpl TestGetGlobalByName
fcd61ec8fff6 8025140: TEST_BUG: java/util/logging/Logger/getGlobal tests fail due to timeout
dfuchs
parents: 18595
diff changeset
    43
 * @run main/othervm/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.DummyLogManagerImpl TestGetGlobalByName
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 TestGetGlobalByName {
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) {
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
        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
    62
             // 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
    63
        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(messages[1]); // calling getLogger() will
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    64
             // 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
    65
        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
    66
             // initialized, this message should appear too.
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    67
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    68
        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
    69
        if (!testgetglobal.HandlerImpl.received.equals(expected)) {
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    70
            throw 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
    71
        }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    72
    }
c6f81d76027a 7184195: java.util.logging.Logger.getGlobal().info() doesn't log without configuration
dfuchs
parents:
diff changeset
    73
}