use of com.apple.foundationdb.record.provider.foundationdb.layers.interning.ScopedInterningLayer in project fdb-record-layer by FoundationDB.
the class ResolverCreateHooksTest method testPreWriteChecks.
@Test
void testPreWriteChecks() {
// reads the key, and chooses the resolver based on the value
final PreWriteCheck check = (context, providedResolver) -> {
CompletableFuture<LocatableResolver> expectedResolverFuture = root().add("should-use-A").toTupleAsync(context).thenCompose(keyTuple -> context.ensureActive().get(keyTuple.pack())).thenApply(value -> {
boolean useA = Tuple.fromBytes(value).getBoolean(0);
return new ScopedInterningLayer(database, resolverPath(context, useA ? "A" : "B"));
});
return expectedResolverFuture.thenApply(expectedResolver -> expectedResolver.equals(providedResolver));
};
final ResolverCreateHooks hooks = new ResolverCreateHooks(check, ResolverCreateHooks.DEFAULT_HOOK);
// use resolver A
database.run(context -> root().add("should-use-A").toTupleAsync(context).thenAccept(tuple -> context.ensureActive().set(tuple.pack(), Tuple.from(true).pack())));
try (FDBRecordContext context = database.openContext()) {
LocatableResolver resolverA = new ScopedInterningLayer(database, resolverPath(context, "A"));
LocatableResolver resolverB = new ScopedInterningLayer(database, resolverPath(context, "B"));
assertChecks(context, resolverA, hooks, true);
assertChecks(context, resolverB, hooks, false);
}
// use resolver B
database.run(context -> root().add("should-use-A").toTupleAsync(context).thenAccept(tuple -> context.ensureActive().set(tuple.pack(), Tuple.from(false).pack())));
// after migration
try (FDBRecordContext context = database.openContext()) {
LocatableResolver resolverA = new ScopedInterningLayer(database, resolverPath(context, "A"));
LocatableResolver resolverB = new ScopedInterningLayer(database, resolverPath(context, "B"));
assertChecks(context, resolverA, hooks, false);
assertChecks(context, resolverB, hooks, true);
}
}
use of com.apple.foundationdb.record.provider.foundationdb.layers.interning.ScopedInterningLayer in project fdb-record-layer by FoundationDB.
the class ResolverMappingDigestTest method testInterningLayerAndInterningLayer.
@Test
public void testInterningLayerAndInterningLayer() throws Exception {
LocatableResolver primary;
LocatableResolver replica;
try (FDBRecordContext context = database.openContext()) {
primary = new ScopedInterningLayer(database, keySpace.path("test-path").add("to").add("primary").toResolvedPath(context));
replica = new ScopedInterningLayer(database, keySpace.path("test-path").add("to").add("replica").toResolvedPath(context));
}
testComputeDigest(primary, replica, false);
}
use of com.apple.foundationdb.record.provider.foundationdb.layers.interning.ScopedInterningLayer in project fdb-record-layer by FoundationDB.
the class ResolverMappingDigestTest method testInterningLayerAndInterningLayerWithMetadata.
@Test
public void testInterningLayerAndInterningLayerWithMetadata() throws Exception {
LocatableResolver primary;
LocatableResolver replica;
try (FDBRecordContext context = database.openContext()) {
primary = new ScopedInterningLayer(database, keySpace.path("test-path").add("to").add("primary").toResolvedPath(context));
replica = new ScopedInterningLayer(database, keySpace.path("test-path").add("to").add("replica").toResolvedPath(context));
}
byte[] metadata = Tuple.from("some-metadata").pack();
testComputeDigest(primary, replica, true);
}
use of com.apple.foundationdb.record.provider.foundationdb.layers.interning.ScopedInterningLayer in project fdb-record-layer by FoundationDB.
the class ResolverMappingDigestTest method testInterningLayerAndExtendedLayerWithMetadata.
@Test
public void testInterningLayerAndExtendedLayerWithMetadata() throws Exception {
LocatableResolver primary;
LocatableResolver replica;
try (FDBRecordContext context = database.openContext()) {
primary = new ScopedInterningLayer(database, keySpace.path("test-path").add("to").add("primary").toResolvedPath(context));
replica = new ExtendedDirectoryLayer(database, keySpace.path("test-path").add("to").add("replica").toResolvedPath(context));
}
testComputeDigest(primary, replica, true);
}
use of com.apple.foundationdb.record.provider.foundationdb.layers.interning.ScopedInterningLayer in project fdb-record-layer by FoundationDB.
the class KeySpaceDirectoryTest method getGenerator.
private Function<FDBRecordContext, CompletableFuture<LocatableResolver>> getGenerator() {
String tmpDirLayer = "tmp-dir-layer-" + random.nextLong();
KeySpace dirLayerKeySpace = new KeySpace(new KeySpaceDirectory(tmpDirLayer, KeyType.STRING, tmpDirLayer));
return context -> CompletableFuture.completedFuture(new ScopedInterningLayer(context.getDatabase(), dirLayerKeySpace.path(tmpDirLayer).toResolvedPath(context)));
}
Aggregations