@Test
public void testExclusiveLockParallel() {

    // test that when parallel threads/instances attempt to get the exclusive lock only one will win.
    List<CompletableFuture<Void>> parallelGets = new ArrayList<>();
    AtomicInteger lockGetCount = new AtomicInteger();
    for (int i = 0; i < 20; i++) {
        parallelGets.add(globalScope.exclusiveLock().handle((ignore, ex) -> {
            if (ex == null) {
                lockGetCount.incrementAndGet();
                return null;
            } else if (ex instanceof LocatableResolverLockedException ||
                       (ex instanceof CompletionException && ex.getCause() instanceof LocatableResolverLockedException)) {
                return null;
            }
            throw new AssertionError("unexpected error", ex);
        }));
    }
    CompletableFuture.allOf(parallelGets.toArray(new CompletableFuture<?>[0])).join();
    assertThat("only one exclusiveLock succeeds", lockGetCount.get(), is(1));
    assertLocked(database, globalScope);
}