use of com.google.cloud.spanner.AsyncTransactionManager.CommitTimestampFuture in project java-spanner by googleapis.
the class RetryOnInvalidatedSessionTest method asyncTransactionManager_readSync.
private void asyncTransactionManager_readSync(final Function<TransactionContext, ResultSet> fn) throws InterruptedException {
final ExecutorService queryExecutor = Executors.newSingleThreadExecutor();
try (AsyncTransactionManager manager = client.transactionManagerAsync()) {
TransactionContextFuture context = manager.beginAsync();
while (true) {
try {
AsyncTransactionStep<Void, Long> count = context.then((transaction, ignored) -> {
long counter = 0L;
try (ResultSet rs = fn.apply(transaction)) {
while (rs.next()) {
counter++;
}
}
return ApiFutures.immediateFuture(counter);
}, executor);
CommitTimestampFuture ts = count.commitAsync();
assertThrowsSessionNotFoundIfShouldFail(() -> get(ts));
break;
} catch (AbortedException e) {
context = manager.resetForRetryAsync();
}
}
} finally {
queryExecutor.shutdown();
}
}
use of com.google.cloud.spanner.AsyncTransactionManager.CommitTimestampFuture in project java-spanner by googleapis.
the class RetryOnInvalidatedSessionTest method asyncTransactionManager_updateFunction.
private <T> void asyncTransactionManager_updateFunction(final Function<TransactionContext, ApiFuture<T>> fn, T expected) throws InterruptedException {
try (AsyncTransactionManager manager = client.transactionManagerAsync()) {
TransactionContextFuture transaction = manager.beginAsync();
while (true) {
try {
AsyncTransactionStep<Void, T> res = transaction.then((txn, input) -> fn.apply(txn), executor);
CommitTimestampFuture ts = res.commitAsync();
assertThrowsSessionNotFoundIfShouldFail(() -> get(ts));
break;
} catch (AbortedException e) {
transaction = manager.resetForRetryAsync();
}
}
}
}
Aggregations