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