Search in sources :

Example 1 with ListDatabasesResponse

use of com.google.spanner.admin.database.v1.ListDatabasesResponse in project java-spanner by googleapis.

the class DatabaseAdminClientTest method listDatabasesTest2.

@Test
public void listDatabasesTest2() throws Exception {
    Database responsesElement = Database.newBuilder().build();
    ListDatabasesResponse expectedResponse = ListDatabasesResponse.newBuilder().setNextPageToken("").addAllDatabases(Arrays.asList(responsesElement)).build();
    mockDatabaseAdmin.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListDatabasesPagedResponse pagedListResponse = client.listDatabases(parent);
    List<Database> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getDatabasesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListDatabasesRequest actualRequest = ((ListDatabasesRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListDatabasesPagedResponse(com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabasesPagedResponse) Database(com.google.spanner.admin.database.v1.Database) ByteString(com.google.protobuf.ByteString) ListDatabasesResponse(com.google.spanner.admin.database.v1.ListDatabasesResponse) ListDatabasesRequest(com.google.spanner.admin.database.v1.ListDatabasesRequest) Test(org.junit.Test)

Example 2 with ListDatabasesResponse

use of com.google.spanner.admin.database.v1.ListDatabasesResponse in project java-spanner by googleapis.

the class GapicSpannerRpc method listDatabases.

@Override
public Paginated<Database> listDatabases(String instanceName, int pageSize, @Nullable String pageToken) throws SpannerException {
    acquireAdministrativeRequestsRateLimiter();
    ListDatabasesRequest.Builder requestBuilder = ListDatabasesRequest.newBuilder().setParent(instanceName).setPageSize(pageSize);
    if (pageToken != null) {
        requestBuilder.setPageToken(pageToken);
    }
    final ListDatabasesRequest request = requestBuilder.build();
    final GrpcCallContext context = newCallContext(null, instanceName, request, DatabaseAdminGrpc.getListDatabasesMethod());
    ListDatabasesResponse response = runWithRetryOnAdministrativeRequestsExceeded(() -> get(databaseAdminStub.listDatabasesCallable().futureCall(request, context)));
    return new Paginated<>(response.getDatabasesList(), response.getNextPageToken());
}
Also used : GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) ListDatabasesRequest(com.google.spanner.admin.database.v1.ListDatabasesRequest) ListDatabasesResponse(com.google.spanner.admin.database.v1.ListDatabasesResponse)

Example 3 with ListDatabasesResponse

use of com.google.spanner.admin.database.v1.ListDatabasesResponse in project java-spanner by googleapis.

the class DatabaseAdminClientTest method listDatabasesTest.

@Test
public void listDatabasesTest() throws Exception {
    Database responsesElement = Database.newBuilder().build();
    ListDatabasesResponse expectedResponse = ListDatabasesResponse.newBuilder().setNextPageToken("").addAllDatabases(Arrays.asList(responsesElement)).build();
    mockDatabaseAdmin.addResponse(expectedResponse);
    InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
    ListDatabasesPagedResponse pagedListResponse = client.listDatabases(parent);
    List<Database> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getDatabasesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListDatabasesRequest actualRequest = ((ListDatabasesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : InstanceName(com.google.spanner.admin.database.v1.InstanceName) AbstractMessage(com.google.protobuf.AbstractMessage) ListDatabasesPagedResponse(com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabasesPagedResponse) Database(com.google.spanner.admin.database.v1.Database) ListDatabasesResponse(com.google.spanner.admin.database.v1.ListDatabasesResponse) ListDatabasesRequest(com.google.spanner.admin.database.v1.ListDatabasesRequest) Test(org.junit.Test)

Aggregations

ListDatabasesRequest (com.google.spanner.admin.database.v1.ListDatabasesRequest)3 ListDatabasesResponse (com.google.spanner.admin.database.v1.ListDatabasesResponse)3 ListDatabasesPagedResponse (com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabasesPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Database (com.google.spanner.admin.database.v1.Database)2 Test (org.junit.Test)2 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)1 ByteString (com.google.protobuf.ByteString)1 InstanceName (com.google.spanner.admin.database.v1.InstanceName)1