test/jdk/java/lang/System/Logger/custom/CustomLoggerTest.java
author kvn
Fri, 21 Jun 2019 13:04:14 -0700
changeset 55462 6dfdcd31463d
parent 47216 71c04702a3d5
permissions -rw-r--r--
8185139: [Graal] Tests which set too restrictive security manager fail with Graal Summary: tests should also check default policy Reviewed-by: mchung, dfuchs, alanb, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
     1
/*
55462
6dfdcd31463d 8185139: [Graal] Tests which set too restrictive security manager fail with Graal
kvn
parents: 47216
diff changeset
     2
 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
     4
 *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
     8
 *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    14
 *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    18
 *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    21
 * questions.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    22
 */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    23
import java.security.AccessControlException;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    24
import java.security.AccessController;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    25
import java.security.CodeSource;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    26
import java.security.Permission;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    27
import java.security.PermissionCollection;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    28
import java.security.Permissions;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    29
import java.security.Policy;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    30
import java.security.PrivilegedAction;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    31
import java.security.ProtectionDomain;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    32
import java.util.Arrays;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    33
import java.util.Collections;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    34
import java.util.Enumeration;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    35
import java.util.HashMap;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    36
import java.util.Map;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    37
import java.util.Objects;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    38
import java.util.Queue;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    39
import java.util.ResourceBundle;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    40
import java.util.concurrent.ArrayBlockingQueue;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    41
import java.util.concurrent.ConcurrentHashMap;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    42
import java.util.concurrent.atomic.AtomicBoolean;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    43
import java.util.concurrent.atomic.AtomicLong;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    44
import java.util.function.Supplier;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    45
import java.lang.System.LoggerFinder;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    46
import java.lang.System.Logger;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    47
import java.lang.System.Logger.Level;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    48
import java.util.stream.Stream;
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
    49
import java.security.AllPermission;
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    50
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    51
/**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    52
 * @test
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    53
 * @bug     8140364
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    54
 * @summary Tests loggers returned by System.getLogger with a naive implementation
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    55
 *          of LoggerFinder, and in particular the default body of
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    56
 *          System.Logger methods.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    57
 * @build CustomLoggerTest AccessSystemLogger
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    58
 * @run driver AccessSystemLogger
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    59
 * @run main/othervm -Xbootclasspath/a:boot CustomLoggerTest NOSECURITY
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    60
 * @run main/othervm -Xbootclasspath/a:boot CustomLoggerTest NOPERMISSIONS
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    61
 * @run main/othervm -Xbootclasspath/a:boot CustomLoggerTest WITHPERMISSIONS
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    62
 * @author danielfuchs
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    63
 */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    64
