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:22:03 UTC
[logging-log4j2] 01/01: Test RecyclerFactory read from XML config.
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 963db9fac1fda3496ca770ca95ccb28c5a516694
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 | 19 ++++++++++++++
...rFactoryCustomizedJsonTemplateLayoutLogging.xml | 30 ++++++++++++++++++++++
2 files changed, 49 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..1ecc53e 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,15 @@ 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.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 +123,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>