Skip to content

Commit

Permalink
Add test run for Disruptor 4.x
Browse files Browse the repository at this point in the history
An additional test run will ensure `log4j-core` works with Disruptor
4.x.
  • Loading branch information
ppkarwasz committed Dec 19, 2023
1 parent 463e259 commit 9ceb5df
Show file tree
Hide file tree
Showing 20 changed files with 116 additions and 10 deletions.
30 changes: 30 additions & 0 deletions log4j-core-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@
java.allocation.instrumenter;substitute="java-allocation-instrumenter",
spring.test;substitute="spring-test"
</bnd-extra-module-options>

<!-- Additional version of LMAX Disruptor to test -->
<disruptor4.version>4.0.0</disruptor4.version>
</properties>

<dependencies>
<!-- Pull in useful test classes from API -->
<dependency>
Expand Down Expand Up @@ -371,6 +375,32 @@
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>test-disruptor-4</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<additionalClasspathDependencies>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>${disruptor4.version}</version>
</dependency>
</additionalClasspathDependencies>
<classpathDependencyExcludes>
<classpathDependencyExclude>com.lmax:disruptor</classpathDependencyExclude>
</classpathDependencyExcludes>
<groups>org.apache.logging.log4j.core.test.categories.AsyncLoggers</groups>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.core.test.junit;

