@Test
public void testDirectoryIsolation() {

    KeySpace keySpace = new KeySpace(
            new KeySpaceDirectory("path", KeyType.STRING, "path")
                    .addSubdirectory(new KeySpaceDirectory("to", KeyType.STRING, "to")
                            .addSubdirectory(new KeySpaceDirectory("dirLayer1", KeyType.STRING, "dirLayer1"))
                            .addSubdirectory(new KeySpaceDirectory("dirLayer2", KeyType.STRING, "dirLayer2"))
                    )
    );
    try (FDBRecordContext context = database.openContext()) {
        ResolvedKeySpacePath path1 = keySpace.resolveFromKey(context, Tuple.from("path", "to", "dirLayer1"));
        ResolvedKeySpacePath path2 = keySpace.resolveFromKey(context, Tuple.from("path", "to", "dirLayer2"));
        LocatableResolver resolver = scopedDirectoryGenerator.apply(database, path1);
        LocatableResolver sameResolver = scopedDirectoryGenerator.apply(database, path1);
        LocatableResolver differentResolver = scopedDirectoryGenerator.apply(database, path2);
        List<String> names = ImmutableList.of("a", "set", "of", "names", "to", "resolve");
        List<Long> resolved = new ArrayList<>();
        List<Long> same = new ArrayList<>();
        List<Long> different = new ArrayList<>();
        for (String name : names) {
            resolved.add(resolver.resolve(context.getTimer(), name).join());
            same.add(sameResolver.resolve(context.getTimer(), name).join());
            different.add(differentResolver.resolve(context.getTimer(), name).join());
        }
        assertThat("same resolvers produce identical results", resolved, contains(same.toArray()));
        assertThat("different resolvers are independent", resolved, not(contains(different.toArray())));
    }
}