|
1 | 1 | /* |
2 | | - * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
@@ -86,7 +86,7 @@ public void run(List<Properties> properties) throws Exception { |
86 | 86 | TIMEOUT_FACTOR = Double.parseDouble(toFactor); |
87 | 87 | } |
88 | 88 | static int adjustCount(int count) { |
89 | | - return (int) Math.ceil(TIMEOUT_FACTOR * count); |
| 89 | + return Math.min(count, (int) Math.ceil(TIMEOUT_FACTOR * count)); |
90 | 90 | } |
91 | 91 |
|
92 | 92 | private static final String PREFIX = |
@@ -211,21 +211,20 @@ static void test(String name, List<Properties> properties) |
211 | 211 |
|
212 | 212 | ReferenceQueue<Logger> queue = new ReferenceQueue(); |
213 | 213 | WeakReference<Logger> fooRef = new WeakReference<>(Logger.getLogger("com.foo"), queue); |
214 | | - if (fooRef.get() != fooChild.getParent()) { |
| 214 | + if (!fooRef.refersTo(fooChild.getParent())) { |
215 | 215 | throw new RuntimeException("Unexpected parent logger: " |
216 | 216 | + fooChild.getParent() +"\n\texpected: " + fooRef.get()); |
217 | 217 | } |
218 | 218 | WeakReference<Logger> barRef = new WeakReference<>(Logger.getLogger("com.bar"), queue); |
219 | | - if (barRef.get() != barChild.getParent()) { |
| 219 | + if (!barRef.refersTo(barChild.getParent())) { |
220 | 220 | throw new RuntimeException("Unexpected parent logger: " |
221 | 221 | + barChild.getParent() +"\n\texpected: " + barRef.get()); |
222 | 222 | } |
223 | 223 | Reference<? extends Logger> ref2; |
224 | | - int max = adjustCount(3); |
| 224 | + int max = adjustCount(6); |
225 | 225 | barChild = null; |
226 | | - while ((ref2 = queue.poll()) == null) { |
| 226 | + while ((ref2 = queue.remove(500)) == null) { |
227 | 227 | System.gc(); |
228 | | - Thread.sleep(1000); |
229 | 228 | if (--max == 0) break; |
230 | 229 | } |
231 | 230 |
|
@@ -347,7 +346,7 @@ static void test(String name, List<Properties> properties) |
347 | 346 | throw new RuntimeException("Unexpected reference: " |
348 | 347 | + ref2 +"\n\texpected: " + fooRef); |
349 | 348 | } |
350 | | - if (ref2.get() != null) { |
| 349 | + if (!ref2.refersTo(null)) { |
351 | 350 | throw new RuntimeException("Referent not cleared: " + ref2.get()); |
352 | 351 | } |
353 | 352 | System.out.println("Got fooRef after reset(), fooChild is " + fooChild); |
|
0 commit comments