diff --git a/test/jdk/java/util/logging/LogManager/Configuration/updateConfiguration/HandlersOnComplexResetUpdate.java b/test/jdk/java/util/logging/LogManager/Configuration/updateConfiguration/HandlersOnComplexResetUpdate.java index f0796bed901..032457aedb3 100644 --- a/test/jdk/java/util/logging/LogManager/Configuration/updateConfiguration/HandlersOnComplexResetUpdate.java +++ b/test/jdk/java/util/logging/LogManager/Configuration/updateConfiguration/HandlersOnComplexResetUpdate.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -86,7 +86,7 @@ public class HandlersOnComplexResetUpdate { TIMEOUT_FACTOR = Double.parseDouble(toFactor); } static int adjustCount(int count) { - return (int) Math.ceil(TIMEOUT_FACTOR * count); + return Math.min(count, (int) Math.ceil(TIMEOUT_FACTOR * count)); } private static final String PREFIX = @@ -211,21 +211,20 @@ public class HandlersOnComplexResetUpdate { ReferenceQueue queue = new ReferenceQueue(); WeakReference fooRef = new WeakReference<>(Logger.getLogger("com.foo"), queue); - if (fooRef.get() != fooChild.getParent()) { + if (!fooRef.refersTo(fooChild.getParent())) { throw new RuntimeException("Unexpected parent logger: " + fooChild.getParent() +"\n\texpected: " + fooRef.get()); } WeakReference barRef = new WeakReference<>(Logger.getLogger("com.bar"), queue); - if (barRef.get() != barChild.getParent()) { + if (!barRef.refersTo(barChild.getParent())) { throw new RuntimeException("Unexpected parent logger: " + barChild.getParent() +"\n\texpected: " + barRef.get()); } Reference ref2; - int max = adjustCount(3); + int max = adjustCount(6); barChild = null; - while ((ref2 = queue.poll()) == null) { + while ((ref2 = queue.remove(500)) == null) { System.gc(); - Thread.sleep(1000); if (--max == 0) break; } @@ -347,7 +346,7 @@ public class HandlersOnComplexResetUpdate { throw new RuntimeException("Unexpected reference: " + ref2 +"\n\texpected: " + fooRef); } - if (ref2.get() != null) { + if (!ref2.refersTo(null)) { throw new RuntimeException("Referent not cleared: " + ref2.get()); } System.out.println("Got fooRef after reset(), fooChild is " + fooChild); diff --git a/test/jdk/java/util/logging/LogManager/Configuration/updateConfiguration/HandlersOnComplexUpdate.java b/test/jdk/java/util/logging/LogManager/Configuration/updateConfiguration/HandlersOnComplexUpdate.java index a8d3240b976..2f9f360d7d4 100644 --- a/test/jdk/java/util/logging/LogManager/Configuration/updateConfiguration/HandlersOnComplexUpdate.java +++ b/test/jdk/java/util/logging/LogManager/Configuration/updateConfiguration/HandlersOnComplexUpdate.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -86,7 +86,7 @@ public class HandlersOnComplexUpdate { TIMEOUT_FACTOR = Double.parseDouble(toFactor); } static int adjustCount(int count) { - return (int) Math.ceil(TIMEOUT_FACTOR * count); + return Math.min(count, (int) Math.ceil(TIMEOUT_FACTOR * count)); } private static final String PREFIX = @@ -211,21 +211,20 @@ public class HandlersOnComplexUpdate { ReferenceQueue queue = new ReferenceQueue(); WeakReference fooRef = new WeakReference<>(Logger.getLogger("com.foo"), queue); - if (fooRef.get() != fooChild.getParent()) { + if (!fooRef.refersTo(fooChild.getParent())) { throw new RuntimeException("Unexpected parent logger: " + fooChild.getParent() +"\n\texpected: " + fooRef.get()); } WeakReference barRef = new WeakReference<>(Logger.getLogger("com.bar"), queue); - if (barRef.get() != barChild.getParent()) { + if (!barRef.refersTo(barChild.getParent())) { throw new RuntimeException("Unexpected parent logger: " + barChild.getParent() +"\n\texpected: " + barRef.get()); } Reference ref2; - int max = adjustCount(3); + int max = adjustCount(6); barChild = null; - while ((ref2 = queue.poll()) == null) { + while ((ref2 = queue.remove(500)) == null) { System.gc(); - Thread.sleep(1000); if (--max == 0) break; } @@ -335,7 +334,7 @@ public class HandlersOnComplexUpdate { throw new RuntimeException("Unexpected reference: " + ref2 +"\n\texpected: " + fooRef); } - if (ref2.get() != null) { + if (!ref2.refersTo(null)) { throw new RuntimeException("Referent not cleared: " + ref2.get()); } System.out.println("Got fooRef after reset(), fooChild is " + fooChild);