use of com.google.spanner.v1.BeginTransactionRequest in project spring-cloud-gcp by spring-cloud.
the class ReactiveFirestoreTransactionManager method startTransaction.
private Mono<ReactiveFirestoreResourceHolder> startTransaction(TransactionDefinition definition) {
TransactionOptions.Builder txOptions = definition.isReadOnly() ? TransactionOptions.newBuilder().setReadOnly(TransactionOptions.ReadOnly.newBuilder().build()) : TransactionOptions.newBuilder().setReadWrite(TransactionOptions.ReadWrite.newBuilder().build());
BeginTransactionRequest beginTransactionRequest = BeginTransactionRequest.newBuilder().setOptions(txOptions).setDatabase(this.databasePath).build();
return ObservableReactiveUtil.<BeginTransactionResponse>unaryCall(obs -> this.firestore.beginTransaction(beginTransactionRequest, obs)).map(beginTransactionResponse -> new ReactiveFirestoreResourceHolder(beginTransactionResponse.getTransaction()));
}
use of com.google.spanner.v1.BeginTransactionRequest in project spring-cloud-gcp by GoogleCloudPlatform.
the class ReactiveFirestoreTransactionManager method startTransaction.
private Mono<ReactiveFirestoreResourceHolder> startTransaction(TransactionDefinition definition) {
TransactionOptions.Builder txOptions = definition.isReadOnly() ? TransactionOptions.newBuilder().setReadOnly(TransactionOptions.ReadOnly.newBuilder().build()) : TransactionOptions.newBuilder().setReadWrite(TransactionOptions.ReadWrite.newBuilder().build());
BeginTransactionRequest beginTransactionRequest = BeginTransactionRequest.newBuilder().setOptions(txOptions).setDatabase(this.databasePath).build();
return ObservableReactiveUtil.<BeginTransactionResponse>unaryCall(obs -> this.firestore.beginTransaction(beginTransactionRequest, obs)).map(beginTransactionResponse -> new ReactiveFirestoreResourceHolder(beginTransactionResponse.getTransaction()));
}
use of com.google.spanner.v1.BeginTransactionRequest in project java-spanner by googleapis.
the class SessionImpl method beginTransactionAsync.
ApiFuture<ByteString> beginTransactionAsync() {
final SettableApiFuture<ByteString> res = SettableApiFuture.create();
final Span span = tracer.spanBuilder(SpannerImpl.BEGIN_TRANSACTION).startSpan();
final BeginTransactionRequest request = BeginTransactionRequest.newBuilder().setSession(name).setOptions(TransactionOptions.newBuilder().setReadWrite(TransactionOptions.ReadWrite.getDefaultInstance())).build();
final ApiFuture<Transaction> requestFuture = spanner.getRpc().beginTransactionAsync(request, options);
requestFuture.addListener(tracer.withSpan(span, () -> {
try {
Transaction txn = requestFuture.get();
if (txn.getId().isEmpty()) {
throw newSpannerException(ErrorCode.INTERNAL, "Missing id in transaction\n" + getName());
}
span.end(TraceUtil.END_SPAN_OPTIONS);
res.set(txn.getId());
} catch (ExecutionException e) {
TraceUtil.endSpanWithFailure(span, e);
res.setException(SpannerExceptionFactory.newSpannerException(e.getCause() == null ? e : e.getCause()));
} catch (InterruptedException e) {
TraceUtil.endSpanWithFailure(span, e);
res.setException(SpannerExceptionFactory.propagateInterrupt(e));
} catch (Exception e) {
TraceUtil.endSpanWithFailure(span, e);
res.setException(e);
}
}), MoreExecutors.directExecutor());
return res;
}
use of com.google.spanner.v1.BeginTransactionRequest in project java-firestore by googleapis.
the class FirestoreClientTest method beginTransactionTest.
@Test
public void beginTransactionTest() throws Exception {
BeginTransactionResponse expectedResponse = BeginTransactionResponse.newBuilder().setTransaction(ByteString.EMPTY).build();
mockFirestore.addResponse(expectedResponse);
String database = "database1789464955";
BeginTransactionResponse actualResponse = client.beginTransaction(database);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockFirestore.getRequests();
Assert.assertEquals(1, actualRequests.size());
BeginTransactionRequest actualRequest = ((BeginTransactionRequest) actualRequests.get(0));
Assert.assertEquals(database, actualRequest.getDatabase());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.v1.BeginTransactionRequest in project appengine-java-standard by GoogleCloudPlatform.
the class CloudDatastoreV1ClientImplTest method runAsyncStackTraceCaptureTest.
private void runAsyncStackTraceCaptureTest(boolean asyncStackTraceCaptureEnabled) throws Exception {
DatastoreServiceGlobalConfig.setConfig(DatastoreServiceGlobalConfig.builder().appId(APP_ID).emulatorHost("dummy-value-to-stub-out-credentials").asyncStackTraceCaptureEnabled(asyncStackTraceCaptureEnabled).build());
BeginTransactionRequest req = BeginTransactionRequest.getDefaultInstance();
CloudDatastoreV1ClientImpl client = new CloudDatastoreV1ClientImpl(datastore, 1);
DatastoreException lastException = nonRetryableException();
when(datastore.beginTransaction(req)).thenThrow(lastException);
try {
client.beginTransaction(req).get();
fail("expected exception");
} catch (ExecutionException e) {
assertThat(e).hasCauseThat().hasCauseThat().isEqualTo(lastException);
if (asyncStackTraceCaptureEnabled) {
assertThat(e).hasMessageThat().contains("stack trace when async call was initiated");
} else {
assertThat(e).hasMessageThat().contains("(stack trace capture for async call is disabled)");
}
}
}
Aggregations