use of com.google.spanner.v1.ListSessionsResponse 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.ListSessionsResponse 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.ListSessionsResponse in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerLoadTest method testListSessionsFuture.
public static void testListSessionsFuture() throws InterruptedException, ExecutionException {
logger.info("Start testing ListSessions Future..");
File configFile = new File(SpannerLoadTest.class.getClassLoader().getResource(API_FILE).getFile());
ManagedChannel channel = GcpManagedChannelBuilder.forDelegateBuilder(builder).withApiConfigJsonFile(configFile).build();
SpannerFutureStub stub = getSpannerFutureStub(channel);
List<String> futureNames = createFutureSessions(stub);
ListSessionsResponse responseList = stub.listSessions(ListSessionsRequest.newBuilder().setDatabase(DATABASE).build()).get();
Set<String> trueNames = new HashSet<>();
for (Session s : responseList.getSessionsList()) {
trueNames.add(s.getName());
}
for (String name : futureNames) {
if (!trueNames.contains(name)) {
logger.warning(String.format("Listed Sessions doesn't contain session %s", name));
}
}
deleteFutureSessions(stub, futureNames);
}
use of com.google.spanner.v1.ListSessionsResponse in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerLoadTest method testListSessionsAsync.
public static void testListSessionsAsync() throws InterruptedException {
logger.info("Start testing ListSessions StreamObserver..");
File configFile = new File(SpannerLoadTest.class.getClassLoader().getResource(API_FILE).getFile());
ManagedChannel channel = GcpManagedChannelBuilder.forDelegateBuilder(builder).withApiConfigJsonFile(configFile).build();
SpannerStub stub = getSpannerStub(channel);
List<String> respNames = createAsyncSessions(stub);
AsyncResponseObserver<ListSessionsResponse> respList = new AsyncResponseObserver<>();
stub.listSessions(ListSessionsRequest.newBuilder().setDatabase(DATABASE).build(), respList);
ListSessionsResponse responseList = respList.get();
Set<String> trueNames = new HashSet<>();
for (Session s : responseList.getSessionsList()) {
trueNames.add(s.getName());
}
for (String name : respNames) {
if (!trueNames.contains(name)) {
logger.warning(String.format("Listed Sessions doesn't contain session %s", name));
}
}
deleteAsyncSessions(stub, respNames);
}
use of com.google.spanner.v1.ListSessionsResponse in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerProbes method sessionManagementProber.
/**
* Probes to test session related grpc call from Spanner stub.
*
* <p>Includes tests against CreateSession, GetSession, ListSessions, and DeleteSession of Spanner
* stub.
*/
public static void sessionManagementProber(SpannerGrpc.SpannerBlockingStub stub) throws ProberException {
Session session = null;
try {
session = stub.createSession(CreateSessionRequest.newBuilder().setDatabase(DATABASE).build());
// Get session.
Session responseGet = stub.getSession(GetSessionRequest.newBuilder().setName(session.getName()).build());
if (!session.getName().equals(responseGet.getName())) {
throw new ProberException(String.format("Incorrect session name %s, should be %s.", responseGet.getName(), session.getName()));
}
// List sessions.
ListSessionsResponse responseList = stub.listSessions(ListSessionsRequest.newBuilder().setDatabase(DATABASE).build());
int inList = 0;
for (Session s : responseList.getSessionsList()) {
if (s.getName().equals(session.getName())) {
inList = 1;
break;
}
}
if (inList == 0) {
throw new ProberException(String.format("The session list doesn't contain %s.", session.getName()));
}
} finally {
deleteSession(stub, session);
}
}
Aggregations