Skip to content

Commit d02cb74

Browse files
committedJun 6, 2024
8333270: HandlersOnComplexResetUpdate and HandlersOnComplexUpdate tests fail with "Unexpected reference" if timeoutFactor is less than 1/3
Reviewed-by: jpai
1 parent 02f2404 commit d02cb74

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed
 

‎test/jdk/java/util/logging/LogManager/Configuration/updateConfiguration/HandlersOnComplexResetUpdate.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* 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 {
8686
TIMEOUT_FACTOR = Double.parseDouble(toFactor);
8787
}
8888
static int adjustCount(int count) {
89-
return (int) Math.ceil(TIMEOUT_FACTOR * count);
89+
return Math.min(count, (int) Math.ceil(TIMEOUT_FACTOR * count));
9090
}
9191

9292
private static final String PREFIX =
@@ -211,21 +211,20 @@ static void test(String name, List<Properties> properties)
211211

212212
ReferenceQueue<Logger> queue = new ReferenceQueue();
213213
WeakReference<Logger> fooRef = new WeakReference<>(Logger.getLogger("com.foo"), queue);
214-
if (fooRef.get() != fooChild.getParent()) {
214+
if (!fooRef.refersTo(fooChild.getParent())) {
215215
throw new RuntimeException("Unexpected parent logger: "
216216
+ fooChild.getParent() +"\n\texpected: " + fooRef.get());
217217
}
218218
WeakReference<Logger> barRef = new WeakReference<>(Logger.getLogger("com.bar"), queue);
219-
if (barRef.get() != barChild.getParent()) {
219+
if (!barRef.refersTo(barChild.getParent())) {
220220
throw new RuntimeException("Unexpected parent logger: "
221221
+ barChild.getParent() +"\n\texpected: " + barRef.get());
222222
}
223223
Reference<? extends Logger> ref2;
224-
int max = adjustCount(3);
224+
int max = adjustCount(6);
225225
barChild = null;
226-
while ((ref2 = queue.poll()) == null) {
226+
while ((ref2 = queue.remove(500)) == null) {
227227
System.gc();
228-
Thread.sleep(1000);
229228
if (--max == 0) break;
230229
}
231230

@@ -347,7 +346,7 @@ static void test(String name, List<Properties> properties)
347346
throw new RuntimeException("Unexpected reference: "
348347
+ ref2 +"\n\texpected: " + fooRef);
349348
}
350-
if (ref2.get() != null) {
349+
if (!ref2.refersTo(null)) {
351350
throw new RuntimeException("Referent not cleared: " + ref2.get());
352351
}
353352
System.out.println("Got fooRef after reset(), fooChild is " + fooChild);

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* 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 {
8686
TIMEOUT_FACTOR = Double.parseDouble(toFactor);
8787
}
8888
static int adjustCount(int count) {
89-
return (int) Math.ceil(TIMEOUT_FACTOR * count);
89+
return Math.min(count, (int) Math.ceil(TIMEOUT_FACTOR * count));
9090
}
9191

9292
private static final String PREFIX =
@@ -211,21 +211,20 @@ static void test(String name, List<Properties> properties)
211211

212212
ReferenceQueue<Logger> queue = new ReferenceQueue();
213213
WeakReference<Logger> fooRef = new WeakReference<>(Logger.getLogger("com.foo"), queue);
214-
if (fooRef.get() != fooChild.getParent()) {
214+
if (!fooRef.refersTo(fooChild.getParent())) {
215215
throw new RuntimeException("Unexpected parent logger: "
216216
+ fooChild.getParent() +"\n\texpected: " + fooRef.get());
217217
}
218218
WeakReference<Logger> barRef = new WeakReference<>(Logger.getLogger("com.bar"), queue);
219-
if (barRef.get() != barChild.getParent()) {
219+
if (!barRef.refersTo(barChild.getParent())) {
220220
throw new RuntimeException("Unexpected parent logger: "
221221
+ barChild.getParent() +"\n\texpected: " + barRef.get());
222222
}
223223
Reference<? extends Logger> ref2;
224-
int max = adjustCount(3);
224+
int max = adjustCount(6);
225225
barChild = null;
226-
while ((ref2 = queue.poll()) == null) {
226+
while ((ref2 = queue.remove(500)) == null) {
227227
System.gc();
228-
Thread.sleep(1000);
229228
if (--max == 0) break;
230229
}
231230

@@ -335,7 +334,7 @@ static void test(String name, List<Properties> properties)
335334
throw new RuntimeException("Unexpected reference: "
336335
+ ref2 +"\n\texpected: " + fooRef);
337336
}
338-
if (ref2.get() != null) {
337+
if (!ref2.refersTo(null)) {
339338
throw new RuntimeException("Referent not cleared: " + ref2.get());
340339
}
341340
System.out.println("Got fooRef after reset(), fooChild is " + fooChild);

0 commit comments

Comments
 (0)
Please sign in to comment.