You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ra...@apache.org on 2026/09/16 07:06:23 UTC
(logging-log4j2) branch 2.x updated: Fix the log4j-spring-cloud-config-client test harness (#4317)
This is an automated email from the ASF dual-hosted git repository.
ramanathan1504 pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/2.x by this push:
new 6ad11e4003 Fix the log4j-spring-cloud-config-client test harness (#4317)
6ad11e4003 is described below
commit 6ad11e40037c033e2eeece72817b4e7441026aa5
Author: Ramanathan <ra...@apache.org>
AuthorDate: Wed Sep 16 12:36:16 2026 +0530
Fix the log4j-spring-cloud-config-client test harness (#4317)
* Fix the `log4j-spring-cloud-config-client` test harness
* Fix `log4j-spring-cloud-config-client` test harness and update `junit-vintage-engine` dependency
---
log4j-spring-cloud-config-client/pom.xml | 27 ++++++++++++++++++++
.../config/client/Log4j2EventListenerTest.java | 29 ++++++++--------------
.../src/test/resources/log4j2-console.xml | 2 +-
3 files changed, 39 insertions(+), 19 deletions(-)
diff --git a/log4j-spring-cloud-config-client/pom.xml b/log4j-spring-cloud-config-client/pom.xml
index 914f42c611..4248884f2e 100644
--- a/log4j-spring-cloud-config-client/pom.xml
+++ b/log4j-spring-cloud-config-client/pom.xml
@@ -113,6 +113,33 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.junit.vintage</groupId>
+ <artifactId>junit-vintage-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <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>run-tests</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>default-test</id>
+ <phase>none</phase>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
</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" />