@Test public void isNotImmediatelyExpired() { assertThat(timer.isExpired()).isFalse(); }
/** * Unlocks if expired, and returns whether the locks are now unlocked (regardless of whether or not they were * unlocked as a result of calling this method). */ public synchronized boolean unlockIfExpired() { if (expirationTimer.isExpired()) { if (unlock()) { lockLog.lockExpired(token.getRequestId(), getLockDescriptors()); } } return isUnlocked; }
@Test public void isExpiredWhenAppropriateTimeHasElapsed() { mockOffsetFromStartTime(LeaseExpirationTimer.LEASE_TIMEOUT_MILLIS + 1L); assertThat(timer.isExpired()).isTrue(); }
@Test public void unlocksIfExpired() { when(timer.isExpired()).thenReturn(true); assertTrue(heldLocks.unlockIfExpired()); }
@Test public void doesNotUnlockIfNotExpired() { when(timer.isExpired()).thenReturn(false); assertFalse(heldLocks.unlockIfExpired()); }
@Before public void before() { when(timer.isExpired()).thenReturn(false); lockA.lock(REQUEST_ID); lockB.lock(REQUEST_ID); heldLocks = new HeldLocks(new LockLog(new MetricRegistry(), () -> 2L), ImmutableList.of(lockA, lockB), REQUEST_ID, timer); }
@Test public void refreshResetsTimer() { mockOffsetFromStartTime(LeaseExpirationTimer.LEASE_TIMEOUT_MILLIS); timer.refresh(); mockOffsetFromStartTime(LeaseExpirationTimer.LEASE_TIMEOUT_MILLIS * 2); timer.refresh(); assertThat(timer.isExpired()).isFalse(); }
/** * Unlocks if expired, and returns whether the locks are now unlocked (regardless of whether or not they were * unlocked as a result of calling this method). */ public synchronized boolean unlockIfExpired() { if (expirationTimer.isExpired()) { if (unlock()) { lockLog.lockExpired(token.getRequestId(), getLockDescriptors()); } } return isUnlocked; }