Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 0 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ ext {
hibernateValidationVersion = '8.0.2.Final'
jacksonBomVersion = '2.18.3'
jaywayJsonPathVersion = '2.9.0'
junit4Version = '4.13.2'
junitJupiterVersion = '5.12.2'
kafkaVersion = '4.0.0'
kotlinCoroutinesVersion = '1.10.2'
Expand Down Expand Up @@ -378,9 +377,6 @@ project ('spring-kafka-test') {
api 'org.junit.platform:junit-platform-launcher'
optionalApi "org.hamcrest:hamcrest-core:$hamcrestVersion"
optionalApi "org.mockito:mockito-core:$mockitoVersion"
optionalApi ("junit:junit:$junit4Version") {
Copy link
Member

Choose a reason for hiding this comment

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

This is not correct.
We are talking about deprecation of the utility, but not total removal.
Therefore dependency and deprecated classes must still be here.
Again: we develop library, so whatever we do here might break target projects using our library.

Removing it temporary locally is a good way to check if we still have any JUnit 4 tests left. 😄

exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
optionalApi "org.apache.logging.log4j:log4j-core:$log4jVersion"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,32 +14,34 @@
* limitations under the License.
*/

package org.springframework.kafka.test.rule;
package org.springframework.kafka.test.extensions;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.apache.logging.log4j.Level;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.InvocationInterceptor;
import org.junit.jupiter.api.extension.ReflectiveInvocationContext;

import org.springframework.kafka.test.utils.JUnitUtils;
import org.springframework.kafka.test.utils.JUnitUtils.LevelsContainer;

/**
* A JUnit method @Rule that changes the logger level for a set of classes
* A JUnit extension @ that changes the logger level for a set of classes
* while a test method is running. Useful for performance or scalability tests
* where we don't want to generate a large log in a tight inner loop.
*
* @author Dave Syer
* @author Artem Bilan
* @author Gary Russell
* @author Sanghyoek An
*
*/
public class Log4j2LevelAdjuster implements MethodRule {
public class Log4j2LevelAdjuster implements InvocationInterceptor {
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is this class used with Junit5?

Copy link
Member

Choose a reason for hiding this comment

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

This is not correct.
The class is public and for end-user consumption.
It is totally wrong to change the class contract.
We develop here a library for target projects, so whatever is public cannot be changed like this.
We have to revert the change here and deprecate it.
We may come up with JUnit 5 variant. But that is a different story.
You may take a inspiration from Spring AMQP: https://github.com/spring-projects/spring-amqp/blob/main/spring-rabbit-junit/src/main/java/org/springframework/amqp/rabbit/junit/LogLevels.java

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can deprecate it on the 3.3.x line and then still remove it in 4.0.0. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah... That would be inconsistent with Spring Framework plans.
They do deprecate JUnit 4 in version 7.0.

Copy link
Contributor Author

@chickenchickenlove chickenchickenlove May 1, 2025

Choose a reason for hiding this comment

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

@sobychacko

As @artembilan mentioned before, this class is to configure log levels.
Also, It can be replace with @LogLevels in Junit5.


private final List<Class<?>> classes;

Expand All @@ -60,25 +62,25 @@ public Log4j2LevelAdjuster categories(String... categoriesToAdjust) {
}

@Override
public Statement apply(final Statement base, FrameworkMethod method, Object target) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
LevelsContainer container = null;
try {
container = JUnitUtils.adjustLogLevels(method.getName(),
Log4j2LevelAdjuster.this.classes, Log4j2LevelAdjuster.this.categories,
Log4j2LevelAdjuster.this.level);
base.evaluate();
}
finally {
if (container != null) {
JUnitUtils.revertLevels(method.getName(), container);
}
}
}
public void interceptTestMethod(Invocation<Void> invocation,
ReflectiveInvocationContext<Method> invocationContext,
ExtensionContext extensionContext) throws Throwable {
String methodName = extensionContext.getRequiredTestMethod().getName();
LevelsContainer container = null;

};
try {
container = JUnitUtils.adjustLogLevels(
methodName,
Log4j2LevelAdjuster.this.classes,
Log4j2LevelAdjuster.this.categories,
Log4j2LevelAdjuster.this.level);
invocation.proceed();
}
finally {
if (container != null) {
JUnitUtils.revertLevels(methodName, container);
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Provides JUnit5 extensions.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.kafka.test.extensions;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.kafka.test.rule;
package org.springframework.kafka.test.extensions;
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't look like this class logic does something with log adjustment.
Might be better to move it to some other package.
Probably to the root one alongside with the EmbeddedKafkaKraftBrokerTests


import java.io.IOException;
import java.net.ServerSocket;
Expand Down