Search in sources :

Example 6 with ListSessionsResponse

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

the class SpannerIntegrationTest method cleanupSessions.

private static void cleanupSessions() {
    ManagedChannel channel = builder.build();
    GoogleCredentials creds = getCreds();
    SpannerBlockingStub stub = SpannerGrpc.newBlockingStub(channel).withCallCredentials(MoreCallCredentials.from(creds));
    ListSessionsResponse responseList = stub.listSessions(ListSessionsRequest.newBuilder().setDatabase(DATABASE_PATH).build());
    for (Session s : responseList.getSessionsList()) {
        deleteSession(stub, s);
    }
    channel.shutdownNow();
}
Also used : ListSessionsResponse(com.google.spanner.v1.ListSessionsResponse) SpannerBlockingStub(com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub) ManagedChannel(io.grpc.ManagedChannel) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) Session(com.google.spanner.v1.Session)

Example 7 with ListSessionsResponse

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

the class SpannerIntegrationTest method testListSessionsAsync.

@Test
public void testListSessionsAsync() throws Exception {
    SpannerStub stub = getSpannerStub();
    List<String> respNames = createAsyncSessions(stub);
    AsyncResponseObserver<ListSessionsResponse> respList = new AsyncResponseObserver<>();
    stub.listSessions(ListSessionsRequest.newBuilder().setDatabase(DATABASE_PATH).build(), respList);
    ListSessionsResponse responseList = respList.get();
    deleteAsyncSessions(stub, respNames);
}
Also used : ListSessionsResponse(com.google.spanner.v1.ListSessionsResponse) SpannerStub(com.google.spanner.v1.SpannerGrpc.SpannerStub) Test(org.junit.Test)

Example 8 with ListSessionsResponse

use of com.google.spanner.v1.ListSessionsResponse 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);
}
Also used : ListSessionsResponse(com.google.spanner.v1.ListSessionsResponse) SpannerBlockingStub(com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub) ManagedChannel(io.grpc.ManagedChannel) GcpManagedChannel(com.google.grpc.gcp.GcpManagedChannel) ListSessionsRequest(com.google.spanner.v1.ListSessionsRequest)

Example 9 with ListSessionsResponse

use of com.google.spanner.v1.ListSessionsResponse in project java-spanner by googleapis.

the class MockSpannerServiceImpl method listSessions.

@Override
public void listSessions(ListSessionsRequest request, StreamObserver<ListSessionsResponse> responseObserver) {
    requests.add(request);
    try {
        listSessionsExecutionTime.simulateExecutionTime(exceptions, stickyGlobalExceptions, freezeLock);
        List<Session> res = new ArrayList<>();
        for (Session session : sessions.values()) {
            if (session.getName().startsWith(request.getDatabase())) {
                res.add(session.toBuilder().setApproximateLastUseTime(getCurrentGoogleTimestamp()).build());
            }
        }
        res.sort(Comparator.comparing(Session::getName));
        responseObserver.onNext(ListSessionsResponse.newBuilder().addAllSessions(res).build());
        responseObserver.onCompleted();
    } catch (StatusRuntimeException e) {
        responseObserver.onError(e);
    } catch (Throwable t) {
        responseObserver.onError(Status.INTERNAL.asRuntimeException());
    }
}
Also used : ArrayList(java.util.ArrayList) StatusRuntimeException(io.grpc.StatusRuntimeException) Session(com.google.spanner.v1.Session)

Example 10 with ListSessionsResponse

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

the class SpannerProbesTest method testSessionManagement.

@Test
public void testSessionManagement() throws Exception {
    ListSessionsResponse sessions = ListSessionsResponse.newBuilder().addSessions(session).build();
    serviceImpl.addResponse(session);
    serviceImpl.addResponse(session);
    serviceImpl.addResponse(sessions);
    serviceImpl.addResponse(emptyResponse);
    SpannerProbes.sessionManagementProber(stub);
    verify(serviceImpl, times(1)).createSession(any(), any());
    verify(serviceImpl, times(1)).getSession(any(), any());
    verify(serviceImpl, times(1)).listSessions(any(), any());
    verify(serviceImpl, times(1)).deleteSession(any(), any());
}
Also used : ListSessionsResponse(com.google.spanner.v1.ListSessionsResponse) Test(org.junit.Test)

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