use of com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseFactoryImpl 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);
}
Aggregations