/**
* Container for a Junit 5 tags used in tests.
*/
public final class Tags {

/**
* Tests that use LMAX Disruptor. Same name as the JUnit 4 category.
*/
public static final String ASYNC_LOGGERS = "org.apache.logging.log4j.core.test.categories.AsyncLoggers";

private Tags() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @see org.junit.rules.TestRule
*/
@Export
@Version("2.21.1")
@Version("2.23.0")
package org.apache.logging.log4j.core.test.junit;

import org.osgi.annotation.bundle.Export;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.test.junit.Tags;
import org.junit.jupiter.api.Tag;

@Tag(Tags.ASYNC_LOGGERS)
class AsyncLoggerClassLoadDeadlock {
static {
final Logger log = LogManager.getLogger("com.foo.bar.deadlock");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@
import org.apache.logging.log4j.core.config.NullConfiguration;
import org.apache.logging.log4j.core.test.CoreLoggerContexts;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.core.test.junit.Tags;
import org.apache.logging.log4j.message.SimpleMessage;
import org.apache.logging.log4j.test.junit.TempLoggingDir;
import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Tag("AsyncLoggers")
@Tag(Tags.ASYNC_LOGGERS)
@UsingStatusListener
public class AsyncLoggerConfigTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.logging.log4j.ThreadContext;
import org.apache.logging.log4j.core.test.CoreLoggerContexts;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.core.test.junit.Tags;
import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.test.TestProperties;
import org.apache.logging.log4j.test.junit.TempLoggingDir;
Expand All @@ -35,7 +36,7 @@
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Tag("AsyncLoggers")
@Tag(Tags.ASYNC_LOGGERS)
@UsingTestProperties
@UsingStatusListener
public class AsyncLoggerThreadContextTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.appender.ListAppender;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.core.test.junit.Tags;
import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.test.junit.SetTestProperty;
import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Tag("AsyncLoggers")
@Tag(Tags.ASYNC_LOGGERS)
@SetTestProperty(
key = Constants.LOG4J_CONTEXT_SELECTOR,
value = "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
package org.apache.logging.log4j.core.async;

import java.nio.file.Path;
import org.apache.logging.log4j.core.test.junit.Tags;
import org.apache.logging.log4j.test.junit.TempLoggingDir;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

// Note: the different ThreadContextMap implementations cannot be parameterized:
// ThreadContext initialization will result in static final fields being set in various components.
// To use a different ThreadContextMap, the test needs to be run in a new JVM.
@Tag(Tags.ASYNC_LOGGERS)
public class AsyncThreadContextCopyOnWriteTest extends AbstractAsyncThreadContextTestBase {

@TempLoggingDir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
package org.apache.logging.log4j.core.async;

import java.nio.file.Path;
import org.apache.logging.log4j.core.test.junit.Tags;
import org.apache.logging.log4j.test.junit.TempLoggingDir;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

// Note: the different ThreadContextMap implementations cannot be parameterized:
// ThreadContext initialization will result in static final fields being set in various components.
// To use a different ThreadContextMap, the test needs to be run in a new JVM.
@Tag(Tags.ASYNC_LOGGERS)
public class AsyncThreadContextDefaultTest extends AbstractAsyncThreadContextTestBase {

@TempLoggingDir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
package org.apache.logging.log4j.core.async;

import java.nio.file.Path;
import org.apache.logging.log4j.core.test.junit.Tags;
import org.apache.logging.log4j.test.junit.TempLoggingDir;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

// Note: the different ThreadContextMap implementations cannot be parameterized:
// ThreadContext initialization will result in static final fields being set in various components.
// To use a different ThreadContextMap, the test needs to be run in a new JVM.
@Tag(Tags.ASYNC_LOGGERS)
public class AsyncThreadContextGarbageFreeTest extends AbstractAsyncThreadContextTestBase {

@TempLoggingDir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.apache.logging.log4j.core.async;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -58,10 +58,14 @@ public void testIncorrectConfigWaitStrategyFactory() throws Exception {

final AsyncLogger logger = (AsyncLogger) context.getRootLogger();
final AsyncLoggerDisruptor delegate = logger.getAsyncLoggerDisruptor();
assertEquals(
TimeoutBlockingWaitStrategy.class, delegate.getWaitStrategy().getClass());
assertThat(
"waitstrategy is TimeoutBlockingWaitStrategy",
delegate.getWaitStrategy() instanceof TimeoutBlockingWaitStrategy);
if (DisruptorUtil.DISRUPTOR_MAJOR_VERSION == 3) {
assertEquals(
TimeoutBlockingWaitStrategy.class,
delegate.getWaitStrategy().getClass());
} else {
assertEquals(
Class.forName("com.lmax.disruptor.TimeoutBlockingWaitStrategy"),
delegate.getWaitStrategy().getClass());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.core.test.junit.Named;
import org.apache.logging.log4j.core.test.junit.Tags;
import org.apache.logging.log4j.test.junit.SetTestProperty;
import org.apache.logging.log4j.util.Constants;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

/**
Expand All @@ -31,6 +33,7 @@
@SetTestProperty(key = "log4j2.enableThreadlocals", value = "true")
@SetTestProperty(key = "log4j2.isWebapp", value = "false")
@SetTestProperty(key = "log4j2.asyncLoggerConfigRingBufferSize", value = "128")
@Tag(Tags.ASYNC_LOGGERS)
public class QueueFullAsyncLoggerConfigLoggingFromToStringTest extends QueueFullAbstractTest {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
package org.apache.logging.log4j.core.async;

import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.Tags;
import org.apache.logging.log4j.test.junit.SetTestProperty;
import org.junit.jupiter.api.Tag;

/**
* Tests queue full scenarios with AsyncLoggers in configuration.
*/
@SetTestProperty(key = "log4j2.formatMsgAsync", value = "true")
@Tag(Tags.ASYNC_LOGGERS)
public class QueueFullAsyncLoggerConfigLoggingFromToStringTest2
extends QueueFullAsyncLoggerConfigLoggingFromToStringTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.core.test.junit.Named;
import org.apache.logging.log4j.core.test.junit.Tags;
import org.apache.logging.log4j.test.junit.SetTestProperty;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

/**
* Tests queue full scenarios with AsyncLoggers in configuration.
*/
@SetTestProperty(key = "log4j2.asyncLoggerConfigRingBufferSize", value = "128")
@Tag(Tags.ASYNC_LOGGERS)
public class QueueFullAsyncLoggerConfigTest extends QueueFullAbstractTest {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
package org.apache.logging.log4j.core.async;

import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.Tags;
import org.apache.logging.log4j.test.junit.SetTestProperty;
import org.junit.jupiter.api.Tag;

/**
* Tests queue full scenarios with AsyncLoggers in configuration.
*/
@SetTestProperty(key = "log4j2.formatMsgAsync", value = "true")
@Tag(Tags.ASYNC_LOGGERS)
public class QueueFullAsyncLoggerConfigTest2 extends QueueFullAsyncLoggerConfigTest {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.core.test.junit.Named;
import org.apache.logging.log4j.core.test.junit.Tags;
import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.test.junit.SetTestProperty;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

/**
Expand All @@ -30,6 +32,7 @@
key = Constants.LOG4J_CONTEXT_SELECTOR,
value = "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector")
@SetTestProperty(key = "log4j2.asyncLoggerRingBufferSize", value = "128")
@Tag(Tags.ASYNC_LOGGERS)
public class QueueFullAsyncLoggerLoggingFromToStringTest extends QueueFullAbstractTest {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
import static org.junit.Assert.*;

import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.Tags;
import org.apache.logging.log4j.test.junit.SetTestProperty;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;

/**
* Tests queue full scenarios with pure AsyncLoggers (all loggers async).
*/
@SetTestProperty(key = "log4j2.formatMsgAsync", value = "true")
@Tag(Tags.ASYNC_LOGGERS)
public class QueueFullAsyncLoggerLoggingFromToStringTest2 extends QueueFullAsyncLoggerLoggingFromToStringTest {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.core.test.junit.Named;
import org.apache.logging.log4j.core.test.junit.Tags;
import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.test.junit.SetTestProperty;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

/**
Expand All @@ -30,6 +32,7 @@
key = Constants.LOG4J_CONTEXT_SELECTOR,
value = "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector")
@SetTestProperty(key = "log4j2.asyncLoggerRingBufferSize", value = "128")
@Tag(Tags.ASYNC_LOGGERS)
public class QueueFullAsyncLoggerTest extends QueueFullAbstractTest {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
package org.apache.logging.log4j.core.async;

import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.Tags;
import org.apache.logging.log4j.test.junit.SetTestProperty;
import org.junit.jupiter.api.Tag;

/**
* Needs to be a separate class since {@link org.apache.logging.log4j.core.util.Constants#FORMAT_MESSAGES_IN_BACKGROUND}
* is immutable.
*/
@SetTestProperty(key = "log4j2.formatMsgAsync", value = "true")
@Tag(Tags.ASYNC_LOGGERS)
public class QueueFullAsyncLoggerTest2 extends QueueFullAsyncLoggerTest {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.core.test.junit.Named;
import org.apache.logging.log4j.core.test.junit.Tags;
import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.test.junit.SetTestProperty;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

Expand All @@ -41,6 +43,7 @@
@SetTestProperty(key = "log4j2.asyncLoggerRingBufferSize", value = "128")
@SetTestProperty(key = "log4j2.formatMsgAsync", value = "true")
@SetTestProperty(key = "log4j2.asyncQueueFullPolicy", value = "Discard")
@Tag(Tags.ASYNC_LOGGERS)
public class QueueFullAsyncLoggerTest3 extends QueueFullAbstractTest {

@Override
Expand Down

0 comments on commit 9ceb5df

Please sign in to comment.