Search in sources :

Example 6 with BackupName

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

the class BaseBigtableTableAdminClientTest method deleteBackupExceptionTest.

@Test
public void deleteBackupExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableTableAdmin.addException(exception);
    try {
        BackupName name = BackupName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[BACKUP]");
        client.deleteBackup(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) BackupName(com.google.bigtable.admin.v2.BackupName) Test(org.junit.Test)

Example 7 with BackupName

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

the class BaseBigtableTableAdminClientTest method getBackupTest.

@Test
public void getBackupTest() throws Exception {
    Backup expectedResponse = Backup.newBuilder().setName(BackupName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[BACKUP]").toString()).setSourceTable("sourceTable-95372173").setExpireTime(Timestamp.newBuilder().build()).setStartTime(Timestamp.newBuilder().build()).setEndTime(Timestamp.newBuilder().build()).setSizeBytes(-1796325715).setEncryptionInfo(EncryptionInfo.newBuilder().build()).build();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    BackupName name = BackupName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[BACKUP]");
    Backup actualResponse = client.getBackup(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetBackupRequest actualRequest = ((GetBackupRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) GetBackupRequest(com.google.bigtable.admin.v2.GetBackupRequest) Backup(com.google.bigtable.admin.v2.Backup) BackupName(com.google.bigtable.admin.v2.BackupName) Test(org.junit.Test)

Example 8 with BackupName

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

the class BaseBigtableTableAdminClientTest method getBackupExceptionTest.

@Test
public void getBackupExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableTableAdmin.addException(exception);
    try {
        BackupName name = BackupName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[BACKUP]");
        client.getBackup(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) BackupName(com.google.bigtable.admin.v2.BackupName) Test(org.junit.Test)

Example 9 with BackupName

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

the class GapicSpannerRpc method getBackup.

@Override
public Backup getBackup(String backupName) throws SpannerException {
    acquireAdministrativeRequestsRateLimiter();
    final GetBackupRequest request = GetBackupRequest.newBuilder().setName(backupName).build();
    final GrpcCallContext context = newCallContext(null, backupName, request, DatabaseAdminGrpc.getGetBackupMethod());
    return runWithRetryOnAdministrativeRequestsExceeded(() -> get(databaseAdminStub.getBackupCallable().futureCall(request, context)));
}
Also used : GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) GetBackupRequest(com.google.spanner.admin.database.v1.GetBackupRequest)

Example 10 with BackupName

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

the class DatabaseAdminClient method deleteBackup.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Deletes a pending or completed [Backup][google.spanner.admin.database.v1.Backup].
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
 *   BackupName name = BackupName.of("[PROJECT]", "[INSTANCE]", "[BACKUP]");
 *   databaseAdminClient.deleteBackup(name);
 * }
 * }</pre>
 *
 * @param name Required. Name of the backup to delete. Values are of the form
 *     `projects/&lt;project&gt;/instances/&lt;instance&gt;/backups/&lt;backup&gt;`.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteBackup(BackupName name) {
    DeleteBackupRequest request = DeleteBackupRequest.newBuilder().setName(name == null ? null : name.toString()).build();
    deleteBackup(request);
}
Also used : DeleteBackupRequest(com.google.spanner.admin.database.v1.DeleteBackupRequest)

Aggregations

Test (org.junit.Test)12 BackupName (com.google.spanner.admin.database.v1.BackupName)8 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)6 AbstractMessage (com.google.protobuf.AbstractMessage)6 StatusRuntimeException (io.grpc.StatusRuntimeException)6 BackupName (com.google.bigtable.admin.v2.BackupName)4 ByteString (com.google.protobuf.ByteString)4 DeleteBackupRequest (com.google.spanner.admin.database.v1.DeleteBackupRequest)3 ArrayList (java.util.ArrayList)3 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)2 Operation (com.google.longrunning.Operation)2 Empty (com.google.protobuf.Empty)2 Database (com.google.spanner.admin.database.v1.Database)2 GetBackupRequest (com.google.spanner.admin.database.v1.GetBackupRequest)2 InstanceName (com.google.spanner.admin.database.v1.InstanceName)2 RestoreDatabaseRequest (com.google.spanner.admin.database.v1.RestoreDatabaseRequest)2 ExecutionException (java.util.concurrent.ExecutionException)2 Backup (com.google.bigtable.admin.v2.Backup)1 DeleteBackupRequest (com.google.bigtable.admin.v2.DeleteBackupRequest)1 GetBackupRequest (com.google.bigtable.admin.v2.GetBackupRequest)1