make ThreadsWatcher log at fixed intervals, not continuously
[serviceutils.git] / metrics / impl / src / test / java / org / opendaylight / infrautils / metrics / internal / ThreadsWatcherTest.java
index 1d767348ea9f8f4ab70483cb5162e1d70d098a95..e6256b6d15be25850eaa30d48e87053104f7dd71 100644 (file)
@@ -7,7 +7,10 @@
  */
 package org.opendaylight.infrautils.metrics.internal;
 
+import static com.google.common.truth.Truth.assertThat;
+
 import java.time.Duration;
+import java.time.Instant;
 import org.junit.Test;
 
 public class ThreadsWatcherTest {
@@ -19,4 +22,15 @@ public class ThreadsWatcherTest {
         threadsWatcher.logAllThreads();
         threadsWatcher.close();
     }
+
+    @Test
+    public void testIsConsidered() {
+        Instant now = Instant.now();
+        ThreadsWatcher tw = new ThreadsWatcher(100, Duration.ofNanos(1));
+
+        assertThat(tw.isConsidered(null, now, Duration.ofMinutes(1))).isTrue();
+        assertThat(tw.isConsidered(now, now, Duration.ofMinutes(1))).isFalse();
+        assertThat(tw.isConsidered(now, now.plusSeconds(30), Duration.ofMinutes(1))).isFalse();
+        assertThat(tw.isConsidered(now, now.plusSeconds(60), Duration.ofMinutes(1))).isTrue();
+    }
 }