summaryrefslogtreecommitdiffstats
path: root/logserver
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@verizonmedia.com>2021-02-09 14:11:47 +0100
committerBjørn Christian Seime <bjorncs@verizonmedia.com>2021-02-09 14:13:16 +0100
commit1c8adc956f304154d72dc7162db33e101c36070c (patch)
tree5493dcaaa64c750fa5bac89897a47599cb114bc4 /logserver
parentdcf48329e291a06082e6693c6925f22b16000f3e (diff)
Speedup Flusher unit test
Finish test as soon as flush is invoked on mock handler
Diffstat (limited to 'logserver')
-rw-r--r--logserver/src/test/java/com/yahoo/logserver/FlusherTestCase.java36
1 files changed, 26 insertions, 10 deletions
diff --git a/logserver/src/test/java/com/yahoo/logserver/FlusherTestCase.java b/logserver/src/test/java/com/yahoo/logserver/FlusherTestCase.java
index f2128114178..3de6413b6ce 100644
--- a/logserver/src/test/java/com/yahoo/logserver/FlusherTestCase.java
+++ b/logserver/src/test/java/com/yahoo/logserver/FlusherTestCase.java
@@ -1,25 +1,41 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.logserver;
-import static org.junit.Assert.*;
-
+import com.yahoo.log.LogMessage;
+import com.yahoo.logserver.handlers.LogHandler;
import org.junit.Test;
-import com.yahoo.logserver.handlers.LogHandler;
-import com.yahoo.logserver.test.LogDispatcherTestCase;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.assertTrue;
public class FlusherTestCase {
@Test
- public void testFlusher() throws InterruptedException {
+ public void flush_is_invoked_on_handler_and_flusher_can_be_shut_down() throws InterruptedException {
Flusher flusher = new Flusher();
- LogDispatcherTestCase.MockHandler handler = new LogDispatcherTestCase.MockHandler();
+ MockHandler handler = new MockHandler();
Flusher.register(handler);
flusher.start();
- Thread.sleep(5000);
- flusher.interrupt();
- flusher.join();
- assertTrue(handler.flushCalled > 0);
+ try {
+ assertTrue(handler.flushInvoked.await(60, TimeUnit.SECONDS));
+ } finally {
+ flusher.interrupt();
+ flusher.join();
+ }
+ }
+
+ private static class MockHandler implements LogHandler {
+
+ private final CountDownLatch flushInvoked = new CountDownLatch(1);
+
+ @Override public void flush() { flushInvoked.countDown(); }
+
+ @Override public void handle(LogMessage msg) {}
+ @Override public void handle(List<LogMessage> messages) {}
+ @Override public void close() {}
}
}