You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2022/01/06 13:45:10 UTC

[logging-log4j2] branch release-2.x updated (0773f7f -> faf8180)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git.


    from 0773f7f  Follow current convention of tests being public.
     new 433e738  Follow current convention of test methods being prefixed with "test".
     new 1b1513b  Sort methods.
     new faf8180  Add some API tests.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../log4j/core/appender/AsyncAppenderTest.java     | 100 ++++++++++++---------
 1 file changed, 60 insertions(+), 40 deletions(-)

[logging-log4j2] 02/03: Sort methods.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 1b1513bcd92c8f4b29f4c453b76a4c8296e8d856
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Jan 6 08:33:04 2022 -0500

    Sort methods.
---
 .../log4j/core/appender/AsyncAppenderTest.java     | 60 +++++++++++-----------
 1 file changed, 30 insertions(+), 30 deletions(-)

diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderTest.java
index 3c4e0a3..33ae365 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderTest.java
@@ -35,39 +35,46 @@ import static org.junit.jupiter.api.Assertions.*;
 
 public class AsyncAppenderTest {
 
-    static void rewriteTest(final LoggerContext context) throws InterruptedException {
+    static void exceptionTest(final LoggerContext context) throws InterruptedException {
         final ExtendedLogger logger = context.getLogger(AsyncAppender.class);
-        logger.error("This is a test");
-        logger.warn("Hello world!");
+        final Exception parent = new IllegalStateException("Test");
+        final Throwable child = new LoggingException("This is a test", parent);
+        logger.error("This is a test", child);
         final ListAppender appender = context.getConfiguration().getAppender("List");
         final List<String> messages;
         try {
-            messages = appender.getMessages(2, 2, TimeUnit.SECONDS);
+            messages = appender.getMessages(1, 2, TimeUnit.SECONDS);
         } finally {
             appender.clear();
         }
         assertNotNull(messages);
-        assertEquals(2, messages.size());
-        final String messagePrefix = AsyncAppenderTest.class.getName() + " rewriteTest ";
-        assertEquals(messagePrefix + "This is a test", messages.get(0));
-        assertEquals(messagePrefix + "Hello world!", messages.get(1));
+        assertEquals(1, messages.size());
+        assertTrue(messages.get(0).contains(parent.getClass().getName()));
     }
 
-    static void exceptionTest(final LoggerContext context) throws InterruptedException {
+    static void rewriteTest(final LoggerContext context) throws InterruptedException {
         final ExtendedLogger logger = context.getLogger(AsyncAppender.class);
-        final Exception parent = new IllegalStateException("Test");
-        final Throwable child = new LoggingException("This is a test", parent);
-        logger.error("This is a test", child);
+        logger.error("This is a test");
+        logger.warn("Hello world!");
         final ListAppender appender = context.getConfiguration().getAppender("List");
         final List<String> messages;
         try {
-            messages = appender.getMessages(1, 2, TimeUnit.SECONDS);
+            messages = appender.getMessages(2, 2, TimeUnit.SECONDS);
         } finally {
             appender.clear();
         }
         assertNotNull(messages);
-        assertEquals(1, messages.size());
-        assertTrue(messages.get(0).contains(parent.getClass().getName()));
+        assertEquals(2, messages.size());
+        final String messagePrefix = AsyncAppenderTest.class.getName() + " rewriteTest ";
+        assertEquals(messagePrefix + "This is a test", messages.get(0));
+        assertEquals(messagePrefix + "Hello world!", messages.get(1));
+    }
+
+    @Test
+    @LoggerContextSource("BlockingQueueFactory-ArrayBlockingQueue.xml")
+    public void testArrayBlockingQueue(final LoggerContext context) throws InterruptedException {
+        rewriteTest(context);
+        exceptionTest(context);
     }
 
     @Test
@@ -86,13 +93,6 @@ public class AsyncAppenderTest {
     }
 
     @Test
-    @LoggerContextSource("BlockingQueueFactory-ArrayBlockingQueue.xml")
-    public void testArrayBlockingQueue(final LoggerContext context) throws InterruptedException {
-        rewriteTest(context);
-        exceptionTest(context);
-    }
-
-    @Test
     @Tag("disruptor")
     @LoggerContextSource("BlockingQueueFactory-DisruptorBlockingQueue.xml")
     public void testDisruptorBlockingQueue(final LoggerContext context) throws InterruptedException {
@@ -116,14 +116,6 @@ public class AsyncAppenderTest {
     }
 
     @Test
-    @Timeout(5)
-    @LoggerContextSource("log4j-asynch-shutdownTimeout.xml")
-    public void testShutdownTimeout(final LoggerContext context) {
-        context.getLogger("Logger").info("This is a test");
-        context.stop();
-    }
-
-    @Test
     @LoggerContextSource("log4j-asynch-no-location.xml")
     public void testNoLocationInformation(final LoggerContext context, @Named("List") final ListAppender appender) throws InterruptedException {
         final ExtendedLogger logger = context.getLogger(getClass());
@@ -140,4 +132,12 @@ public class AsyncAppenderTest {
         assertEquals("?  This is a test", messages.get(0));
         assertEquals("?  Hello world!", messages.get(1));
     }
+
+    @Test
+    @Timeout(5)
+    @LoggerContextSource("log4j-asynch-shutdownTimeout.xml")
+    public void testShutdownTimeout(final LoggerContext context) {
+        context.getLogger("Logger").info("This is a test");
+        context.stop();
+    }
 }

[logging-log4j2] 01/03: Follow current convention of test methods being prefixed with "test".

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 433e738e90785b52eedbf974aaf866bb81bf8d27
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Jan 6 08:32:55 2022 -0500

    Follow current convention of test methods being prefixed with "test".
---
 .../logging/log4j/core/appender/AsyncAppenderTest.java     | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderTest.java
index 685b729..3c4e0a3 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderTest.java
@@ -72,7 +72,7 @@ public class AsyncAppenderTest {
 
     @Test
     @LoggerContextSource("log4j-asynch.xml")
-    public void defaultAsyncAppenderConfig(final LoggerContext context) throws InterruptedException {
+    public void testDefaultAsyncAppenderConfig(final LoggerContext context) throws InterruptedException {
         rewriteTest(context);
         exceptionTest(context);
 
@@ -87,7 +87,7 @@ public class AsyncAppenderTest {
 
     @Test
     @LoggerContextSource("BlockingQueueFactory-ArrayBlockingQueue.xml")
-    public void arrayBlockingQueue(final LoggerContext context) throws InterruptedException {
+    public void testArrayBlockingQueue(final LoggerContext context) throws InterruptedException {
         rewriteTest(context);
         exceptionTest(context);
     }
@@ -95,7 +95,7 @@ public class AsyncAppenderTest {
     @Test
     @Tag("disruptor")
     @LoggerContextSource("BlockingQueueFactory-DisruptorBlockingQueue.xml")
-    public void disruptorBlockingQueue(final LoggerContext context) throws InterruptedException {
+    public void testDisruptorBlockingQueue(final LoggerContext context) throws InterruptedException {
         rewriteTest(context);
         exceptionTest(context);
     }
@@ -103,14 +103,14 @@ public class AsyncAppenderTest {
     @Test
     @Tag("jctools")
     @LoggerContextSource("BlockingQueueFactory-JCToolsBlockingQueue.xml")
-    public void jcToolsBlockingQueue(final LoggerContext context) throws InterruptedException {
+    public void testJcToolsBlockingQueue(final LoggerContext context) throws InterruptedException {
         rewriteTest(context);
         exceptionTest(context);
     }
 
     @Test
     @LoggerContextSource("BlockingQueueFactory-LinkedTransferQueue.xml")
-    public void linkedTransferQueue(final LoggerContext context) throws InterruptedException {
+    public void testLinkedTransferQueue(final LoggerContext context) throws InterruptedException {
         rewriteTest(context);
         exceptionTest(context);
     }
@@ -118,14 +118,14 @@ public class AsyncAppenderTest {
     @Test
     @Timeout(5)
     @LoggerContextSource("log4j-asynch-shutdownTimeout.xml")
-    public void shutdownTimeout(final LoggerContext context) {
+    public void testShutdownTimeout(final LoggerContext context) {
         context.getLogger("Logger").info("This is a test");
         context.stop();
     }
 
     @Test
     @LoggerContextSource("log4j-asynch-no-location.xml")
-    public void noLocationInformation(final LoggerContext context, @Named("List") final ListAppender appender) throws InterruptedException {
+    public void testNoLocationInformation(final LoggerContext context, @Named("List") final ListAppender appender) throws InterruptedException {
         final ExtendedLogger logger = context.getLogger(getClass());
         logger.error("This is a test");
         logger.warn("Hello world!");

[logging-log4j2] 03/03: Add some API tests.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit faf8180356fb5540600e16dbd39d7913a4c63762
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Jan 6 08:45:07 2022 -0500

    Add some API tests.
---
 .../log4j/core/appender/AsyncAppenderTest.java     | 32 ++++++++++++++++++----
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderTest.java
index 33ae365..d89aaee 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderTest.java
@@ -17,6 +17,17 @@
 
 package org.apache.logging.log4j.core.appender;
 
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
 import org.apache.logging.log4j.LoggingException;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.junit.LoggerContextSource;
@@ -27,12 +38,6 @@ import org.junit.jupiter.api.Tag;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.Timeout;
 
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
-
-import static org.junit.jupiter.api.Assertions.*;
-
 public class AsyncAppenderTest {
 
     static void exceptionTest(final LoggerContext context) throws InterruptedException {
@@ -101,6 +106,21 @@ public class AsyncAppenderTest {
     }
 
     @Test
+    @LoggerContextSource("log4j-asynch.xml")
+    public void testGetAppenderRefStrings(final LoggerContext context) throws InterruptedException {
+        final AsyncAppender appender = context.getConfiguration().getAppender("Async");
+        assertArrayEquals(new String[] {"List"}, appender.getAppenderRefStrings());
+        assertNotSame(appender.getAppenderRefStrings(), appender.getAppenderRefStrings());
+    }
+
+    @Test
+    @LoggerContextSource("log4j-asynch.xml")
+    public void testGetErrorRef(final LoggerContext context) throws InterruptedException {
+        final AsyncAppender appender = context.getConfiguration().getAppender("Async");
+        assertEquals("STDOUT", appender.getErrorRef());
+    }
+
+    @Test
     @Tag("jctools")
     @LoggerContextSource("BlockingQueueFactory-JCToolsBlockingQueue.xml")
     public void testJcToolsBlockingQueue(final LoggerContext context) throws InterruptedException {