private AsyncResult<HeldLocks> acquireLocks(UUID requestId, Set<LockDescriptor> lockDescriptors, TimeLimit timeout) { OrderedLocks orderedLocks = locks.getAll(lockDescriptors); return lockAcquirer.acquireLocks(requestId, orderedLocks, timeout); }
private AsyncResult<Void> awaitLocks(UUID requestId, Set<LockDescriptor> lockDescriptors, TimeLimit timeout) { OrderedLocks orderedLocks = locks.getAll(lockDescriptors); return lockAcquirer.waitForLocks(requestId, orderedLocks, timeout); }
@Before public void before() { when(acquirer.acquireLocks(any(), any(), any())).thenReturn(new AsyncResult<>()); when(acquirer.waitForLocks(any(), any(), any())).thenReturn(new AsyncResult<>()); when(locks.getAll(any())).thenReturn(OrderedLocks.fromSingleLock(newLock())); when(immutableTimestampTracker.getImmutableTimestamp()).thenReturn(Optional.empty()); when(immutableTimestampTracker.getLockFor(anyLong())).thenReturn(newLock()); }
public static AsyncLockService createDefault( LockLog lockLog, ScheduledExecutorService reaperExecutor, ScheduledExecutorService timeoutExecutor) { return new AsyncLockService( new LockCollection(), new ImmutableTimestampTracker(), new LockAcquirer(lockLog, timeoutExecutor), new HeldLocksCollection(), new AwaitedLocksCollection(), reaperExecutor); }
public static AsyncLockService createDefault( LockLog lockLog, ScheduledExecutorService reaperExecutor, ScheduledExecutorService timeoutExecutor) { return new AsyncLockService( new LockCollection(), new ImmutableTimestampTracker(), new LockAcquirer(lockLog, timeoutExecutor), new HeldLocksCollection(), new AwaitedLocksCollection(), reaperExecutor); }
private AsyncResult<HeldLocks> acquireImmutableTimestampLock(UUID requestId, long timestamp) { AsyncLock immutableTsLock = immutableTsTracker.getLockFor(timestamp); return lockAcquirer.acquireLocks(requestId, OrderedLocks.fromSingleLock(immutableTsLock), TimeLimit.zero()); }
private AsyncResult<Void> waitFor(AsyncLock... locks) { return lockAcquirer.waitForLocks(REQUEST_ID, OrderedLocks.fromOrderedList(ImmutableList.copyOf(locks)), TIMEOUT); }
private AsyncResult<HeldLocks> acquire(List<AsyncLock> locks) { return lockAcquirer.acquireLocks(REQUEST_ID, OrderedLocks.fromOrderedList(locks), TIMEOUT); }
@Test public void doesNotWaitForDuplicateRequests() { Set<LockDescriptor> descriptors = descriptors(LOCK_A); lockService.waitForLocks(REQUEST_ID, descriptors, DEADLINE); lockService.waitForLocks(REQUEST_ID, descriptors, DEADLINE); verify(acquirer, times(1)).waitForLocks(any(), any(), any()); verifyNoMoreInteractions(acquirer); }
@Test public void doesNotAcquireDuplicateRequests() { Set<LockDescriptor> descriptors = descriptors(LOCK_A); lockService.lock(REQUEST_ID, descriptors, DEADLINE); lockService.lock(REQUEST_ID, descriptors, DEADLINE); verify(acquirer, times(1)).acquireLocks(any(), any(), any()); verifyNoMoreInteractions(acquirer); }
@Test public void passesOrderedLocksToAcquirerWhenWaitingForLocks() { OrderedLocks expected = orderedLocks(newLock(), newLock()); Set<LockDescriptor> descriptors = descriptors(LOCK_A, LOCK_B); when(locks.getAll(descriptors)).thenReturn(expected); lockService.waitForLocks(REQUEST_ID, descriptors, DEADLINE); verify(acquirer).waitForLocks(REQUEST_ID, expected, DEADLINE); }
@Test public void propagatesTimeoutExceptionIfRequestTimesOut() { AsyncResult<HeldLocks> timedOutResult = new AsyncResult<>(); timedOutResult.timeout(); when(acquirer.acquireLocks(any(), any(), any())).thenReturn(timedOutResult); AsyncResult<?> result = lockService.lock(REQUEST_ID, descriptors(LOCK_A), DEADLINE); assertThat(result.isTimedOut()).isTrue(); }
private AsyncResult<Void> awaitLocks(UUID requestId, Set<LockDescriptor> lockDescriptors, TimeLimit timeout) { OrderedLocks orderedLocks = locks.getAll(lockDescriptors); return lockAcquirer.waitForLocks(requestId, orderedLocks, timeout); }
@Test public void delegatesImmutableTimestampRequestsToTracker() { UUID requestId = UUID.randomUUID(); long timestamp = 123L; AsyncLock immutableTsLock = spy(newLock()); when(immutableTimestampTracker.getLockFor(timestamp)).thenReturn(immutableTsLock); lockService.lockImmutableTimestamp(requestId, timestamp); verify(acquirer).acquireLocks(requestId, orderedLocks(immutableTsLock), TimeLimit.zero()); }
@Test public void passesOrderedLocksToAcquirer() { OrderedLocks expected = orderedLocks(newLock(), newLock()); Set<LockDescriptor> descriptors = descriptors(LOCK_A, LOCK_B); when(locks.getAll(descriptors)).thenReturn(expected); lockService.lock(REQUEST_ID, descriptors, DEADLINE); verify(acquirer).acquireLocks(REQUEST_ID, expected, DEADLINE); }
private AsyncResult<HeldLocks> acquireLocks(UUID requestId, Set<LockDescriptor> lockDescriptors, TimeLimit timeout) { OrderedLocks orderedLocks = locks.getAll(lockDescriptors); return lockAcquirer.acquireLocks(requestId, orderedLocks, timeout); }
private AsyncResult<HeldLocks> acquireImmutableTimestampLock(UUID requestId, long timestamp) { AsyncLock immutableTsLock = immutableTsTracker.getLockFor(timestamp); return lockAcquirer.acquireLocks(requestId, OrderedLocks.fromSingleLock(immutableTsLock), TimeLimit.zero()); }