Search in sources :

Example 1 with GetBackupRequest

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

the class BigtableTableAdminClientTest 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 2 with GetBackupRequest

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

the class BaseBigtableTableAdminClientTest method getBackupTest2.

@Test
public void getBackupTest2() 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);
    String name = "name3373707";
    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, 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) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 3 with GetBackupRequest

use of com.google.spanner.admin.database.v1.GetBackupRequest 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 4 with GetBackupRequest

use of com.google.spanner.admin.database.v1.GetBackupRequest 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 5 with GetBackupRequest

use of com.google.spanner.admin.database.v1.GetBackupRequest 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)

Aggregations

Test (org.junit.Test)5 AbstractMessage (com.google.protobuf.AbstractMessage)4 GetBackupRequest (com.google.bigtable.admin.v2.GetBackupRequest)3 GetBackupRequest (com.google.spanner.admin.database.v1.GetBackupRequest)3 Backup (com.google.bigtable.admin.v2.Backup)2 ByteString (com.google.protobuf.ByteString)2 Backup (com.google.spanner.admin.database.v1.Backup)2 ArrayList (java.util.ArrayList)2 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)1 State (com.google.bigtable.admin.v2.Backup.State)1 BackupName (com.google.bigtable.admin.v2.BackupName)1 Backup (com.google.cloud.bigtable.admin.v2.models.Backup)1 Timestamp (com.google.protobuf.Timestamp)1 BackupName (com.google.spanner.admin.database.v1.BackupName)1