Search in sources :

Example 1 with ListSessionsRequest

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

the class SpannerClientTest method listSessionsTest.

@Test
public void listSessionsTest() throws Exception {
    Session responsesElement = Session.newBuilder().build();
    ListSessionsResponse expectedResponse = ListSessionsResponse.newBuilder().setNextPageToken("").addAllSessions(Arrays.asList(responsesElement)).build();
    mockSpanner.addResponse(expectedResponse);
    DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
    ListSessionsPagedResponse pagedListResponse = client.listSessions(database);
    List<Session> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getSessionsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListSessionsRequest actualRequest = ((ListSessionsRequest) actualRequests.get(0));
    Assert.assertEquals(database.toString(), actualRequest.getDatabase());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListSessionsResponse(com.google.spanner.v1.ListSessionsResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ListSessionsPagedResponse(com.google.cloud.spanner.v1.SpannerClient.ListSessionsPagedResponse) DatabaseName(com.google.spanner.v1.DatabaseName) ListSessionsRequest(com.google.spanner.v1.ListSessionsRequest) Session(com.google.spanner.v1.Session) Test(org.junit.Test)

Example 2 with ListSessionsRequest

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

the class SpannerClientTest method listSessionsTest2.

@Test
public void listSessionsTest2() throws Exception {
    Session responsesElement = Session.newBuilder().build();
    ListSessionsResponse expectedResponse = ListSessionsResponse.newBuilder().setNextPageToken("").addAllSessions(Arrays.asList(responsesElement)).build();
    mockSpanner.addResponse(expectedResponse);
    String database = "database1789464955";
    ListSessionsPagedResponse pagedListResponse = client.listSessions(database);
    List<Session> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getSessionsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListSessionsRequest actualRequest = ((ListSessionsRequest) actualRequests.get(0));
    Assert.assertEquals(database, actualRequest.getDatabase());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListSessionsResponse(com.google.spanner.v1.ListSessionsResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ListSessionsPagedResponse(com.google.cloud.spanner.v1.SpannerClient.ListSessionsPagedResponse) ByteString(com.google.protobuf.ByteString) ListSessionsRequest(com.google.spanner.v1.ListSessionsRequest) Session(com.google.spanner.v1.Session) Test(org.junit.Test)

Example 3 with ListSessionsRequest

use of com.google.spanner.v1.ListSessionsRequest 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));
}
Also used : ListSessionsRequest(com.google.spanner.v1.ListSessionsRequest)

Example 4 with ListSessionsRequest

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

use of com.google.spanner.v1.ListSessionsRequest 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)

Aggregations

ListSessionsRequest (com.google.spanner.v1.ListSessionsRequest)7 ListSessionsResponse (com.google.spanner.v1.ListSessionsResponse)4 ListSessionsPagedResponse (com.google.cloud.spanner.v1.SpannerClient.ListSessionsPagedResponse)3 Session (com.google.spanner.v1.Session)3 GcpManagedChannel (com.google.grpc.gcp.GcpManagedChannel)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 ManagedChannel (io.grpc.ManagedChannel)2 Test (org.junit.Test)2 SpannerClient (com.google.cloud.spanner.v1.SpannerClient)1 ByteString (com.google.protobuf.ByteString)1 DatabaseName (com.google.spanner.v1.DatabaseName)1 SpannerBlockingStub (com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub)1 SpannerStub (com.google.spanner.v1.SpannerGrpc.SpannerStub)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 ArrayList (java.util.ArrayList)1