Search in sources :

Example 11 with SpannerBlockingStub

use of com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.

the class SpannerTestCases method testPartitionQuery.

void testPartitionQuery() throws InterruptedException {
    System.out.println("\nTestPartitionQuery");
    ManagedChannel channel = getChannel();
    SpannerBlockingStub stub = getBlockingStub(channel);
    Session session = stub.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();
    BlockingCall<PartitionQueryRequest, PartitionResponse> blockingCall = (PartitionQueryRequest req) -> stub.partitionQuery(req);
    doTestBlocking(channel, request, blockingCall);
    stub.deleteSession(DeleteSessionRequest.newBuilder().setName(session.getName()).build());
    channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
}
Also used : PartitionResponse(com.google.spanner.v1.PartitionResponse) SpannerBlockingStub(com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub) TransactionOptions(com.google.spanner.v1.TransactionOptions) TransactionSelector(com.google.spanner.v1.TransactionSelector) PartitionQueryRequest(com.google.spanner.v1.PartitionQueryRequest) ManagedChannel(io.grpc.ManagedChannel) GcpManagedChannel(com.google.grpc.gcp.GcpManagedChannel) Session(com.google.spanner.v1.Session)

Example 12 with SpannerBlockingStub

use of com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.

the class SpannerIntegrationTest method testCreateAndGetSessionBlocking.

@Test
public void testCreateAndGetSessionBlocking() throws Exception {
    SpannerBlockingStub stub = getSpannerBlockingStub();
    CreateSessionRequest req = CreateSessionRequest.newBuilder().setDatabase(DATABASE_PATH).build();
    // The first MAX_CHANNEL requests (without affinity) should be distributed 1 per channel.
    List<Session> sessions = new ArrayList<>();
    for (int i = 0; i < MAX_CHANNEL; i++) {
        Session session = stub.createSession(req);
        assertThat(session).isNotEqualTo(null);
        sessions.add(session);
        Session responseGet = stub.getSession(GetSessionRequest.newBuilder().setName(session.getName()).build());
        assertEquals(responseGet.getName(), session.getName());
    }
    checkChannelRefs(MAX_CHANNEL, 0, 1);
    for (Session session : sessions) {
        deleteSession(stub, session);
    }
    checkChannelRefs(MAX_CHANNEL, 0, 0);
}
Also used : CreateSessionRequest(com.google.spanner.v1.CreateSessionRequest) SpannerBlockingStub(com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub) ArrayList(java.util.ArrayList) Session(com.google.spanner.v1.Session) Test(org.junit.Test)

Example 13 with SpannerBlockingStub

use of com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.

the class SpannerIntegrationTest method testBoundAfterUnbind.

@Test
public void testBoundAfterUnbind() {
    SpannerBlockingStub stub = getSpannerBlockingStub();
    CreateSessionRequest req = CreateSessionRequest.newBuilder().setDatabase(DATABASE_PATH).build();
    Session session = stub.createSession(req);
    stub.deleteSession(DeleteSessionRequest.newBuilder().setName(session.getName()).build());
    expectedEx.expect(StatusRuntimeException.class);
    expectedEx.expectMessage("NOT_FOUND: Session not found: " + session.getName());
    stub.getSession(GetSessionRequest.newBuilder().setName(session.getName()).build());
}
Also used : CreateSessionRequest(com.google.spanner.v1.CreateSessionRequest) SpannerBlockingStub(com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub) Session(com.google.spanner.v1.Session) Test(org.junit.Test)

Example 14 with SpannerBlockingStub

use of com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.

the class SpannerIntegrationTest method getSpannerBlockingStub.

/**
 * Helper functions for BlockingStub.
 */
private SpannerBlockingStub getSpannerBlockingStub() {
    GoogleCredentials creds = getCreds();
    SpannerBlockingStub stub = SpannerGrpc.newBlockingStub(gcpChannel).withCallCredentials(MoreCallCredentials.from(creds));
    return stub;
}
Also used : SpannerBlockingStub(com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials)

Aggregations

SpannerBlockingStub (com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub)13 Session (com.google.spanner.v1.Session)11 ManagedChannel (io.grpc.ManagedChannel)7 GcpManagedChannel (com.google.grpc.gcp.GcpManagedChannel)6 Test (org.junit.Test)5 CreateSessionRequest (com.google.spanner.v1.CreateSessionRequest)4 PartialResultSet (com.google.spanner.v1.PartialResultSet)3 ArrayList (java.util.ArrayList)3 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)2 ExecuteSqlRequest (com.google.spanner.v1.ExecuteSqlRequest)2 ListSessionsRequest (com.google.spanner.v1.ListSessionsRequest)2 ListSessionsResponse (com.google.spanner.v1.ListSessionsResponse)2 ResultSet (com.google.spanner.v1.ResultSet)2 BatchCreateSessionsRequest (com.google.spanner.v1.BatchCreateSessionsRequest)1 BatchCreateSessionsResponse (com.google.spanner.v1.BatchCreateSessionsResponse)1 BeginTransactionRequest (com.google.spanner.v1.BeginTransactionRequest)1 PartitionQueryRequest (com.google.spanner.v1.PartitionQueryRequest)1 PartitionResponse (com.google.spanner.v1.PartitionResponse)1 ReadRequest (com.google.spanner.v1.ReadRequest)1 Transaction (com.google.spanner.v1.Transaction)1