< prev index next >
test/jdk/java/lang/System/LoggerFinder/internal/PlatformLoggerBridgeTest/PlatformLoggerBridgeTest.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 56,66 ****
* @summary JDK implementation specific unit test for JDK internal artifacts.
* Tests all bridge methods from PlatformLogger with the a custom
* backend whose loggers implement PlatformLogger.Bridge.
* @modules java.base/sun.util.logging
* java.logging
! * @build CustomSystemClassLoader PlatformLoggerBridgeTest
* @run main/othervm -Djava.system.class.loader=CustomSystemClassLoader PlatformLoggerBridgeTest NOSECURITY
* @run main/othervm -Djava.system.class.loader=CustomSystemClassLoader PlatformLoggerBridgeTest NOPERMISSIONS
* @run main/othervm -Djava.system.class.loader=CustomSystemClassLoader PlatformLoggerBridgeTest WITHPERMISSIONS
* @author danielfuchs
*/
--- 56,66 ----
* @summary JDK implementation specific unit test for JDK internal artifacts.
* Tests all bridge methods from PlatformLogger with the a custom
* backend whose loggers implement PlatformLogger.Bridge.
* @modules java.base/sun.util.logging
* java.logging
! * @build CustomSystemClassLoader LogProducerFinder PlatformLoggerBridgeTest
* @run main/othervm -Djava.system.class.loader=CustomSystemClassLoader PlatformLoggerBridgeTest NOSECURITY
* @run main/othervm -Djava.system.class.loader=CustomSystemClassLoader PlatformLoggerBridgeTest NOPERMISSIONS
* @run main/othervm -Djava.system.class.loader=CustomSystemClassLoader PlatformLoggerBridgeTest WITHPERMISSIONS
* @author danielfuchs
*/
*** 87,109 ****
protected AtomicBoolean initialValue() {
return new AtomicBoolean(false);
}
};
static final Class<?> providerClass;
static {
try {
// Preload classes before the security manager is on.
! providerClass = ClassLoader.getSystemClassLoader().loadClass("PlatformLoggerBridgeTest$LogProducerFinder");
((LoggerFinder)providerClass.newInstance()).getLogger("foo", providerClass.getModule());
} catch (Exception ex) {
throw new ExceptionInInitializerError(ex);
}
}
- public static final Queue<LogEvent> eventQueue = new ArrayBlockingQueue<>(128);
-
public static final class LogEvent implements Cloneable {
public LogEvent() {
this(sequencer.getAndIncrement());
}
--- 87,109 ----
protected AtomicBoolean initialValue() {
return new AtomicBoolean(false);
}
};
+ public static final Queue<LogEvent> eventQueue = new ArrayBlockingQueue<>(128);
+
static final Class<?> providerClass;
static {
try {
// Preload classes before the security manager is on.
! providerClass = ClassLoader.getSystemClassLoader().loadClass("LogProducerFinder");
((LoggerFinder)providerClass.newInstance()).getLogger("foo", providerClass.getModule());
} catch (Exception ex) {
throw new ExceptionInInitializerError(ex);
}
}
public static final class LogEvent implements Cloneable {
public LogEvent() {
this(sequencer.getAndIncrement());
}
*** 232,248 ****
className, methodName, level, bundle, supplier, thrown, params);
}
}
! public static class LogProducerFinder extends LoggerFinder {
! static final RuntimePermission LOGGERFINDER_PERMISSION =
! new RuntimePermission("loggerFinder");
! final ConcurrentHashMap<String, LoggerImpl> system = new ConcurrentHashMap<>();
! final ConcurrentHashMap<String, LoggerImpl> user = new ConcurrentHashMap<>();
!
! public class LoggerImpl implements Logger, PlatformLogger.Bridge {
private final String name;
private sun.util.logging.PlatformLogger.Level level = sun.util.logging.PlatformLogger.Level.INFO;
private sun.util.logging.PlatformLogger.Level OFF = sun.util.logging.PlatformLogger.Level.OFF;
private sun.util.logging.PlatformLogger.Level FINE = sun.util.logging.PlatformLogger.Level.FINE;
private sun.util.logging.PlatformLogger.Level FINER = sun.util.logging.PlatformLogger.Level.FINER;
--- 232,242 ----
className, methodName, level, bundle, supplier, thrown, params);
}
}
! public static class LoggerImpl implements System.Logger, PlatformLogger.Bridge {
private final String name;
private sun.util.logging.PlatformLogger.Level level = sun.util.logging.PlatformLogger.Level.INFO;
private sun.util.logging.PlatformLogger.Level OFF = sun.util.logging.PlatformLogger.Level.OFF;
private sun.util.logging.PlatformLogger.Level FINE = sun.util.logging.PlatformLogger.Level.FINE;
private sun.util.logging.PlatformLogger.Level FINER = sun.util.logging.PlatformLogger.Level.FINER;
*** 254,263 ****
--- 248,261 ----
public LoggerImpl(String name) {
this.name = name;
}
+ public void configureLevel(sun.util.logging.PlatformLogger.Level level) {
+ this.level = level;
+ }
+
@Override
public String getName() {
return name;
}
*** 276,286 ****
public void log(Level level, ResourceBundle bundle,
String format, Object... params) {
throw new UnsupportedOperationException();
}
! void log(LogEvent event) {
eventQueue.add(event);
}
@Override
public void log(Level level, Supplier<String> msgSupplier) {
--- 274,284 ----
public void log(Level level, ResourceBundle bundle,
String format, Object... params) {
throw new UnsupportedOperationException();
}
! void log(PlatformLoggerBridgeTest.LogEvent event) {
eventQueue.add(event);
}
@Override
public void log(Level level, Supplier<String> msgSupplier) {
*** 294,311 ****
}
@Override
public void log(sun.util.logging.PlatformLogger.Level level, String msg) {
log(LogEvent.of(isLoggable(level), name, null, null,
! level, null, msg, null, (Object[])null));
}
@Override
public void log(sun.util.logging.PlatformLogger.Level level,
Supplier<String> msgSupplier) {
log(LogEvent.of(isLoggable(level), name, null, null,
! level, null, msgSupplier, null, (Object[])null));
}
@Override
public void log(sun.util.logging.PlatformLogger.Level level, String msg,
Object... params) {
--- 292,309 ----
}
@Override
public void log(sun.util.logging.PlatformLogger.Level level, String msg) {
log(LogEvent.of(isLoggable(level), name, null, null,
! level, null, msg, null, (Object[]) null));
}
@Override
public void log(sun.util.logging.PlatformLogger.Level level,
Supplier<String> msgSupplier) {
log(LogEvent.of(isLoggable(level), name, null, null,
! level, null, msgSupplier, null, (Object[]) null));
}
@Override
public void log(sun.util.logging.PlatformLogger.Level level, String msg,
Object... params) {
*** 315,348 ****
@Override
public void log(sun.util.logging.PlatformLogger.Level level, String msg,
Throwable thrown) {
log(LogEvent.of(isLoggable(level), name, null, null,
! level, null, msg, thrown, (Object[])null));
}
@Override
public void log(sun.util.logging.PlatformLogger.Level level, Throwable thrown,
Supplier<String> msgSupplier) {
log(LogEvent.of(isLoggable(level), name, null, null,
! level, null, msgSupplier, thrown, (Object[])null));
}
@Override
public void logp(sun.util.logging.PlatformLogger.Level level, String sourceClass,
String sourceMethod, String msg) {
log(LogEvent.of(isLoggable(level), name,
sourceClass, sourceMethod,
! level, null, msg, null, (Object[])null));
}
@Override
public void logp(sun.util.logging.PlatformLogger.Level level, String sourceClass,
String sourceMethod, Supplier<String> msgSupplier) {
log(LogEvent.of(isLoggable(level), name,
sourceClass, sourceMethod,
! level, null, msgSupplier, null, (Object[])null));
}
@Override
public void logp(sun.util.logging.PlatformLogger.Level level, String sourceClass,
String sourceMethod, String msg, Object... params) {
--- 313,346 ----
@Override
public void log(sun.util.logging.PlatformLogger.Level level, String msg,
Throwable thrown) {
log(LogEvent.of(isLoggable(level), name, null, null,
! level, null, msg, thrown, (Object[]) null));
}
@Override
public void log(sun.util.logging.PlatformLogger.Level level, Throwable thrown,
Supplier<String> msgSupplier) {
log(LogEvent.of(isLoggable(level), name, null, null,
! level, null, msgSupplier, thrown, (Object[]) null));
}
@Override
public void logp(sun.util.logging.PlatformLogger.Level level, String sourceClass,
String sourceMethod, String msg) {
log(LogEvent.of(isLoggable(level), name,
sourceClass, sourceMethod,
! level, null, msg, null, (Object[]) null));
}
@Override
public void logp(sun.util.logging.PlatformLogger.Level level, String sourceClass,
String sourceMethod, Supplier<String> msgSupplier) {
log(LogEvent.of(isLoggable(level), name,
sourceClass, sourceMethod,
! level, null, msgSupplier, null, (Object[]) null));
}
@Override
public void logp(sun.util.logging.PlatformLogger.Level level, String sourceClass,
String sourceMethod, String msg, Object... params) {
*** 354,373 ****
@Override
public void logp(sun.util.logging.PlatformLogger.Level level, String sourceClass,
String sourceMethod, String msg, Throwable thrown) {
log(LogEvent.of(isLoggable(level), name,
sourceClass, sourceMethod,
! level, null, msg, thrown, (Object[])null));
}
@Override
public void logp(sun.util.logging.PlatformLogger.Level level, String sourceClass,
String sourceMethod, Throwable thrown,
Supplier<String> msgSupplier) {
log(LogEvent.of(isLoggable(level), name,
sourceClass, sourceMethod,
! level, null, msgSupplier, thrown, (Object[])null));
}
@Override
public void logrb(sun.util.logging.PlatformLogger.Level level, String sourceClass,
String sourceMethod, ResourceBundle bundle, String msg,
--- 352,371 ----
@Override
public void logp(sun.util.logging.PlatformLogger.Level level, String sourceClass,
String sourceMethod, String msg, Throwable thrown) {
log(LogEvent.of(isLoggable(level), name,
sourceClass, sourceMethod,
! level, null, msg, thrown, (Object[]) null));
}
@Override
public void logp(sun.util.logging.PlatformLogger.Level level, String sourceClass,
String sourceMethod, Throwable thrown,
Supplier<String> msgSupplier) {
log(LogEvent.of(isLoggable(level), name,
sourceClass, sourceMethod,
! level, null, msgSupplier, thrown, (Object[]) null));
}
@Override
public void logrb(sun.util.logging.PlatformLogger.Level level, String sourceClass,
String sourceMethod, ResourceBundle bundle, String msg,
*** 388,405 ****
public void logrb(sun.util.logging.PlatformLogger.Level level, String sourceClass,
String sourceMethod, ResourceBundle bundle, String msg,
Throwable thrown) {
log(LogEvent.of(isLoggable(level), name,
sourceClass, sourceMethod,
! level, bundle, msg, thrown, (Object[])null));
}
@Override
public void logrb(sun.util.logging.PlatformLogger.Level level, ResourceBundle bundle,
String msg, Throwable thrown) {
log(LogEvent.of(isLoggable(level), name, null, null,
! level, bundle, msg, thrown, (Object[])null));
}
@Override
public boolean isLoggable(sun.util.logging.PlatformLogger.Level level) {
return this.level != OFF && level.intValue()
--- 386,403 ----
public void logrb(sun.util.logging.PlatformLogger.Level level, String sourceClass,
String sourceMethod, ResourceBundle bundle, String msg,
Throwable thrown) {
log(LogEvent.of(isLoggable(level), name,
sourceClass, sourceMethod,
! level, bundle, msg, thrown, (Object[]) null));
}
@Override
public void logrb(sun.util.logging.PlatformLogger.Level level, ResourceBundle bundle,
String msg, Throwable thrown) {
log(LogEvent.of(isLoggable(level), name, null, null,
! level, bundle, msg, thrown, (Object[]) null));
}
@Override
public boolean isLoggable(sun.util.logging.PlatformLogger.Level level) {
return this.level != OFF && level.intValue()
*** 412,437 ****
}
}
- @Override
- public Logger getLogger(String name, Module caller) {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- sm.checkPermission(LOGGERFINDER_PERMISSION);
- }
- PrivilegedAction<ClassLoader> pa = () -> caller.getClassLoader();
- ClassLoader callerLoader = AccessController.doPrivileged(pa);
- if (callerLoader == null) {
- return system.computeIfAbsent(name, (n) -> new LoggerImpl(n));
- } else {
- return user.computeIfAbsent(name, (n) -> new LoggerImpl(n));
- }
- }
- }
-
static final sun.util.logging.PlatformLogger.Level[] julLevels = {
sun.util.logging.PlatformLogger.Level.ALL,
sun.util.logging.PlatformLogger.Level.FINEST,
sun.util.logging.PlatformLogger.Level.FINER,
sun.util.logging.PlatformLogger.Level.FINE,
--- 410,419 ----
*** 591,605 ****
allowAccess.get().set(old);
}
System.out.println("Got expected exception for system logger: " + acx);
}
! final LogProducerFinder.LoggerImpl sysSink;
boolean old = allowControl.get().get();
allowControl.get().set(true);
try {
! sysSink = LogProducerFinder.LoggerImpl.class.cast(
provider.getLogger("foo", Thread.class.getModule()));
} finally {
allowControl.get().set(old);
}
--- 573,587 ----
allowAccess.get().set(old);
}
System.out.println("Got expected exception for system logger: " + acx);
}
! final LoggerImpl sysSink;
boolean old = allowControl.get().get();
allowControl.get().set(true);
try {
! sysSink = LoggerImpl.class.cast(
provider.getLogger("foo", Thread.class.getModule()));
} finally {
allowControl.get().set(old);
}
*** 645,668 ****
verbose("Got expected results for "
+ desc + "\n\t" + expected);
}
}
! static void setLevel( LogProducerFinder.LoggerImpl sink,
sun.util.logging.PlatformLogger.Level loggerLevel) {
! sink.level = loggerLevel;
}
// Calls the methods defined on LogProducer and verify the
! // parameters received by the underlying LogProducerFinder.LoggerImpl
// logger.
private static void testLogger(LoggerFinder provider,
Map<PlatformLogger, String> loggerDescMap,
String name,
ResourceBundle loggerBundle,
PlatformLogger logger,
! LogProducerFinder.LoggerImpl sink) {
System.out.println("Testing " + loggerDescMap.get(logger) + " [" + logger +"]");
final sun.util.logging.PlatformLogger.Level OFF = sun.util.logging.PlatformLogger.Level.OFF;
final sun.util.logging.PlatformLogger.Level ALL = sun.util.logging.PlatformLogger.Level.OFF;
--- 627,650 ----
verbose("Got expected results for "
+ desc + "\n\t" + expected);
}
}
! static void setLevel(LoggerImpl sink,
sun.util.logging.PlatformLogger.Level loggerLevel) {
! sink.configureLevel(loggerLevel);
}
// Calls the methods defined on LogProducer and verify the
! // parameters received by the underlying LoggerImpl
// logger.
private static void testLogger(LoggerFinder provider,
Map<PlatformLogger, String> loggerDescMap,
String name,
ResourceBundle loggerBundle,
PlatformLogger logger,
! LoggerImpl sink) {
System.out.println("Testing " + loggerDescMap.get(logger) + " [" + logger +"]");
final sun.util.logging.PlatformLogger.Level OFF = sun.util.logging.PlatformLogger.Level.OFF;
final sun.util.logging.PlatformLogger.Level ALL = sun.util.logging.PlatformLogger.Level.OFF;
< prev index next >