Search in sources :

Example 1 with ListSessionsPagedResponse

use of com.google.cloud.spanner.v1.SpannerClient.ListSessionsPagedResponse in project java-spanner by googleapis.

the class RetryOnInvalidatedSessionTest method invalidateSessionPool.

private static void invalidateSessionPool(DatabaseClient client, int minSessions) throws InterruptedException {
    // Wait for all sessions to have been created, and then delete them.
    Stopwatch watch = Stopwatch.createStarted();
    while (((DatabaseClientImpl) client).pool.totalSessions() < minSessions) {
        if (watch.elapsed(TimeUnit.SECONDS) > 5L) {
            fail(String.format("Failed to create MinSessions=%d", minSessions));
        }
        Thread.sleep(1L);
    }
    ListSessionsPagedResponse response = spannerClient.listSessions("projects/[PROJECT]/instances/[INSTANCE]/databases/[DATABASE]");
    for (com.google.spanner.v1.Session session : response.iterateAll()) {
        spannerClient.deleteSession(session.getName());
    }
}
Also used : ListSessionsPagedResponse(com.google.cloud.spanner.v1.SpannerClient.ListSessionsPagedResponse) Stopwatch(com.google.common.base.Stopwatch)

Example 2 with ListSessionsPagedResponse

use of com.google.cloud.spanner.v1.SpannerClient.ListSessionsPagedResponse 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 3 with ListSessionsPagedResponse

use of com.google.cloud.spanner.v1.SpannerClient.ListSessionsPagedResponse 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 4 with ListSessionsPagedResponse

use of com.google.cloud.spanner.v1.SpannerClient.ListSessionsPagedResponse in project grpc-gcp-java by GoogleCloudPlatform.

the class SpannerClientV1TestCases method testListSessions.

void testListSessions() throws InterruptedException {
    System.out.println("\nTestListSessions");
    SpannerClient client = getClient();
    ListSessionsRequest request = ListSessionsRequest.newBuilder().setDatabase(database).build();
    for (int i = 0; i < NUM_WARMUP; i++) {
        client.listSessions(request);
    }
    // for (Session element : spannerClient.listSessions(request).iterateAll())
    RpcCall<ListSessionsRequest, ListSessionsPagedResponse> rpcCall = (ListSessionsRequest req) -> client.listSessions(req);
    doTestBlocking(request, rpcCall);
    client.shutdown();
    client.awaitTermination(5, TimeUnit.SECONDS);
}
Also used : ListSessionsPagedResponse(com.google.cloud.spanner.v1.SpannerClient.ListSessionsPagedResponse) SpannerClient(com.google.cloud.spanner.v1.SpannerClient) ListSessionsRequest(com.google.spanner.v1.ListSessionsRequest)

Aggregations

ListSessionsPagedResponse (com.google.cloud.spanner.v1.SpannerClient.ListSessionsPagedResponse)4 ListSessionsRequest (com.google.spanner.v1.ListSessionsRequest)3 AbstractMessage (com.google.protobuf.AbstractMessage)2 ListSessionsResponse (com.google.spanner.v1.ListSessionsResponse)2 Session (com.google.spanner.v1.Session)2 Test (org.junit.Test)2 SpannerClient (com.google.cloud.spanner.v1.SpannerClient)1 Stopwatch (com.google.common.base.Stopwatch)1 ByteString (com.google.protobuf.ByteString)1 DatabaseName (com.google.spanner.v1.DatabaseName)1