Skip to content

Commit

Permalink
Add test verifying log42j updateLoggers is called (#5822)
Browse files Browse the repository at this point in the history
This will ensure it is not removed in the future because it is needed even if it is not apparent. See gh-872 and gh-867 for related history.

Signed-off-by: Patrik Ivarsson <[email protected]>
  • Loading branch information
pativa authored Jan 28, 2025
1 parent 56cd839 commit e73ead8
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 e73ead8

Please sign in to comment.