13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.io.PrintStream; 25 import java.lang.System.Logger; 26 import java.lang.System.Logger.Level; 27 import java.util.ArrayList; 28 import java.util.concurrent.atomic.AtomicBoolean; 29 import java.util.Enumeration; 30 import java.util.List; 31 import java.util.ResourceBundle; 32 import java.util.Set; 33 34 import jdk.internal.logger.BootstrapLogger; 35 import jdk.internal.logger.LazyLoggers; 36 37 /* 38 * @test 39 * @bug 8144460 8144214 40 * @summary Cover the logXX and LogEvent.valueOf APIs of BootstrapLogger 41 * and logXX APIs of SimpleConsoleLogger. 42 * @modules java.base/jdk.internal.logger 43 * java.base/sun.util.logging 44 * @build BootstrapLoggerUtils LogStream 45 * @run main/othervm BootstrapLoggerAPIsTest 46 */ 47 48 public class BootstrapLoggerAPIsTest { 49 50 private static final LogStream ERR = new LogStream(); 51 52 public static void main(String[] args) throws Exception { 53 54 final ContentManager MGR = new ContentManager(); 55 56 // private reflection hook that allows us to simulate a non booted VM 57 final AtomicBoolean VM_BOOTED = new AtomicBoolean(false); 58 59 BootstrapLoggerUtils.setBootedHook(() -> VM_BOOTED.get()); 60 61 // We replace System.err to check the messages that have been logged 62 // by the JUL ConsoleHandler and default SimpleConsoleLogger 63 // implementaion 64 System.setErr(new PrintStream(ERR)); 65 66 VM_BOOTED.getAndSet(false); 67 if (BootstrapLogger.isBooted()) { 68 throw new RuntimeException("VM should not be booted!"); 69 } 70 71 final Logger LOGGER = 72 LazyLoggers.getLogger("foo.bar", Thread.class); 73 final sun.util.logging.PlatformLogger.Level PLATFORM_LEVEL = 74 sun.util.logging.PlatformLogger.Level.SEVERE; 75 final MyResources BUNDLE = new MyResources(); 76 77 /* 78 * Test logXX APIs for interface java.lang.System.Logger. Log content 79 * before VM is booted should be retained. Log content after VM was 80 * booted should be flushed instantly. VM is not booted in first round 81 * of loop, VM is booted in second round of loop. 82 */ 83 for (int i = 0; i < 2; i++) { 84 boolean booted = BootstrapLogger.isBooted(); 85 86 // make sure there is no [remaining] content in the LogStream. 87 MGR.failLog("xyz", "throwable #", "MyClass_#", "MyMethod_#"); 88 89 /* 90 * test logXX APIs for interface java.lang.System.Logger. 91 */ 92 // void log(java.lang.System$Logger$Level,java.util.ResourceBundle, | 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.io.PrintStream; 25 import java.lang.System.Logger; 26 import java.lang.System.Logger.Level; 27 import java.util.ArrayList; 28 import java.util.concurrent.atomic.AtomicBoolean; 29 import java.util.Enumeration; 30 import java.util.List; 31 import java.util.ResourceBundle; 32 import java.util.Set; 33 import java.lang.reflect.Module; 34 import jdk.internal.logger.BootstrapLogger; 35 import jdk.internal.logger.LazyLoggers; 36 37 /* 38 * @test 39 * @bug 8144460 8144214 40 * @summary Cover the logXX and LogEvent.valueOf APIs of BootstrapLogger 41 * and logXX APIs of SimpleConsoleLogger. 42 * @modules java.base/jdk.internal.logger 43 * java.base/sun.util.logging 44 * @build BootstrapLoggerUtils LogStream 45 * @run main/othervm BootstrapLoggerAPIsTest 46 */ 47 48 public class BootstrapLoggerAPIsTest { 49 50 private static final LogStream ERR = new LogStream(); 51 52 public static void main(String[] args) throws Exception { 53 54 final ContentManager MGR = new ContentManager(); 55 56 // private reflection hook that allows us to simulate a non booted VM 57 final AtomicBoolean VM_BOOTED = new AtomicBoolean(false); 58 59 BootstrapLoggerUtils.setBootedHook(() -> VM_BOOTED.get()); 60 61 // We replace System.err to check the messages that have been logged 62 // by the JUL ConsoleHandler and default SimpleConsoleLogger 63 // implementaion 64 System.setErr(new PrintStream(ERR)); 65 66 VM_BOOTED.getAndSet(false); 67 if (BootstrapLogger.isBooted()) { 68 throw new RuntimeException("VM should not be booted!"); 69 } 70 71 final Logger LOGGER = 72 LazyLoggers.getLogger("foo.bar", Thread.class.getModule()); 73 final sun.util.logging.PlatformLogger.Level PLATFORM_LEVEL = 74 sun.util.logging.PlatformLogger.Level.SEVERE; 75 final MyResources BUNDLE = new MyResources(); 76 77 /* 78 * Test logXX APIs for interface java.lang.System.Logger. Log content 79 * before VM is booted should be retained. Log content after VM was 80 * booted should be flushed instantly. VM is not booted in first round 81 * of loop, VM is booted in second round of loop. 82 */ 83 for (int i = 0; i < 2; i++) { 84 boolean booted = BootstrapLogger.isBooted(); 85 86 // make sure there is no [remaining] content in the LogStream. 87 MGR.failLog("xyz", "throwable #", "MyClass_#", "MyMethod_#"); 88 89 /* 90 * test logXX APIs for interface java.lang.System.Logger. 91 */ 92 // void log(java.lang.System$Logger$Level,java.util.ResourceBundle, |