You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by pk...@apache.org on 2022/03/13 20:24:56 UTC
[logging-log4j2] branch release-2.x updated: Catch all FileAppenderTest asynchronous errors
This is an automated email from the ASF dual-hosted git repository.
pkarwasz pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/release-2.x by this push:
new 3a146ee Catch all FileAppenderTest asynchronous errors
3a146ee is described below
commit 3a146ee07a092807605e2a34412cc3f550803037
Author: Piotr P. Karwasz <pi...@karwasz.org>
AuthorDate: Sun Mar 13 21:19:34 2022 +0100
Catch all FileAppenderTest asynchronous errors
Assertions are not exceptions, so they were not passed on to the Junit
thread.
---
.../logging/log4j/core/appender/FileAppenderTest.java | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java
index f207f6b..04f9534 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java
@@ -168,17 +168,17 @@ public class FileAppenderTest {
private void testMultipleLockingAppenderThreads(final boolean lock, final int threadCount, boolean createOnDemand)
throws InterruptedException, Exception {
final ExecutorService threadPool = Executors.newFixedThreadPool(threadCount);
- final AtomicReference<Exception> exceptionRef = new AtomicReference<>();
+ final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
final int logEventCount = 100;
- final Runnable runnable = new FileWriterRunnable(createOnDemand, lock, logEventCount, exceptionRef);
+ final Runnable runnable = new FileWriterRunnable(createOnDemand, lock, logEventCount, throwableRef);
for (int i = 0; i < threadCount; ++i) {
threadPool.execute(runnable);
}
threadPool.shutdown();
assertTrue(
threadPool.awaitTermination(10, TimeUnit.SECONDS), "The thread pool has not shutdown: " + threadPool);
- if (exceptionRef.get() != null) {
- throw exceptionRef.get();
+ if (throwableRef.get() != null) {
+ Throwables.rethrow(throwableRef.get());
}
verifyFile(threadCount * logEventCount);
}
@@ -291,14 +291,14 @@ public class FileAppenderTest {
private final boolean createOnDemand;
private final boolean lock;
private final int logEventCount;
- private final AtomicReference<Exception> exceptionRef;
+ private final AtomicReference<Throwable> throwableRef;
public FileWriterRunnable(
- boolean createOnDemand, final boolean lock, final int logEventCount, final AtomicReference<Exception> exceptionRef) {
+ boolean createOnDemand, final boolean lock, final int logEventCount, final AtomicReference<Throwable> throwableRef) {
this.createOnDemand = createOnDemand;
this.lock = lock;
this.logEventCount = logEventCount;
- this.exceptionRef = exceptionRef;
+ this.throwableRef = throwableRef;
}
@Override
@@ -307,9 +307,8 @@ public class FileAppenderTest {
try {
writer(lock, logEventCount, thread.getName(), createOnDemand, true);
- } catch (final Exception e) {
- exceptionRef.set(e);;
- Throwables.rethrow(e);
+ } catch (final Throwable e) {
+ throwableRef.set(e);
}
}
}