@Test
public void testCopyWithConcurrentAccess() throws Exception {

    Map<String, ResolverResult> dirLayerMappings;
    try (FDBRecordContext context = database.openContext()) {
        dirLayerMappings = seedDirectoryLayer(context, primary, 50);
    }
    List<CompletableFuture<Void>> work = new ArrayList<>();
    // start copy
    ResolverMappingReplicator replicator = new ResolverMappingReplicator(primary, 10);
    work.add(replicator.copyToAsync(replica));
    Map<String, ResolverResult> concurrentlyAddedMappings = new ConcurrentHashMap<>();
    for (int i = 0; i < 50; i++) {
        final String key = randomLetters(25);
        work.add(CompletableFuture.supplyAsync(() -> database.openContext())
                .thenCompose(context -> primary.resolveWithMetadata(context.getTimer(), key, ResolverCreateHooks.getDefault())
                        .thenCompose(resolved -> {
                            context.addAfterCommit(() -> concurrentlyAddedMappings.put(key, resolved));
                            return context.commitAsync();
                        })
                )
        );
    }
    CompletableFuture.allOf(work.toArray(new CompletableFuture<?>[0])).join();
    assertContainsMappings(replica, dirLayerMappings);
    assertContainsMappings(primary, concurrentlyAddedMappings);
}