use of com.google.cloud.spanner.AsyncTransactionManager.AsyncTransactionStep in project java-spanner by googleapis.
the class AsyncTransactionManagerTest method asyncTransactionManagerRead.
@Test
public void asyncTransactionManagerRead() throws Exception {
try (AsyncTransactionManager manager = client().transactionManagerAsync()) {
TransactionContextFuture transactionContextFuture = manager.beginAsync();
while (true) {
try {
AsyncTransactionStep<Void, List<String>> values = transactionContextFuture.then((transactionContext, ignored) -> transactionContext.readAsync(READ_TABLE_NAME, KeySet.all(), READ_COLUMN_NAMES).toListAsync(input -> input.getString("Value"), MoreExecutors.directExecutor()), executor);
// Commit the transaction.
values.commitAsync().get();
assertThat(values.get()).containsExactly("v1", "v2", "v3");
break;
} catch (AbortedException e) {
transactionContextFuture = manager.resetForRetryAsync();
}
}
}
}
Aggregations