public HeldLocks(LockLog lockLog, Collection<AsyncLock> acquiredLocks, UUID requestId) { this(lockLog, acquiredLocks, requestId, new LeaseExpirationTimer(System::currentTimeMillis)); }
public synchronized boolean refresh() { if (isUnlocked) { return false; } expirationTimer.refresh(); return true; }
@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 refreshRefreshesExpirationTimer() { heldLocks.refresh(); verify(timer).refresh(); }
@Before public void before() { when(clock.getTimeMillis()).thenReturn(START_TIME_MILLIS); timer = new LeaseExpirationTimer(clock); }
@Test public void unlocksIfExpired() { when(timer.isExpired()).thenReturn(true); assertTrue(heldLocks.unlockIfExpired()); }
public synchronized boolean refresh() { if (isUnlocked) { return false; } expirationTimer.refresh(); return true; }
public HeldLocks(LockLog lockLog, Collection<AsyncLock> acquiredLocks, UUID requestId) { this(lockLog, acquiredLocks, requestId, new LeaseExpirationTimer(System::currentTimeMillis)); }
@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); }
/** * 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; }