use of com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerTestCases method listSessionsSingleCall.
private void listSessionsSingleCall(SpannerBlockingStub stub) {
ListSessionsRequest request = ListSessionsRequest.newBuilder().setDatabase(database).build();
long start = System.currentTimeMillis();
stub.listSessions(request);
System.out.println(String.format("-- Finished executing listSessions in %d ms in another thread. -- ", System.currentTimeMillis() - start));
}
use of com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerTestCases method testListSessions.
void testListSessions() throws InterruptedException {
System.out.println("\nTestListSessions");
ManagedChannel channel = getChannel();
SpannerBlockingStub stub = getBlockingStub(channel);
ListSessionsRequest request = ListSessionsRequest.newBuilder().setDatabase(database).build();
for (int i = 0; i < NUM_WARMUP; i++) {
stub.listSessions(request);
}
BlockingCall<ListSessionsRequest, ListSessionsResponse> blockingCall = (ListSessionsRequest req) -> stub.listSessions(req);
Func func = (List<Long> result) -> doBlockingCalls(result, numOfRpcs, request, blockingCall);
runTest(channel, func);
channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
}
use of com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerTestCases method testRead.
void testRead() throws InterruptedException {
System.out.println("\nTestRead");
ManagedChannel channel = getChannel();
SpannerBlockingStub stub = getBlockingStub(channel);
Session session = stub.createSession(CreateSessionRequest.newBuilder().setDatabase(database).build());
ReadRequest request = ReadRequest.newBuilder().setSession(session.getName()).setTable("small_table").setKeySet(KeySet.newBuilder().setAll(true).build()).addColumns("users").addColumns("firstname").addColumns("lastname").build();
BlockingCall<ReadRequest, ResultSet> blockingCall = (ReadRequest req) -> stub.read(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 SpannerTestCases method testExecuteSql.
void testExecuteSql() throws InterruptedException {
System.out.println("\nTestExecuteSql");
ManagedChannel channel = getChannel();
SpannerBlockingStub stub = getBlockingStub(channel);
Session session = stub.createSession(CreateSessionRequest.newBuilder().setDatabase(database).build());
ExecuteSqlRequest request = ExecuteSqlRequest.newBuilder().setSession(session.getName()).setSql("select * FROM " + TABLE).build();
BlockingCall<ExecuteSqlRequest, ResultSet> blockingCall = (ExecuteSqlRequest req) -> stub.executeSql(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 SpannerTestCases method testMaxConcurrentStream.
void testMaxConcurrentStream() throws InterruptedException {
System.out.println("\nTestMaxConcurrentStream");
ManagedChannel channel = getChannel();
SpannerBlockingStub stub = getBlockingStub(channel);
Session session = stub.createSession(CreateSessionRequest.newBuilder().setDatabase(database).build());
// Warm up.
ExecuteSqlRequest request = ExecuteSqlRequest.newBuilder().setSession(session.getName()).setSql("select * FROM " + LARGE_TABLE).build();
for (int i = 0; i < NUM_WARMUP; i++) {
Iterator<PartialResultSet> iter = stub.executeStreamingSql(request);
while (iter.hasNext()) {
iter.next();
}
}
// Start concurrent rpc calls.
List<Iterator<PartialResultSet>> responses = new ArrayList<>();
long start = System.currentTimeMillis();
for (int i = 0; i < numOfRpcs; i++) {
responses.add(stub.executeStreamingSql(request));
}
System.out.println(String.format("Started %d ExecuteStreamingSql calls in %dms", numOfRpcs, System.currentTimeMillis() - start));
// Start another rpc call using a new thread.
Thread t = new Thread(() -> listSessionsSingleCall(stub));
t.start();
System.out.println("I'm sleeping and will wake up after 2000ms zzzZZZZ.");
Thread.sleep(2000);
System.out.println("Good morning!");
// Free one call.
while (responses.get(0).hasNext()) {
responses.get(0).next();
}
System.out.println(String.format("Freed one call in %dms.", System.currentTimeMillis() - start));
// Free all the calls.
for (int i = 1; i < responses.size(); i++) {
Iterator<PartialResultSet> iter = responses.get(i);
while (iter.hasNext()) {
iter.next();
}
}
System.out.println(String.format("Freed %d call(s) in %dms.", numOfRpcs, System.currentTimeMillis() - start));
t.join();
stub.deleteSession(DeleteSessionRequest.newBuilder().setName(session.getName()).build());
channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
}
Aggregations