use of com.apple.foundationdb.record.provider.foundationdb.keyspace.ScopedDirectoryLayer in project fdb-record-layer by FoundationDB.
the class FDBReverseDirectoryCacheTest method testPutIfNotExistsNotVisibleUntilCommit.
@Test
public void testPutIfNotExistsNotVisibleUntilCommit() throws Exception {
final ScopedDirectoryLayer scope = globalScope;
final String name = "dir_" + Math.abs(new Random().nextInt());
final FDBReverseDirectoryCache rdc = fdb.getReverseDirectoryCache();
final ScopedValue<String> scopedName = scope.wrap(name);
// Create a new directory layer entry, put it in the cache in the same transaction
try (FDBRecordContext context = openContext()) {
Transaction transaction = context.ensureActive();
DirectoryLayer directoryLayerToUse = new DirectoryLayer(context.join(scope.getNodeSubspace(context)), scope.getContentSubspace());
final byte[] rawDirectoryEntry = directoryLayerToUse.createOrOpen(transaction, Collections.singletonList(name)).get().getKey();
final Long id = Tuple.fromBytes(rawDirectoryEntry).getLong(0);
rdc.putIfNotExists(context, scopedName, id).get();
// This happens in its own transaction so should not yet see the uncommitted directory and reverse
// directory entries that are being created.
Optional<String> result = rdc.get(scope.wrap(id)).join();
assertFalse(result.isPresent(), "Should not have gotten a result from RDC lookup");
commit(context);
}
}
use of com.apple.foundationdb.record.provider.foundationdb.keyspace.ScopedDirectoryLayer in project fdb-record-layer by FoundationDB.
the class FDBReverseDirectoryCacheTest method createRandomDirectoryScope.
private LocatableResolver createRandomDirectoryScope() {
final String name = String.format("name-%d", Math.abs(random.nextLong()));
KeySpace keySpace = new KeySpace(new KeySpaceDirectory(name, KeySpaceDirectory.KeyType.STRING, name));
ResolvedKeySpacePath path;
try (FDBRecordContext context = fdb.openContext()) {
path = keySpace.resolveFromKey(context, Tuple.from(name));
}
return new ScopedDirectoryLayer(fdb, path);
}
Aggregations