This is an automated email from the ASF dual-hosted git repository. ramanathan1504 pushed a commit to branch fix-spring-cloud-config-client-test-harness in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 919dead95982dc6ed81120e40447686c6df527fc Author: Ramanathan <[email protected]> AuthorDate: Thu Sep 10 15:32:30 2026 +0530 Fix the `log4j-spring-cloud-config-client` test harness The module has run no tests since `8d706b4b27` (2024-01-04) removed `junit-vintage-engine` while `Log4j2EventListenerTest` stayed on JUnit 4: Surefire selects the JUnit Platform provider, discovers nothing and reports `Tests run: 0` with a green build. Restoring the engine exposes three further breakages that kept the only assertion in the module unreachable: - `CONFIG` named `log4j-console.xml`; the resource is `log4j2-console.xml`. - `spring-boot-starter-log4j2` is a test dependency, so Boot installs its own bundled `log4j2.xml` before `LoggerContextRule` can install the module's. - Neither configuration declares `monitorInterval`, so `AbstractConfiguration.isConfigurationMonitoringEnabled()` is false, `WatchManager.start()` never runs, nothing subscribes to `WatchEventManager` and `publishEvent()` iterates an empty map. `logging.config` now points Boot at the module's own configuration and the test reads the `LoggerContext` that Boot installed, which retires the `LoggerContextRule` and `RuleChain`. `withCleanFilesRule("target/logs")` is dropped with them; the configuration declares a single console appender and has never written there. Verified: `Tests run: 1, Failures: 0` with both halves in place, and `Failures: 1` with either `monitorInterval` or the `logging.config` property removed. Full `verify` on the module is green through spotbugs, RAT, spotless and bnd-baseline. --- log4j-spring-cloud-config-client/pom.xml | 5 ++++ .../config/client/Log4j2EventListenerTest.java | 29 ++++++++-------------- .../src/test/resources/log4j2-console.xml | 2 +- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/log4j-spring-cloud-config-client/pom.xml b/log4j-spring-cloud-config-client/pom.xml index 914f42c611..7018de832a 100644 --- a/log4j-spring-cloud-config-client/pom.xml +++ b/log4j-spring-cloud-config-client/pom.xml @@ -113,6 +113,11 @@ <scope>test</scope> </dependency> + <dependency> + <groupId>org.junit.vintage</groupId> + <artifactId>junit-vintage-engine</artifactId> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/log4j-spring-cloud-config-client/src/test/java/org/apache/logging/log4j/spring/cloud/config/client/Log4j2EventListenerTest.java b/log4j-spring-cloud-config-client/src/test/java/org/apache/logging/log4j/spring/cloud/config/client/Log4j2EventListenerTest.java index 57749b2de8..c8d3b3d8e6 100644 --- a/log4j-spring-cloud-config-client/src/test/java/org/apache/logging/log4j/spring/cloud/config/client/Log4j2EventListenerTest.java +++ b/log4j-spring-cloud-config-client/src/test/java/org/apache/logging/log4j/spring/cloud/config/client/Log4j2EventListenerTest.java @@ -22,14 +22,14 @@ import java.io.File; import java.util.HashSet; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.config.ConfigurationListener; import org.apache.logging.log4j.core.config.Reconfigurable; -import org.apache.logging.log4j.core.test.junit.LoggerContextRule; import org.apache.logging.log4j.core.util.Source; +import org.apache.logging.log4j.core.util.WatchManager; import org.apache.logging.log4j.core.util.Watcher; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.RuleChain; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -41,30 +41,23 @@ import org.springframework.test.context.junit4.SpringRunner; * Class Description goes here. */ @RunWith(SpringRunner.class) -@SpringBootTest(classes = {SpringConfiguration.class}) +@SpringBootTest( + classes = {SpringConfiguration.class}, + properties = {"logging.config=classpath:log4j2-console.xml"}) public class Log4j2EventListenerTest { - private static final String CONFIG = "log4j-console.xml"; - private static final String DIR = "target/logs"; - - public static LoggerContextRule loggerContextRule = - LoggerContextRule.createShutdownTimeoutLoggerContextRule(CONFIG); - - @Rule - public RuleChain chain = loggerContextRule.withCleanFilesRule(DIR); - @Autowired private ApplicationEventPublisher publisher; + private static WatchManager watchManager() { + return ((LoggerContext) LogManager.getContext(false)).getConfiguration().getWatchManager(); + } + @Test public void test() { final AtomicInteger count = new AtomicInteger(0); final Source source = new Source(new File("test.java")); - loggerContextRule - .getLoggerContext() - .getConfiguration() - .getWatchManager() - .watch(source, new TestWatcher(count)); + watchManager().watch(source, new TestWatcher(count)); publisher.publishEvent(new EnvironmentChangeEvent(new HashSet<>())); assertTrue(count.get() > 0); } diff --git a/log4j-spring-cloud-config-client/src/test/resources/log4j2-console.xml b/log4j-spring-cloud-config-client/src/test/resources/log4j2-console.xml index d85749123b..6594f9fb1a 100644 --- a/log4j-spring-cloud-config-client/src/test/resources/log4j2-console.xml +++ b/log4j-spring-cloud-config-client/src/test/resources/log4j2-console.xml @@ -15,7 +15,7 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> -<Configuration status="OFF"> +<Configuration status="OFF" monitorInterval="300"> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d [%t] %-5level: %msg%n%throwable" />
