This is an automated email from the ASF dual-hosted git repository.
pkarwasz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/main by this push:
new a61678df1d Try fixing `AsyncThreadContext*` tests
a61678df1d is described below
commit a61678df1d84601005a93af04e1eefaea27fe261
Author: Piotr P. Karwasz <[email protected]>
AuthorDate: Tue Apr 16 15:20:45 2024 +0200
Try fixing `AsyncThreadContext*` tests
---
.../log4j/async/logger/AsyncThreadContextTest.java | 26 ++++++++++++++--------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git
a/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncThreadContextTest.java
b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncThreadContextTest.java
index 7aabf10461..ea3c345cce 100644
---
a/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncThreadContextTest.java
+++
b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncThreadContextTest.java
@@ -31,6 +31,7 @@ import org.apache.logging.log4j.ThreadContext;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.ThreadContextTestAccess;
+import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.impl.Log4jContextFactory;
import org.apache.logging.log4j.core.selector.ClassLoaderContextSelector;
import org.apache.logging.log4j.core.selector.ContextSelector;
@@ -141,6 +142,20 @@ public class AsyncThreadContextTest {
runTest(context, contextImpl, asyncMode, testLoggingPath);
}
+ private static LongSupplier remainingCapacity(final LoggerContext
loggerContext, final LoggerConfig loggerConfig) {
+ final LongSupplier contextSupplier = loggerContext instanceof final
AsyncLoggerContext asyncLoggerContext
+ ?
asyncLoggerContext.getAsyncLoggerDisruptor().getRingBuffer()::remainingCapacity
+ : null;
+ if (loggerConfig instanceof final AsyncLoggerConfig asyncLoggerConfig)
{
+ final LongSupplier configSupplier =
+
asyncLoggerConfig.getAsyncLoggerConfigDisruptor().getRingBuffer()::remainingCapacity;
+ return contextSupplier == null
+ ? configSupplier
+ : () -> Math.min(contextSupplier.getAsLong(),
configSupplier.getAsLong());
+ }
+ return contextSupplier != null ? contextSupplier : () ->
Long.MAX_VALUE;
+ }
+
private static void runTest(
final LoggerContext context, final ContextImpl contextImpl, final
Mode asyncMode, final Path loggingPath)
throws Exception {
@@ -154,16 +169,9 @@ public class AsyncThreadContextTest {
ThreadContext.put("KEY", "mapvalue");
final Logger log = context.getLogger("com.foo.Bar");
+ final LoggerConfig loggerConfig = log.get();
final String loggerContextName = context.getClass().getSimpleName();
- final LongSupplier remainingCapacity;
- if (context instanceof AsyncLoggerContext) {
- remainingCapacity =
- ((AsyncLoggerContext)
context).getAsyncLoggerDisruptor().getRingBuffer()::remainingCapacity;
- } else {
- remainingCapacity =
- ((AsyncLoggerConfigDisruptor) ((AsyncLoggerConfig)
log.get()).getAsyncLoggerConfigDisruptor())
- .getRingBuffer()::remainingCapacity;
- }
+ final LongSupplier remainingCapacity = remainingCapacity(context,
loggerConfig);
for (int i = 0; i < LINE_COUNT; i++) {
// buffer may be full