use of com.apple.foundationdb.directory.DirectoryLayer in project fdb-record-layer by FoundationDB.
the class ScopedDirectoryLayerTest method testDefaultDirectoryResolver.
@Test
public void testDefaultDirectoryResolver() {
LocatableResolver resolver = globalScope;
try (FDBRecordContext context = database.openContext()) {
Long value = resolver.resolve(context.getTimer(), "foo").join();
DirectoryLayer directoryLayer = DirectoryLayer.getDefault();
validate(context, resolver, directoryLayer, "foo", value);
}
}
use of com.apple.foundationdb.directory.DirectoryLayer in project fdb-record-layer by FoundationDB.
the class ScopedDirectoryLayerTest method testLocatableDirectoryResolver.
@Test
public void testLocatableDirectoryResolver() {
KeySpace keySpace = new KeySpace(new KeySpaceDirectory("path", KeyType.STRING, "path").addSubdirectory(new KeySpaceDirectory("to", KeyType.STRING, "to").addSubdirectory(new KeySpaceDirectory("dirLayer", KeyType.STRING, "dirLayer"))));
ResolvedKeySpacePath path;
try (FDBRecordContext context = database.openContext()) {
path = keySpace.resolveFromKey(context, Tuple.from("path", "to", "dirLayer"));
}
LocatableResolver resolver = resolverFactory.create(path);
Long value = resolver.resolve("foo").join();
DirectoryLayer directoryLayer = new DirectoryLayer(new Subspace(Bytes.concat(path.toTuple().pack(), DirectoryLayer.DEFAULT_NODE_SUBSPACE.getKey())), path.toSubspace());
try (FDBRecordContext context = database.openContext()) {
validate(context, resolver, directoryLayer, "foo", value);
DirectoryLayer defaultDirectoryLayer = DirectoryLayer.getDefault();
List<String> defaultDirectories = defaultDirectoryLayer.list(context.ensureActive()).join();
assertThat("entry is not in the default directory layer", defaultDirectories, not(hasItem("foo")));
}
}
use of com.apple.foundationdb.directory.DirectoryLayer in project fdb-record-layer by FoundationDB.
the class ExtendedDirectoryLayerTest method testParallelAllocation.
private static void testParallelAllocation(boolean checkDirectoryLayer, FDBDatabase database, Function<String, CompletableFuture<Long>> resolveCall1, Function<String, CompletableFuture<Long>> resolveCall2, LocatableResolver resolver1, LocatableResolver resolver2) {
Map<String, Long> mappings1 = new ConcurrentHashMap<>();
Map<String, Long> mappings2 = new ConcurrentHashMap<>();
List<CompletableFuture<?>> operations = new ArrayList<>();
for (int i = 0; i < 100; i++) {
String key = "key-" + i;
operations.add(resolveCall1.apply(key).thenAccept(value -> mappings1.put(key, value)));
operations.add(resolveCall2.apply(key).thenAccept(value -> mappings2.put(key, value)));
}
CompletableFuture.allOf(operations.toArray(new CompletableFuture<?>[0])).join();
for (Map.Entry<String, Long> entry : mappings1.entrySet()) {
assertThat(String.format("the mappings for %s are identical", entry.getKey()), mappings2.get(entry.getKey()), is(entry.getValue()));
try (FDBRecordContext context = database.openContext()) {
if (checkDirectoryLayer) {
// only applies when the scope is global
final DirectoryLayer directoryLayer = DirectoryLayer.getDefault();
Long value = directoryLayer.open(context.ensureActive(), Collections.singletonList(entry.getKey())).thenApply(subspace -> Tuple.fromBytes(subspace.pack()).getLong(0)).join();
assertThat("the FDB directory layer sees the mapping", value, is(entry.getValue()));
}
assertThat(resolver1.getClass().getName() + " sees the mapping", resolver1.mustResolve(context, entry.getKey()).join(), is(entry.getValue()));
assertThat(resolver2.getClass().getName() + " sees the mapping", resolver2.mustResolve(context, entry.getKey()).join(), is(entry.getValue()));
checkMappingInReverseCache(resolver1, entry.getKey(), entry.getValue());
checkMappingInReverseCache(resolver2, entry.getKey(), entry.getValue());
}
}
}
Aggregations