Search in sources :

Example 6 with ListBackupsRequest

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

the class BaseBigtableTableAdminClientTest method listBackupsTest.

@Test
public void listBackupsTest() throws Exception {
    Backup responsesElement = Backup.newBuilder().build();
    ListBackupsResponse expectedResponse = ListBackupsResponse.newBuilder().setNextPageToken("").addAllBackups(Arrays.asList(responsesElement)).build();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    ClusterName parent = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
    ListBackupsPagedResponse pagedListResponse = client.listBackups(parent);
    List<Backup> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getBackupsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListBackupsRequest actualRequest = ((ListBackupsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Backup(com.google.bigtable.admin.v2.Backup) ListBackupsRequest(com.google.bigtable.admin.v2.ListBackupsRequest) ClusterName(com.google.bigtable.admin.v2.ClusterName) ListBackupsResponse(com.google.bigtable.admin.v2.ListBackupsResponse) ListBackupsPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPagedResponse) Test(org.junit.Test)

Example 7 with ListBackupsRequest

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

the class GapicSpannerRpc method listBackups.

@Override
public Paginated<Backup> listBackups(String instanceName, int pageSize, @Nullable String filter, @Nullable String pageToken) throws SpannerException {
    acquireAdministrativeRequestsRateLimiter();
    ListBackupsRequest.Builder requestBuilder = ListBackupsRequest.newBuilder().setParent(instanceName).setPageSize(pageSize);
    if (filter != null) {
        requestBuilder.setFilter(filter);
    }
    if (pageToken != null) {
        requestBuilder.setPageToken(pageToken);
    }
    final ListBackupsRequest request = requestBuilder.build();
    final GrpcCallContext context = newCallContext(null, instanceName, request, DatabaseAdminGrpc.getListBackupsMethod());
    ListBackupsResponse response = runWithRetryOnAdministrativeRequestsExceeded(() -> get(databaseAdminStub.listBackupsCallable().futureCall(request, context)));
    return new Paginated<>(response.getBackupsList(), response.getNextPageToken());
}
Also used : GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) ListBackupsRequest(com.google.spanner.admin.database.v1.ListBackupsRequest) ListBackupsResponse(com.google.spanner.admin.database.v1.ListBackupsResponse)

Example 8 with ListBackupsRequest

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

the class DatabaseAdminClientTest method listBackupsTest.

@Test
public void listBackupsTest() throws Exception {
    Backup responsesElement = Backup.newBuilder().build();
    ListBackupsResponse expectedResponse = ListBackupsResponse.newBuilder().setNextPageToken("").addAllBackups(Arrays.asList(responsesElement)).build();
    mockDatabaseAdmin.addResponse(expectedResponse);
    InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
    ListBackupsPagedResponse pagedListResponse = client.listBackups(parent);
    List<Backup> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getBackupsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListBackupsRequest actualRequest = ((ListBackupsRequest) 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) Backup(com.google.spanner.admin.database.v1.Backup) ListBackupsRequest(com.google.spanner.admin.database.v1.ListBackupsRequest) ListBackupsResponse(com.google.spanner.admin.database.v1.ListBackupsResponse) ListBackupsPagedResponse(com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupsPagedResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 ListBackupsRequest (com.google.bigtable.admin.v2.ListBackupsRequest)5 ListBackupsPagedResponse (com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPagedResponse)5 AbstractMessage (com.google.protobuf.AbstractMessage)4 ByteString (com.google.protobuf.ByteString)4 ListBackupsPage (com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPage)3 Backup (com.google.cloud.bigtable.admin.v2.models.Backup)3 ListBackupsRequest (com.google.spanner.admin.database.v1.ListBackupsRequest)3 ListBackupsResponse (com.google.spanner.admin.database.v1.ListBackupsResponse)3 Backup (com.google.bigtable.admin.v2.Backup)2 ListBackupsResponse (com.google.bigtable.admin.v2.ListBackupsResponse)2 ListBackupsPagedResponse (com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupsPagedResponse)2 Backup (com.google.spanner.admin.database.v1.Backup)2 ApiFuture (com.google.api.core.ApiFuture)1 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)1 ClusterName (com.google.bigtable.admin.v2.ClusterName)1 ImmutableList (com.google.common.collect.ImmutableList)1 InstanceName (com.google.spanner.admin.database.v1.InstanceName)1 List (java.util.List)1