You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by vy...@apache.org on 2021/02/17 14:19:16 UTC

[logging-log4j2] branch master updated (7d4aab6 -> e5e3308)

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

vy pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git.


    from 7d4aab6  Fixing typos in docs. (#465)
     new ff50835  Cut down test time by moving recycler-specific test schemes from Surefire executions to JUnit parameters.
     new e5e3308  Test RecyclerFactory read from XML config.

The 2 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-layout-template-json/pom.xml                 | 95 ++--------------------
 .../JsonTemplateLayoutConcurrentEncodeTest.java    | 27 ++++--
 .../template/json/util/RecyclerFactoriesTest.java  | 21 +++++
 ...rFactoryCustomizedJsonTemplateLayoutLogging.xml | 11 ++-
 4 files changed, 52 insertions(+), 102 deletions(-)
 copy log4j-core/src/test/resources/log4j2-744.xml => log4j-layout-template-json/src/test/resources/recyclerFactoryCustomizedJsonTemplateLayoutLogging.xml (82%)


[logging-log4j2] 01/02: Cut down test time by moving recycler-specific test schemes from Surefire executions to JUnit parameters.

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

vy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit ff5083574c5564a8a11d6ee68722bf7e5688ed43
Author: Volkan Yazici <vo...@gmail.com>
AuthorDate: Wed Feb 17 14:56:17 2021 +0100

    Cut down test time by moving recycler-specific test schemes from Surefire executions to JUnit parameters.
---
 log4j-layout-template-json/pom.xml                 | 95 ++--------------------
 .../JsonTemplateLayoutConcurrentEncodeTest.java    | 27 ++++--
 2 files changed, 26 insertions(+), 96 deletions(-)

diff --git a/log4j-layout-template-json/pom.xml b/log4j-layout-template-json/pom.xml
index 3e10b05..782a484 100644
--- a/log4j-layout-template-json/pom.xml
+++ b/log4j-layout-template-json/pom.xml
@@ -70,12 +70,15 @@
     </dependency>
 
     <dependency>
-      <groupId>org.junit.vintage</groupId>
-      <artifactId>junit-vintage-engine</artifactId>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-engine</artifactId>
+      <scope>test</scope>
     </dependency>
+
     <dependency>
       <groupId>org.junit.jupiter</groupId>
-      <artifactId>junit-jupiter-engine</artifactId>
+      <artifactId>junit-jupiter-params</artifactId>
+      <scope>test</scope>
     </dependency>
 
     <dependency>
@@ -186,9 +189,6 @@
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
         <configuration>
-          <!-- Disabling the default execution and only using it to provide
-               the shared settings between individual executions. -->
-          <skip>true</skip>
           <!-- Enforcing a non-UTF-8 encoding to check that the layout
                indeed handles everything in UTF-8 without implicitly
                relying on the system defaults. -->
@@ -199,89 +199,6 @@
             <junit.jupiter.execution.parallel.mode.default>concurrent</junit.jupiter.execution.parallel.mode.default>
           </systemPropertyVariables>
         </configuration>
-        <executions>
-          <execution>
-            <id>default</id>
-            <goals>
-              <goal>test</goal>
-            </goals>
-            <configuration>
-              <skip>${skipTests}</skip>
-              <excludes>
-                <exclude>**/JsonTemplateLayoutConcurrentEncodeTest.java</exclude>
-                <exclude>**/JsonTemplateLayoutTest.java</exclude>
-              </excludes>
-            </configuration>
-          </execution>
-          <!-- Dummy recycler execution -->
-          <execution>
-            <id>recycler-dummy</id>
-            <goals>
-              <goal>test</goal>
-            </goals>
-            <configuration>
-              <skip>${skipTests}</skip>
-              <systemPropertyVariables>
-                <log4j2.layout.jsonTemplate.recyclerFactory>dummy</log4j2.layout.jsonTemplate.recyclerFactory>
-              </systemPropertyVariables>
-              <includes>
-                <include>**/JsonTemplateLayoutConcurrentEncodeTest.java</include>
-                <include>**/JsonTemplateLayoutTest.java</include>
-              </includes>
-            </configuration>
-          </execution>
-          <!-- Thread-Local recycler execution -->
-          <execution>
-            <id>recycler-tl</id>
-            <goals>
-              <goal>test</goal>
-            </goals>
-            <configuration>
-              <skip>${skipTests}</skip>
-              <systemPropertyVariables>
-                <log4j2.layout.jsonTemplate.recyclerFactory>threadLocal</log4j2.layout.jsonTemplate.recyclerFactory>
-              </systemPropertyVariables>
-              <includes>
-                <include>**/JsonTemplateLayoutConcurrentEncodeTest.java</include>
-                <include>**/JsonTemplateLayoutTest.java</include>
-              </includes>
-            </configuration>
-          </execution>
-          <!-- ArrayBlockingQueue recycler execution -->
-          <execution>
-            <id>recycler-abq</id>
-            <goals>
-              <goal>test</goal>
-            </goals>
-            <configuration>
-              <skip>${skipTests}</skip>
-              <systemPropertyVariables>
-                <log4j2.layout.jsonTemplate.recyclerFactory>queue:supplier=java.util.concurrent.ArrayBlockingQueue.new</log4j2.layout.jsonTemplate.recyclerFactory>
-              </systemPropertyVariables>
-              <includes>
-                <include>**/JsonTemplateLayoutConcurrentEncodeTest.java</include>
-                <include>**/JsonTemplateLayoutTest.java</include>
-              </includes>
-            </configuration>
-          </execution>
-          <!-- MpmcArrayQueue recycler execution -->
-          <execution>
-            <id>recycler-mpmc</id>
-            <goals>
-              <goal>test</goal>
-            </goals>
-            <configuration>
-              <skip>${skipTests}</skip>
-              <systemPropertyVariables>
-                <log4j2.layout.jsonTemplate.recyclerFactory>queue:supplier=org.jctools.queues.MpmcArrayQueue.new</log4j2.layout.jsonTemplate.recyclerFactory>
-              </systemPropertyVariables>
-              <includes>
-                <include>**/JsonTemplateLayoutConcurrentEncodeTest.java</include>
-                <include>**/JsonTemplateLayoutTest.java</include>
-              </includes>
-            </configuration>
-          </execution>
-        </executions>
       </plugin>
 
       <!-- Disable ITs, which are Docker-dependent, by default. -->
diff --git a/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutConcurrentEncodeTest.java b/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutConcurrentEncodeTest.java
index 9cb32e3..d62e63c 100644
--- a/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutConcurrentEncodeTest.java
+++ b/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutConcurrentEncodeTest.java
@@ -20,8 +20,11 @@ import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.DefaultConfiguration;
 import org.apache.logging.log4j.core.layout.ByteBufferDestination;
+import org.apache.logging.log4j.layout.template.json.util.RecyclerFactories;
+import org.apache.logging.log4j.layout.template.json.util.RecyclerFactory;
 import org.assertj.core.api.Assertions;
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
 import java.nio.ByteBuffer;
 import java.util.List;
@@ -117,16 +120,25 @@ class JsonTemplateLayoutConcurrentEncodeTest {
         return logEvents;
     }
 
-    @Test
-    void test_concurrent_encode() {
+    @ParameterizedTest
+    @ValueSource(strings = {
+            "dummy",
+            "threadLocal",
+            "queue:supplier=java.util.concurrent.ArrayBlockingQueue.new",
+            "queue:supplier=org.jctools.queues.MpmcArrayQueue.new"
+    })
+    void test_concurrent_encode(final String recyclerFactorySpec) {
+        final RecyclerFactory recyclerFactory = RecyclerFactories.ofSpec(recyclerFactorySpec);
         final AtomicReference<Exception> encodeFailureRef = new AtomicReference<>(null);
-        produce(encodeFailureRef);
+        produce(recyclerFactory, encodeFailureRef);
         Assertions.assertThat(encodeFailureRef.get()).isNull();
     }
 
-    private void produce(final AtomicReference<Exception> encodeFailureRef) {
+    private void produce(
+            final RecyclerFactory recyclerFactory,
+            final AtomicReference<Exception> encodeFailureRef) {
         final int threadCount = 10;
-        final JsonTemplateLayout layout = createLayout();
+        final JsonTemplateLayout layout = createLayout(recyclerFactory);
         final ByteBufferDestination destination =
                 new ConcurrentAccessDetectingByteBufferDestination();
         final AtomicLong encodeCounter = new AtomicLong(0);
@@ -150,7 +162,7 @@ class JsonTemplateLayoutConcurrentEncodeTest {
         });
     }
 
-    private static JsonTemplateLayout createLayout() {
+    private static JsonTemplateLayout createLayout(final RecyclerFactory recyclerFactory) {
         final Configuration config = new DefaultConfiguration();
         return JsonTemplateLayout
                 .newBuilder()
@@ -158,6 +170,7 @@ class JsonTemplateLayoutConcurrentEncodeTest {
                 .setEventTemplate("{\"message\": \"${json:message}\"}")
                 .setStackTraceEnabled(false)
                 .setLocationInfoEnabled(false)
+                .setRecyclerFactory(recyclerFactory)
                 .build();
     }
 


[logging-log4j2] 02/02: Test RecyclerFactory read from XML config.

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

vy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit e5e33087ff903d724bc7ec66742ac7a54aeb1fe6
Author: Volkan Yazici <vo...@gmail.com>
AuthorDate: Wed Feb 17 15:10:59 2021 +0100

    Test RecyclerFactory read from XML config.
---
 .../template/json/util/RecyclerFactoriesTest.java  | 21 +++++++++++++++
 ...rFactoryCustomizedJsonTemplateLayoutLogging.xml | 30 ++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/util/RecyclerFactoriesTest.java b/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/util/RecyclerFactoriesTest.java
index fdb71bf..9e4b677 100644
--- a/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/util/RecyclerFactoriesTest.java
+++ b/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/util/RecyclerFactoriesTest.java
@@ -18,9 +18,17 @@ package org.apache.logging.log4j.layout.template.json.util;
 
 import org.apache.logging.log4j.plugins.convert.TypeConverter;
 import org.apache.logging.log4j.plugins.convert.TypeConverterRegistry;
+import org.apache.logging.log4j.core.config.plugins.convert.TypeConverter;
+import org.apache.logging.log4j.core.config.plugins.convert.TypeConverterRegistry;
+import org.apache.logging.log4j.junit.LoggerContextSource;
+import org.apache.logging.log4j.junit.Named;
+import org.apache.logging.log4j.layout.template.json.JsonTemplateLayout;
+import org.apache.logging.log4j.test.appender.ListAppender;
 import org.assertj.core.api.Assertions;
+import org.jctools.queues.MpmcArrayQueue;
 import org.junit.jupiter.api.Test;
 
+import java.lang.reflect.Field;
 import java.util.ArrayDeque;
 import java.util.concurrent.ArrayBlockingQueue;
 
@@ -117,4 +125,17 @@ class RecyclerFactoriesTest {
 
     }
 
+    @Test
+    @LoggerContextSource("recyclerFactoryCustomizedJsonTemplateLayoutLogging.xml")
+    void test_RecyclerFactoryConverter_using_XML_config(
+            final @Named(value = "List") ListAppender appender)
+            throws Exception {
+        final JsonTemplateLayout layout = (JsonTemplateLayout) appender.getLayout();
+        final Field field = JsonTemplateLayout.class.getDeclaredField("contextRecycler");
+        field.setAccessible(true);
+        final QueueingRecycler<?> contextRecycler = (QueueingRecycler<?>) field.get(layout);
+        final MpmcArrayQueue<?> queue = (MpmcArrayQueue<?>) contextRecycler.getQueue();
+        Assertions.assertThat(queue.capacity()).isEqualTo(512);
+    }
+
 }
diff --git a/log4j-layout-template-json/src/test/resources/recyclerFactoryCustomizedJsonTemplateLayoutLogging.xml b/log4j-layout-template-json/src/test/resources/recyclerFactoryCustomizedJsonTemplateLayoutLogging.xml
new file mode 100644
index 0000000..8fd8957
--- /dev/null
+++ b/log4j-layout-template-json/src/test/resources/recyclerFactoryCustomizedJsonTemplateLayoutLogging.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<Configuration status="OFF">
+  <Appenders>
+    <List name="List" raw="true">
+      <JsonTemplateLayout
+          recyclerFactory="queue:supplier=org.jctools.queues.MpmcArrayQueue.new,capacity=512"/>
+    </List>
+  </Appenders>
+  <Loggers>
+    <Root level="TRACE">
+      <AppenderRef ref="List"/>
+    </Root>
+  </Loggers>
+</Configuration>