/** * 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 returnsCorrectlyConfiguredHeldLocks() throws Exception { HeldLocks heldLocks = acquire(lockA, lockB).get(); assertThat(heldLocks.getLocks()).contains(lockA, lockB); assertThat(heldLocks.getRequestId()).isEqualTo(REQUEST_ID); }
public AsyncResult<HeldLocks> acquireLocks(UUID requestId, OrderedLocks locks, TimeLimit timeout) { return new Acquisition(requestId, locks, timeout, lock -> lock.lock(requestId)).execute() .map(ignored -> new HeldLocks(lockLog, locks.get(), requestId)); }
private LockToken mockExpiredRequest() { return mockHeldLocksForNewRequest( heldLocks -> when(heldLocks.unlockIfExpired()).thenReturn(true)); }
@Test public void refreshRefreshesExpirationTimer() { heldLocks.refresh(); verify(timer).refresh(); }
@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 unlocksHeldLocks() { heldLocks.unlock(); verify(lockA).unlock(REQUEST_ID); verify(lockB).unlock(REQUEST_ID); }
private LockToken mockNonExpiredRequest() { return mockHeldLocksForNewRequest( heldLocks -> when(heldLocks.unlockIfExpired()).thenReturn(false)); }
@Test public void canRefreshBeforeUnlocking() { assertTrue(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; }
public AsyncResult<HeldLocks> acquireLocks(UUID requestId, OrderedLocks locks, TimeLimit timeout) { return new Acquisition(requestId, locks, timeout, lock -> lock.lock(requestId)).execute() .map(ignored -> new HeldLocks(lockLog, locks.get(), requestId)); }
@Test public void unlocksIfExpired() { when(timer.isExpired()).thenReturn(true); assertTrue(heldLocks.unlockIfExpired()); }
@Test public void doesNotUnlockIfNotExpired() { when(timer.isExpired()).thenReturn(false); assertFalse(heldLocks.unlockIfExpired()); }