Search in sources :

Example 11 with ListSessionsResponse

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

the class SpannerTestCases method testListSessionsAsync.

void testListSessionsAsync() throws InterruptedException {
    System.out.println("\nTestListSessionsAsync");
    ManagedChannel channel = getChannel();
    SpannerStub stub = getStub(channel);
    ListSessionsRequest request = ListSessionsRequest.newBuilder().setDatabase(database).build();
    for (int i = 0; i < NUM_WARMUP; i++) {
        AsyncResponseObserver<ListSessionsResponse> respList = new AsyncResponseObserver<>();
        stub.listSessions(request, respList);
        respList.get();
    }
    AsyncCall<ListSessionsRequest, ListSessionsResponse> asyncCall = (ListSessionsRequest req, AsyncResponseObserver<ListSessionsResponse> resp) -> stub.listSessions(req, resp);
    Func func = (List<Long> result) -> doAsyncCalls(result, numOfRpcs, request, asyncCall);
    runTest(channel, func);
    channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
}
Also used : ListSessionsResponse(com.google.spanner.v1.ListSessionsResponse) SpannerStub(com.google.spanner.v1.SpannerGrpc.SpannerStub) ManagedChannel(io.grpc.ManagedChannel) GcpManagedChannel(com.google.grpc.gcp.GcpManagedChannel) ListSessionsRequest(com.google.spanner.v1.ListSessionsRequest)

Example 12 with ListSessionsResponse

use of com.google.spanner.v1.ListSessionsResponse 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 13 with ListSessionsResponse

use of com.google.spanner.v1.ListSessionsResponse in project cloud-spanner-r2dbc by GoogleCloudPlatform.

the class SessionCleanupUtils method getSessionNames.

private static List<String> getSessionNames() throws Exception {
    String databaseName = DatabaseName.format(ServiceOptions.getDefaultProjectId(), DatabaseProperties.INSTANCE, DatabaseProperties.DATABASE);
    String nextPageToken = null;
    List<String> sessionNames = new ArrayList<>();
    do {
        ListSessionsRequest.Builder requestBuilder = ListSessionsRequest.newBuilder().setDatabase(databaseName);
        if (nextPageToken != null) {
            requestBuilder.setPageToken(nextPageToken);
        }
        ListSessionsResponse listSessionsResponse = ObservableReactiveUtil.<ListSessionsResponse>unaryCall(obs -> spannerStub.listSessions(requestBuilder.build(), obs)).block();
        nextPageToken = listSessionsResponse.getNextPageToken();
        sessionNames.addAll(listSessionsResponse.getSessionsList().stream().map(Session::getName).collect(Collectors.toList()));
    } while (nextPageToken != null && !"".equals(nextPageToken));
    return sessionNames;
}
Also used : ListSessionsResponse(com.google.spanner.v1.ListSessionsResponse) Session(com.google.spanner.v1.Session) SpannerStub(com.google.spanner.v1.SpannerGrpc.SpannerStub) ManagedChannel(io.grpc.ManagedChannel) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) DeleteSessionRequest(com.google.spanner.v1.DeleteSessionRequest) ListSessionsResponse(com.google.spanner.v1.ListSessionsResponse) MoreCallCredentials(io.grpc.auth.MoreCallCredentials) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ObservableReactiveUtil(com.google.cloud.spanner.r2dbc.util.ObservableReactiveUtil) Empty(com.google.protobuf.Empty) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) ListSessionsRequest(com.google.spanner.v1.ListSessionsRequest) List(java.util.List) StreamObserver(io.grpc.stub.StreamObserver) ServiceOptions(com.google.cloud.ServiceOptions) DatabaseName(com.google.spanner.v1.DatabaseName) SpannerGrpc(com.google.spanner.v1.SpannerGrpc) ArrayList(java.util.ArrayList) ListSessionsRequest(com.google.spanner.v1.ListSessionsRequest) Session(com.google.spanner.v1.Session)

Aggregations

ListSessionsResponse (com.google.spanner.v1.ListSessionsResponse)12 Session (com.google.spanner.v1.Session)8 ManagedChannel (io.grpc.ManagedChannel)6 ListSessionsRequest (com.google.spanner.v1.ListSessionsRequest)5 Test (org.junit.Test)5 SpannerStub (com.google.spanner.v1.SpannerGrpc.SpannerStub)4 HashSet (java.util.HashSet)3 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)2 ListSessionsPagedResponse (com.google.cloud.spanner.v1.SpannerClient.ListSessionsPagedResponse)2 GcpManagedChannel (com.google.grpc.gcp.GcpManagedChannel)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 DatabaseName (com.google.spanner.v1.DatabaseName)2 SpannerBlockingStub (com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub)2 SpannerFutureStub (com.google.spanner.v1.SpannerGrpc.SpannerFutureStub)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ServiceOptions (com.google.cloud.ServiceOptions)1 ObservableReactiveUtil (com.google.cloud.spanner.r2dbc.util.ObservableReactiveUtil)1 ByteString (com.google.protobuf.ByteString)1 Empty (com.google.protobuf.Empty)1