Search in sources :

Example 1 with SpannerFutureStub

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);
}
Also used : ListSessionsResponse(com.google.spanner.v1.ListSessionsResponse) SpannerFutureStub(com.google.spanner.v1.SpannerGrpc.SpannerFutureStub) ManagedChannel(io.grpc.ManagedChannel) File(java.io.File) HashSet(java.util.HashSet) Session(com.google.spanner.v1.Session)

Example 2 with SpannerFutureStub

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;
}
Also used : CreateSessionRequest(com.google.spanner.v1.CreateSessionRequest) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Session(com.google.spanner.v1.Session)

Example 3 with SpannerFutureStub

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;
}
Also used : SpannerFutureStub(com.google.spanner.v1.SpannerGrpc.SpannerFutureStub) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials)

Example 4 with SpannerFutureStub

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);
}
Also used : ListSessionsResponse(com.google.spanner.v1.ListSessionsResponse) SpannerFutureStub(com.google.spanner.v1.SpannerGrpc.SpannerFutureStub) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with SpannerFutureStub

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

Aggregations

SpannerFutureStub (com.google.spanner.v1.SpannerGrpc.SpannerFutureStub)6 Session (com.google.spanner.v1.Session)3 Test (org.junit.Test)3 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 CreateSessionRequest (com.google.spanner.v1.CreateSessionRequest)2 ListSessionsResponse (com.google.spanner.v1.ListSessionsResponse)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ExecuteBatchDmlResponse (com.google.spanner.v1.ExecuteBatchDmlResponse)1 PartialResultSet (com.google.spanner.v1.PartialResultSet)1 ResultSet (com.google.spanner.v1.ResultSet)1 TransactionOptions (com.google.spanner.v1.TransactionOptions)1 TransactionSelector (com.google.spanner.v1.TransactionSelector)1 ManagedChannel (io.grpc.ManagedChannel)1 File (java.io.File)1