You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/11/13 06:58:29 UTC
logging-log4j2 git commit: LOG4J2-1688 move test class from log4j-api
module to log4j-core module, the async package;
use CountDownLatch to ensure background thread processed the event
Repository: logging-log4j2
Updated Branches:
refs/heads/master 7c629a6af -> 33432919d
LOG4J2-1688 move test class from log4j-api module to log4j-core module, the async package; use CountDownLatch to ensure background thread processed the event
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/33432919
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/33432919
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/33432919
Branch: refs/heads/master
Commit: 33432919df515f7f1079c9880a4e99a98cb2f5f4
Parents: 7c629a6
Author: rpopma <rp...@apache.org>
Authored: Sun Nov 13 15:58:30 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sun Nov 13 15:58:30 2016 +0900
----------------------------------------------------------------------
.../logging/log4j/spi/Log4j2Jira1688Test.java | 42 -----------
.../core/async/Log4j2Jira1688AsyncTest.java | 79 ++++++++++++++++++++
2 files changed, 79 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33432919/log4j-api/src/test/java/org/apache/logging/log4j/spi/Log4j2Jira1688Test.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/spi/Log4j2Jira1688Test.java b/log4j-api/src/test/java/org/apache/logging/log4j/spi/Log4j2Jira1688Test.java
deleted file mode 100644
index eb46e03..0000000
--- a/log4j-api/src/test/java/org/apache/logging/log4j/spi/Log4j2Jira1688Test.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package org.apache.logging.log4j.spi;
-
-import java.util.Arrays;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.BlockJUnit4ClassRunner;
-
-/**
- * Tests LOG4J2-1688 Multiple loggings of arguments are setting these arguments to null.
- */
-@RunWith(BlockJUnit4ClassRunner.class)
-public class Log4j2Jira1688Test {
-
- private static Object[] createArray(final int size) {
- final Object[] args = new Object[size];
- for (int i = 0; i < args.length; i++) {
- args[i] = i;
- }
- return args;
- }
-
- @Test
- public void testLog4j2Only() {
- final org.apache.logging.log4j.Logger log4JLogger = LogManager.getLogger(this.getClass());
- final int limit = 37;
- final Object[] args = createArray(limit);
- final Object[] originalArgs = Arrays.copyOf(args, args.length);
-
- ((ExtendedLogger)log4JLogger).logIfEnabled("test", Level.ERROR, null, "test {}", args);
- //System.out.println("args " + Arrays.toString(args));
- Assert.assertArrayEquals(originalArgs, args);
-
- ((ExtendedLogger)log4JLogger).logIfEnabled("test", Level.ERROR, null, "test {}", args);
- //System.out.println("args " + Arrays.toString(args));
- Assert.assertArrayEquals(originalArgs, args);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33432919/log4j-core/src/test/java/org/apache/logging/log4j/core/async/Log4j2Jira1688AsyncTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/Log4j2Jira1688AsyncTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/Log4j2Jira1688AsyncTest.java
new file mode 100644
index 0000000..e63bb1f
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/Log4j2Jira1688AsyncTest.java
@@ -0,0 +1,79 @@
+package org.apache.logging.log4j.core.async;
+
+import java.util.Arrays;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+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.spi.ExtendedLogger;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.apache.logging.log4j.util.Strings;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.BlockJUnit4ClassRunner;
+
+/**
+ * Tests LOG4J2-1688 Multiple loggings of arguments are setting these arguments to null.
+ */
+@RunWith(BlockJUnit4ClassRunner.class)
+public class Log4j2Jira1688AsyncTest {
+
+ @BeforeClass
+ public static void beforeClass() {
+ System.setProperty(Constants.LOG4J_CONTEXT_SELECTOR,
+ AsyncLoggerContextSelector.class.getName());
+ System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
+ "log4j-list.xml");
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ System.setProperty(Constants.LOG4J_CONTEXT_SELECTOR, Strings.EMPTY);
+ }
+
+ @Rule
+ public LoggerContextRule context = new LoggerContextRule("log4j-list.xml");
+ private ListAppender listAppender;
+
+ @Before
+ public void before() throws Exception {
+ listAppender = context.getListAppender("List");
+ }
+
+ private static Object[] createArray(final int size) {
+ final Object[] args = new Object[size];
+ for (int i = 0; i < args.length; i++) {
+ args[i] = i;
+ }
+ return args;
+ }
+
+ @Test
+ @Ignore("until LOG4J2-1688 is fixed")
+ public void testLog4j2Only() throws InterruptedException {
+ final org.apache.logging.log4j.Logger log4JLogger = LogManager.getLogger(this.getClass());
+ final int limit = 11; // more than unrolled varargs
+ final Object[] args = createArray(limit);
+ final Object[] originalArgs = Arrays.copyOf(args, args.length);
+
+ listAppender.countDownLatch = new CountDownLatch(1);
+ ((ExtendedLogger)log4JLogger).logIfEnabled("test", Level.ERROR, null, "test {}", args);
+
+ listAppender.countDownLatch.await(1, TimeUnit.SECONDS);
+ Assert.assertArrayEquals(Arrays.toString(args), originalArgs, args);
+
+ ((ExtendedLogger)log4JLogger).logIfEnabled("test", Level.ERROR, null, "test {}", args);
+ Assert.assertArrayEquals(Arrays.toString(args), originalArgs, args);
+ }
+
+}
\ No newline at end of file