use of com.google.cloud.spanner.SessionPool.SessionPoolTransactionContext in project java-spanner by googleapis.
the class AsyncTransactionManagerTest method asyncTransactionManager_shouldRollbackOnCloseAsync.
@Test
public void asyncTransactionManager_shouldRollbackOnCloseAsync() throws Exception {
AsyncTransactionManager manager = client().transactionManagerAsync();
TransactionContext txn = manager.beginAsync().get();
txn.executeUpdateAsync(UPDATE_STATEMENT).get();
final TransactionSelector selector = ((TransactionContextImpl) ((SessionPoolTransactionContext) txn).delegate).getTransactionSelector();
SpannerApiFutures.get(manager.closeAsync());
// The mock server should already have the Rollback request, as we are waiting for the returned
// ApiFuture to be done.
mockSpanner.waitForRequestsToContain(input -> {
if (input instanceof RollbackRequest) {
RollbackRequest request = (RollbackRequest) input;
return request.getTransactionId().equals(selector.getId());
}
return false;
}, 0L);
}
use of com.google.cloud.spanner.SessionPool.SessionPoolTransactionContext in project java-spanner by googleapis.
the class MockSpannerServiceImpl method abortTransaction.
/**
* Instruct the mock server to abort the specified transaction. Use this method to test handling
* of {@link AbortedException} in your code.
*/
public void abortTransaction(TransactionContext transactionContext) {
Preconditions.checkNotNull(transactionContext);
if (transactionContext instanceof SessionPoolTransactionContext) {
transactionContext = ((SessionPoolTransactionContext) transactionContext).delegate;
}
if (transactionContext instanceof TransactionContextImpl) {
TransactionContextImpl impl = (TransactionContextImpl) transactionContext;
ByteString id = impl.getTransactionSelector() == null ? null : impl.getTransactionSelector().getId();
if (id != null) {
markAbortedTransaction(id);
}
} else {
throw new IllegalArgumentException("Unsupported TransactionContext type: " + transactionContext.getClass().getName());
}
}
Aggregations