use of com.google.datastore.v1.TransactionOptions in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerClientV1TestCases method testPartitionQuery.
void testPartitionQuery() throws InterruptedException {
System.out.println("\nTestPartitionQuery");
SpannerClient client = getClient();
Session session = client.createSession(CreateSessionRequest.newBuilder().setDatabase(database).build());
TransactionOptions options = TransactionOptions.newBuilder().setReadOnly(TransactionOptions.ReadOnly.getDefaultInstance()).build();
TransactionSelector selector = TransactionSelector.newBuilder().setBegin(options).build();
PartitionQueryRequest request = PartitionQueryRequest.newBuilder().setSession(session.getName()).setSql("select * FROM " + LARGE_TABLE).setTransaction(selector).build();
RpcCall<PartitionQueryRequest, PartitionResponse> rpcCall = (PartitionQueryRequest req) -> client.partitionQuery(req);
doTestBlocking(request, rpcCall);
cleanUpClient(client, session.getName());
}
use of com.google.datastore.v1.TransactionOptions in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerTestCases method testPartitionQueryAsync.
void testPartitionQueryAsync() throws InterruptedException {
System.out.println("\nTestPartitionQueryAsync");
ManagedChannel channel = getChannel();
SpannerStub stub = getStub(channel);
AsyncResponseObserver<Session> sessionObs = new AsyncResponseObserver<>();
stub.createSession(CreateSessionRequest.newBuilder().setDatabase(database).build(), sessionObs);
TransactionOptions options = TransactionOptions.newBuilder().setReadOnly(TransactionOptions.ReadOnly.getDefaultInstance()).build();
TransactionSelector selector = TransactionSelector.newBuilder().setBegin(options).build();
PartitionQueryRequest request = PartitionQueryRequest.newBuilder().setSession(sessionObs.get().getName()).setSql("select * FROM " + LARGE_TABLE).setTransaction(selector).build();
AsyncCall<PartitionQueryRequest, PartitionResponse> asyncCall = (PartitionQueryRequest req, AsyncResponseObserver<PartitionResponse> resp) -> stub.partitionQuery(req, resp);
doTestAsync(channel, request, asyncCall);
deleteAndCloseAsync(stub, channel, sessionObs.get().getName());
}
use of com.google.datastore.v1.TransactionOptions in project java-datastore by googleapis.
the class ITDatastoreTest method testRunInTransactionWithReadWriteOption.
@Test
public void testRunInTransactionWithReadWriteOption() {
EasyMock.expect(rpcMock.beginTransaction(EasyMock.anyObject(BeginTransactionRequest.class))).andReturn(BeginTransactionResponse.getDefaultInstance());
EasyMock.expect(rpcMock.rollback(EasyMock.anyObject(RollbackRequest.class))).andReturn(RollbackResponse.getDefaultInstance()).once();
EasyMock.expect(rpcMock.beginTransaction(EasyMock.anyObject(BeginTransactionRequest.class))).andReturn(BeginTransactionResponse.getDefaultInstance());
EasyMock.expect(rpcMock.commit(EasyMock.anyObject(CommitRequest.class))).andReturn(CommitResponse.newBuilder().build());
EasyMock.replay(rpcFactoryMock, rpcMock);
Datastore mockDatastore = rpcMockOptions.getService();
Datastore.TransactionCallable<Integer> callable = new Datastore.TransactionCallable<Integer>() {
private Integer attempts = 1;
@Override
public Integer run(DatastoreReaderWriter transaction) {
if (attempts < 2) {
++attempts;
throw new DatastoreException(10, "", "ABORTED", false, null);
}
return attempts;
}
};
TransactionOptions options = TransactionOptions.newBuilder().setReadWrite(TransactionOptions.ReadWrite.getDefaultInstance()).build();
Integer result = mockDatastore.runInTransaction(callable, options);
EasyMock.verify(rpcFactoryMock, rpcMock);
assertEquals(2, result.intValue());
}
use of com.google.datastore.v1.TransactionOptions in project java-spanner by googleapis.
the class SpannerClientTest method commitExceptionTest2.
@Test
public void commitExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockSpanner.addException(exception);
try {
SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
TransactionOptions singleUseTransaction = TransactionOptions.newBuilder().build();
List<Mutation> mutations = new ArrayList<>();
client.commit(session, singleUseTransaction, mutations);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.datastore.v1.TransactionOptions in project java-spanner by googleapis.
the class SpannerClientTest method beginTransactionExceptionTest.
@Test
public void beginTransactionExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockSpanner.addException(exception);
try {
SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
TransactionOptions options = TransactionOptions.newBuilder().build();
client.beginTransaction(session, options);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
Aggregations