Skip to content

Commit

Permalink
Fix ThrottlingAppenderWrapperTest
Browse files Browse the repository at this point in the history
  • Loading branch information
joschi authored and renovate[bot] committed Nov 5, 2023
1 parent 61a67ef commit 07319a3
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import ch.qos.logback.classic.filter.LevelFilter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.classic.util.LogbackMDCAdapter;
import ch.qos.logback.core.spi.FilterReply;
import ch.qos.logback.core.spi.LifeCycle;
import ch.qos.logback.core.status.ErrorStatus;
Expand Down Expand Up @@ -37,6 +38,7 @@ class ThrottlingAppenderWrapperTest {
void setup() {
context = new LoggerContext();
context.setName("context-test");
context.setMDCAdapter(new LogbackMDCAdapter());
context.start();

collectingAppender = new CollectingAppender<>();
Expand Down Expand Up @@ -109,7 +111,7 @@ private void runLineTest(final long messageRateNanos, final int lineCount, final
final RateLimiter rateLimiter = RateLimiter.create(limit);
for (int i = 0; i < lineCount; i++) {
rateLimiter.acquire();
final LoggingEvent event = new LoggingEvent();
final LoggingEvent event = newLoggingEvent();
event.setLevel(Level.INFO);
event.setLoggerName("test");
event.setMessage(APP_LOG_PREFIX + " " + i);
Expand Down Expand Up @@ -177,7 +179,7 @@ void testLifeCycle() {
void testDoAppend() {
final ThrottlingAppenderWrapper<ILoggingEvent> wrapper = new ThrottlingAppenderWrapper<>(asyncAppender, 1L, TimeUnit.SECONDS);
wrapper.start();
final LoggingEvent event = new LoggingEvent();
final LoggingEvent event = newLoggingEvent();
wrapper.doAppend(event);
wrapper.stop();

Expand Down Expand Up @@ -293,7 +295,7 @@ void testGetFilterChainDecision() {
wrapper.addFilter(filter);
wrapper.start();

final LoggingEvent event = new LoggingEvent();
final LoggingEvent event = newLoggingEvent();
event.setLevel(Level.DEBUG);

assertThat(wrapper.getFilterChainDecision(event)).isEqualTo(FilterReply.DENY);
Expand All @@ -304,4 +306,10 @@ void testToString() {
final ThrottlingAppenderWrapper<ILoggingEvent> wrapper = new ThrottlingAppenderWrapper<>(asyncAppender, 1L, TimeUnit.SECONDS);
assertThat(wrapper.toString()).isEqualTo("io.dropwizard.logback.ThrottlingAppenderWrapper[async-appender-test]");
}

private LoggingEvent newLoggingEvent() {
final LoggingEvent event = new LoggingEvent();
event.setLoggerContext(context);
return event;
}
}

0 comments on commit 07319a3

Please sign in to comment.