Search in sources :

Example 36 with Backup

use of com.google.bigtable.admin.v2.Backup in project java-spanner by googleapis.

the class DatabaseAdminClientTest method createBackupTest2.

@Test
public void createBackupTest2() throws Exception {
    Backup expectedResponse = Backup.newBuilder().setDatabase(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString()).setVersionTime(Timestamp.newBuilder().build()).setExpireTime(Timestamp.newBuilder().build()).setName(BackupName.of("[PROJECT]", "[INSTANCE]", "[BACKUP]").toString()).setCreateTime(Timestamp.newBuilder().build()).setSizeBytes(-1796325715).addAllReferencingDatabases(new ArrayList<String>()).setEncryptionInfo(EncryptionInfo.newBuilder().build()).setDatabaseDialect(DatabaseDialect.forNumber(0)).build();
    Operation resultOperation = Operation.newBuilder().setName("createBackupTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockDatabaseAdmin.addResponse(resultOperation);
    String parent = "parent-995424086";
    Backup backup = Backup.newBuilder().build();
    String backupId = "backupId2121930365";
    Backup actualResponse = client.createBackupAsync(parent, backup, backupId).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateBackupRequest actualRequest = ((CreateBackupRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertEquals(backup, actualRequest.getBackup());
    Assert.assertEquals(backupId, actualRequest.getBackupId());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : CreateBackupRequest(com.google.spanner.admin.database.v1.CreateBackupRequest) AbstractMessage(com.google.protobuf.AbstractMessage) Backup(com.google.spanner.admin.database.v1.Backup) ArrayList(java.util.ArrayList) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 37 with Backup

use of com.google.bigtable.admin.v2.Backup in project java-spanner by googleapis.

the class DatabaseAdminClientTest method updateBackupExceptionTest.

@Test
public void updateBackupExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDatabaseAdmin.addException(exception);
    try {
        Backup backup = Backup.newBuilder().build();
        FieldMask updateMask = FieldMask.newBuilder().build();
        client.updateBackup(backup, updateMask);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) Backup(com.google.spanner.admin.database.v1.Backup) StatusRuntimeException(io.grpc.StatusRuntimeException) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 38 with Backup

use of com.google.bigtable.admin.v2.Backup in project java-spanner by googleapis.

the class DatabaseAdminClientTest method getBackupTest2.

@Test
public void getBackupTest2() throws Exception {
    Backup expectedResponse = Backup.newBuilder().setDatabase(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString()).setVersionTime(Timestamp.newBuilder().build()).setExpireTime(Timestamp.newBuilder().build()).setName(BackupName.of("[PROJECT]", "[INSTANCE]", "[BACKUP]").toString()).setCreateTime(Timestamp.newBuilder().build()).setSizeBytes(-1796325715).addAllReferencingDatabases(new ArrayList<String>()).setEncryptionInfo(EncryptionInfo.newBuilder().build()).setDatabaseDialect(DatabaseDialect.forNumber(0)).build();
    mockDatabaseAdmin.addResponse(expectedResponse);
    String name = "name3373707";
    Backup actualResponse = client.getBackup(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetBackupRequest actualRequest = ((GetBackupRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) GetBackupRequest(com.google.spanner.admin.database.v1.GetBackupRequest) Backup(com.google.spanner.admin.database.v1.Backup) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 39 with Backup

use of com.google.bigtable.admin.v2.Backup in project java-spanner by googleapis.

the class DatabaseAdminClientTest method getBackupTest.

@Test
public void getBackupTest() throws Exception {
    Backup expectedResponse = Backup.newBuilder().setDatabase(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString()).setVersionTime(Timestamp.newBuilder().build()).setExpireTime(Timestamp.newBuilder().build()).setName(BackupName.of("[PROJECT]", "[INSTANCE]", "[BACKUP]").toString()).setCreateTime(Timestamp.newBuilder().build()).setSizeBytes(-1796325715).addAllReferencingDatabases(new ArrayList<String>()).setEncryptionInfo(EncryptionInfo.newBuilder().build()).setDatabaseDialect(DatabaseDialect.forNumber(0)).build();
    mockDatabaseAdmin.addResponse(expectedResponse);
    BackupName name = BackupName.of("[PROJECT]", "[INSTANCE]", "[BACKUP]");
    Backup actualResponse = client.getBackup(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.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.spanner.admin.database.v1.GetBackupRequest) Backup(com.google.spanner.admin.database.v1.Backup) ArrayList(java.util.ArrayList) BackupName(com.google.spanner.admin.database.v1.BackupName) Test(org.junit.Test)

Example 40 with Backup

use of com.google.bigtable.admin.v2.Backup 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)36 Backup (com.google.spanner.admin.database.v1.Backup)21 AbstractMessage (com.google.protobuf.AbstractMessage)15 ByteString (com.google.protobuf.ByteString)14 Backup (com.google.bigtable.admin.v2.Backup)10 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)8 StatusRuntimeException (io.grpc.StatusRuntimeException)8 ArrayList (java.util.ArrayList)6 ListBackupsRequest (com.google.bigtable.admin.v2.ListBackupsRequest)5 ListBackupsPagedResponse (com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPagedResponse)5 Backup (com.google.cloud.bigtable.admin.v2.models.Backup)5 CreateBackupMetadata (com.google.spanner.admin.database.v1.CreateBackupMetadata)5 ExecutionException (java.util.concurrent.ExecutionException)5 BackupName (com.google.bigtable.admin.v2.BackupName)4 GetBackupRequest (com.google.bigtable.admin.v2.GetBackupRequest)4 Timestamp (com.google.cloud.Timestamp)4 Operation (com.google.longrunning.Operation)4 FieldMask (com.google.protobuf.FieldMask)4 CreateBackupRequest (com.google.spanner.admin.database.v1.CreateBackupRequest)4 ClusterName (com.google.bigtable.admin.v2.ClusterName)3