use of com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory in project fdb-record-layer by FoundationDB.
the class LocatableResolverTest method testParallelDbAndScopeGetVersion.
@Test
public void testParallelDbAndScopeGetVersion() {
// version is cached for 30 seconds by default
database.setResolverStateRefreshTimeMillis(100);
// sets the timeout for all the db instances we create
final FDBDatabaseFactory parallelFactory = new FDBDatabaseFactoryImpl();
parallelFactory.setStateRefreshTimeMillis(100);
Supplier<FDBDatabase> databaseSupplier = () -> new FDBDatabase(parallelFactory, null);
consistently("uninitialized version is 0", () -> {
try (FDBRecordContext context = database.openContext()) {
return globalScope.getVersion(context.getTimer()).join();
}
}, is(0), 200, 10);
List<Pair<FDBDatabase, LocatableResolver>> simulatedInstances = IntStream.range(0, 20).mapToObj(i -> {
FDBDatabase db = databaseSupplier.get();
return Pair.of(db, resolverFactory.getGlobalScope(db));
}).collect(Collectors.toList());
Supplier<CompletableFuture<Set<Integer>>> supplier = () -> {
List<CompletableFuture<Integer>> parallelOperations = simulatedInstances.stream().map(pair -> {
FDBDatabase db = pair.getKey();
LocatableResolver resolver = pair.getValue();
FDBRecordContext context = db.openContext();
return resolver.getVersion(context.getTimer()).whenComplete((ignore, e) -> context.close());
}).collect(Collectors.toList());
return AsyncUtil.getAll(parallelOperations).thenApply(HashSet::new);
};
consistently("all instances report the version as 0", () -> supplier.get().join(), is(Collections.singleton(0)), 200, 10);
globalScope.incrementVersion().join();
eventually("all instances report the new version once the caches have refreshed", () -> supplier.get().join(), is(Collections.singleton(1)), 120, 10);
}
use of com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory in project fdb-record-layer by FoundationDB.
the class ResolverMappingDigestTest method setup.
@BeforeEach
public void setup() {
keySpace = new KeySpace(new KeySpaceDirectory("test-path", KeyType.STRING, "test-path-" + random.nextLong()).addSubdirectory(new KeySpaceDirectory("to", KeyType.STRING, "to").addSubdirectory(new KeySpaceDirectory("primary", KeyType.STRING, "primary")).addSubdirectory(new KeySpaceDirectory("replica", KeyType.STRING, "replica"))));
FDBDatabaseFactory factory = FDBDatabaseFactory.instance();
factory.setDirectoryCacheSize(100);
database = factory.getDatabase();
// wipe test keyspace
KeySpacePath basePath = keySpace.path("test-path");
database.run(context -> {
basePath.deleteAllData(context);
return null;
});
}
use of com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactory in project fdb-record-layer by FoundationDB.
the class ResolverMappingReplicatorTest method setupBase.
@BeforeEach
public void setupBase() {
keySpace = new KeySpace(new KeySpaceDirectory("test-path", KeyType.STRING, "test-path-" + random.nextLong()).addSubdirectory(new KeySpaceDirectory("to", KeyType.STRING, "to").addSubdirectory(new KeySpaceDirectory("primary", KeyType.STRING, "primary")).addSubdirectory(new KeySpaceDirectory("replica", KeyType.STRING, "replica"))));
FDBDatabaseFactory factory = FDBDatabaseFactory.instance();
factory.setDirectoryCacheSize(100);
database = factory.getDatabase();
database.clearCaches();
KeySpacePath basePath = keySpace.path("test-path");
// wipe test keyspace
database.run(context -> {
context.ensureActive().clear(Range.startsWith(basePath.toTuple(context).pack()));
return null;
});
}
Aggregations