diff options
author | Håkon Hallingstad <hakon@verizonmedia.com> | 2020-09-28 13:49:49 +0200 |
---|---|---|
committer | Håkon Hallingstad <hakon@verizonmedia.com> | 2020-09-28 13:49:49 +0200 |
commit | 4fd2db62039bf5fed95dcb71bd3ff59267812c7c (patch) | |
tree | e87e51758151beaf7b8ea386de928f59dd8f9791 /zkfacade/src/test | |
parent | 6e284ef06a2e6dafbaeae8e486b6f68fa53d5d48 (diff) |
LockInfo -> LockAttempt, ThreadLockInfo -> ThreadLockStats, and more
Diffstat (limited to 'zkfacade/src/test')
-rw-r--r-- | zkfacade/src/test/java/com/yahoo/vespa/curator/stats/LockAttemptSamplesTest.java (renamed from zkfacade/src/test/java/com/yahoo/vespa/curator/stats/LockInfoSamplesTest.java) | 24 | ||||
-rw-r--r-- | zkfacade/src/test/java/com/yahoo/vespa/curator/stats/LockTest.java | 56 |
2 files changed, 44 insertions, 36 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/LockAttemptSamplesTest.java index 4a14b0cc1b2..6f877631b7b 100644 --- a/zkfacade/src/test/java/com/yahoo/vespa/curator/stats/LockInfoSamplesTest.java +++ b/zkfacade/src/test/java/com/yahoo/vespa/curator/stats/LockAttemptSamplesTest.java @@ -1,4 +1,5 @@ -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. +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.curator.stats; import org.junit.Test; @@ -11,13 +12,16 @@ 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; +/** + * @author hakon + */ +public class LockAttemptSamplesTest { + private final LockAttemptSamples samples = new LockAttemptSamples(2); + private ThreadLockStats threadLockStats; @Test public void test() { - threadLockInfo = new ThreadLockInfo(Thread.currentThread()); + threadLockStats = new ThreadLockStats(Thread.currentThread()); assertTrue(maybeSample("1", 10)); @@ -36,7 +40,7 @@ public class LockInfoSamplesTest { // new path, expels "2" assertTrue(maybeSample("4", 6)); - Map<String, LockInfo> lockInfos = samples.asList().stream().collect(Collectors.toMap( + Map<String, LockAttempt> lockInfos = samples.asList().stream().collect(Collectors.toMap( lockInfo -> lockInfo.getLockPath(), lockInfo -> lockInfo)); assertEquals(2, lockInfos.size()); @@ -49,10 +53,10 @@ public class LockInfoSamplesTest { } 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); + LockAttempt lockAttempt = LockAttempt.invokingAcquire(threadLockStats, lockPath, Duration.ofSeconds(1)); + Instant instant = lockAttempt.getTimeAcquiredWasInvoked().plus(Duration.ofSeconds(secondsDuration)); + lockAttempt.setTerminalState(LockAttempt.LockState.RELEASED, instant); + return samples.maybeSample(lockAttempt); } }
\ 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 984a04c6d4e..477fe650bb5 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 @@ -1,4 +1,5 @@ -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. +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.curator.stats; import com.yahoo.vespa.curator.Lock; import org.apache.curator.framework.recipes.locks.InterProcessLock; @@ -19,6 +20,9 @@ import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +/** + * @author hakon + */ public class LockTest { private final InterProcessLock mutex = mock(InterProcessLock.class); private final String lockPath = "/lock/path"; @@ -27,7 +31,7 @@ public class LockTest { @Before public void setUp() { - ThreadLockInfo.clearStaticDataForTesting(); + ThreadLockStats.clearStaticDataForTesting(); } @Test @@ -45,22 +49,22 @@ public class LockTest { var expectedCounters = new LockCounters(); expectedCounters.invokeAcquireCount.set(1); expectedCounters.acquireFailedCount.set(1); - assertEquals(Map.of(lockPath, expectedCounters), ThreadLockInfo.getLockCountersByPath()); + assertEquals(Map.of(lockPath, expectedCounters), ThreadLockStats.getLockCountersByPath()); - List<LockInfo> slowLockInfos = ThreadLockInfo.getLockInfoSamples(); - assertEquals(1, slowLockInfos.size()); - LockInfo slowLockInfo = slowLockInfos.get(0); - assertEquals(acquireTimeout, slowLockInfo.getAcquireTimeout()); - Optional<String> stackTrace = slowLockInfo.getStackTrace(); + List<LockAttempt> slowLockAttempts = ThreadLockStats.getLockInfoSamples(); + assertEquals(1, slowLockAttempts.size()); + LockAttempt slowLockAttempt = slowLockAttempts.get(0); + assertEquals(acquireTimeout, slowLockAttempt.getAcquireTimeout()); + Optional<String> stackTrace = slowLockAttempt.getStackTrace(); assertTrue(stackTrace.isPresent()); assertTrue("bad stacktrace: " + stackTrace.get(), stackTrace.get().contains(".Lock.acquire(Lock.java")); - assertEquals(LockInfo.LockState.ACQUIRE_FAILED, slowLockInfo.getLockState()); - assertTrue(slowLockInfo.getTimeTerminalStateWasReached().isPresent()); + assertEquals(LockAttempt.LockState.ACQUIRE_FAILED, slowLockAttempt.getLockState()); + assertTrue(slowLockAttempt.getTimeTerminalStateWasReached().isPresent()); - List<ThreadLockInfo> threadLockInfos = ThreadLockInfo.getThreadLockInfos(); - assertEquals(1, threadLockInfos.size()); - ThreadLockInfo threadLockInfo = threadLockInfos.get(0); - assertEquals(0, threadLockInfo.getLockInfos().size()); + List<ThreadLockStats> threadLockStatsList = ThreadLockStats.getThreadLockInfos(); + assertEquals(1, threadLockStatsList.size()); + ThreadLockStats threadLockStats = threadLockStatsList.get(0); + assertEquals(0, threadLockStats.getLockAttempts().size()); } @Test @@ -77,7 +81,7 @@ public class LockTest { var expectedCounters = new LockCounters(); expectedCounters.invokeAcquireCount.set(1); expectedCounters.acquireTimedOutCount.set(1); - assertEquals(Map.of(lockPath, expectedCounters), ThreadLockInfo.getLockCountersByPath()); + assertEquals(Map.of(lockPath, expectedCounters), ThreadLockStats.getLockCountersByPath()); } @Test @@ -90,7 +94,7 @@ public class LockTest { expectedCounters.invokeAcquireCount.set(1); expectedCounters.lockAcquiredCount.set(1); expectedCounters.inCriticalRegionCount.set(1); - assertEquals(Map.of(lockPath, expectedCounters), ThreadLockInfo.getLockCountersByPath()); + assertEquals(Map.of(lockPath, expectedCounters), ThreadLockStats.getLockCountersByPath()); // reenter lock.acquire(acquireTimeout); @@ -102,13 +106,13 @@ public class LockTest { lock.close(); expectedCounters.inCriticalRegionCount.set(1); expectedCounters.locksReleasedCount.set(1); - assertEquals(Map.of(lockPath, expectedCounters), ThreadLockInfo.getLockCountersByPath()); + assertEquals(Map.of(lockPath, expectedCounters), ThreadLockStats.getLockCountersByPath()); // outer-most closes lock.close(); expectedCounters.inCriticalRegionCount.set(0); expectedCounters.locksReleasedCount.set(2); - assertEquals(Map.of(lockPath, expectedCounters), ThreadLockInfo.getLockCountersByPath()); + assertEquals(Map.of(lockPath, expectedCounters), ThreadLockStats.getLockCountersByPath()); } @Test @@ -121,14 +125,14 @@ public class LockTest { lock.acquire(acquireTimeout); lock2.acquire(acquireTimeout); - List<ThreadLockInfo> threadLockInfos = ThreadLockInfo.getThreadLockInfos(); - assertEquals(1, threadLockInfos.size()); - List<LockInfo> lockInfos = threadLockInfos.get(0).getLockInfos(); - assertEquals(2, lockInfos.size()); - assertEquals(lockPath, lockInfos.get(0).getLockPath()); - assertEquals(LockInfo.LockState.ACQUIRED, lockInfos.get(0).getLockState()); - assertEquals(lockPath2, lockInfos.get(1).getLockPath()); - assertEquals(LockInfo.LockState.ACQUIRED, lockInfos.get(1).getLockState()); + List<ThreadLockStats> threadLockStats = ThreadLockStats.getThreadLockInfos(); + assertEquals(1, threadLockStats.size()); + List<LockAttempt> lockAttempts = threadLockStats.get(0).getLockAttempts(); + assertEquals(2, lockAttempts.size()); + assertEquals(lockPath, lockAttempts.get(0).getLockPath()); + assertEquals(LockAttempt.LockState.ACQUIRED, lockAttempts.get(0).getLockState()); + assertEquals(lockPath2, lockAttempts.get(1).getLockPath()); + assertEquals(LockAttempt.LockState.ACQUIRED, lockAttempts.get(1).getLockState()); lock.close(); lock.close(); |