You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by pk...@apache.org on 2024/01/25 15:29:32 UTC
(logging-log4j2) 03/03: Fix failing tests
This is an automated email from the ASF dual-hosted git repository.
pkarwasz pushed a commit to branch move-async-end
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 2fb51110e067b9f0099e382fffb4762b3e3bb24c
Author: Piotr P. Karwasz <pi...@karwasz.org>
AuthorDate: Thu Jan 25 16:24:00 2024 +0100
Fix failing tests
---
log4j-async-logger/pom.xml | 20 ++++-
.../AsyncLoggerEventTranslationExceptionTest.java | 2 +-
.../async/logger/DefaultIncludeLocationTest.java | 91 ++++++++++++++++++++++
.../async/logger/NestedAsyncLoggerConfigTest.java | 21 +++++
.../async/logger/QueueFullAsyncAbstractTest.java | 2 +-
.../async/logger/QueueFullAsyncLogger3Test.java | 5 +-
...ueueFullAsyncLoggerLoggingFromToStringTest.java | 5 +-
.../async/logger/QueueFullAsyncLoggerTest.java | 5 +-
.../NestedAsyncLoggerConfigTest}/default-level.xml | 0
.../NestedAsyncLoggerConfigTest}/inherit-level.xml | 0
.../JavaPropsConfigurationFactoryTest.java | 2 +-
.../config/yaml/YamlConfigurationFactoryTest.java | 2 +-
.../{ => test}/async/QueueFullAbstractTest.java | 7 +-
.../config/AbstractConfigurationFactoryTest.java | 3 +-
.../config/AbstractNestedLoggerConfigTest.java} | 35 +++------
.../{ => test}/async/QueueFullAbstractTest.xml | 0
.../appender/RandomAccessFileAppenderTest.java | 79 +++++--------------
.../async}/AsyncQueueFullPolicyFactoryTest.java | 7 +-
.../core/async/QueueFullAsyncAppenderTest.java | 1 +
.../core/config/ConfigurationFactoryTest.java | 1 +
.../log4j/core/config/NestedLoggerConfigTest.java | 58 +-------------
.../RandomAccessFileAppenderLocationTest.xml | 35 ---------
.../resources/RandomAccessFileAppenderTest.xml | 35 ---------
.../RollingRandomAccessFileAppenderTest.xml | 37 ---------
.../appender/RandomAccessFileAppenderTest.xml} | 28 ++++---
.../NestedLoggerConfigTest}/default-level.xml | 0
.../NestedLoggerConfigTest}/inherit-level.xml | 0
27 files changed, 197 insertions(+), 284 deletions(-)
diff --git a/log4j-async-logger/pom.xml b/log4j-async-logger/pom.xml
index 5d37d3d80f..aba22bd83d 100644
--- a/log4j-async-logger/pom.xml
+++ b/log4j-async-logger/pom.xml
@@ -25,7 +25,7 @@
</parent>
<artifactId>log4j-async-logger</artifactId>
- <name>Log4j Async Logger</name>
+ <name>Apache Log4j Async Logger</name>
<description>Alternative implementation of logger that uses LMAX Disruptor.</description>
<dependencies>
@@ -65,4 +65,22 @@
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <annotationProcessorPaths combine.children="append">
+ <path>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-plugin-processor</artifactId>
+ <version>${project.version}</version>
+ </path>
+ </annotationProcessorPaths>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerEventTranslationExceptionTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerEventTranslationExceptionTest.java
index 418b8bedf7..a5a32b29f1 100644
--- a/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerEventTranslationExceptionTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerEventTranslationExceptionTest.java
@@ -46,7 +46,7 @@ import org.junitpioneer.jupiter.SetSystemProperty;
@ContextSelectorType(AsyncLoggerContextSelector.class)
@SetSystemProperty(
key = Log4jPropertyKey.Constant.ASYNC_LOGGER_EXCEPTION_HANDLER_CLASS_NAME,
- value = "org.apache.logging.log4j.core.async.AsyncLoggerEventTranslationExceptionTest$TestExceptionHandler")
+ value = "org.apache.logging.log4j.async.logger.AsyncLoggerEventTranslationExceptionTest$TestExceptionHandler")
class AsyncLoggerEventTranslationExceptionTest {
@Test
diff --git a/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/DefaultIncludeLocationTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/DefaultIncludeLocationTest.java
new file mode 100644
index 0000000000..9f92ff02c6
--- /dev/null
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/DefaultIncludeLocationTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.
+ */
+package org.apache.logging.log4j.async.logger;
+
+import java.util.stream.Stream;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.LoggerConfig;
+import org.apache.logging.log4j.core.config.NullConfiguration;
+import org.apache.logging.log4j.util.PropertiesUtil;
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+class DefaultIncludeLocationTest {
+
+ private static final String LOGGER_NAME = DefaultIncludeLocationTest.class.getName();
+
+ private static Stream<Arguments> loggerConfigs(final Configuration config) {
+ return Stream.of(
+ Arguments.of(
+ LoggerConfig.newBuilder()
+ .setConfig(config)
+ .setLoggerName(LOGGER_NAME)
+ .build(),
+ true),
+ Arguments.of(
+ LoggerConfig.RootLogger.newRootBuilder()
+ .setConfig(config)
+ .build(),
+ true),
+ Arguments.of(
+ AsyncLoggerConfig.newAsyncBuilder()
+ .setConfig(config)
+ .setLoggerName(LOGGER_NAME)
+ .build(),
+ false),
+ Arguments.of(
+ AsyncLoggerConfig.RootLogger.newAsyncRootBuilder()
+ .setConfig(config)
+ .build(),
+ false));
+ }
+
+ static Stream<Arguments> loggerContextDefaultLocation() {
+ final LoggerContext ctx = new LoggerContext("sync");
+ ctx.setProperties(PropertiesUtil.getProperties());
+ final NullConfiguration config = new NullConfiguration(ctx);
+ ctx.setConfiguration(config);
+ return loggerConfigs(config);
+ }
+
+ @ParameterizedTest
+ @MethodSource
+ void loggerContextDefaultLocation(final LoggerConfig loggerConfig, final boolean expected) {
+ Assertions.assertThat(loggerConfig.isIncludeLocation())
+ .as("Default `includeLocation` value")
+ .isEqualTo(expected);
+ }
+
+ static Stream<LoggerConfig> asyncLoggerContextDefaultLocation() {
+ final AsyncLoggerContext ctx = new AsyncLoggerContext("async");
+ ctx.setProperties(PropertiesUtil.getProperties());
+ final NullConfiguration config = new NullConfiguration(ctx);
+ ctx.setConfiguration(config);
+ return loggerConfigs(config).map(args -> (LoggerConfig) args.get()[0]);
+ }
+
+ @ParameterizedTest
+ @MethodSource
+ void asyncLoggerContextDefaultLocation(final LoggerConfig loggerConfig) {
+ Assertions.assertThat(loggerConfig.isIncludeLocation())
+ .as("Default `includeLocation` value")
+ .isFalse();
+ }
+}
diff --git a/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/NestedAsyncLoggerConfigTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/NestedAsyncLoggerConfigTest.java
new file mode 100644
index 0000000000..8a2161c955
--- /dev/null
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/NestedAsyncLoggerConfigTest.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+package org.apache.logging.log4j.async.logger;
+
+import org.apache.logging.log4j.core.test.config.AbstractNestedLoggerConfigTest;
+
+public class NestedAsyncLoggerConfigTest extends AbstractNestedLoggerConfigTest {}
diff --git a/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncAbstractTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncAbstractTest.java
index 93ef280d44..1e5e4bf3bc 100644
--- a/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncAbstractTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncAbstractTest.java
@@ -26,10 +26,10 @@ import java.util.stream.Collectors;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.async.QueueFullAbstractTest;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.test.async.BlockingAppender;
+import org.apache.logging.log4j.core.test.async.QueueFullAbstractTest;
import org.apache.logging.log4j.status.StatusData;
import org.apache.logging.log4j.test.ListStatusListener;
diff --git a/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLogger3Test.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLogger3Test.java
index 575f15c422..d9416e79b8 100644
--- a/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLogger3Test.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLogger3Test.java
@@ -26,6 +26,7 @@ import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.async.AsyncQueueFullPolicyFactory;
import org.apache.logging.log4j.core.async.DiscardingAsyncQueueFullPolicy;
import org.apache.logging.log4j.core.test.async.BlockingAppender;
+import org.apache.logging.log4j.core.test.junit.ContextSelectorType;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.core.test.junit.Named;
import org.apache.logging.log4j.message.Message;
@@ -37,9 +38,7 @@ import org.junit.jupiter.api.Timeout;
/**
* Tests queue full scenarios with pure AsyncLoggers (all loggers async).
*/
-@SetTestProperty(
- key = "LoggerContext.selector",
- value = "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector")
+@ContextSelectorType(AsyncLoggerContextSelector.class)
@SetTestProperty(key = "AsyncLogger.ringBufferSize", value = "128")
@SetTestProperty(key = "AsyncLogger.formatMsg", value = "true")
@SetTestProperty(key = "AsyncLogger.queueFullPolicy", value = "Discard")
diff --git a/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerLoggingFromToStringTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerLoggingFromToStringTest.java
index 5ac3c0aa21..d95ec2966a 100644
--- a/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerLoggingFromToStringTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerLoggingFromToStringTest.java
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.async.logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.async.BlockingAppender;
+import org.apache.logging.log4j.core.test.junit.ContextSelectorType;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.core.test.junit.Named;
import org.apache.logging.log4j.test.junit.SetTestProperty;
@@ -26,9 +27,7 @@ import org.junit.jupiter.api.Test;
/**
* Tests queue full scenarios with pure AsyncLoggers (all loggers async).
*/
-@SetTestProperty(
- key = "LoggerContext.selector",
- value = "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector")
+@ContextSelectorType(AsyncLoggerContextSelector.class)
@SetTestProperty(key = "AsyncLogger.ringBufferSize", value = "128")
public class QueueFullAsyncLoggerLoggingFromToStringTest extends QueueFullAsyncAbstractTest {
diff --git a/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerTest.java
index e6043dc880..f1e8e44107 100644
--- a/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerTest.java
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.async.logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.async.BlockingAppender;
+import org.apache.logging.log4j.core.test.junit.ContextSelectorType;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.core.test.junit.Named;
import org.apache.logging.log4j.test.junit.SetTestProperty;
@@ -26,9 +27,7 @@ import org.junit.jupiter.api.Test;
/**
* Tests queue full scenarios with pure AsyncLoggers (all loggers async).
*/
-@SetTestProperty(
- key = "LoggerContext.selector",
- value = "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector")
+@ContextSelectorType(AsyncLoggerContextSelector.class)
@SetTestProperty(key = "AsyncLogger.ringBufferSize", value = "128")
public class QueueFullAsyncLoggerTest extends QueueFullAsyncAbstractTest {
diff --git a/log4j-core-test/src/test/resources/logger-config/AsyncLoggerConfig/default-level.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/NestedAsyncLoggerConfigTest/default-level.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/logger-config/AsyncLoggerConfig/default-level.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/NestedAsyncLoggerConfigTest/default-level.xml
diff --git a/log4j-core-test/src/test/resources/logger-config/AsyncLoggerConfig/inherit-level.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/NestedAsyncLoggerConfigTest/inherit-level.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/logger-config/AsyncLoggerConfig/inherit-level.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/NestedAsyncLoggerConfigTest/inherit-level.xml
diff --git a/log4j-config-properties/src/test/java/org/apache/logging/log4j/config/properties/JavaPropsConfigurationFactoryTest.java b/log4j-config-properties/src/test/java/org/apache/logging/log4j/config/properties/JavaPropsConfigurationFactoryTest.java
index a02814efb6..f1656be526 100644
--- a/log4j-config-properties/src/test/java/org/apache/logging/log4j/config/properties/JavaPropsConfigurationFactoryTest.java
+++ b/log4j-config-properties/src/test/java/org/apache/logging/log4j/config/properties/JavaPropsConfigurationFactoryTest.java
@@ -23,9 +23,9 @@ import java.nio.file.Path;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.AbstractConfigurationFactoryTest;
import org.apache.logging.log4j.core.filter.ThresholdFilter;
import org.apache.logging.log4j.core.test.appender.ListAppender;
+import org.apache.logging.log4j.core.test.config.AbstractConfigurationFactoryTest;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.test.junit.TempLoggingDir;
import org.junit.jupiter.api.Test;
diff --git a/log4j-config-yaml/src/test/java/org/apache/logging/log4j/config/yaml/YamlConfigurationFactoryTest.java b/log4j-config-yaml/src/test/java/org/apache/logging/log4j/config/yaml/YamlConfigurationFactoryTest.java
index 02d21323ab..8e88f321e0 100644
--- a/log4j-config-yaml/src/test/java/org/apache/logging/log4j/config/yaml/YamlConfigurationFactoryTest.java
+++ b/log4j-config-yaml/src/test/java/org/apache/logging/log4j/config/yaml/YamlConfigurationFactoryTest.java
@@ -19,7 +19,7 @@ package org.apache.logging.log4j.config.yaml;
import java.io.IOException;
import java.nio.file.Path;
import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.AbstractConfigurationFactoryTest;
+import org.apache.logging.log4j.core.test.config.AbstractConfigurationFactoryTest;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.test.junit.TempLoggingDir;
import org.junit.jupiter.api.Test;
diff --git a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/async/QueueFullAbstractTest.java b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/async/QueueFullAbstractTest.java
similarity index 96%
rename from log4j-core-test/src/main/java/org/apache/logging/log4j/core/async/QueueFullAbstractTest.java
rename to log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/async/QueueFullAbstractTest.java
index f6ea81eb13..4943de6314 100644
--- a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/async/QueueFullAbstractTest.java
+++ b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/async/QueueFullAbstractTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.core.test.async;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
@@ -32,7 +32,6 @@ import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.AsyncAppender;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
-import org.apache.logging.log4j.core.test.async.BlockingAppender;
import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.status.StatusLogger;
import org.apache.logging.log4j.test.junit.UsingStatusListener;
@@ -58,10 +57,10 @@ public abstract class QueueFullAbstractTest {
protected static class Unlocker extends Thread {
- final CountDownLatch countDownLatch;
+ public final CountDownLatch countDownLatch;
final BlockingAppender blockingAppender;
- Unlocker(final CountDownLatch countDownLatch, final BlockingAppender blockingAppender) {
+ public Unlocker(final CountDownLatch countDownLatch, final BlockingAppender blockingAppender) {
this.countDownLatch = countDownLatch;
this.blockingAppender = blockingAppender;
}
diff --git a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/config/AbstractConfigurationFactoryTest.java b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/config/AbstractConfigurationFactoryTest.java
similarity index 97%
rename from log4j-core-test/src/main/java/org/apache/logging/log4j/core/config/AbstractConfigurationFactoryTest.java
rename to log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/config/AbstractConfigurationFactoryTest.java
index 52f8ff9ee3..a0b3fc45ac 100644
--- a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/config/AbstractConfigurationFactoryTest.java
+++ b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/config/AbstractConfigurationFactoryTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.config;
+package org.apache.logging.log4j.core.test.config;
import static org.apache.logging.log4j.util.Unbox.box;
import static org.junit.jupiter.api.Assertions.assertAll;
@@ -35,6 +35,7 @@ import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
+import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.filter.ThreadContextMapFilter;
import org.apache.logging.log4j.util.Strings;
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/NestedLoggerConfigTest.java b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/config/AbstractNestedLoggerConfigTest.java
similarity index 65%
copy from log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/NestedLoggerConfigTest.java
copy to log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/config/AbstractNestedLoggerConfigTest.java
index abdcd11303..4c0a3cbb5f 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/NestedLoggerConfigTest.java
+++ b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/config/AbstractNestedLoggerConfigTest.java
@@ -14,41 +14,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.config;
+package org.apache.logging.log4j.core.test.config;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.io.InputStream;
-import java.util.List;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.xml.XmlConfiguration;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.Test;
-/**
- * Tests for LoggerConfig hierarchies.
- */
-@RunWith(Parameterized.class)
-public class NestedLoggerConfigTest {
-
- @Parameterized.Parameters(name = "{0}")
- public static List<String> data() throws IOException {
- return ImmutableList.of("logger-config/LoggerConfig/", "logger-config/AsyncLoggerConfig/");
- }
-
- private final String prefix;
-
- public NestedLoggerConfigTest(final String prefix) {
- this.prefix = prefix;
- }
+public abstract class AbstractNestedLoggerConfigTest {
@Test
public void testInheritParentDefaultLevel() throws IOException {
- final Configuration configuration = loadConfiguration(prefix + "default-level.xml");
+ final Configuration configuration = loadConfiguration("/default-level.xml");
try {
assertEquals(Level.ERROR, configuration.getLoggerConfig("com.foo").getLevel());
} finally {
@@ -58,7 +41,7 @@ public class NestedLoggerConfigTest {
@Test
public void testInheritParentLevel() throws IOException {
- final Configuration configuration = loadConfiguration(prefix + "inherit-level.xml");
+ final Configuration configuration = loadConfiguration("/inherit-level.xml");
try {
assertEquals(Level.TRACE, configuration.getLoggerConfig("com.foo").getLevel());
} finally {
@@ -67,7 +50,7 @@ public class NestedLoggerConfigTest {
}
private Configuration loadConfiguration(final String resourcePath) throws IOException {
- try (final InputStream in = getClass().getClassLoader().getResourceAsStream(resourcePath)) {
+ try (final InputStream in = getClass().getResourceAsStream(getClass().getSimpleName() + resourcePath)) {
final Configuration configuration =
new XmlConfiguration(new LoggerContext("test"), new ConfigurationSource(in));
configuration.initialize();
diff --git a/log4j-core-test/src/main/resources/org/apache/logging/log4j/core/async/QueueFullAbstractTest.xml b/log4j-core-test/src/main/resources/org/apache/logging/log4j/core/test/async/QueueFullAbstractTest.xml
similarity index 100%
rename from log4j-core-test/src/main/resources/org/apache/logging/log4j/core/async/QueueFullAbstractTest.xml
rename to log4j-core-test/src/main/resources/org/apache/logging/log4j/core/test/async/QueueFullAbstractTest.xml
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTest.java
index 1266ff7804..6b0292f74d 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTest.java
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTest.java
@@ -16,75 +16,38 @@
*/
package org.apache.logging.log4j.core.appender;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.not;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.util.Arrays;
-import java.util.Collection;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.test.junit.LoggerContextRule;
-import org.apache.logging.log4j.test.junit.CleanFiles;
-import org.hamcrest.Matcher;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.RuleChain;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
+import org.apache.logging.log4j.test.junit.TempLoggingDir;
+import org.junit.jupiter.api.Test;
/**
* Simple tests for both the RandomAccessFileAppender and RollingRandomAccessFileAppender.
*/
-@RunWith(Parameterized.class)
public class RandomAccessFileAppenderTest {
- @Parameterized.Parameters(name = "{0}, locationEnabled={1}, type={2}")
- public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][] {
- {"RandomAccessFileAppenderTest", false, ".xml"},
- {"RandomAccessFileAppenderLocationTest", true, ".xml"},
- {"RollingRandomAccessFileAppenderTest", false, ".xml"},
- {"RollingRandomAccessFileAppenderLocationTest", true, ".xml"}
- });
- }
-
- private final LoggerContextRule init;
- private final CleanFiles files;
-
- @Rule
- public final RuleChain chain;
+ public static final String MESSAGE = "This is a test log message brought to you by Slurm.";
- private final File logFile;
- private final boolean locationEnabled;
-
- public RandomAccessFileAppenderTest(final String testName, final boolean locationEnabled, final String type) {
- this.init = new LoggerContextRule(testName + type);
- this.logFile = new File("target", testName + ".log");
- this.files = new CleanFiles(this.logFile);
- this.locationEnabled = locationEnabled;
- this.chain = RuleChain.outerRule(files).around(init);
- }
+ @TempLoggingDir
+ private static Path loggingPath;
@Test
- public void testRandomAccessConfiguration() throws Exception {
- final Logger logger = this.init.getLogger("com.foo.Bar");
- final String message = "This is a test log message brought to you by Slurm.";
- logger.info(message);
- this.init.getLoggerContext().stop(); // stop async thread
-
- String line;
- try (final BufferedReader reader = new BufferedReader(new FileReader(this.logFile))) {
- line = reader.readLine();
+ @LoggerContextSource
+ public void testRandomAccessConfiguration(final LoggerContext ctx) throws Exception {
+ final Logger logger = ctx.getLogger(getClass());
+ logger.info(MESSAGE);
+ ctx.stop();
+
+ for (final String fileName : List.of("RandomAccessFile.log", "RollingRandomAccessFile.log")) {
+ final Path file = loggingPath.resolve(fileName);
+ assertThat(file).isNotEmptyFile();
+ assertThat(Files.readAllLines(file)).hasSize(1).containsExactly(MESSAGE);
}
- assertNotNull(line);
- assertThat(line, containsString(message));
- final Matcher<String> containsLocationInformation = containsString("testRandomAccessConfiguration");
- final Matcher<String> containsLocationInformationIfEnabled =
- this.locationEnabled ? containsLocationInformation : not(containsLocationInformation);
- assertThat(line, containsLocationInformationIfEnabled);
}
}
diff --git a/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncQueueFullPolicyFactoryTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncQueueFullPolicyFactoryTest.java
similarity index 93%
rename from log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncQueueFullPolicyFactoryTest.java
rename to log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncQueueFullPolicyFactoryTest.java
index 7f9f9c1c30..532cb9fe6e 100644
--- a/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncQueueFullPolicyFactoryTest.java
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncQueueFullPolicyFactoryTest.java
@@ -14,17 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.async.logger;
+package org.apache.logging.log4j.core.async;
import static org.apache.logging.log4j.util.Strings.toRootLowerCase;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.core.async.AsyncQueueFullPolicy;
-import org.apache.logging.log4j.core.async.AsyncQueueFullPolicyFactory;
-import org.apache.logging.log4j.core.async.DefaultAsyncQueueFullPolicy;
-import org.apache.logging.log4j.core.async.DiscardingAsyncQueueFullPolicy;
-import org.apache.logging.log4j.core.async.EventRoute;
import org.apache.logging.log4j.core.impl.Log4jPropertyKey;
import org.apache.logging.log4j.util.PropertiesUtil;
import org.junit.jupiter.api.AfterEach;
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncAppenderTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncAppenderTest.java
index e2383a8691..d4d15772ac 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncAppenderTest.java
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncAppenderTest.java
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.async;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.async.BlockingAppender;
+import org.apache.logging.log4j.core.test.async.QueueFullAbstractTest;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.core.test.junit.Named;
import org.junit.jupiter.api.Test;
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfigurationFactoryTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfigurationFactoryTest.java
index 623f841be8..b78741cd6c 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfigurationFactoryTest.java
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfigurationFactoryTest.java
@@ -19,6 +19,7 @@ package org.apache.logging.log4j.core.config;
import java.io.IOException;
import java.nio.file.Path;
import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.test.config.AbstractConfigurationFactoryTest;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.test.junit.TempLoggingDir;
import org.junit.jupiter.api.Tag;
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/NestedLoggerConfigTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/NestedLoggerConfigTest.java
index abdcd11303..72fc5726fd 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/NestedLoggerConfigTest.java
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/NestedLoggerConfigTest.java
@@ -16,63 +16,9 @@
*/
package org.apache.logging.log4j.core.config;
-import static org.junit.Assert.assertEquals;
-
-import com.google.common.collect.ImmutableList;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.List;
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.xml.XmlConfiguration;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.apache.logging.log4j.core.test.config.AbstractNestedLoggerConfigTest;
/**
* Tests for LoggerConfig hierarchies.
*/
-@RunWith(Parameterized.class)
-public class NestedLoggerConfigTest {
-
- @Parameterized.Parameters(name = "{0}")
- public static List<String> data() throws IOException {
- return ImmutableList.of("logger-config/LoggerConfig/", "logger-config/AsyncLoggerConfig/");
- }
-
- private final String prefix;
-
- public NestedLoggerConfigTest(final String prefix) {
- this.prefix = prefix;
- }
-
- @Test
- public void testInheritParentDefaultLevel() throws IOException {
- final Configuration configuration = loadConfiguration(prefix + "default-level.xml");
- try {
- assertEquals(Level.ERROR, configuration.getLoggerConfig("com.foo").getLevel());
- } finally {
- configuration.stop();
- }
- }
-
- @Test
- public void testInheritParentLevel() throws IOException {
- final Configuration configuration = loadConfiguration(prefix + "inherit-level.xml");
- try {
- assertEquals(Level.TRACE, configuration.getLoggerConfig("com.foo").getLevel());
- } finally {
- configuration.stop();
- }
- }
-
- private Configuration loadConfiguration(final String resourcePath) throws IOException {
- try (final InputStream in = getClass().getClassLoader().getResourceAsStream(resourcePath)) {
- final Configuration configuration =
- new XmlConfiguration(new LoggerContext("test"), new ConfigurationSource(in));
- configuration.initialize();
- configuration.start();
- return configuration;
- }
- }
-}
+public class NestedLoggerConfigTest extends AbstractNestedLoggerConfigTest {}
diff --git a/log4j-core-test/src/test/resources/RandomAccessFileAppenderLocationTest.xml b/log4j-core-test/src/test/resources/RandomAccessFileAppenderLocationTest.xml
deleted file mode 100644
index 38a76f0a89..0000000000
--- a/log4j-core-test/src/test/resources/RandomAccessFileAppenderLocationTest.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?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>
- <RandomAccessFile name="RandomAccessFile" fileName="target/RandomAccessFileAppenderLocationTest.log" immediateFlush="false" append="false">
- <PatternLayout>
- <Pattern>%d %p %c{1.} [%t] %X{aKey} %m %location %ex%n</Pattern>
- <!--
- <Pattern>%d %p %c{1.} %C %location %line [%t] %X{aKey} %m %ex%n</Pattern>
- -->
- </PatternLayout>
- </RandomAccessFile>
- </Appenders>
-
- <Loggers>
- <AsyncRoot level="info" includeLocation="true">
- <AppenderRef ref="RandomAccessFile"/>
- </AsyncRoot>
- </Loggers>
-</Configuration>
diff --git a/log4j-core-test/src/test/resources/RandomAccessFileAppenderTest.xml b/log4j-core-test/src/test/resources/RandomAccessFileAppenderTest.xml
deleted file mode 100644
index 146dd390cb..0000000000
--- a/log4j-core-test/src/test/resources/RandomAccessFileAppenderTest.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?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>
- <RandomAccessFile name="RandomAccessFile" fileName="target/RandomAccessFileAppenderTest.log" immediateFlush="false" append="false">
- <PatternLayout>
- <Pattern>%d %p %c{1.} [%t] %X{aKey} %m %location %ex%n</Pattern>
- <!--
- <Pattern>%d %p %c{1.} %C %location %line [%t] %X{aKey} %m %ex%n</Pattern>
- -->
- </PatternLayout>
- </RandomAccessFile>
- </Appenders>
-
- <Loggers>
- <AsyncRoot level="info" includeLocation="false">
- <AppenderRef ref="RandomAccessFile"/>
- </AsyncRoot>
- </Loggers>
-</Configuration>
diff --git a/log4j-core-test/src/test/resources/RollingRandomAccessFileAppenderTest.xml b/log4j-core-test/src/test/resources/RollingRandomAccessFileAppenderTest.xml
deleted file mode 100644
index fcea9c717c..0000000000
--- a/log4j-core-test/src/test/resources/RollingRandomAccessFileAppenderTest.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?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>
- <RollingRandomAccessFile name="RollingRandomAccessFile" fileName="target/RollingRandomAccessFileAppenderTest.log"
- filePattern="target/afterRollover-%i.log" append="false"
- immediateFlush="false">
- <PatternLayout>
- <Pattern>%d %p %c{1.} [%t] %X{aKey} %m %location %ex%n</Pattern>
- </PatternLayout>
- <Policies>
- <SizeBasedTriggeringPolicy size="250 B"/>
- </Policies>
- </RollingRandomAccessFile>
- </Appenders>
-
- <Loggers>
- <AsyncRoot level="info" includeLocation="false">
- <AppenderRef ref="RollingRandomAccessFile"/>
- </AsyncRoot>
- </Loggers>
-</Configuration>
diff --git a/log4j-core-test/src/test/resources/RollingRandomAccessFileAppenderLocationTest.xml b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTest.xml
similarity index 58%
rename from log4j-core-test/src/test/resources/RollingRandomAccessFileAppenderLocationTest.xml
rename to log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTest.xml
index 9e4f844552..06b2dd8035 100644
--- a/log4j-core-test/src/test/resources/RollingRandomAccessFileAppenderLocationTest.xml
+++ b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTest.xml
@@ -17,21 +17,25 @@
-->
<Configuration status="OFF">
<Appenders>
- <RollingRandomAccessFile name="RollingRandomAccessFile" fileName="target/RollingRandomAccessFileAppenderLocationTest.log"
- filePattern="test-%d{MM-dd-yyyy}-%i.log.gz" append="false"
- immediateFlush="false">
- <PatternLayout>
- <Pattern>%d %p %c{1.} [%t] %X{aKey} %m %location %ex%n</Pattern>
- </PatternLayout>
- <Policies>
- <TimeBasedTriggeringPolicy />
- </Policies>
+ <RandomAccessFile name="RandomAccessFile"
+ fileName="${test:logging.path}/RandomAccessFile.log"
+ immediateFlush="false"
+ append="false">
+ <PatternLayout/>
+ </RandomAccessFile>
+ <RollingRandomAccessFile name="RollingRandomAccessFile"
+ fileName="${test:logging.path}/RollingRandomAccessFile.log"
+ filePattern="${test:logging.path}/afterRollover-%i.log"
+ append="false"
+ immediateFlush="false">
+ <PatternLayout/>
+ <SizeBasedTriggeringPolicy size="250 B"/>
</RollingRandomAccessFile>
</Appenders>
-
<Loggers>
- <AsyncRoot level="info" includeLocation="true">
+ <Root level="INFO">
+ <AppenderRef ref="RandomAccessFile"/>
<AppenderRef ref="RollingRandomAccessFile"/>
- </AsyncRoot>
+ </Root>
</Loggers>
</Configuration>
diff --git a/log4j-core-test/src/test/resources/logger-config/LoggerConfig/default-level.xml b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/config/NestedLoggerConfigTest/default-level.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/logger-config/LoggerConfig/default-level.xml
rename to log4j-core-test/src/test/resources/org/apache/logging/log4j/core/config/NestedLoggerConfigTest/default-level.xml
diff --git a/log4j-core-test/src/test/resources/logger-config/LoggerConfig/inherit-level.xml b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/config/NestedLoggerConfigTest/inherit-level.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/logger-config/LoggerConfig/inherit-level.xml
rename to log4j-core-test/src/test/resources/org/apache/logging/log4j/core/config/NestedLoggerConfigTest/inherit-level.xml