Search in sources :

Example 16 with TransactionSelector

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);
}
Also used : TransactionOptions(com.google.spanner.v1.TransactionOptions) TransactionSelector(com.google.spanner.v1.TransactionSelector) SpannerFutureStub(com.google.spanner.v1.SpannerGrpc.SpannerFutureStub) ExecuteBatchDmlResponse(com.google.spanner.v1.ExecuteBatchDmlResponse) Test(org.junit.Test)

Example 17 with TransactionSelector

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);
}
Also used : PartitionResponse(com.google.spanner.v1.PartitionResponse) SpannerStub(com.google.spanner.v1.SpannerGrpc.SpannerStub) TransactionOptions(com.google.spanner.v1.TransactionOptions) TransactionSelector(com.google.spanner.v1.TransactionSelector) Test(org.junit.Test)

Aggregations

TransactionSelector (com.google.spanner.v1.TransactionSelector)13 ByteString (com.google.protobuf.ByteString)7 TransactionOptions (com.google.spanner.v1.TransactionOptions)6 Session (com.google.spanner.v1.Session)5 PartitionResponse (com.google.spanner.v1.PartitionResponse)4 Test (org.junit.Test)4 ExecuteSqlRequest (com.google.spanner.v1.ExecuteSqlRequest)3 PartitionQueryRequest (com.google.spanner.v1.PartitionQueryRequest)3 Transaction (com.google.spanner.v1.Transaction)3 GrpcResultSet (com.google.cloud.spanner.AbstractResultSet.GrpcResultSet)2 GrpcStreamIterator (com.google.cloud.spanner.AbstractResultSet.GrpcStreamIterator)2 ResumableStreamIterator (com.google.cloud.spanner.AbstractResultSet.ResumableStreamIterator)2 SpannerRpc (com.google.cloud.spanner.spi.v1.SpannerRpc)2 GcpManagedChannel (com.google.grpc.gcp.GcpManagedChannel)2 PartialResultSet (com.google.spanner.v1.PartialResultSet)2 ResultSetMetadata (com.google.spanner.v1.ResultSetMetadata)2 SpannerStub (com.google.spanner.v1.SpannerGrpc.SpannerStub)2 ManagedChannel (io.grpc.ManagedChannel)2 Map (java.util.Map)2 Nullable (javax.annotation.Nullable)2