Skip to content

Commit 03b250d

Browse files
committed
Fix an test error by awaiting the thread termination using ExecutorService
1 parent 70e3cf9 commit 03b250d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/test/java/org/fluentd/logger/TestFluentLogger.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import java.io.IOException;
1313
import java.net.Socket;
1414
import java.util.*;
15+
import java.util.concurrent.Executor;
16+
import java.util.concurrent.ExecutorService;
17+
import java.util.concurrent.Executors;
1518
import java.util.concurrent.TimeUnit;
1619

1720
import static org.junit.Assert.assertEquals;
@@ -103,7 +106,8 @@ public void process(MessagePack msgpack, Socket socket) throws IOException {
103106
}
104107
}
105108
});
106-
fluentd.start();
109+
ExecutorService executor = Executors.newFixedThreadPool(1);
110+
executor.submit(fluentd);
107111

108112
// start loggers
109113
FluentLogger[] loggers = new FluentLogger[loggerCount];
@@ -143,7 +147,8 @@ public void process(MessagePack msgpack, Socket socket) throws IOException {
143147
fluentd.close();
144148

145149
// wait for unpacking event data on fluentd
146-
Thread.sleep(1000);
150+
while(executor.awaitTermination(1000, TimeUnit.MILLISECONDS)) {
151+
}
147152

148153
// check data
149154
assertEquals(counts[0], elists[0].size());

0 commit comments

Comments
 (0)