use of com.google.cloud.spanner.MockSpannerTestUtil.READ_COLUMN_NAMES in project java-spanner by googleapis.
the class AsyncTransactionManagerTest method asyncTransactionManagerChain.
@Test
public void asyncTransactionManagerChain() throws Exception {
try (AsyncTransactionManager manager = client().transactionManagerAsync()) {
TransactionContextFuture transactionContextFuture = manager.beginAsync();
while (true) {
try {
CommitTimestampFuture commitTimestamp = transactionContextFuture.then((transaction, ignored) -> transaction.executeUpdateAsync(UPDATE_STATEMENT), executor).then((transactionContext, ignored) -> transactionContext.readRowAsync(READ_TABLE_NAME, Key.of(1L), READ_COLUMN_NAMES), executor).then((ignored, input) -> ApiFutures.immediateFuture(input.getString("Value")), executor).then((ignored, input) -> {
assertThat(input).isEqualTo("v1");
return ApiFutures.immediateFuture(null);
}, executor).commitAsync();
assertThat(commitTimestamp.get()).isNotNull();
break;
} catch (AbortedException e) {
transactionContextFuture = manager.resetForRetryAsync();
}
}
}
}
use of com.google.cloud.spanner.MockSpannerTestUtil.READ_COLUMN_NAMES in project java-spanner by googleapis.
the class AsyncTransactionManagerTest method asyncTransactionManagerReadRow.
@Test
public void asyncTransactionManagerReadRow() throws Exception {
try (AsyncTransactionManager manager = client().transactionManagerAsync()) {
TransactionContextFuture transactionContextFuture = manager.beginAsync();
while (true) {
try {
AsyncTransactionStep<Struct, String> value = transactionContextFuture.then((transactionContext, ignored) -> transactionContext.readRowAsync(READ_TABLE_NAME, Key.of(1L), READ_COLUMN_NAMES), executor).then((ignored, input) -> ApiFutures.immediateFuture(input.getString("Value")), executor);
value.commitAsync().get();
assertThat(value.get()).isEqualTo("v1");
break;
} catch (AbortedException e) {
transactionContextFuture = manager.resetForRetryAsync();
}
}
}
}
use of com.google.cloud.spanner.MockSpannerTestUtil.READ_COLUMN_NAMES 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