use of com.google.spanner.v1.TransactionSelector in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerIntegrationTest method testExecuteBatchDmlFuture.
@Test
public void testExecuteBatchDmlFuture() throws Exception {
SpannerFutureStub stub = getSpannerFutureStub();
List<String> futureNames = createFutureSessions(stub);
for (String futureName : futureNames) {
TransactionOptions options = TransactionOptions.newBuilder().setReadWrite(TransactionOptions.ReadWrite.getDefaultInstance()).build();
TransactionSelector selector = TransactionSelector.newBuilder().setBegin(options).build();
// Will use only one session for the whole batch.
ListenableFuture<ExecuteBatchDmlResponse> responseFuture = stub.executeBatchDml(ExecuteBatchDmlRequest.newBuilder().setSession(futureName).setTransaction(selector).addStatements(Statement.newBuilder().setSql("select * FROM Users").build()).build());
// The ChannelRef which is bound with the current affinity key.
GcpManagedChannel.ChannelRef currentChannel = gcpChannel.affinityKeyToChannelRef.get(futureName);
// Verify the channel is in use.
assertEquals(1, currentChannel.getActiveStreamsCount());
ExecuteBatchDmlResponse response = responseFuture.get();
assertEquals(0, currentChannel.getActiveStreamsCount());
}
deleteFutureSessions(stub, futureNames);
}
use of com.google.spanner.v1.TransactionSelector in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerIntegrationTest method testPartitionQueryAsync.
@Test
public void testPartitionQueryAsync() throws Exception {
SpannerStub stub = getSpannerStub();
List<String> respNames = createAsyncSessions(stub);
for (String respName : respNames) {
TransactionOptions options = TransactionOptions.newBuilder().setReadOnly(TransactionOptions.ReadOnly.getDefaultInstance()).build();
TransactionSelector selector = TransactionSelector.newBuilder().setBegin(options).build();
AsyncResponseObserver<PartitionResponse> resp = new AsyncResponseObserver<>();
stub.partitionQuery(PartitionQueryRequest.newBuilder().setSession(respName).setSql("select * FROM Users").setTransaction(selector).build(), resp);
// The ChannelRef which is bound with the current affinity key.
GcpManagedChannel.ChannelRef currentChannel = gcpChannel.affinityKeyToChannelRef.get(respName);
// Verify the channel is in use.
assertEquals(1, currentChannel.getActiveStreamsCount());
PartitionResponse response = resp.get();
assertEquals(0, currentChannel.getActiveStreamsCount());
}
deleteAsyncSessions(stub, respNames);
}
Aggregations