public class CustomLoggerTest {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    65
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    66
    final static AtomicLong sequencer = new AtomicLong();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    67
    final static boolean VERBOSE = false;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    68
    static final ThreadLocal<AtomicBoolean> allowControl = new ThreadLocal<AtomicBoolean>() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    69
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    70
        protected AtomicBoolean initialValue() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    71
            return  new AtomicBoolean(false);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    72
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    73
    };
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
    74
    static final ThreadLocal<AtomicBoolean> allowAll = new ThreadLocal<AtomicBoolean>() {
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
    75
        @Override
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
    76
        protected AtomicBoolean initialValue() {
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
    77
            return  new AtomicBoolean(false);
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
    78
        }
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
    79
    };
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    80
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    81
    public static class MyBundle extends ResourceBundle {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    82
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    83
        final ConcurrentHashMap<String,String> map = new ConcurrentHashMap<>();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    84
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    85
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    86
        protected Object handleGetObject(String key) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    87
            if (key.contains(" (translated)")) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    88
                throw new RuntimeException("Unexpected key: " + key);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    89
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    90
            return map.computeIfAbsent(key, k -> k + " (translated)");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    91
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    92
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    93
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    94
        public Enumeration<String> getKeys() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    95
            return Collections.enumeration(map.keySet());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    96
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    97
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    98
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
    99
    public static class MyLoggerBundle extends MyBundle {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   100
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   101
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   102
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   103
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   104
    public static class BaseLoggerFinder extends LoggerFinder {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   105
        final ConcurrentHashMap<String, LoggerImpl> system = new ConcurrentHashMap<>();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   106
        final ConcurrentHashMap<String, LoggerImpl> user = new ConcurrentHashMap<>();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   107
        public Queue<LogEvent> eventQueue = new ArrayBlockingQueue<>(128);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   108
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   109
        // changing this to true requires changing the logic in the
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   110
        // test in order to load this class with a protection domain
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   111
        // that has the CONTROL_PERMISSION (e.g. by using a custom
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   112
        // system class loader.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   113
        final boolean doChecks = false;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   114
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   115
        public static final class LogEvent {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   116
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   117
            public LogEvent() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   118
                this(sequencer.getAndIncrement());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   119
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   120
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   121
            LogEvent(long sequenceNumber) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   122
                this.sequenceNumber = sequenceNumber;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   123
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   124
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   125
            long sequenceNumber;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   126
            boolean isLoggable;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   127
            String loggerName;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   128
            Level level;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   129
            ResourceBundle bundle;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   130
            Throwable thrown;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   131
            Object[] args;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   132
            Supplier<String> supplier;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   133
            String msg;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   134
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   135
            Object[] toArray() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   136
                return new Object[] {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   137
                    sequenceNumber,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   138
                    isLoggable,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   139
                    loggerName,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   140
                    level,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   141
                    bundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   142
                    thrown,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   143
                    args,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   144
                    supplier,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   145
                    msg,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   146
                };
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   147
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   148
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   149
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   150
            public String toString() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   151
                return Arrays.deepToString(toArray());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   152
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   153
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   154
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   155
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   156
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   157
            public boolean equals(Object obj) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   158
                return obj instanceof LogEvent
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   159
                        && Objects.deepEquals(this.toArray(), ((LogEvent)obj).toArray());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   160
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   161
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   162
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   163
            public int hashCode() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   164
                return Objects.hash(toArray());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   165
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   166
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   167
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   168
            public static LogEvent of(boolean isLoggable, String name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   169
                    Level level, ResourceBundle bundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   170
                    String key, Throwable thrown) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   171
                LogEvent evt = new LogEvent();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   172
                evt.isLoggable = isLoggable;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   173
                evt.loggerName = name;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   174
                evt.level = level;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   175
                evt.args = null;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   176
                evt.bundle = bundle;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   177
                evt.thrown = thrown;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   178
                evt.supplier = null;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   179
                evt.msg = key;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   180
                return evt;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   181
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   182
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   183
            public static LogEvent of(boolean isLoggable, String name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   184
                    Level level, ResourceBundle bundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   185
                    String key, Object... params) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   186
                LogEvent evt = new LogEvent();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   187
                evt.isLoggable = isLoggable;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   188
                evt.loggerName = name;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   189
                evt.level = level;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   190
                evt.args = params;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   191
                evt.bundle = bundle;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   192
                evt.thrown = null;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   193
                evt.supplier = null;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   194
                evt.msg = key;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   195
                return evt;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   196
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   197
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   198
            public static LogEvent of(long sequenceNumber,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   199
                    boolean isLoggable, String name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   200
                    Level level, ResourceBundle bundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   201
                    String key, Supplier<String> supplier,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   202
                    Throwable thrown, Object... params) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   203
                LogEvent evt = new LogEvent(sequenceNumber);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   204
                evt.loggerName = name;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   205
                evt.level = level;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   206
                evt.args = params;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   207
                evt.bundle = bundle;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   208
                evt.thrown = thrown;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   209
                evt.supplier = supplier;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   210
                evt.msg = key;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   211
                evt.isLoggable = isLoggable;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   212
                return evt;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   213
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   214
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   215
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   216
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   217
        public class LoggerImpl implements Logger {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   218
            private final String name;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   219
            private Level level = Level.INFO;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   220
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   221
            public LoggerImpl(String name) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   222
                this.name = name;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   223
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   224
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   225
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   226
            public String getName() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   227
                return name;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   228
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   229
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   230
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   231
            public boolean isLoggable(Level level) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   232
                return this.level != Level.OFF && this.level.getSeverity() <= level.getSeverity();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   233
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   234
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   235
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   236
            public void log(Level level, ResourceBundle bundle, String key, Throwable thrown) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   237
                log(LogEvent.of(isLoggable(level), this.name, level, bundle, key, thrown));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   238
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   239
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   240
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   241
            public void log(Level level, ResourceBundle bundle, String format, Object... params) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   242
                log(LogEvent.of(isLoggable(level), name, level, bundle, format, params));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   243
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   244
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   245
            void log(LogEvent event) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   246
                eventQueue.add(event);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   247
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   248
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   249
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   250
        @Override
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   251
        public Logger getLogger(String name, Module caller) {
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   252
            // We should check the permission to obey the API contract, but
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   253
            // what happens if we don't?
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   254
            // This is the main difference compared with what we test in
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   255
            // java/lang/System/LoggerFinder/BaseLoggerFinderTest
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   256
            SecurityManager sm = System.getSecurityManager();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   257
            if (sm != null && doChecks) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   258
                sm.checkPermission(SimplePolicy.LOGGERFINDER_PERMISSION);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   259
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   260
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   261
            final boolean before = allowAll.get().getAndSet(true);
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   262
            final ClassLoader callerLoader;
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   263
            try {
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   264
                callerLoader = caller.getClassLoader();
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   265
            } finally {
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   266
                allowAll.get().set(before);
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   267
            }
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   268
            if (callerLoader == null) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   269
                return system.computeIfAbsent(name, (n) -> new LoggerImpl(n));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   270
            } else {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   271
                return user.computeIfAbsent(name, (n) -> new LoggerImpl(n));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   272
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   273
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   274
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   275
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   276
    static final AccessSystemLogger accessSystemLogger = new AccessSystemLogger();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   277
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   278
    static enum TestCases {NOSECURITY, NOPERMISSIONS, WITHPERMISSIONS};
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   279
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   280
    static void setSecurityManager() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   281
        if (System.getSecurityManager() == null) {
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   282
            Policy.setPolicy(new SimplePolicy(allowControl, allowAll));
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   283
            System.setSecurityManager(new SecurityManager());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   284
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   285
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   286
    public static void main(String[] args) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   287
        if (args.length == 0)
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   288
            args = new String[] {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   289
                "NOSECURITY",
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   290
                "NOPERMISSIONS",
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   291
                "WITHPERMISSIONS"
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   292
            };
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   293
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   294
        // 1. Obtain destination loggers directly from the LoggerFinder
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   295
        //   - LoggerFinder.getLogger("foo", type)
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   296
        BaseLoggerFinder provider =
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   297
                BaseLoggerFinder.class.cast(LoggerFinder.getLoggerFinder());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   298
        BaseLoggerFinder.LoggerImpl appSink =
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   299
                BaseLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", CustomLoggerTest.class.getModule()));
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   300
        BaseLoggerFinder.LoggerImpl sysSink =
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   301
                BaseLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", Thread.class.getModule()));
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   302
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   303
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   304
        Stream.of(args).map(TestCases::valueOf).forEach((testCase) -> {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   305
            switch (testCase) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   306
                case NOSECURITY:
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   307
                    System.out.println("\n*** Without Security Manager\n");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   308
                    test(provider, true, appSink, sysSink);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   309
                    System.out.println("Tetscase count: " + sequencer.get());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   310
                    break;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   311
                case NOPERMISSIONS:
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   312
                    System.out.println("\n*** With Security Manager, without permissions\n");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   313
                    setSecurityManager();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   314
                    test(provider, false, appSink, sysSink);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   315
                    System.out.println("Tetscase count: " + sequencer.get());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   316
                    break;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   317
                case WITHPERMISSIONS:
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   318
                    System.out.println("\n*** With Security Manager, with control permission\n");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   319
                    setSecurityManager();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   320
                    final boolean control = allowControl.get().get();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   321
                    try {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   322
                        allowControl.get().set(true);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   323
                        test(provider, true, appSink, sysSink);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   324
                    } finally {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   325
                        allowControl.get().set(control);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   326
                    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   327
                    break;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   328
                default:
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   329
                    throw new RuntimeException("Unknown test case: " + testCase);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   330
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   331
        });
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   332
        System.out.println("\nPASSED: Tested " + sequencer.get() + " cases.");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   333
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   334
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   335
    public static void test(BaseLoggerFinder provider, boolean hasRequiredPermissions,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   336
            BaseLoggerFinder.LoggerImpl appSink, BaseLoggerFinder.LoggerImpl sysSink) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   337
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   338
        ResourceBundle loggerBundle = ResourceBundle.getBundle(MyLoggerBundle.class.getName());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   339
        final Map<Logger, String> loggerDescMap = new HashMap<>();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   340
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   341
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   342
        // 1. Test loggers returned by:
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   343
        //   - System.getLogger("foo")
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   344
        //   - and AccessSystemLogger.getLogger("foo")
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   345
        Logger appLogger1 = System.getLogger("foo");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   346
        loggerDescMap.put(appLogger1, "System.getLogger(\"foo\");");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   347
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   348
        Logger sysLogger1 = null;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   349
        try {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   350
            sysLogger1 = accessSystemLogger.getLogger("foo");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   351
            loggerDescMap.put(sysLogger1, "AccessSystemLogger.getLogger(\"foo\")");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   352
        } catch (AccessControlException acx) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   353
            if (hasRequiredPermissions) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   354
                throw new RuntimeException("Unexpected security exception: ", acx);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   355
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   356
            if (!acx.getPermission().equals(SimplePolicy.LOGGERFINDER_PERMISSION)) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   357
                throw new RuntimeException("Unexpected permission in exception: " + acx, acx);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   358
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   359
            throw new RuntimeException("unexpected exception: " + acx, acx);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   360
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   361
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   362
        if (appLogger1 == sysLogger1) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   363
            throw new RuntimeException("identical loggers");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   364
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   365
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   366
        if (provider.system.contains(appLogger1)) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   367
            throw new RuntimeException("app logger in system map");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   368
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   369
        if (provider.user.contains(sysLogger1)) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   370
            throw new RuntimeException("sys logger in appplication map");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   371
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   372
        if (provider.system.contains(sysLogger1)) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   373
            // sysLogger should be a a LazyLoggerWrapper
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   374
            throw new RuntimeException("sys logger is in system map (should be wrapped)");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   375
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   376
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   377
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   378
        // 2. Test loggers returned by:
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   379
        //   - System.getLogger(\"foo\", loggerBundle)
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   380
        //   - and AccessSystemLogger.getLogger(\"foo\", loggerBundle)
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   381
        Logger appLogger2 =
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   382
                System.getLogger("foo", loggerBundle);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   383
        loggerDescMap.put(appLogger2, "System.getLogger(\"foo\", loggerBundle)");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   384
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   385
        Logger sysLogger2 = null;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   386
        try {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   387
            sysLogger2 = accessSystemLogger.getLogger("foo", loggerBundle);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   388
            loggerDescMap.put(sysLogger2, "AccessSystemLogger.getLogger(\"foo\", loggerBundle)");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   389
        } catch (AccessControlException acx) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   390
            if (hasRequiredPermissions) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   391
                throw new RuntimeException("Unexpected security exception: ", acx);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   392
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   393
            if (!acx.getPermission().equals(SimplePolicy.LOGGERFINDER_PERMISSION)) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   394
                throw new RuntimeException("Unexpected permission in exception: " + acx, acx);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   395
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   396
            throw new RuntimeException("unexpected exception: " + acx, acx);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   397
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   398
        if (appLogger2 == sysLogger2) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   399
            throw new RuntimeException("identical loggers");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   400
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   401
        if (appLogger2 == appSink) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   402
            throw new RuntimeException("identical loggers");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   403
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   404
        if (sysLogger2 == sysSink) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   405
            throw new RuntimeException("identical loggers");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   406
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   407
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   408
        if (provider.system.contains(appLogger2)) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   409
            throw new RuntimeException("localized app logger in system map");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   410
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   411
        if (provider.user.contains(appLogger2)) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   412
            throw new RuntimeException("localized app logger  in appplication map");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   413
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   414
        if (provider.user.contains(sysLogger2)) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   415
            throw new RuntimeException("localized sys logger in appplication map");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   416
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   417
        if (provider.system.contains(sysLogger2)) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   418
            throw new RuntimeException("localized sys logger not in system map");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   419
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   420
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   421
        testLogger(provider, loggerDescMap, "foo", null, appLogger1, appSink);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   422
        testLogger(provider, loggerDescMap, "foo", null, sysLogger1, sysSink);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   423
        testLogger(provider, loggerDescMap, "foo", loggerBundle, appLogger2, appSink);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   424
        testLogger(provider, loggerDescMap, "foo", loggerBundle, sysLogger2, sysSink);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   425
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   426
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   427
    public static class Foo {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   428
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   429
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   430
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   431
    static void verbose(String msg) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   432
       if (VERBOSE) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   433
           System.out.println(msg);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   434
       }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   435
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   436
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   437
    // Calls the 8 methods defined on Logger and verify the
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   438
    // parameters received by the underlying BaseLoggerFinder.LoggerImpl
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   439
    // logger.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   440
    private static void testLogger(BaseLoggerFinder provider,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   441
            Map<Logger, String> loggerDescMap,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   442
            String name,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   443
            ResourceBundle loggerBundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   444
            Logger logger,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   445
            BaseLoggerFinder.LoggerImpl sink) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   446
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   447
        System.out.println("Testing " + loggerDescMap.get(logger));
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   448
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   449
        Foo foo = new Foo();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   450
        String fooMsg = foo.toString();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   451
        for (Level loggerLevel : Level.values()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   452
            sink.level = loggerLevel;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   453
            for (Level messageLevel : Level.values()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   454
                String desc = "logger.log(messageLevel, foo): loggerLevel="
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   455
                        + loggerLevel+", messageLevel="+messageLevel;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   456
                BaseLoggerFinder.LogEvent expected =
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   457
                        BaseLoggerFinder.LogEvent.of(
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   458
                            sequencer.get(),
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   459
                            messageLevel.compareTo(loggerLevel) >= 0,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   460
                            name, messageLevel, (ResourceBundle)null,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   461
                            fooMsg, null, (Throwable)null, (Object[])null);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   462
                logger.log(messageLevel, foo);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   463
                if (loggerLevel == Level.OFF || messageLevel.compareTo(loggerLevel) < 0) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   464
                    if (provider.eventQueue.poll() != null) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   465
                        throw new RuntimeException("unexpected event in queue for " + desc);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   466
                    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   467
                } else {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   468
                    BaseLoggerFinder.LogEvent actual =  provider.eventQueue.poll();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   469
                    if (!expected.equals(actual)) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   470
                        throw new RuntimeException("mismatch for " + desc
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   471
                                + "\n\texpected=" + expected
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   472
                                + "\n\t  actual=" + actual);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   473
                    } else {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   474
                        verbose("Got expected results for "
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   475
                                + desc + "\n\t" + expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   476
                    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   477
                }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   478
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   479
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   480
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   481
        String msg = "blah";
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   482
        for (Level loggerLevel : Level.values()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   483
            sink.level = loggerLevel;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   484
            for (Level messageLevel : Level.values()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   485
                String desc = "logger.log(messageLevel, \"blah\"): loggerLevel="
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   486
                        + loggerLevel+", messageLevel="+messageLevel;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   487
                BaseLoggerFinder.LogEvent expected =
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   488
                        BaseLoggerFinder.LogEvent.of(
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   489
                            sequencer.get(),
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   490
                            messageLevel.compareTo(loggerLevel) >= 0 && loggerLevel != Level.OFF,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   491
                            name, messageLevel, loggerBundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   492
                            msg, null, (Throwable)null, (Object[])null);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   493
                logger.log(messageLevel, msg);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   494
                BaseLoggerFinder.LogEvent actual =  provider.eventQueue.poll();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   495
                if (!expected.equals(actual)) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   496
                    throw new RuntimeException("mismatch for " + desc
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   497
                            + "\n\texpected=" + expected
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   498
                            + "\n\t  actual=" + actual);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   499
                } else {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   500
                    verbose("Got expected results for "
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   501
                            + desc + "\n\t" + expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   502
                }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   503
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   504
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   505
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   506
        Supplier<String> fooSupplier = new Supplier<String>() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   507
            @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   508
            public String get() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   509
                return this.toString();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   510
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   511
        };
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   512
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   513
        for (Level loggerLevel : Level.values()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   514
            sink.level = loggerLevel;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   515
            for (Level messageLevel : Level.values()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   516
                String desc = "logger.log(messageLevel, fooSupplier): loggerLevel="
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   517
                        + loggerLevel+", messageLevel="+messageLevel;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   518
                BaseLoggerFinder.LogEvent expected =
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   519
                        BaseLoggerFinder.LogEvent.of(
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   520
                            sequencer.get(),
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   521
                            messageLevel.compareTo(loggerLevel) >= 0,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   522
                            name, messageLevel, (ResourceBundle)null,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   523
                            fooSupplier.get(), null,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   524
                            (Throwable)null, (Object[])null);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   525
                logger.log(messageLevel, fooSupplier);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   526
                if (loggerLevel == Level.OFF || messageLevel.compareTo(loggerLevel) < 0) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   527
                    if (provider.eventQueue.poll() != null) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   528
                        throw new RuntimeException("unexpected event in queue for " + desc);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   529
                    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   530
                } else {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   531
                    BaseLoggerFinder.LogEvent actual =  provider.eventQueue.poll();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   532
                    if (!expected.equals(actual)) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   533
                        throw new RuntimeException("mismatch for " + desc
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   534
                                + "\n\texpected=" + expected
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   535
                                + "\n\t  actual=" + actual);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   536
                    } else {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   537
                        verbose("Got expected results for "
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   538
                                + desc + "\n\t" + expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   539
                    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   540
                }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   541
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   542
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   543
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   544
        String format = "two params [{1} {2}]";
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   545
        Object arg1 = foo;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   546
        Object arg2 = msg;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   547
        for (Level loggerLevel : Level.values()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   548
            sink.level = loggerLevel;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   549
            for (Level messageLevel : Level.values()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   550
                String desc = "logger.log(messageLevel, format, params...): loggerLevel="
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   551
                        + loggerLevel+", messageLevel="+messageLevel;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   552
                BaseLoggerFinder.LogEvent expected =
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   553
                        BaseLoggerFinder.LogEvent.of(
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   554
                            sequencer.get(),
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   555
                            messageLevel.compareTo(loggerLevel) >= 0 && loggerLevel != Level.OFF,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   556
                            name, messageLevel, loggerBundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   557
                            format, null, (Throwable)null, new Object[] {arg1, arg2});
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   558
                logger.log(messageLevel, format, arg1, arg2);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   559
                BaseLoggerFinder.LogEvent actual =  provider.eventQueue.poll();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   560
                if (!expected.equals(actual)) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   561
                    throw new RuntimeException("mismatch for " + desc
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   562
                            + "\n\texpected=" + expected
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   563
                            + "\n\t  actual=" + actual);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   564
                } else {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   565
                    verbose("Got expected results for "
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   566
                            + desc + "\n\t" + expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   567
                }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   568
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   569
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   570
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   571
        Throwable thrown = new Exception("OK: log me!");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   572
        for (Level loggerLevel : Level.values()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   573
            sink.level = loggerLevel;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   574
            for (Level messageLevel : Level.values()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   575
                String desc = "logger.log(messageLevel, \"blah\", thrown): loggerLevel="
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   576
                        + loggerLevel+", messageLevel="+messageLevel;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   577
                BaseLoggerFinder.LogEvent expected =
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   578
                        BaseLoggerFinder.LogEvent.of(
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   579
                            sequencer.get(),
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   580
                            messageLevel.compareTo(loggerLevel) >= 0 && loggerLevel != Level.OFF,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   581
                            name, messageLevel, loggerBundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   582
                            msg, null, thrown, (Object[]) null);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   583
                logger.log(messageLevel, msg, thrown);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   584
                BaseLoggerFinder.LogEvent actual =  provider.eventQueue.poll();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   585
                if (!expected.equals(actual)) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   586
                    throw new RuntimeException("mismatch for " + desc
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   587
                            + "\n\texpected=" + expected
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   588
                            + "\n\t  actual=" + actual);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   589
                } else {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   590
                    verbose("Got expected results for "
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   591
                            + desc + "\n\t" + expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   592
                }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   593
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   594
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   595
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   596
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   597
        for (Level loggerLevel : Level.values()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   598
            sink.level = loggerLevel;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   599
            for (Level messageLevel : Level.values()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   600
                String desc = "logger.log(messageLevel, thrown, fooSupplier): loggerLevel="
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   601
                        + loggerLevel+", messageLevel="+messageLevel;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   602
                BaseLoggerFinder.LogEvent expected =
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   603
                        BaseLoggerFinder.LogEvent.of(
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   604
                            sequencer.get(),
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   605
                            messageLevel.compareTo(loggerLevel) >= 0,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   606
                            name, messageLevel, (ResourceBundle)null,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   607
                            fooSupplier.get(), null,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   608
                            (Throwable)thrown, (Object[])null);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   609
                logger.log(messageLevel, fooSupplier, thrown);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   610
                if (loggerLevel == Level.OFF || messageLevel.compareTo(loggerLevel) < 0) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   611
                    if (provider.eventQueue.poll() != null) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   612
                        throw new RuntimeException("unexpected event in queue for " + desc);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   613
                    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   614
                } else {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   615
                    BaseLoggerFinder.LogEvent actual =  provider.eventQueue.poll();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   616
                    if (!expected.equals(actual)) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   617
                        throw new RuntimeException("mismatch for " + desc
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   618
                                + "\n\texpected=" + expected
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   619
                                + "\n\t  actual=" + actual);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   620
                    } else {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   621
                        verbose("Got expected results for "
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   622
                                + desc + "\n\t" + expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   623
                    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   624
                }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   625
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   626
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   627
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   628
        ResourceBundle bundle = ResourceBundle.getBundle(MyBundle.class.getName());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   629
        for (Level loggerLevel : Level.values()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   630
            sink.level = loggerLevel;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   631
            for (Level messageLevel : Level.values()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   632
                String desc = "logger.log(messageLevel, bundle, format, params...): loggerLevel="
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   633
                        + loggerLevel+", messageLevel="+messageLevel;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   634
                BaseLoggerFinder.LogEvent expected =
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   635
                        BaseLoggerFinder.LogEvent.of(
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   636
                            sequencer.get(),
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   637
                            messageLevel.compareTo(loggerLevel) >= 0 && loggerLevel != Level.OFF,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   638
                            name, messageLevel, bundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   639
                            format, null, (Throwable)null, new Object[] {foo, msg});
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   640
                logger.log(messageLevel, bundle, format, foo, msg);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   641
                BaseLoggerFinder.LogEvent actual =  provider.eventQueue.poll();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   642
                if (!expected.equals(actual)) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   643
                    throw new RuntimeException("mismatch for " + desc
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   644
                            + "\n\texpected=" + expected
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   645
                            + "\n\t  actual=" + actual);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   646
                } else {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   647
                    verbose("Got expected results for "
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   648
                            + desc + "\n\t" + expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   649
                }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   650
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   651
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   652
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   653
        for (Level loggerLevel : Level.values()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   654
            sink.level = loggerLevel;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   655
            for (Level messageLevel : Level.values()) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   656
                String desc = "logger.log(messageLevel, bundle, \"blah\", thrown): loggerLevel="
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   657
                        + loggerLevel+", messageLevel="+messageLevel;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   658
                BaseLoggerFinder.LogEvent expected =
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   659
                        BaseLoggerFinder.LogEvent.of(
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   660
                            sequencer.get(),
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   661
                            messageLevel.compareTo(loggerLevel) >= 0 && loggerLevel != Level.OFF,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   662
                            name, messageLevel, bundle,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   663
                            msg, null, thrown, (Object[]) null);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   664
                logger.log(messageLevel, bundle, msg, thrown);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   665
                BaseLoggerFinder.LogEvent actual =  provider.eventQueue.poll();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   666
                if (!expected.equals(actual)) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   667
                    throw new RuntimeException("mismatch for " + desc
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   668
                            + "\n\texpected=" + expected
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   669
                            + "\n\t  actual=" + actual);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   670
                } else {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   671
                    verbose("Got expected results for "
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   672
                            + desc + "\n\t" + expected);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   673
                }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   674
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   675
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   676
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   677
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   678
    final static class PermissionsBuilder {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   679
        final Permissions perms;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   680
        public PermissionsBuilder() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   681
            this(new Permissions());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   682
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   683
        public PermissionsBuilder(Permissions perms) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   684
            this.perms = perms;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   685
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   686
        public PermissionsBuilder add(Permission p) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   687
            perms.add(p);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   688
            return this;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   689
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   690
        public PermissionsBuilder addAll(PermissionCollection col) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   691
            if (col != null) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   692
                for (Enumeration<Permission> e = col.elements(); e.hasMoreElements(); ) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   693
                    perms.add(e.nextElement());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   694
                }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   695
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   696
            return this;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   697
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   698
        public Permissions toPermissions() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   699
            final PermissionsBuilder builder = new PermissionsBuilder();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   700
            builder.addAll(perms);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   701
            return builder.perms;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   702
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   703
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   704
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   705
    public static class SimplePolicy extends Policy {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   706
55462
6dfdcd31463d 8185139: [Graal] Tests which set too restrictive security manager fail with Graal
kvn
parents: 47216
diff changeset
   707
        static final Policy DEFAULT_POLICY = Policy.getPolicy();
6dfdcd31463d 8185139: [Graal] Tests which set too restrictive security manager fail with Graal
kvn
parents: 47216
diff changeset
   708
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   709
        static final RuntimePermission LOGGERFINDER_PERMISSION =
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   710
                new RuntimePermission("loggerFinder");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   711
        final Permissions permissions;
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   712
        final Permissions controlPermissions;
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   713
        final Permissions allPermissions;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   714
        final ThreadLocal<AtomicBoolean> allowControl;
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   715
        final ThreadLocal<AtomicBoolean> allowAll;
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   716
        public SimplePolicy(ThreadLocal<AtomicBoolean> allowControl, ThreadLocal<AtomicBoolean> allowAll) {
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   717
            this.allowControl = allowControl;
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   718
            this.allowAll = allowAll;
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   719
            permissions = new Permissions();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   720
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   721
            // these are used for configuring the test itself...
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   722
            controlPermissions = new Permissions();
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   723
            controlPermissions.add(LOGGERFINDER_PERMISSION);
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   724
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   725
            // these are used for simulating a doPrivileged call from
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   726
            // a class in the BCL
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   727
            allPermissions = new Permissions();
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   728
            allPermissions.add(new AllPermission());
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   729
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   730
        }
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   731
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   732
        Permissions permissions() {
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   733
            if (allowAll.get().get()) return allPermissions;
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   734
            if (allowControl.get().get()) return controlPermissions;
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   735
            return permissions;
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   736
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   737
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   738
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   739
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   740
        public boolean implies(ProtectionDomain domain, Permission permission) {
55462
6dfdcd31463d 8185139: [Graal] Tests which set too restrictive security manager fail with Graal
kvn
parents: 47216
diff changeset
   741
            return permissions().implies(permission) || DEFAULT_POLICY.implies(domain, permission);
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   742
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   743
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   744
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   745
        public PermissionCollection getPermissions(CodeSource codesource) {
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   746
            return new PermissionsBuilder().addAll(permissions()).toPermissions();
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   747
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   748
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   749
        @Override
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   750
        public PermissionCollection getPermissions(ProtectionDomain domain) {
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 33875
diff changeset
   751
            return new PermissionsBuilder().addAll(permissions()).toPermissions();
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   752
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   753
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents:
diff changeset
   754
}