Search in sources :

Example 1 with ListSessionsResponse

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

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

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);
}
Also used : ListSessionsResponse(com.google.spanner.v1.ListSessionsResponse) SpannerFutureStub(com.google.spanner.v1.SpannerGrpc.SpannerFutureStub) ManagedChannel(io.grpc.ManagedChannel) File(java.io.File) HashSet(java.util.HashSet) Session(com.google.spanner.v1.Session)

Example 4 with ListSessionsResponse

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);
}
Also used : ListSessionsResponse(com.google.spanner.v1.ListSessionsResponse) SpannerStub(com.google.spanner.v1.SpannerGrpc.SpannerStub) ManagedChannel(io.grpc.ManagedChannel) File(java.io.File) HashSet(java.util.HashSet) Session(com.google.spanner.v1.Session)

Example 5 with ListSessionsResponse

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

Aggregations

ListSessionsResponse (com.google.spanner.v1.ListSessionsResponse)12 Session (com.google.spanner.v1.Session)8 ManagedChannel (io.grpc.ManagedChannel)6 ListSessionsRequest (com.google.spanner.v1.ListSessionsRequest)5 Test (org.junit.Test)5 SpannerStub (com.google.spanner.v1.SpannerGrpc.SpannerStub)4 HashSet (java.util.HashSet)3 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)2 ListSessionsPagedResponse (com.google.cloud.spanner.v1.SpannerClient.ListSessionsPagedResponse)2 GcpManagedChannel (com.google.grpc.gcp.GcpManagedChannel)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 DatabaseName (com.google.spanner.v1.DatabaseName)2 SpannerBlockingStub (com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub)2 SpannerFutureStub (com.google.spanner.v1.SpannerGrpc.SpannerFutureStub)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ServiceOptions (com.google.cloud.ServiceOptions)1 ObservableReactiveUtil (com.google.cloud.spanner.r2dbc.util.ObservableReactiveUtil)1 ByteString (com.google.protobuf.ByteString)1 Empty (com.google.protobuf.Empty)1