Skip to content

Commit 0bc42fe

Browse files
committed
Add sleep in tests and use static newBuilder import
Introduce a short Thread.sleep(50L) in newEvent to avoid timing-related flakiness, update test methods to declare throws InterruptedException, and replace direct Log4jLogEvent usage with a static import of newBuilder. Clean up corresponding imports.
1 parent 5be1085 commit 0bc42fe

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

microsphere-log4j2/src/test/java/io/microsphere/logging/log4j2/appender/InMemoryAppenderTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import org.apache.logging.log4j.core.Appender;
2121
import org.apache.logging.log4j.core.LogEvent;
22-
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
2322
import org.apache.logging.log4j.core.layout.PatternLayout;
2423
import org.apache.logging.log4j.message.SimpleMessage;
2524
import org.junit.jupiter.api.Test;
@@ -29,7 +28,9 @@
2928

3029
import static io.microsphere.logging.log4j2.appender.InMemoryAppender.NAME;
3130
import static io.microsphere.logging.log4j2.appender.InMemoryAppender.findInMemoryAppender;
31+
import static java.lang.Thread.sleep;
3232
import static org.apache.logging.log4j.Level.INFO;
33+
import static org.apache.logging.log4j.core.impl.Log4jLogEvent.newBuilder;
3334
import static org.junit.jupiter.api.Assertions.assertEquals;
3435
import static org.junit.jupiter.api.Assertions.assertFalse;
3536
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -63,7 +64,7 @@ void testBasicMethodsAndLifecycle() {
6364
}
6465

6566
@Test
66-
void testAppendTransferAndStopClearsEvents() {
67+
void testAppendTransferAndStopClearsEvents() throws InterruptedException {
6768
InMemoryAppender source = new InMemoryAppender();
6869
CollectingAppender target = new CollectingAppender();
6970

@@ -99,8 +100,9 @@ void testFindInMemoryAppenderWithoutConfiguration() {
99100
assertTrue(result == null || result instanceof InMemoryAppender);
100101
}
101102

102-
private static LogEvent newEvent(String message) {
103-
return Log4jLogEvent.newBuilder()
103+
private static LogEvent newEvent(String message) throws InterruptedException {
104+
sleep(50L);
105+
return newBuilder()
104106
.setLoggerName("test.logger")
105107
.setLoggerFqcn(InMemoryAppenderTest.class.getName())
106108
.setLevel(INFO)

0 commit comments

Comments
 (0)