Search in sources :

Example 1 with BackupName

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

the class BaseBigtableTableAdminClientTest method deleteBackupTest.

@Test
public void deleteBackupTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    BackupName name = BackupName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[BACKUP]");
    client.deleteBackup(name);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteBackupRequest actualRequest = ((DeleteBackupRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) DeleteBackupRequest(com.google.bigtable.admin.v2.DeleteBackupRequest) BackupName(com.google.bigtable.admin.v2.BackupName) Test(org.junit.Test)

Example 2 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 3 with BackupName

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

the class DatabaseAdminClientTest method deleteBackupExceptionTest.

@Test
public void deleteBackupExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDatabaseAdmin.addException(exception);
    try {
        BackupName name = BackupName.of("[PROJECT]", "[INSTANCE]", "[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.spanner.admin.database.v1.BackupName) Test(org.junit.Test)

Example 4 with BackupName

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

the class DatabaseAdminClientTest method restoreDatabaseExceptionTest3.

@Test
public void restoreDatabaseExceptionTest3() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDatabaseAdmin.addException(exception);
    try {
        String parent = "parent-995424086";
        String databaseId = "databaseId1688905718";
        BackupName backup = BackupName.of("[PROJECT]", "[INSTANCE]", "[BACKUP]");
        client.restoreDatabaseAsync(parent, databaseId, backup).get();
        Assert.fail("No exception raised");
    } catch (ExecutionException e) {
        Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
        InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
        Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) BackupName(com.google.spanner.admin.database.v1.BackupName) Test(org.junit.Test)

Example 5 with BackupName

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

the class DatabaseAdminClientTest method restoreDatabaseTest3.

@Test
public void restoreDatabaseTest3() throws Exception {
    Database expectedResponse = Database.newBuilder().setName(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString()).setCreateTime(Timestamp.newBuilder().build()).setRestoreInfo(RestoreInfo.newBuilder().build()).setEncryptionConfig(EncryptionConfig.newBuilder().build()).addAllEncryptionInfo(new ArrayList<EncryptionInfo>()).setVersionRetentionPeriod("versionRetentionPeriod-629783929").setEarliestVersionTime(Timestamp.newBuilder().build()).setDefaultLeader("defaultLeader759009962").setDatabaseDialect(DatabaseDialect.forNumber(0)).build();
    Operation resultOperation = Operation.newBuilder().setName("restoreDatabaseTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockDatabaseAdmin.addResponse(resultOperation);
    String parent = "parent-995424086";
    String databaseId = "databaseId1688905718";
    BackupName backup = BackupName.of("[PROJECT]", "[INSTANCE]", "[BACKUP]");
    Database actualResponse = client.restoreDatabaseAsync(parent, databaseId, backup).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    RestoreDatabaseRequest actualRequest = ((RestoreDatabaseRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertEquals(databaseId, actualRequest.getDatabaseId());
    Assert.assertEquals(backup.toString(), actualRequest.getBackup());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) RestoreDatabaseRequest(com.google.spanner.admin.database.v1.RestoreDatabaseRequest) Database(com.google.spanner.admin.database.v1.Database) ArrayList(java.util.ArrayList) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) BackupName(com.google.spanner.admin.database.v1.BackupName) Test(org.junit.Test)

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