use of com.google.datastore.v1.BeginTransactionRequest in project java-spanner by googleapis.
the class SpannerClientTest method beginTransactionTest.
@Test
public void beginTransactionTest() throws Exception {
Transaction expectedResponse = Transaction.newBuilder().setId(ByteString.EMPTY).setReadTimestamp(Timestamp.newBuilder().build()).build();
mockSpanner.addResponse(expectedResponse);
SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
TransactionOptions options = TransactionOptions.newBuilder().build();
Transaction actualResponse = client.beginTransaction(session, options);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockSpanner.getRequests();
Assert.assertEquals(1, actualRequests.size());
BeginTransactionRequest actualRequest = ((BeginTransactionRequest) actualRequests.get(0));
Assert.assertEquals(session.toString(), actualRequest.getSession());
Assert.assertEquals(options, actualRequest.getOptions());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.datastore.v1.BeginTransactionRequest in project java-spanner by googleapis.
the class SpannerClientTest method beginTransactionTest2.
@Test
public void beginTransactionTest2() throws Exception {
Transaction expectedResponse = Transaction.newBuilder().setId(ByteString.EMPTY).setReadTimestamp(Timestamp.newBuilder().build()).build();
mockSpanner.addResponse(expectedResponse);
String session = "session1984987798";
TransactionOptions options = TransactionOptions.newBuilder().build();
Transaction actualResponse = client.beginTransaction(session, options);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockSpanner.getRequests();
Assert.assertEquals(1, actualRequests.size());
BeginTransactionRequest actualRequest = ((BeginTransactionRequest) actualRequests.get(0));
Assert.assertEquals(session, actualRequest.getSession());
Assert.assertEquals(options, actualRequest.getOptions());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.datastore.v1.BeginTransactionRequest in project java-spanner by googleapis.
the class PartitionedDmlTransaction method initTransaction.
private ByteString initTransaction() {
final BeginTransactionRequest request = BeginTransactionRequest.newBuilder().setSession(session.getName()).setOptions(TransactionOptions.newBuilder().setPartitionedDml(TransactionOptions.PartitionedDml.getDefaultInstance())).build();
Transaction tx = rpc.beginTransaction(request, session.getOptions());
if (tx.getId().isEmpty()) {
throw SpannerExceptionFactory.newSpannerException(ErrorCode.INTERNAL, "Failed to init transaction, missing transaction id\n" + session.getName());
}
return tx.getId();
}
use of com.google.datastore.v1.BeginTransactionRequest in project appengine-java-standard by GoogleCloudPlatform.
the class CloudDatastoreV1ClientImplTest method testRetries_MaxRetriesExceeded.
@Test
public void testRetries_MaxRetriesExceeded() throws Exception {
BeginTransactionRequest req = BeginTransactionRequest.getDefaultInstance();
CloudDatastoreV1ClientImpl client = new CloudDatastoreV1ClientImpl(datastore, 2);
DatastoreException lastException = retryableException();
when(datastore.beginTransaction(req)).thenThrow(retryableException()).thenThrow(retryableException()).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 appengine-java-standard by GoogleCloudPlatform.
the class CloudDatastoreV1ClientImplTest method testStackTrace.
@Test
public void testStackTrace() throws Throwable {
BeginTransactionRequest req = BeginTransactionRequest.getDefaultInstance();
when(datastore.beginTransaction(req)).thenThrow(new DatastoreException("beginTransaction", Code.INVALID_ARGUMENT, "message", null));
CloudDatastoreV1ClientImpl client = newClient(datastore);
Future<BeginTransactionResponse> future = makeBeginTransactionCallForTest(client, req);
try {
future.get();
fail("expected exception");
} catch (ExecutionException e) {
assertThat(e).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
// The test helper method used to call beginTransaction() appears in the error message
// (even though it is no longer on the stack).
assertThat(e).hasMessageThat().contains("makeBeginTransactionCallForTest");
// The underlying cause is also present.
assertThat(e).hasCauseThat().hasCauseThat().isInstanceOf(DatastoreException.class);
}
}
Aggregations