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);
}
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);
}
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());
}
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;
}
Aggregations