use of com.google.cloud.spanner.MockSpannerTestUtil.INVALID_UPDATE_STATEMENT in project java-spanner by googleapis.
the class AsyncTransactionManagerTest method asyncTransactionManagerInvalidBatchUpdate.
@Test
public void asyncTransactionManagerInvalidBatchUpdate() throws Exception {
try (AsyncTransactionManager manager = client().transactionManagerAsync()) {
TransactionContextFuture transactionContextFuture = manager.beginAsync();
SpannerException e = assertThrows(SpannerException.class, () -> get(transactionContextFuture.then((transactionContext, ignored) -> transactionContext.batchUpdateAsync(ImmutableList.of(UPDATE_STATEMENT, INVALID_UPDATE_STATEMENT)), executor).commitAsync()));
assertThat(e.getErrorCode()).isEqualTo(ErrorCode.INVALID_ARGUMENT);
assertThat(e.getMessage()).contains("invalid statement");
}
}
use of com.google.cloud.spanner.MockSpannerTestUtil.INVALID_UPDATE_STATEMENT in project java-spanner by googleapis.
the class AsyncTransactionManagerTest method asyncTransactionManagerFireAndForgetInvalidBatchUpdate.
@Test
public void asyncTransactionManagerFireAndForgetInvalidBatchUpdate() throws Exception {
try (AsyncTransactionManager manager = clientWithEmptySessionPool().transactionManagerAsync()) {
TransactionContextFuture transactionContextFuture = manager.beginAsync();
while (true) {
try {
AsyncTransactionStep<Void, long[]> updateCounts = transactionContextFuture.then((transactionContext, ignored) -> {
transactionContext.batchUpdateAsync(ImmutableList.of(UPDATE_STATEMENT, INVALID_UPDATE_STATEMENT));
return ApiFutures.<Void>immediateFuture(null);
}, executor).then((transactionContext, ignored) -> transactionContext.batchUpdateAsync(ImmutableList.of(UPDATE_STATEMENT, UPDATE_STATEMENT)), executor);
updateCounts.commitAsync().get();
assertThat(updateCounts.get()).asList().containsExactly(UPDATE_COUNT, UPDATE_COUNT);
break;
} catch (AbortedException e) {
transactionContextFuture = manager.resetForRetryAsync();
}
}
}
assertThat(mockSpanner.getRequestTypes()).containsExactly(BatchCreateSessionsRequest.class, ExecuteBatchDmlRequest.class, ExecuteBatchDmlRequest.class, CommitRequest.class);
}
use of com.google.cloud.spanner.MockSpannerTestUtil.INVALID_UPDATE_STATEMENT in project java-spanner by googleapis.
the class AsyncTransactionManagerTest method asyncTransactionManagerChainWithErrorInTheMiddle.
@Test
public void asyncTransactionManagerChainWithErrorInTheMiddle() throws Exception {
try (AsyncTransactionManager manager = client().transactionManagerAsync()) {
TransactionContextFuture transactionContextFuture = manager.beginAsync();
while (true) {
try {
CommitTimestampFuture commitTimestampFuture = transactionContextFuture.then((transactionContext, ignored) -> transactionContext.executeUpdateAsync(INVALID_UPDATE_STATEMENT), executor).then((ignored1, ignored2) -> {
throw new IllegalStateException("this should not be executed");
}, executor).commitAsync();
SpannerException e = assertThrows(SpannerException.class, () -> get(commitTimestampFuture));
assertThat(e.getErrorCode()).isEqualTo(ErrorCode.INVALID_ARGUMENT);
break;
} catch (AbortedException e) {
transactionContextFuture = manager.resetForRetryAsync();
}
}
}
}
use of com.google.cloud.spanner.MockSpannerTestUtil.INVALID_UPDATE_STATEMENT in project java-spanner by googleapis.
the class AsyncTransactionManagerTest method asyncTransactionManagerInvalidUpdate.
@Test
public void asyncTransactionManagerInvalidUpdate() throws Exception {
try (AsyncTransactionManager manager = client().transactionManagerAsync()) {
TransactionContextFuture transactionContextFuture = manager.beginAsync();
CommitTimestampFuture commitTimestamp = transactionContextFuture.then((transaction, ignored) -> transaction.executeUpdateAsync(INVALID_UPDATE_STATEMENT), executor).commitAsync();
SpannerException e = assertThrows(SpannerException.class, () -> get(commitTimestamp));
assertThat(e.getErrorCode()).isEqualTo(ErrorCode.INVALID_ARGUMENT);
assertThat(e.getMessage()).contains("invalid statement");
}
}
Aggregations