aboutsummaryrefslogtreecommitdiffstats
path: root/zkfacade/src/test
diff options
context:
space:
mode:
authorHåkon Hallingstad <hakon@verizonmedia.com>2020-09-26 18:33:19 +0200
committerHåkon Hallingstad <hakon@verizonmedia.com>2020-09-26 18:33:19 +0200
commitd7118a218d4704b52ed9883e4ff381a519adb7c1 (patch)
tree160c7b057390e18c5f18af9d40e17f64d9e3e7f0 /zkfacade/src/test
parente38ba64f8253746739674720035d11bdcda5e155 (diff)
Mock lock path from thread to per-lock (bug)
Diffstat (limited to 'zkfacade/src/test')
-rw-r--r--zkfacade/src/test/java/com/yahoo/vespa/curator/stats/LockInfoSamplesTest.java58
-rw-r--r--zkfacade/src/test/java/com/yahoo/vespa/curator/stats/LockTest.java2
2 files changed, 59 insertions, 1 deletions
diff --git a/zkfacade/src/test/java/com/yahoo/vespa/curator/stats/LockInfoSamplesTest.java b/zkfacade/src/test/java/com/yahoo/vespa/curator/stats/LockInfoSamplesTest.java
new file mode 100644
index 00000000000..4a14b0cc1b2
--- /dev/null
+++ b/zkfacade/src/test/java/com/yahoo/vespa/curator/stats/LockInfoSamplesTest.java
@@ -0,0 +1,58 @@
+package com.yahoo.vespa.curator.stats;// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+import org.junit.Test;
+
+import java.time.Duration;
+import java.time.Instant;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class LockInfoSamplesTest {
+ private final LockInfoSamples samples = new LockInfoSamples(2);
+ private ThreadLockInfo threadLockInfo;
+
+ @Test
+ public void test() {
+ threadLockInfo = new ThreadLockInfo(Thread.currentThread());
+
+ assertTrue(maybeSample("1", 10));
+
+ // new sample has longer duration
+ assertTrue(maybeSample("1", 11));
+
+ // new sample has shorter duration
+ assertFalse(maybeSample("1", 10));
+
+ // new path, will be added
+ assertTrue(maybeSample("2", 5));
+
+ // new path, too low duration be added
+ assertFalse(maybeSample("3", 4));
+
+ // new path, expels "2"
+ assertTrue(maybeSample("4", 6));
+
+ Map<String, LockInfo> lockInfos = samples.asList().stream().collect(Collectors.toMap(
+ lockInfo -> lockInfo.getLockPath(),
+ lockInfo -> lockInfo));
+ assertEquals(2, lockInfos.size());
+
+ assertTrue(lockInfos.containsKey("1"));
+ assertEquals(Duration.ofSeconds(11), lockInfos.get("1").getStableTotalDuration());
+
+ assertTrue(lockInfos.containsKey("4"));
+ assertEquals(Duration.ofSeconds(6), lockInfos.get("4").getStableTotalDuration());
+ }
+
+ private boolean maybeSample(String lockPath, int secondsDuration) {
+ LockInfo lockInfo = LockInfo.invokingAcquire(threadLockInfo, lockPath, Duration.ofSeconds(1));
+ Instant instant = lockInfo.getTimeAcquiredWasInvoked().plus(Duration.ofSeconds(secondsDuration));
+ lockInfo.setTerminalState(LockInfo.LockState.RELEASED, instant);
+ return samples.maybeSample(lockInfo);
+ }
+
+} \ No newline at end of file
diff --git a/zkfacade/src/test/java/com/yahoo/vespa/curator/stats/LockTest.java b/zkfacade/src/test/java/com/yahoo/vespa/curator/stats/LockTest.java
index 23b603eca5c..4b9b6a4429b 100644
--- a/zkfacade/src/test/java/com/yahoo/vespa/curator/stats/LockTest.java
+++ b/zkfacade/src/test/java/com/yahoo/vespa/curator/stats/LockTest.java
@@ -47,7 +47,7 @@ public class LockTest {
expectedCounters.acquireFailedCount.set(1);
assertEquals(Map.of(lockPath, expectedCounters), ThreadLockInfo.getLockCountersByPath());
- List<LockInfo> slowLockInfos = ThreadLockInfo.getSlowLockInfos();
+ List<LockInfo> slowLockInfos = ThreadLockInfo.getLockInfoSamples();
assertEquals(1, slowLockInfos.size());
LockInfo slowLockInfo = slowLockInfos.get(0);
assertEquals(acquireTimeout, slowLockInfo.getAcquireTimeout());