use of com.google.spanner.v1.SpannerGrpc.SpannerFutureStub in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerLoadTest method testListSessionsFuture.
public static void testListSessionsFuture() throws InterruptedException, ExecutionException {
logger.info("Start testing ListSessions Future..");
File configFile = new File(SpannerLoadTest.class.getClassLoader().getResource(API_FILE).getFile());
ManagedChannel channel = GcpManagedChannelBuilder.forDelegateBuilder(builder).withApiConfigJsonFile(configFile).build();
SpannerFutureStub stub = getSpannerFutureStub(channel);
List<String> futureNames = createFutureSessions(stub);
ListSessionsResponse responseList = stub.listSessions(ListSessionsRequest.newBuilder().setDatabase(DATABASE).build()).get();
Set<String> trueNames = new HashSet<>();
for (Session s : responseList.getSessionsList()) {
trueNames.add(s.getName());
}
for (String name : futureNames) {
if (!trueNames.contains(name)) {
logger.warning(String.format("Listed Sessions doesn't contain session %s", name));
}
}
deleteFutureSessions(stub, futureNames);
}
use of com.google.spanner.v1.SpannerGrpc.SpannerFutureStub in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerIntegrationTest method createFutureSessions.
private List<String> createFutureSessions(SpannerFutureStub stub) throws Exception {
List<ListenableFuture<Session>> futures = new ArrayList<>();
List<String> futureNames = new ArrayList<>();
assertEquals(ConnectivityState.IDLE, gcpChannel.getState(false));
// Check CreateSession with multiple channels and streams,
CreateSessionRequest req = CreateSessionRequest.newBuilder().setDatabase(DATABASE_PATH).build();
for (int i = 0; i < MAX_CHANNEL * MAX_STREAM; i++) {
ListenableFuture<Session> future = stub.createSession(req);
futures.add(future);
}
checkChannelRefs(MAX_CHANNEL, MAX_STREAM, 0);
for (ListenableFuture<Session> future : futures) {
futureNames.add(future.get().getName());
}
// Since createSession will bind the key, check the number of keys bound with channels.
assertEquals(ConnectivityState.READY, gcpChannel.getState(false));
assertEquals(MAX_CHANNEL * MAX_STREAM, gcpChannel.affinityKeyToChannelRef.size());
checkChannelRefs(MAX_CHANNEL, 0, MAX_STREAM);
return futureNames;
}
use of com.google.spanner.v1.SpannerGrpc.SpannerFutureStub in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerIntegrationTest method getSpannerFutureStub.
/**
* Helper Functions for FutureStub.
*/
private SpannerFutureStub getSpannerFutureStub() {
GoogleCredentials creds = getCreds();
SpannerFutureStub stub = SpannerGrpc.newFutureStub(gcpChannel).withCallCredentials(MoreCallCredentials.from(creds));
return stub;
}
use of com.google.spanner.v1.SpannerGrpc.SpannerFutureStub in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerIntegrationTest method testListSessionsFuture.
@Test
public void testListSessionsFuture() throws Exception {
SpannerFutureStub stub = getSpannerFutureStub();
List<String> futureNames = createFutureSessions(stub);
ListSessionsResponse responseList = stub.listSessions(ListSessionsRequest.newBuilder().setDatabase(DATABASE_PATH).build()).get();
Set<String> trueNames = new HashSet<>();
deleteFutureSessions(stub, futureNames);
}
use of com.google.spanner.v1.SpannerGrpc.SpannerFutureStub in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerIntegrationTest method testExecuteSqlFuture.
@Test
public void testExecuteSqlFuture() throws Exception {
SpannerFutureStub stub = getSpannerFutureStub();
List<String> futureNames = createFutureSessions(stub);
for (String futureName : futureNames) {
ListenableFuture<ResultSet> responseFuture = stub.executeSql(ExecuteSqlRequest.newBuilder().setSession(futureName).setSql("select * FROM Users").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());
ResultSet response = responseFuture.get();
assertEquals(1, response.getRowsCount());
assertEquals(USERNAME, response.getRows(0).getValuesList().get(1).getStringValue());
assertEquals(0, currentChannel.getActiveStreamsCount());
}
deleteFutureSessions(stub, futureNames);
}
Aggregations