private LockToken mockRefreshableRequest() { return mockHeldLocksForNewRequest( heldLocks -> { when(heldLocks.unlock()).thenReturn(true); when(heldLocks.refresh()).thenReturn(true); }); }
private LockToken mockNonRefreshableRequest() { return mockHeldLocksForNewRequest( heldLocks -> { when(heldLocks.unlock()).thenReturn(false); when(heldLocks.refresh()).thenReturn(false); }); }
/** * 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 unlocksHeldLocks() { heldLocks.unlock(); verify(lockA).unlock(REQUEST_ID); verify(lockB).unlock(REQUEST_ID); }
@Test public void cannotRefreshAfterUnlocking() { heldLocks.unlock(); assertFalse(heldLocks.refresh()); }
/** * 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; }