Skip to content

Add support for LMAX Disruptor 4.x #2112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ updates:
# Json Unit 3.x requires Java 17
- dependency-name: "net.javacrumbs.json-unit:*"
versions: ["[3.0.0,)"]
# LMAX Disruptor requires Java 11
# Update both `disruptor.version` to latest 3.x version
# and `disruptor4.version` to latest 4.x version
- dependency-name: "com.lmax:disruptor"
versions: ["[4.0.0,)"]
update-types: ["version-update:semver-major"]
# WebCompere System Stubs requires Java 11
- dependency-name: "uk.org.webcompere:*"
versions: ["2.1.0,)"]
Expand Down
28 changes: 2 additions & 26 deletions log4j-api-java9/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<!-- Uses a different id than `default-test` to ignore the `java8-tests` profile -->
<execution>
<id>test</id>
<id>run-tests</id>
<goals>
<goal>test</goal>
</goals>
Expand All @@ -100,29 +101,4 @@
</plugins>
</build>

<profiles>
<profile>
<id>java8-tests</id>
<activation>
<property>
<name>env.CI</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration combine.self="override">
<reuseForks>false</reuseForks>
<systemPropertyVariables>
<java.awt.headless>true</java.awt.headless>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
44 changes: 44 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 Expand Up @@ -422,6 +452,20 @@

</profile>

<!--
~ Dummy profile to force Dependabot to upgrade `disruptor4.version`.
~ Using this profile causes a compilation error.
-->
<profile>
<id>disruptor-4</id>
<dependencies>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>${disruptor4.version}</version>
</dependency>
</dependencies>
</profile>
</profiles>

</project>
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
Loading