Initial load
diff --git a/test/java/util/logging/GetGlobalTest.java b/test/java/util/logging/GetGlobalTest.java
new file mode 100644
index 0000000..665b323
--- /dev/null
+++ b/test/java/util/logging/GetGlobalTest.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6476146
+ *
+ * @summary Added convenience method for deprecated Logger.global
+ * @author Serguei Spitsyn
+ *
+ * @build GetGlobalTest
+ * @run main GetGlobalTest
+ */
+
+/**
+ * RFE ID:
+ * 6476146: Add convenience method for deprecated Logger.global
+ * This is simple unit test for the RFE.
+ *
+ * With the deprecation of Logger.global, there is no convenient way of
+ * doing entry-level logging. Logger.getLogger(Logger.GLOBAL_LOGGER_NAME)
+ * is not an adequate substitute for Logger.global.
+ * Solution: A convenience method Logger.getGlobal() should be provided.
+ */
+
+import java.util.logging.*;
+
+public class GetGlobalTest {
+ static final java.io.PrintStream out = System.out;
+ public static void main(String arg[]) {
+ Logger glogger1 = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
+ Logger glogger2 = Logger.getGlobal();
+ if (glogger1.equals(glogger2)) {
+ out.println("Test passed");
+ } else {
+ out.println("Test FAILED");
+ }
+ }
+}
diff --git a/test/java/util/logging/LoggingDeadlock.java b/test/java/util/logging/LoggingDeadlock.java
new file mode 100644
index 0000000..e21e1f4
--- /dev/null
+++ b/test/java/util/logging/LoggingDeadlock.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4994705
+ *
+ * @summary deadlock in LogManager
+ * @author Serguei Spitsyn / SAP
+ *
+ * @build LoggingDeadlock
+ * @run main/timeout=15 LoggingDeadlock
+ *
+ * There can be a deadlock between two class initializations.
+ * It happens if the LogManager.<clinit> and the Logger.<clinit>
+ * are invoked concurrently on two different threads.
+ * There is a cyclic dependence between the two static initializers:
+ * 1. LogManager.<clinit> instantiate the class RootLogger which
+ * is a subclass of the Logger class.
+ * It requires the Logger class initialization to complete.
+ * 2. Logger.<clinit> initializes the field "global", so it
+ * it makes a call: Logger.getLogger("global").
+ * Subsequently the LogManager static method getLogManager()
+ * is called which requires the LogManager class
+ * initialization to complete.
+ * This cyclic dependence causes a deadlock, so two class
+ * initializations are waiting for each other.
+ * This is a regression test for this bug.
+ */
+
+
+import java.util.logging.LogManager;
+import java.util.logging.Logger;
+
+public class LoggingDeadlock {
+
+ public static void randomDelay() {
+ int runs = (int) Math.random() * 1000000;
+ int c = 0;
+
+ for (int i = 0; i < runs; ++i) {
+ c = c + i;
+ }
+ }
+
+ public static void main(String[] args) throws InterruptedException{
+ Thread t1 = new Thread(new Runnable() {
+ public void run() {
+ randomDelay();
+ // Trigger Logger.<clinit>
+ Logger.getAnonymousLogger();
+ }
+ });
+
+ Thread t2 = new Thread(new Runnable() {
+ public void run() {
+ randomDelay();
+ // Trigger LogManager.<clinit>
+ LogManager.getLogManager();
+ }
+ });
+
+ t1.start();
+ t2.start();
+
+ t1.join();
+ t2.join();
+ System.out.println("\nTest passed");
+ }
+}
diff --git a/test/java/util/logging/LoggingDeadlock2.java b/test/java/util/logging/LoggingDeadlock2.java
new file mode 100644
index 0000000..4783193
--- /dev/null
+++ b/test/java/util/logging/LoggingDeadlock2.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6467152
+ *
+ * @summary deadlock occurs in LogManager initialization and JVM termination
+ * @author Serguei Spitsyn / Hittachi
+ *
+ * @build LoggingDeadlock2
+ * @run main/timeout=15 LoggingDeadlock2
+ *
+ * There is a clear deadlock between LogManager.<clinit> and
+ * Cleaner.run() methods.
+ * T1 thread:
+ * The LogManager.<clinit> creates LogManager.manager object,
+ * sets shutdown hook with the Cleaner class and then waits
+ * to lock the LogManager.manager monitor.
+ * T2 thread:
+ * It is started by the System.exit() as shutdown hook thread.
+ * It locks the LogManager.manager monitor and then calls the
+ * static methods of the LogManager class (in this particular
+ * case it is a trick of the inner classes implementation).
+ * It is waits when the LogManager.<clinit> is completed.
+ *
+ * This is a regression test for this bug.
+ */
+
+import java.util.logging.LogManager;
+
+public class LoggingDeadlock2 implements Runnable {
+ static final java.io.PrintStream out = System.out;
+ static Object lock = new Object();
+ static int c = 0;
+ public static void main(String arg[]) {
+ out.println("\nThis test checks that there is no deadlock.");
+ out.println("If not crashed or timed-out then it is passed.");
+ try {
+ new Thread(new LoggingDeadlock2()).start();
+ synchronized(lock) {
+ c++;
+ if (c == 2) lock.notify();
+ else lock.wait();
+ }
+ LogManager log = LogManager.getLogManager();
+ out.println("Test passed");
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ out.println("Test FAILED"); // Not expected
+ }
+ }
+
+ public void run() {
+ try {
+ synchronized(lock) {
+ c++;
+ if (c == 2) lock.notify();
+ else lock.wait();
+ }
+ System.exit(1);
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ out.println("Test FAILED"); // Not expected
+ }
+ }
+}
diff --git a/test/java/util/logging/LoggingMXBeanTest.java b/test/java/util/logging/LoggingMXBeanTest.java
new file mode 100644
index 0000000..b7d4070
--- /dev/null
+++ b/test/java/util/logging/LoggingMXBeanTest.java
@@ -0,0 +1,250 @@
+/*
+ * Copyright 2003-2004 Sun Microsystems, Inc. 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 5007165
+ *
+ * @summary Basic Test for LoggingMXBean via MBeanServer
+ * @author Ron Mann
+ *
+ * @build LoggingMXBeanTest
+ * @run main LoggingMXBeanTest
+ */
+
+import javax.management.*;
+import java.util.logging.*;
+
+
+public class LoggingMXBeanTest
+{
+
+ LoggingMXBean mBean;
+ ObjectName objectName = null;
+ static String LOGGER_NAME_1 = "com.sun.management.Logger1";
+ static String LOGGER_NAME_2 = "com.sun.management.Logger2";
+
+ public LoggingMXBeanTest() throws Exception {
+
+ /*
+ * Create the MBeanServeri, register the LoggingMXBean
+ */
+ System.out.println( "***************************************************" );
+ System.out.println( "********** LoggingMXBean Unit Test **********" );
+ System.out.println( "***************************************************" );
+ System.out.println( "" );
+ System.out.println( "*******************************" );
+ System.out.println( "*********** Phase 1 ***********" );
+ System.out.println( "*******************************" );
+ System.out.println( " Creating MBeanServer " );
+ System.out.print( " Register LoggingMXBean: " );
+ MBeanServer mbs = MBeanServerFactory.createMBeanServer();
+ String[] list = new String[0];
+
+ try {
+ objectName = new ObjectName(LogManager.LOGGING_MXBEAN_NAME);
+ mBean = LogManager.getLoggingMXBean();
+ mbs.registerMBean( mBean, objectName );
+ }
+ catch ( Exception e ) {
+ System.out.println( "FAILED" );
+ throw e;
+ }
+ System.out.println( "PASSED" );
+ System.out.println("");
+
+ /*
+ * Access our MBean to get the current list of Loggers
+ */
+ System.out.println( "*******************************" );
+ System.out.println( "*********** Phase 2 ***********" );
+ System.out.println( "*******************************" );
+ System.out.println( " Test Logger Name retrieval (getLoggerNames) " );
+ // check that Level object are returned properly
+ try {
+ list = (String[]) mbs.getAttribute( objectName, "LoggerNames" );
+ }
+ catch ( Exception e ) {
+ System.out.println(" : FAILED" );
+ throw e;
+ }
+
+ /*
+ * Dump the list of Loggers already present, if any
+ */
+ Object[] params = new Object[1];
+ String[] signature = new String[1];
+ Level l;
+
+ if ( list == null ) {
+ System.out.println(" : PASSED. No Standard Loggers Present" );
+ System.out.println("");
+ }
+ else {
+ System.out.println(" : PASSED. There are " + list.length + " Loggers Present" );
+ System.out.println("");
+ System.out.println( "*******************************" );
+ System.out.println( "*********** Phase 2B **********" );
+ System.out.println( "*******************************" );
+ System.out.println( " Examine Existing Loggers" );
+ for ( int i = 0; i < list.length; i++ ) {
+ try {
+ params[0] = list[i];
+ signature[0] = "java.lang.String";
+ String levelName = (String) mbs.invoke( objectName, "getLoggerLevel", params, signature );
+ System.out.println(" : Logger #" + i + " = " + list[i] );
+ System.out.println(" : Level = " + levelName );
+ }
+ catch ( Exception e ) {
+ System.out.println(" : FAILED" );
+ throw e;
+ }
+ }
+ System.out.println(" : PASSED" );
+ }
+
+ /*
+ * Create two new loggers to the list of Loggers already present
+ */
+ System.out.println("");
+ System.out.println( "*******************************" );
+ System.out.println( "*********** Phase 3 ***********" );
+ System.out.println( "*******************************" );
+ System.out.println( " Create and test new Loggers" );
+ Logger logger1 = Logger.getLogger( LOGGER_NAME_1 );
+ Logger logger2 = Logger.getLogger( LOGGER_NAME_2 );
+
+ // check that Level object are returned properly
+ try {
+ list = (String[]) mbs.getAttribute( objectName, "LoggerNames" );
+ }
+ catch ( Exception e ) {
+ System.out.println(" : FAILED" );
+ throw e;
+ }
+
+ /*
+ * Check for the existence of our new Loggers
+ */
+ boolean log1 = false, log2 = false;
+
+ if ( list == null || list.length < 2 ) {
+ System.out.println(" : FAILED. Could not Detect the presense of the new Loggers" );
+ throw new RuntimeException(
+ "Could not Detect the presense of the new Loggers");
+ }
+ else {
+ for ( int i = 0; i < list.length; i++ ) {
+ if ( list[i].equals( LOGGER_NAME_1 ) ) {
+ log1 = true;
+ System.out.println( " : Found new Logger : " + list[i] );
+ }
+ if ( list[i].equals( LOGGER_NAME_2 ) ) {
+ log2 = true;
+ System.out.println( " : Found new Logger : " + list[i] );
+ }
+ }
+ if ( log1 && log2 )
+ System.out.println( " : PASSED." );
+ else {
+ System.out.println( " : FAILED. Could not Detect the new Loggers." );
+ throw new RuntimeException(
+ "Could not Detect the presense of the new Loggers");
+ }
+ }
+
+ /*
+ * Set a new Logging levels and check that it succeeded
+ */
+ System.out.println("");
+ System.out.println( "*******************************" );
+ System.out.println( "*********** Phase 4 ***********" );
+ System.out.println( "*******************************" );
+ System.out.println( " Set and Check the Logger Level" );
+ log1 = false;
+ log2 = false;
+ try {
+ // Set the level of logger1 to ALL
+ params = new Object[2];
+ signature = new String[2];
+ params[0] = LOGGER_NAME_1;
+ params[1] = Level.ALL.getName();
+ signature[0] = "java.lang.String";
+ signature[1] = "java.lang.String";
+ mbs.invoke( objectName, "setLoggerLevel", params, signature );
+
+ // Set the level of logger2 to FINER
+ params[0] = LOGGER_NAME_2;
+ params[1] = Level.FINER.getName();
+ mbs.invoke( objectName, "setLoggerLevel", params, signature );
+
+ // Okay read back the Level from Logger1. Should be ALL
+ params = new Object[1];
+ signature = new String[1];
+ params[0] = LOGGER_NAME_1;
+ signature[0] = "java.lang.String";
+ String levelName = (String) mbs.invoke( objectName, "getLoggerLevel", params, signature );
+ l = Level.parse(levelName);
+ System.out.print(" Logger1: " );
+ if ( l.equals( l.ALL ) ) {
+ System.out.println("Level Set to ALL: PASSED" );
+ log1 = true;
+ }
+ else {
+ System.out.println("Level Set to ALL: FAILED" );
+ throw new RuntimeException(
+ "Level Set to ALL but returned " + l.toString());
+ }
+
+ // Okay read back the Level from Logger2. Should be FINER
+ params = new Object[1];
+ signature = new String[1];
+ params[0] = LOGGER_NAME_2;
+ signature[0] = "java.lang.String";
+ levelName = (String) mbs.invoke( objectName, "getLoggerLevel", params, signature );
+ l = Level.parse(levelName);
+ System.out.print(" Logger2: " );
+ if ( l.equals( l.FINER ) ) {
+ System.out.println("Level Set to FINER: PASSED" );
+ log2 = true;
+ }
+ else {
+ System.out.println("Level Set to FINER: FAILED" );
+ throw new RuntimeException(
+ "Level Set to FINER but returned " + l.toString());
+ }
+ }
+ catch ( Exception e ) {
+ throw e;
+ }
+
+ System.out.println( "" );
+ System.out.println( "***************************************************" );
+ System.out.println( "***************** All Tests Passed ****************" );
+ System.out.println( "***************************************************" );
+ }
+
+ public static void main(String[] argv) throws Exception {
+ LoggingMXBeanTest p = new LoggingMXBeanTest();
+ }
+}
diff --git a/test/java/util/logging/LoggingMXBeanTest2.java b/test/java/util/logging/LoggingMXBeanTest2.java
new file mode 100644
index 0000000..8eeef68
--- /dev/null
+++ b/test/java/util/logging/LoggingMXBeanTest2.java
@@ -0,0 +1,190 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc. 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 5007165
+ * @summary Basic Test for LoggingMXBean (direct access to MXBean)
+ * @author Mandy Chung
+ *
+ * @build LoggingMXBeanTest2
+ * @run main LoggingMXBeanTest2
+ */
+
+import java.util.logging.*;
+import java.util.List;
+import java.util.ListIterator;
+
+public class LoggingMXBeanTest2
+{
+
+ static LoggingMXBean mbean = LogManager.getLoggingMXBean();
+ static String LOGGER_NAME_1 = "com.sun.management.Logger";
+ static String LOGGER_NAME_2 = "com.sun.management.Logger.Logger2";
+ static String UNKNOWN_LOGGER_NAME = "com.sun.management.Unknown";
+
+ public LoggingMXBeanTest2() throws Exception {
+
+ Logger logger1 = Logger.getLogger( LOGGER_NAME_1 );
+ logger1.setLevel(Level.FINE);
+ Logger logger2 = Logger.getLogger( LOGGER_NAME_2 );
+ logger2.setLevel(null);
+
+ /*
+ * Check for the existence of our new Loggers
+ */
+ System.out.println("Test Logger Name retrieval (getLoggerNames)");
+ boolean log1 = false, log2 = false;
+ List loggers = mbean.getLoggerNames();
+ if (loggers == null || loggers.size() < 2) {
+ throw new RuntimeException(
+ "Could not Detect the presense of the new Loggers");
+ }
+
+ for (ListIterator iter = loggers.listIterator(); iter.hasNext(); ) {
+ String logger = (String) iter.next();
+ if (logger.equals(LOGGER_NAME_1)) {
+ log1 = true;
+ System.out.println(" : Found new Logger : " + logger);
+ }
+ if (logger.equals(LOGGER_NAME_2)) {
+ log2 = true;
+ System.out.println(" : Found new Logger : " + logger);
+ }
+ }
+ if ( log1 && log2 )
+ System.out.println(" : PASSED." );
+ else {
+ System.out.println(" : FAILED. Could not Detect the new Loggers." );
+ throw new RuntimeException(
+ "Could not Detect the presense of the new Loggers");
+ }
+
+ System.out.println("Test getLoggerLevel");
+ String l1 = mbean.getLoggerLevel(LOGGER_NAME_1);
+ System.out.println(" : Level for Logger " + LOGGER_NAME_1 + " : " + l1);
+ if (!l1.equals(Level.FINE.getName())) {
+ throw new RuntimeException(
+ "Expected level for " + LOGGER_NAME_1 + " = " +
+ Level.FINE.getName() + " but got " + l1);
+ }
+ String l2 = mbean.getLoggerLevel(LOGGER_NAME_2);
+ System.out.println(" : Level for Logger " + LOGGER_NAME_2 + " : " + l2);
+ if (!l2.equals("")) {
+ throw new RuntimeException(
+ "Expected level for " + LOGGER_NAME_2 + " = \"\"" +
+ " but got " + l2);
+ }
+ String l3 = mbean.getLoggerLevel(UNKNOWN_LOGGER_NAME);
+ System.out.println(" : Level for unknown logger : " + l3);
+ if (l3 != null) {
+ throw new RuntimeException(
+ "Expected level for " + UNKNOWN_LOGGER_NAME + " = null" +
+ " but got " + l3);
+ }
+
+ System.out.println("Test setLoggerLevel");
+ mbean.setLoggerLevel(LOGGER_NAME_1, "INFO");
+ System.out.println(" : Set Level for Logger " + LOGGER_NAME_1 + " to: INFO");
+ Level l = logger1.getLevel();
+ if (l != Level.INFO) {
+ throw new RuntimeException(
+ "Expected level for " + LOGGER_NAME_1 + " = " +
+ Level.INFO + " but got " + l);
+ }
+
+ mbean.setLoggerLevel(LOGGER_NAME_2, "SEVERE");
+ System.out.println(" : Set Level for Logger " + LOGGER_NAME_2 + " to: SERVER");
+ l = logger2.getLevel();
+ if (l != Level.SEVERE) {
+ throw new RuntimeException(
+ "Expected level for " + LOGGER_NAME_2 + " = " +
+ Level.SEVERE+ " but got " + l);
+ }
+
+ mbean.setLoggerLevel(LOGGER_NAME_1, null);
+ System.out.println(" : Set Level for Logger " + LOGGER_NAME_1 + " to: null");
+ l = logger1.getLevel();
+ if (l != null) {
+ throw new RuntimeException(
+ "Expected level for " + LOGGER_NAME_1 + " = null " +
+ " but got " + l);
+ }
+
+ boolean iaeCaught = false;
+ System.out.println(" : Set Level for unknown Logger to: FINE");
+ try {
+ mbean.setLoggerLevel(UNKNOWN_LOGGER_NAME, "FINE");
+ } catch (IllegalArgumentException e) {
+ // expected
+ iaeCaught = true;
+ System.out.println(" : IllegalArgumentException caught as expected");
+ }
+ if (!iaeCaught) {
+ throw new RuntimeException(
+ "Expected IllegalArgumentException for setting level for " +
+ UNKNOWN_LOGGER_NAME + " not thrown");
+ }
+ iaeCaught = false;
+ System.out.println(" : Set Level for Logger " + LOGGER_NAME_1 + " to: DUMMY");
+ try {
+ mbean.setLoggerLevel(LOGGER_NAME_1, "DUMMY");
+ } catch (IllegalArgumentException e) {
+ // expected
+ iaeCaught = true;
+ System.out.println(" : IllegalArgumentException caught as expected");
+ }
+ if (!iaeCaught) {
+ throw new RuntimeException(
+ "Expected IllegalArgumentException for invalid level.");
+ }
+
+
+ System.out.println("Test getParentLoggerName");
+ String p1 = mbean.getParentLoggerName(LOGGER_NAME_2);
+ System.out.println(" : Parent Logger for " + LOGGER_NAME_2 + " : " + p1);
+ if (!p1.equals(LOGGER_NAME_1)) {
+ throw new RuntimeException(
+ "Expected parent for " + LOGGER_NAME_2 + " = " +
+ LOGGER_NAME_1 + " but got " + p1);
+ }
+ String p2 = mbean.getParentLoggerName("");
+ System.out.println(" : Parent Logger for \"\" : " + p2);
+ if (!p2.equals("")) {
+ throw new RuntimeException(
+ "Expected parent for root logger \"\" = \"\"" +
+ " but got " + p2);
+ }
+ String p3 = mbean.getParentLoggerName(UNKNOWN_LOGGER_NAME);
+ System.out.println(" : Parent Logger for unknown logger : " + p3);
+ if (p3 != null) {
+ throw new RuntimeException(
+ "Expected level for " + UNKNOWN_LOGGER_NAME + " = null" +
+ " but got " + p3);
+ }
+ }
+
+ public static void main(String[] argv) throws Exception {
+ LoggingMXBeanTest2 p = new LoggingMXBeanTest2();
+ }
+}
diff --git a/test/java/util/logging/LoggingNIOChange.java b/test/java/util/logging/LoggingNIOChange.java
new file mode 100644
index 0000000..be43b70
--- /dev/null
+++ b/test/java/util/logging/LoggingNIOChange.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc. 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ @test
+ @bug 4948142
+ @summary test NIO changes don't generate unchecked exceptions
+ @run main LoggingNIOChange
+*/
+import java.util.logging.*;
+
+public class LoggingNIOChange {
+ public static void main(String args[]) throws Exception {
+ ConsoleHandler console = new ConsoleHandler();
+ XMLFormatter f = new XMLFormatter();
+ try {
+ console.setEncoding("junk");
+ f.getHead(console);
+ console.setEncoding(null);
+ f.getHead(console);
+ }catch (java.io.UnsupportedEncodingException e) {
+ }
+ }
+}
diff --git a/test/java/util/logging/ParentLoggersTest.java b/test/java/util/logging/ParentLoggersTest.java
new file mode 100644
index 0000000..2f4a434
--- /dev/null
+++ b/test/java/util/logging/ParentLoggersTest.java
@@ -0,0 +1,148 @@
+/*
+ * @test
+ * @bug 6498300
+ *
+ * @summary regression: parent loggers are not properly registered
+ * @author ss45998
+ *
+ * @build ParentLoggersTest
+ * @run main ParentLoggersTest
+ */
+
+/*
+ * There are several original tests which were failed when
+ * this regression was introduced. This is an extra test
+ * to ensure that the parent loggers with the defined
+ * .level property are implicitly registered.
+ */
+
+import java.util.*;
+import java.io.*;
+import java.util.logging.*;
+
+public class ParentLoggersTest {
+ static final LogManager logMgr = LogManager.getLogManager();
+ static final PrintStream out = System.out;
+
+ static final boolean PASSED = true;
+ static final boolean FAILED = false;
+ static final String MSG_PASSED = "ParentLoggersTest: passed";
+ static final String MSG_FAILED = "ParentLoggersTest: failed";
+
+ /* Properties */
+ static final String TST_SRC_PROP = "test.src";
+ static final String CFG_FILE_PROP = "java.util.logging.config.file";
+ static final String LM_PROP_FNAME = "ParentLoggersTest.props";
+
+ /* Logger names */
+ static final String PARENT_NAME_1 = "myParentLogger";
+ static final String PARENT_NAME_2 = "abc.xyz.foo";
+ static final String LOGGER_NAME_1 = PARENT_NAME_1 + ".myLogger";
+ static final String LOGGER_NAME_2 = PARENT_NAME_2 + ".myBar.myLogger";
+
+ public static void main(String args[]) throws Exception {
+ String tstSrc = System.getProperty(TST_SRC_PROP);
+ File fname = new File(tstSrc, LM_PROP_FNAME);
+ String prop = fname.getCanonicalPath();
+ System.setProperty(CFG_FILE_PROP, prop);
+ logMgr.readConfiguration();
+
+ System.out.println();
+ if (checkLoggers() == PASSED) {
+ System.out.println(MSG_PASSED);
+ } else {
+ System.out.println(MSG_FAILED);
+ throw new Exception(MSG_FAILED);
+ }
+ }
+
+ public static Vector getDefaultLoggerNames() {
+ Vector expectedLoggerNames = new Vector(0);
+
+ // LogManager always creates two loggers:
+ expectedLoggerNames.addElement(""); // root logger: ""
+ expectedLoggerNames.addElement("global"); // global logger: "global"
+ return expectedLoggerNames;
+ }
+
+ /* Check: getLoggerNames() must return correct names
+ * for registered loggers and their parents.
+ * Returns boolean values: PASSED or FAILED
+ */
+ public static boolean checkLoggers() {
+ String failMsg = "# checkLoggers: getLoggerNames() returned unexpected loggers";
+ Vector expectedLoggerNames = getDefaultLoggerNames();
+
+ // Create the logger LOGGER_NAME_1
+ Logger logger1 = Logger.getLogger(LOGGER_NAME_1);
+ expectedLoggerNames.addElement(PARENT_NAME_1);
+ expectedLoggerNames.addElement(LOGGER_NAME_1);
+
+ // Create the logger LOGGER_NAME_2
+ Logger logger2 = Logger.getLogger(LOGGER_NAME_2);
+ expectedLoggerNames.addElement(PARENT_NAME_2);
+ expectedLoggerNames.addElement(LOGGER_NAME_2);
+
+ Enumeration returnedLoggersEnum = logMgr.getLoggerNames();
+ Vector returnedLoggerNames = new Vector(0);
+ while (returnedLoggersEnum.hasMoreElements()) {
+ returnedLoggerNames.addElement(returnedLoggersEnum.nextElement());
+ };
+
+ return checkNames(expectedLoggerNames, returnedLoggerNames, failMsg);
+ }
+
+ // Returns boolean values: PASSED or FAILED
+ private static boolean checkNames(Vector expNames,
+ Vector retNames,
+ String failMsg) {
+ boolean status = PASSED;
+
+ if (expNames.size() != retNames.size()) {
+ status = FAILED;
+ } else {
+ boolean checked[] = new boolean[retNames.size()];
+ for (int i = 0; i < expNames.size(); i++) {
+ int j = 0;
+ for (; j < retNames.size(); j++) {
+ if (!checked[j] &&
+ expNames.elementAt(i).equals(retNames.elementAt(j))) {
+ checked[j] = true;
+ break;
+ }
+ }
+ if (j >= retNames.size()) {
+ status = FAILED;
+ break;
+ }
+ }
+ }
+ if (!status) {
+ printFailMsg(expNames, retNames, failMsg);
+ }
+ return status;
+ }
+
+ private static void printFailMsg(Vector expNames,
+ Vector retNames,
+ String failMsg) {
+ out.println();
+ out.println(failMsg);
+ if (expNames.size() == 0) {
+ out.println("# there are NO expected logger names");
+ } else {
+ out.println("# expected logger names (" + expNames.size() + "):");
+ for (int i = 0; i < expNames.size(); i++) {
+ out.println(" expNames[" + i + "] = " + expNames.elementAt(i));
+ }
+ }
+ if (retNames.size() == 0) {
+ out.println("# there are NO returned logger names");
+ } else {
+ out.println("# returned logger names (" + retNames.size() + "):");
+ for (int i = 0; i < retNames.size(); i++) {
+ out.println(" retNames[" + i + "] = " + retNames.elementAt(i));
+ }
+ }
+ }
+}
diff --git a/test/java/util/logging/ParentLoggersTest.props b/test/java/util/logging/ParentLoggersTest.props
new file mode 100644
index 0000000..20479c7
--- /dev/null
+++ b/test/java/util/logging/ParentLoggersTest.props
@@ -0,0 +1,62 @@
+############################################################
+# Test Logging Configuration File
+#
+# This file is a clone of the Default Logging Configuration File
+#
+# It defines two test specific properties (at the bottom):
+# - myParentLogger.level = INFO
+# - abc.xyz.foo.level = SEVERE
+############################################################
+
+############################################################
+# Global properties
+############################################################
+
+# "handlers" specifies a comma separated list of log Handler
+# classes. These handlers will be installed during VM startup.
+# Note that these classes must be on the system classpath.
+# By default we only configure a ConsoleHandler, which will only
+# show messages at the INFO and above levels.
+handlers= java.util.logging.ConsoleHandler
+
+# To also add the FileHandler, use the following line instead.
+#handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
+
+# Default global logging level.
+# This specifies which kinds of events are logged across
+# all loggers. For any given facility this global level
+# can be overriden by a facility specific level
+# Note that the ConsoleHandler also has a separate level
+# setting to limit messages printed to the console.
+.level= INFO
+
+############################################################
+# Handler specific properties.
+# Describes specific configuration info for Handlers.
+############################################################
+
+# default file output is in user's home directory.
+java.util.logging.FileHandler.pattern = %h/java%u.log
+java.util.logging.FileHandler.limit = 50000
+java.util.logging.FileHandler.count = 1
+java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
+
+# Limit the message that are printed on the console to INFO and above.
+java.util.logging.ConsoleHandler.level = INFO
+java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
+
+
+############################################################
+# Facility specific properties.
+# Provides extra control for each logger.
+############################################################
+
+# For example, set the com.xyz.foo logger to only log SEVERE
+# messages:
+com.xyz.foo.level = SEVERE
+
+############################################################
+# The test specific properties.
+############################################################
+myParentLogger.level = INFO
+abc.xyz.foo.level = SEVERE