Skip to content

Commit

Permalink
Add test verifying log42j updateLoggers is called
Browse files Browse the repository at this point in the history
  • Loading branch information
pativa committed Jan 24, 2025
1 parent c39bda3 commit 9e154a6
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.io.IOException;
import java.time.Duration;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;

import static java.util.Collections.emptyList;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -186,6 +187,27 @@ void asyncLogShouldNotBeDuplicated() throws IOException {
.until(() -> registry.get("log4j2.events").tags("level", "info").counter().count() == 3);
}

// see https://github.com/micrometer-metrics/micrometer/pull/872
@Test
void shouldTriggerLoggersUpdateOnOpenAndClose() {
LoggerContext context = new LoggerContext("test");

AtomicInteger reconfigureCount = new AtomicInteger();
context.addPropertyChangeListener(event -> {
if (event.getNewValue() instanceof Configuration) {
reconfigureCount.incrementAndGet();
}
});

Log4j2Metrics metrics = new Log4j2Metrics(emptyList(), context);

assertThat(reconfigureCount.get()).isEqualTo(0);
metrics.bindTo(registry);
assertThat(reconfigureCount.get()).isEqualTo(1);
metrics.close();
assertThat(reconfigureCount.get()).isEqualTo(2);
}

@Test
void metricsFilterIsReused() {
LoggerContext loggerContext = new LoggerContext("test");
Expand Down

0 comments on commit 9e154a6

Please sign in to comment.