use of com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseRunner in project fdb-record-layer by FoundationDB.
the class AutoContinuingCursorTest method testAutoContinuingCursorGivenCursorGenerator.
private void testAutoContinuingCursorGivenCursorGenerator(BiFunction<FDBRecordContext, byte[], RecordCursor<Integer>> nextCursorGenerator, int maxRetriesOnRetriableException, List<Integer> expectedList) {
try (FDBDatabaseRunner runner = database.newRunner()) {
RecordCursor<Integer> cursor = new AutoContinuingCursor<>(runner, nextCursorGenerator, maxRetriesOnRetriableException);
List<Integer> returnedList = cursor.asList().join();
assertEquals(expectedList, returnedList);
}
}
use of com.apple.foundationdb.record.provider.foundationdb.FDBDatabaseRunner in project fdb-record-layer by FoundationDB.
the class LocatableResolver method runAsyncBorrowingReadVersion.
@Nonnull
private <T> CompletableFuture<T> runAsyncBorrowingReadVersion(@Nonnull FDBRecordContext parentContext, @Nonnull Function<FDBRecordContext, CompletableFuture<T>> retriable, Object... additionalLogMessageKeyValues) {
final FDBDatabaseRunner runner = parentContext.newRunner();
boolean started = false;
try {
final AtomicBoolean first = new AtomicBoolean(true);
CompletableFuture<T> future = runner.runAsync(childContext -> {
if (parentContext.isClosed()) {
// If the parent context is closed, stop this runner, too
throw new FDBDatabaseRunner.RunnerClosed();
}
final CompletableFuture<Long> readVersionFuture;
if (first.get()) {
// The first time around, borrow a read version
first.set(false);
readVersionFuture = parentContext.getReadVersionAsync().thenApply(readVersion -> {
childContext.setReadVersion(readVersion);
return readVersion;
});
} else {
// Other times, get a new read version from the database (explicit here for instrumentation purposes)
readVersionFuture = childContext.getReadVersionAsync();
}
return readVersionFuture.thenCompose(ignore -> retriable.apply(childContext));
}, Arrays.asList(additionalLogMessageKeyValues));
started = true;
return future.whenComplete((valIgnore, errIgnore) -> runner.close());
} finally {
if (!started) {
runner.close();
}
}
}
Aggregations