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());
}
}
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()));
}
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()));
}
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);
}
Aggregations