ExtendedDirectoryLayer extends LocatableResolver { public static ExtendedDirectoryLayer global(@Nonnull FDBDatabase database) { return new ExtendedDirectoryLayer(database, null, null); } @Deprecated @API(API.Status.DEPRECATED)  ExtendedDirectoryLayer(@Nonnull FDBRecordContext context, @Nonnull KeySpacePath path);  ExtendedDirectoryLayer(@Nonnull FDBDatabase database, @Nonnull ResolvedKeySpacePath path); private  ExtendedDirectoryLayer(@Nonnull FDBDatabase database,
                                   @Nullable KeySpacePath path,
                                   @Nullable CompletableFuture<ResolvedKeySpacePath> resolvedPathFuture); static ExtendedDirectoryLayer global(@Nonnull FDBDatabase database); @Override CompletableFuture<Void> setMapping(FDBRecordContext context, String key, ResolverResult value); @Override CompletableFuture<Void> updateMetadata(FDBRecordContext context, String key, byte[] metadata); @Override CompletableFuture<Void> setWindow(long count); @Override @Nonnull CompletableFuture<Subspace> getMappingSubspaceAsync(); @Override @Nonnull ResolverResult deserializeValue(byte[] value); @Override @Nonnull CompletableFuture<Subspace> getBaseSubspaceAsync();  }
@Test public void testWriteCompatibilityGlobal() { testReadCompatible(globalScope, ScopedDirectoryLayer.global(database)); }
@Test public void testReadCompatibilityGlobal() { testReadCompatible(ScopedDirectoryLayer.global(database), globalScope); }
@Test public void testScopedDirectorySeesUpdate() { LocatableResolver scopedDirectoryLayer = ScopedDirectoryLayer.global(database); LocatableResolver extendedDirectoryLayer = ExtendedDirectoryLayer.global(database); loopSeesUpdate(scopedDirectoryLayer, extendedDirectoryLayer); }
@Test public void testExtendedSeesUpdate() { LocatableResolver scopedDirectoryLayer = ScopedDirectoryLayer.global(database); LocatableResolver extendedDirectoryLayer = ExtendedDirectoryLayer.global(database); loopSeesUpdate(extendedDirectoryLayer, scopedDirectoryLayer); }
@Test public void testCanAllocateSameKeysInParallelWithFDBDirectoryLayer() { final DirectoryLayer directoryLayer = DirectoryLayer.getDefault(); testParallelAllocation(true, database, key -> database.runAsync(context -> directoryLayer.createOrOpen(context.ensureActive(), Collections.singletonList(key)) .thenApply(subspace -> Tuple.fromBytes(subspace.pack()).getLong(0))), key -> globalScope.resolve(key), ExtendedDirectoryLayer.global(database), ScopedDirectoryLayer.global(database)); }
@Test public void testGlobalExtendedInParallelWithScopedDirectoryLayer() { LocatableResolver scopedDirectoryLayer = ScopedDirectoryLayer.global(database); LocatableResolver backwardsCompatibleDirectoryLayer = ExtendedDirectoryLayer.global(database); testParallelAllocation(true, database, backwardsCompatibleDirectoryLayer, scopedDirectoryLayer); }
@Test public void testGlobalScopedDirectoryLayerInParallelWithExtended() { LocatableResolver scopedDirectoryLayer = ScopedDirectoryLayer.global(database); LocatableResolver backwardsCompatibleDirectoryLayer = ExtendedDirectoryLayer.global(database); testParallelAllocation(true, database, scopedDirectoryLayer, backwardsCompatibleDirectoryLayer); }
@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(); 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())); } } }
@Test public void testScopedDirectoryLayerResolvesWithoutMetadata() { MetadataHook hook = name -> Tuple.from("metadata-for-" + name).pack(); ResolverCreateHooks createHooks = new ResolverCreateHooks(ResolverCreateHooks.DEFAULT_CHECK, hook); ResolverResult result = globalScope.resolveWithMetadata("some-key", createHooks).join(); assertArrayEquals(Tuple.from("metadata-for-some-key").pack(), result.getMetadata(), "metadata was added"); ResolverResult resultFromScoped = ScopedDirectoryLayer.global(database) .resolveWithMetadata("some-key", ResolverCreateHooks.getDefault()) .join(); assertEquals(resultFromScoped.getValue(), result.getValue()); assertThat(resultFromScoped.getMetadata(), is(nullValue())); try (FDBRecordContext context = database.openContext()) { assertArrayEquals(globalScope.mustResolveWithMetadata(context, "some-key").join().getMetadata(), Tuple.from("metadata-for-some-key").pack(), "we can still read the metadata with " + globalScope.getClass().getName()); } }