< prev index next >

test/jdk/java/util/logging/LogManager/Configuration/updateConfiguration/HandlersOnComplexUpdate.java

Print this page


   1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  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  */


 200         fooChild.info("hello world");
 201         Logger barChild = Logger.getLogger("com.bar.child");
 202         barChild.info("hello world");
 203 
 204         ReferenceQueue<Logger> queue = new ReferenceQueue();
 205         WeakReference<Logger> fooRef = new WeakReference<>(Logger.getLogger("com.foo"), queue);
 206         if (fooRef.get() != fooChild.getParent()) {
 207             throw new RuntimeException("Unexpected parent logger: "
 208                     + fooChild.getParent() +"\n\texpected: " + fooRef.get());
 209         }
 210         WeakReference<Logger> barRef = new WeakReference<>(Logger.getLogger("com.bar"), queue);
 211         if (barRef.get() != barChild.getParent()) {
 212             throw new RuntimeException("Unexpected parent logger: "
 213                     + barChild.getParent() +"\n\texpected: " + barRef.get());
 214         }
 215         Reference<? extends Logger> ref2;
 216         int max = 3;
 217         barChild = null;
 218         while ((ref2 = queue.poll()) == null) {
 219             System.gc();
 220             Thread.sleep(100);
 221             if (--max == 0) break;
 222         }
 223 
 224         Throwable failed = null;
 225         try {
 226             if (ref2 != null) {
 227                 String refName = ref2 == fooRef ? "fooRef" : ref2 == barRef ? "barRef" : "unknown";
 228                 if (ref2 != barRef) {
 229                     throw new RuntimeException("Unexpected logger reference cleared: " + refName);
 230                 } else {
 231                     System.out.println("Reference " + refName + " cleared as expected");
 232                 }
 233             } else if (ref2 == null) {
 234                 throw new RuntimeException("Expected 'barRef' to be cleared");
 235             }
 236             // Now lets try to check handlers, and
 237             // attempt to update the configuration again.
 238             Properties previousProps  = properties.get(0);
 239             int expectedHandlersCount = 1;
 240             boolean checkHandlersOnParent = Boolean.parseBoolean(


 299                 try {
 300                     StringBuilder builder = new StringBuilder();
 301                     Files.list(Paths.get(userDir))
 302                         .filter((f) -> f.toString().contains(PREFIX))
 303                         .filter((f) -> f.toString().endsWith(".lck"))
 304                         .forEach((f) -> {
 305                                 builder.append(f.toString()).append('\n');
 306                         });
 307                     if (!builder.toString().isEmpty()) {
 308                         throw new RuntimeException("Lock files not cleaned:\n"
 309                                 + builder.toString());
 310                     }
 311                 } catch(RuntimeException | Error x) {
 312                     if (suppressed != null) x.addSuppressed(suppressed);
 313                     throw x;
 314                 } catch(Exception x) {
 315                     if (suppressed != null) x.addSuppressed(suppressed);
 316                     throw new RuntimeException(x);
 317                 }
 318             });

 319             fooChild = null;
 320             System.out.println("Setting fooChild to: " + fooChild);
 321             while ((ref2 = queue.poll()) == null) {
 322                 System.gc();
 323                 Thread.sleep(1000);
 324             }
 325             if (ref2 != fooRef) {
 326                 throw new RuntimeException("Unexpected reference: "
 327                         + ref2 +"\n\texpected: " + fooRef);
 328             }
 329             if (ref2.get() != null) {
 330                 throw new RuntimeException("Referent not cleared: " + ref2.get());
 331             }
 332             System.out.println("Got fooRef after reset(), fooChild is " + fooChild);
 333 



 334         }
 335         if (failed != null) {
 336             // should rarely happen...
 337             throw new RuntimeException(failed);
 338         }
 339 
 340     }
 341 
 342     public static void main(String... args) throws Exception {
 343 
 344 
 345         if (args == null || args.length == 0) {
 346             args = new String[] {
 347                 TestCase.UNSECURE.name(),
 348                 TestCase.SECURE.name(),
 349             };
 350         }
 351 
 352         try {
 353             for (String testName : args) {


   1 /*
   2  * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  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  */


 200         fooChild.info("hello world");
 201         Logger barChild = Logger.getLogger("com.bar.child");
 202         barChild.info("hello world");
 203 
 204         ReferenceQueue<Logger> queue = new ReferenceQueue();
 205         WeakReference<Logger> fooRef = new WeakReference<>(Logger.getLogger("com.foo"), queue);
 206         if (fooRef.get() != fooChild.getParent()) {
 207             throw new RuntimeException("Unexpected parent logger: "
 208                     + fooChild.getParent() +"\n\texpected: " + fooRef.get());
 209         }
 210         WeakReference<Logger> barRef = new WeakReference<>(Logger.getLogger("com.bar"), queue);
 211         if (barRef.get() != barChild.getParent()) {
 212             throw new RuntimeException("Unexpected parent logger: "
 213                     + barChild.getParent() +"\n\texpected: " + barRef.get());
 214         }
 215         Reference<? extends Logger> ref2;
 216         int max = 3;
 217         barChild = null;
 218         while ((ref2 = queue.poll()) == null) {
 219             System.gc();
 220             Thread.sleep(1000);
 221             if (--max == 0) break;
 222         }
 223 
 224         Throwable failed = null;
 225         try {
 226             if (ref2 != null) {
 227                 String refName = ref2 == fooRef ? "fooRef" : ref2 == barRef ? "barRef" : "unknown";
 228                 if (ref2 != barRef) {
 229                     throw new RuntimeException("Unexpected logger reference cleared: " + refName);
 230                 } else {
 231                     System.out.println("Reference " + refName + " cleared as expected");
 232                 }
 233             } else if (ref2 == null) {
 234                 throw new RuntimeException("Expected 'barRef' to be cleared");
 235             }
 236             // Now lets try to check handlers, and
 237             // attempt to update the configuration again.
 238             Properties previousProps  = properties.get(0);
 239             int expectedHandlersCount = 1;
 240             boolean checkHandlersOnParent = Boolean.parseBoolean(


 299                 try {
 300                     StringBuilder builder = new StringBuilder();
 301                     Files.list(Paths.get(userDir))
 302                         .filter((f) -> f.toString().contains(PREFIX))
 303                         .filter((f) -> f.toString().endsWith(".lck"))
 304                         .forEach((f) -> {
 305                                 builder.append(f.toString()).append('\n');
 306                         });
 307                     if (!builder.toString().isEmpty()) {
 308                         throw new RuntimeException("Lock files not cleaned:\n"
 309                                 + builder.toString());
 310                     }
 311                 } catch(RuntimeException | Error x) {
 312                     if (suppressed != null) x.addSuppressed(suppressed);
 313                     throw x;
 314                 } catch(Exception x) {
 315                     if (suppressed != null) x.addSuppressed(suppressed);
 316                     throw new RuntimeException(x);
 317                 }
 318             });
 319             try {
 320                 fooChild = null;
 321                 System.out.println("Setting fooChild to: " + fooChild);
 322                 while ((ref2 = queue.poll()) == null) {
 323                     System.gc();
 324                     Thread.sleep(1000);
 325                 }
 326                 if (ref2 != fooRef) {
 327                     throw new RuntimeException("Unexpected reference: "
 328                             + ref2 +"\n\texpected: " + fooRef);
 329                 }
 330                 if (ref2.get() != null) {
 331                     throw new RuntimeException("Referent not cleared: " + ref2.get());
 332                 }
 333                 System.out.println("Got fooRef after reset(), fooChild is " + fooChild);
 334            } catch (Throwable t) {
 335                if (failed != null) t.addSuppressed(failed);
 336                throw t;
 337            }
 338         }
 339         if (failed != null) {
 340             // should rarely happen...
 341             throw new RuntimeException(failed);
 342         }
 343 
 344     }
 345 
 346     public static void main(String... args) throws Exception {
 347 
 348 
 349         if (args == null || args.length == 0) {
 350             args = new String[] {
 351                 TestCase.UNSECURE.name(),
 352                 TestCase.SECURE.name(),
 353             };
 354         }
 355 
 356         try {
 357             for (String testName : args) {


< prev index next >