Search in sources :

Example 26 with Backup

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

the class BigtableTableAdminClientTests method testGetBackup.

@Test
public void testGetBackup() {
    // Setup
    Mockito.when(mockStub.getBackupCallable()).thenReturn(mockGetBackupCallable);
    Timestamp expireTime = Timestamp.newBuilder().setSeconds(123456789).build();
    Timestamp startTime = Timestamp.newBuilder().setSeconds(1234).build();
    Timestamp endTime = Timestamp.newBuilder().setSeconds(5678).build();
    com.google.bigtable.admin.v2.Backup.State state = State.CREATING;
    long sizeBytes = 12345L;
    GetBackupRequest testRequest = GetBackupRequest.newBuilder().setName(NameUtil.formatBackupName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID, BACKUP_ID)).build();
    Mockito.when(mockGetBackupCallable.futureCall(testRequest)).thenReturn(ApiFutures.immediateFuture(com.google.bigtable.admin.v2.Backup.newBuilder().setName(NameUtil.formatBackupName(PROJECT_ID, INSTANCE_ID, CLUSTER_ID, BACKUP_ID)).setSourceTable(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID)).setExpireTime(expireTime).setStartTime(startTime).setEndTime(endTime).setSizeBytes(sizeBytes).setState(state).build()));
    // Execute
    Backup actualResult = adminClient.getBackup(CLUSTER_ID, BACKUP_ID);
    // Verify
    assertThat(actualResult.getId()).isEqualTo(BACKUP_ID);
    assertThat(actualResult.getSourceTableId()).isEqualTo(TABLE_ID);
    assertThat(actualResult.getExpireTime()).isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(expireTime)));
    assertThat(actualResult.getStartTime()).isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(startTime)));
    assertThat(actualResult.getEndTime()).isEqualTo(Instant.ofEpochMilli(Timestamps.toMillis(endTime)));
    assertThat(actualResult.getSizeBytes()).isEqualTo(sizeBytes);
    assertThat(actualResult.getState()).isEqualTo(Backup.State.fromProto(state));
}
Also used : GetBackupRequest(com.google.bigtable.admin.v2.GetBackupRequest) Backup(com.google.cloud.bigtable.admin.v2.models.Backup) State(com.google.bigtable.admin.v2.Backup.State) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 27 with Backup

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

the class BaseBigtableTableAdminClientTest method listBackupsTest2.

@Test
public void listBackupsTest2() throws Exception {
    Backup responsesElement = Backup.newBuilder().build();
    ListBackupsResponse expectedResponse = ListBackupsResponse.newBuilder().setNextPageToken("").addAllBackups(Arrays.asList(responsesElement)).build();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    String parent = "parent-995424086";
    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, 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) ListBackupsResponse(com.google.bigtable.admin.v2.ListBackupsResponse) ListBackupsPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPagedResponse) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 28 with Backup

use of com.google.bigtable.admin.v2.Backup 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 29 with Backup

use of com.google.bigtable.admin.v2.Backup 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 30 with Backup

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

the class GapicSpannerRpc method createBackup.

@Override
public OperationFuture<Backup, CreateBackupMetadata> createBackup(final com.google.cloud.spanner.Backup backupInfo) throws SpannerException {
    final String instanceName = backupInfo.getInstanceId().getName();
    final String databaseName = backupInfo.getDatabase().getName();
    final String backupId = backupInfo.getId().getBackup();
    final Backup.Builder backupBuilder = com.google.spanner.admin.database.v1.Backup.newBuilder().setDatabase(databaseName).setExpireTime(backupInfo.getExpireTime().toProto());
    if (backupInfo.getVersionTime() != null) {
        backupBuilder.setVersionTime(backupInfo.getVersionTime().toProto());
    }
    final Backup backup = backupBuilder.build();
    final CreateBackupRequest.Builder requestBuilder = CreateBackupRequest.newBuilder().setParent(instanceName).setBackupId(backupId).setBackup(backup);
    if (backupInfo.getEncryptionConfig() != null) {
        requestBuilder.setEncryptionConfig(EncryptionConfigProtoMapper.createBackupEncryptionConfig(backupInfo.getEncryptionConfig()));
    }
    final CreateBackupRequest request = requestBuilder.build();
    final OperationFutureCallable<CreateBackupRequest, Backup, CreateBackupMetadata> callable = new OperationFutureCallable<>(databaseAdminStub.createBackupOperationCallable(), request, DatabaseAdminGrpc.getCreateBackupMethod(), instanceName, nextPageToken -> listBackupOperations(instanceName, 0, String.format("(metadata.@type:type.googleapis.com/%s) AND (metadata.name:%s)", CreateBackupMetadata.getDescriptor().getFullName(), String.format("%s/backups/%s", instanceName, backupId)), nextPageToken), input -> {
        try {
            return input.getMetadata().unpack(CreateBackupMetadata.class).getProgress().getStartTime();
        } catch (InvalidProtocolBufferException e) {
            return null;
        }
    });
    return RetryHelper.runWithRetries(callable, databaseAdminStubSettings.createBackupOperationSettings().getInitialCallSettings().getRetrySettings(), new OperationFutureRetryAlgorithm<>(), NanoClock.getDefaultClock());
}
Also used : CreateBackupRequest(com.google.spanner.admin.database.v1.CreateBackupRequest) Backup(com.google.spanner.admin.database.v1.Backup) CreateBackupMetadata(com.google.spanner.admin.database.v1.CreateBackupMetadata) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException)

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