use of com.google.datastore.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.datastore.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.datastore.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)");
}
}
}
use of com.google.datastore.v1.BeginTransactionRequest in project appengine-java-standard by GoogleCloudPlatform.
the class CloudDatastoreV1ClientImplTest method testRetries_NonRetryable.
@Test
public void testRetries_NonRetryable() throws Exception {
BeginTransactionRequest req = BeginTransactionRequest.getDefaultInstance();
CloudDatastoreV1ClientImpl client = new CloudDatastoreV1ClientImpl(datastore, 2);
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);
}
}
use of com.google.datastore.v1.BeginTransactionRequest in project liquibase-spanner by cloudspannerecosystem.
the class MergeColumnsTest method testMergeSingersFirstNamdAndLastNameFromYaml.
@Test
void testMergeSingersFirstNamdAndLastNameFromYaml() throws Exception {
String[] expectedSql = new String[] { "ALTER TABLE Singers ADD COLUMN FullName STRING(500)", "ALTER TABLE Singers DROP COLUMN FirstName", "ALTER TABLE Singers DROP COLUMN LastName" };
for (String sql : expectedSql) {
addUpdateDdlStatementsResponse(sql);
}
for (String file : new String[] { "merge-singers-firstname-and-lastname.spanner.yaml" }) {
try (Connection con = createConnection();
Liquibase liquibase = getLiquibase(con, file)) {
liquibase.update(new Contexts("test"));
}
}
assertThat(mockAdmin.getRequests()).hasSize(expectedSql.length);
for (int i = 0; i < expectedSql.length; i++) {
assertThat(mockAdmin.getRequests().get(i)).isInstanceOf(UpdateDatabaseDdlRequest.class);
UpdateDatabaseDdlRequest request = (UpdateDatabaseDdlRequest) mockAdmin.getRequests().get(i);
assertThat(request.getStatementsList()).hasSize(1);
assertThat(request.getStatementsList().get(0)).isEqualTo(expectedSql[i]);
}
// Verify that the mock server received one BeginTransactionRequest for a PDML transaction.
assertThat(mockSpanner.getRequests().stream().filter(new Predicate<AbstractMessage>() {
@Override
public boolean test(AbstractMessage t) {
return t instanceof BeginTransactionRequest;
}
}).map(new Function<AbstractMessage, BeginTransactionRequest>() {
@Override
public BeginTransactionRequest apply(AbstractMessage t) {
return (BeginTransactionRequest) t;
}
}).filter(new Predicate<BeginTransactionRequest>() {
@Override
public boolean test(BeginTransactionRequest t) {
return t.hasOptions() && t.getOptions().hasPartitionedDml();
}
}).count()).isEqualTo(1L);
}
Aggregations