LOG4J2-2031 refactor to get remaining queue capacity for AsyncAppender as well as Async Loggers
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/44100738 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/44100738 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/44100738 Branch: refs/heads/master Commit: 4410073823047fc0bc16ee7693a1efc1b32c264d Parents: 1265087 Author: rpopma <[email protected]> Authored: Wed Sep 20 23:58:46 2017 +0900 Committer: rpopma <[email protected]> Committed: Wed Sep 20 23:58:46 2017 +0900 ---------------------------------------------------------------------- .../log4j/core/async/QueueFullAbstractTest.java | 17 ++++++++++++----- ...llAsyncLoggerConfigLoggingFromToStringTest.java | 2 +- .../core/async/QueueFullAsyncLoggerConfigTest.java | 5 +---- ...ueueFullAsyncLoggerLoggingFromToStringTest.java | 2 +- .../log4j/core/async/QueueFullAsyncLoggerTest.java | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/44100738/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAbstractTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAbstractTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAbstractTest.java index cbf6e06..3666903 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAbstractTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAbstractTest.java @@ -25,7 +25,9 @@ import java.util.concurrent.CountDownLatch; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.Appender; import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.appender.AsyncAppender; import org.apache.logging.log4j.core.config.LoggerConfig; import com.lmax.disruptor.dsl.Disruptor; @@ -74,7 +76,7 @@ public abstract class QueueFullAbstractTest { for (int i = 0; i < count; i++) { TRACE("DomainObject decrementing unlocker countdown latch before logging. Count was " + unlocker.countDownLatch.getCount()); unlocker.countDownLatch.countDown(); - TRACE("DomainObject logging message " + i + ". Remaining capacity=" + getDisruptor(innerLogger).getRingBuffer().remainingCapacity()); + TRACE("DomainObject logging message " + i + ". Remaining capacity=" + asyncRemainingCapacity(innerLogger)); innerLogger.info("Logging in toString() #" + i); } return "Who's bad?!"; @@ -92,11 +94,11 @@ public abstract class QueueFullAbstractTest { return result; } - static Disruptor getDisruptor(Logger logger) { + static long asyncRemainingCapacity(Logger logger) { if (logger instanceof AsyncLogger) { try { Field f = field(AsyncLogger.class, "loggerDisruptor"); - return ((AsyncLoggerDisruptor) f.get(logger)).getDisruptor(); + return ((AsyncLoggerDisruptor) f.get(logger)).getDisruptor().getRingBuffer().remainingCapacity(); } catch (Exception ex) { throw new RuntimeException(ex); } @@ -105,13 +107,18 @@ public abstract class QueueFullAbstractTest { if (loggerConfig instanceof AsyncLoggerConfig) { try { Object delegate = field(AsyncLoggerConfig.class, "delegate").get(loggerConfig); - return (Disruptor) field(AsyncLoggerConfigDisruptor.class, "disruptor").get(delegate); + return ((Disruptor) field(AsyncLoggerConfigDisruptor.class, "disruptor").get(delegate)).getRingBuffer().remainingCapacity(); } catch (Exception ex) { throw new RuntimeException(ex); } + } else { + Appender async = loggerConfig.getAppenders().get("async"); + if (async instanceof AsyncAppender) { + return ((AsyncAppender) async).getQueueCapacity(); + } } } - throw new IllegalStateException("Async Loggers are not configured"); + throw new IllegalStateException("Neither Async Loggers nor AsyncAppender are configured"); } private static Field field(Class<?> c, String name) throws NoSuchFieldException { Field f = c.getDeclaredField(name); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/44100738/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigLoggingFromToStringTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigLoggingFromToStringTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigLoggingFromToStringTest.java index 37328fc..0af0647 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigLoggingFromToStringTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigLoggingFromToStringTest.java @@ -70,7 +70,7 @@ public class QueueFullAsyncLoggerConfigLoggingFromToStringTest extends QueueFull unlocker.start(); for (int i = 0; i < 1; i++) { - TRACE("Test logging message " + i + ". Remaining capacity=" + getDisruptor(logger).getRingBuffer().remainingCapacity()); + TRACE("Test logging message " + i + ". Remaining capacity=" + asyncRemainingCapacity(logger)); TRACE("Test decrementing unlocker countdown latch. Count=" + unlocker.countDownLatch.getCount()); unlocker.countDownLatch.countDown(); final DomainObject obj = new DomainObject(129); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/44100738/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigTest.java index 7e99bfe..a7ef8ed 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigTest.java @@ -23,11 +23,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.categories.AsyncLoggers; import org.apache.logging.log4j.core.config.ConfigurationFactory; -import org.apache.logging.log4j.core.util.Constants; import org.apache.logging.log4j.junit.LoggerContextRule; import org.apache.logging.log4j.message.ParameterizedMessage; -import org.apache.logging.log4j.util.Strings; -import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; @@ -71,7 +68,7 @@ public class QueueFullAsyncLoggerConfigTest extends QueueFullAbstractTest { unlocker.start(); for (int i = 0; i < 130; i++) { - TRACE("Test logging message " + i + ". Remaining capacity=" + getDisruptor(logger).getRingBuffer().remainingCapacity()); + TRACE("Test logging message " + i + ". Remaining capacity=" + asyncRemainingCapacity(logger)); TRACE("Test decrementing unlocker countdown latch. Count=" + unlocker.countDownLatch.getCount()); unlocker.countDownLatch.countDown(); final String param = "I'm innocent"; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/44100738/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerLoggingFromToStringTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerLoggingFromToStringTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerLoggingFromToStringTest.java index 2e8e7e8..6aedc0e 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerLoggingFromToStringTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerLoggingFromToStringTest.java @@ -77,7 +77,7 @@ public class QueueFullAsyncLoggerLoggingFromToStringTest extends QueueFullAbstra unlocker.start(); for (int i = 0; i < 1; i++) { - TRACE("Test logging message " + i + ". Remaining capacity=" + getDisruptor(logger).getRingBuffer().remainingCapacity()); + TRACE("Test logging message " + i + ". Remaining capacity=" + asyncRemainingCapacity(logger)); TRACE("Test decrementing unlocker countdown latch. Count=" + unlocker.countDownLatch.getCount()); unlocker.countDownLatch.countDown(); final DomainObject obj = new DomainObject(129); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/44100738/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest.java index 77d411a..9dad517 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest.java @@ -77,7 +77,7 @@ public class QueueFullAsyncLoggerTest extends QueueFullAbstractTest { unlocker.start(); for (int i = 0; i < 130; i++) { - TRACE("Test logging message " + i + ". Remaining capacity=" + getDisruptor(logger).getRingBuffer().remainingCapacity()); + TRACE("Test logging message " + i + ". Remaining capacity=" + asyncRemainingCapacity(logger)); TRACE("Test decrementing unlocker countdown latch. Count=" + unlocker.countDownLatch.getCount()); unlocker.countDownLatch.countDown(); final String param = "I'm innocent";
