private AsyncResult<Void> awaitLocks(UUID requestId, Set<LockDescriptor> lockDescriptors, TimeLimit timeout) { OrderedLocks orderedLocks = locks.getAll(lockDescriptors); return lockAcquirer.waitForLocks(requestId, orderedLocks, timeout); }
private AsyncResult<HeldLocks> acquireLocks(UUID requestId, Set<LockDescriptor> lockDescriptors, TimeLimit timeout) { OrderedLocks orderedLocks = locks.getAll(lockDescriptors); return lockAcquirer.acquireLocks(requestId, orderedLocks, timeout); }
@Test public void returnsLocksInOrder() { List<LockDescriptor> orderedDescriptors = IntStream.range(0, 10) .mapToObj(i -> UUID.randomUUID().toString()) .map(StringLockDescriptor::of) .sorted().collect(Collectors.toList()); List<AsyncLock> expectedOrder = orderedDescriptors.stream() .map(descriptor -> lockCollection.getAll(ImmutableSet.of(descriptor))) .map(orderedLocks -> orderedLocks.get().get(0)) .collect(Collectors.toList()); List<AsyncLock> actualOrder = lockCollection.getAll(ImmutableSet.copyOf(orderedDescriptors)).get(); assertThat(actualOrder).isEqualTo(expectedOrder); }
@Test public void createsLocksOnDemand() { Set<LockDescriptor> descriptors = descriptors("foo", "bar"); List<AsyncLock> locks = lockCollection.getAll(descriptors).get(); assertThat(locks.size()).isEqualTo(2); assertThat(ImmutableSet.copyOf(locks).size()).isEqualTo(2); }
@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()); }
@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); }
@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); }
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); }