private void timeoutAll() { for (AsyncLock lock : locks.get()) { lock.timeout(requestId); } } }
private void unlockAll() { try { for (AsyncLock lock : locks.get()) { lock.unlock(requestId); } } catch (Throwable t) { log.error("Error while unlocking locks", SafeArg.of("requestId", requestId), t); } }
private void acquireLocks() { try { AsyncResult<Void> lockResult = AsyncResult.completedResult(); for (AsyncLock lock : locks.get()) { lockResult = lockResult.concatWith(() -> lockFunction.apply(lock)); } this.result = lockResult; } catch (Throwable t) { log.error("Error while acquiring locks"); unlockAll(); throw Throwables.propagate(t); } }
@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); }
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 void timeoutAll() { for (AsyncLock lock : locks.get()) { lock.timeout(requestId); } } }
private void unlockAll() { try { for (AsyncLock lock : locks.get()) { lock.unlock(requestId); } } catch (Throwable t) { log.error("Error while unlocking locks", SafeArg.of("requestId", requestId), t); } }
private void acquireLocks() { try { AsyncResult<Void> lockResult = AsyncResult.completedResult(); for (AsyncLock lock : locks.get()) { lockResult = lockResult.concatWith(() -> lockFunction.apply(lock)); } this.result = lockResult; } catch (Throwable t) { log.error("Error while acquiring locks"); unlockAll(); throw Throwables.propagate(t); } }
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)); }