@Test
public void testDefaultCanAllocateIndependentKeysInParallel() {

    final ScopedDirectoryLayer directoryLayer = ScopedDirectoryLayer.global(database);
    Map<String, Long> mappingsFromOld = new ConcurrentHashMap<>();
    Map<String, Long> mappingsFromNew = new ConcurrentHashMap<>();
    List<CompletableFuture<?>> operations = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        String oldDirLayerKey = i + "-old-dl-key";
        String newDirLayerKey = i + "-new-dl-key";
        operations.add(directoryLayer.resolve(oldDirLayerKey).thenApply(value -> mappingsFromOld.put(oldDirLayerKey, value)));
        operations.add(globalScope.resolve(newDirLayerKey).thenApply(value -> mappingsFromNew.put(newDirLayerKey, value)));
    }
    CompletableFuture.allOf(operations.toArray(new CompletableFuture<?>[0])).join();
    // Implicitly checks that there are no duplicate keys or values in the two maps
    BiMap<String, Long> completeMapping = ImmutableBiMap.<String, Long>builder()
            .putAll(mappingsFromOld)
            .putAll(mappingsFromNew)
            .build();
    for (Map.Entry<String, Long> entry : completeMapping.entrySet()) {
        try (FDBRecordContext context = database.openContext()) {
            assertThat("the FDB directory layer sees the mapping",
                    directoryLayer.mustResolve(context, entry.getKey()).join(), is(entry.getValue()));
            assertThat("the ScopedDirectoryLayer sees the mapping",
                    globalScope.mustResolve(context, entry.getKey()).join(), is(entry.getValue()));
        }
    }
}