Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.async;

import static org.assertj.core.api.Assertions.assertThat;

import java.lang.reflect.Method;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.status.StatusData;
import org.apache.logging.log4j.test.ListStatusListener;
import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.junit.jupiter.api.Test;

@UsingStatusListener
class DisruptorUtilTest {

@Test
void detectDisruptorMajorVersion_logsVersionDetection(final ListStatusListener statusListener) throws Exception {
final Method method = DisruptorUtil.class.getDeclaredMethod("detectDisruptorMajorVersion");
method.setAccessible(true);
final int detectedVersion = (int) method.invoke(null);

assertThat(detectedVersion).isIn(3, 4);

final List<StatusData> debugData =
statusListener.findStatusData(Level.DEBUG).collect(Collectors.toList());
assertThat(debugData).anySatisfy(data -> assertThat(data.getMessage().getFormattedMessage())
.contains("LMAX Disruptor version detected: " + detectedVersion));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ final class DisruptorUtil {
// TODO: replace with LoaderUtil.isClassAvailable() when TCCL is removed
// See: https://github.com/apache/logging-log4j2/issues/3706
private static int detectDisruptorMajorVersion() {
final int version;
try {
Class.forName(
"com.lmax.disruptor.SequenceReportingEventHandler", true, DisruptorUtil.class.getClassLoader());
"com.lmax.disruptor.SequenceReportingEventHandler", false, DisruptorUtil.class.getClassLoader());
version = 3;
return 3;
} catch (final ClassNotFoundException e) {
return 4;
} catch (final ClassNotFoundException ignored) {
version = 4;
}
Comment on lines +58 to 66
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final int version;
try {
Class.forName(
"com.lmax.disruptor.SequenceReportingEventHandler", true, DisruptorUtil.class.getClassLoader());
"com.lmax.disruptor.SequenceReportingEventHandler", false, DisruptorUtil.class.getClassLoader());
version = 3;
return 3;
} catch (final ClassNotFoundException e) {
return 4;
} catch (final ClassNotFoundException ignored) {
version = 4;
}
int version = 4;
try {
Class.forName(
"com.lmax.disruptor.SequenceReportingEventHandler", false, DisruptorUtil.class.getClassLoader());
version = 3;
return 3;
} catch (final ClassNotFoundException ignored) {
// Do nothing
}

LOGGER.debug("LMAX Disruptor version detected: {}", version);
return version;
}

private DisruptorUtil() {}
Expand Down
Loading