use of com.google.spanner.admin.database.v1.Backup in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method updateBackupTest.
@Test
public void updateBackupTest() 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);
Backup backup = Backup.newBuilder().build();
FieldMask updateMask = FieldMask.newBuilder().build();
Backup actualResponse = client.updateBackup(backup, updateMask);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
UpdateBackupRequest actualRequest = ((UpdateBackupRequest) actualRequests.get(0));
Assert.assertEquals(backup, actualRequest.getBackup());
Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.admin.database.v1.Backup in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method createBackupTest2.
@Test
public void createBackupTest2() 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();
Operation resultOperation = Operation.newBuilder().setName("createBackupTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
mockBigtableTableAdmin.addResponse(resultOperation);
String parent = "parent-995424086";
String backupId = "backupId2121930365";
Backup backup = Backup.newBuilder().build();
Backup actualResponse = client.createBackupAsync(parent, backupId, backup).get();
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateBackupRequest actualRequest = ((CreateBackupRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertEquals(backupId, actualRequest.getBackupId());
Assert.assertEquals(backup, actualRequest.getBackup());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.admin.database.v1.Backup in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method createBackupExceptionTest.
@Test
public void createBackupExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockBigtableTableAdmin.addException(exception);
try {
ClusterName parent = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
String backupId = "backupId2121930365";
Backup backup = Backup.newBuilder().build();
client.createBackupAsync(parent, backupId, 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());
}
}
use of com.google.spanner.admin.database.v1.Backup in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method createBackupTest.
@Test
public void createBackupTest() 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();
Operation resultOperation = Operation.newBuilder().setName("createBackupTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
mockBigtableTableAdmin.addResponse(resultOperation);
ClusterName parent = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
String backupId = "backupId2121930365";
Backup backup = Backup.newBuilder().build();
Backup actualResponse = client.createBackupAsync(parent, backupId, backup).get();
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateBackupRequest actualRequest = ((CreateBackupRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(backupId, actualRequest.getBackupId());
Assert.assertEquals(backup, actualRequest.getBackup());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.admin.database.v1.Backup in project java-spanner by googleapis.
the class DatabaseAdminClientImplTest method updateBackup.
@Test
public void updateBackup() {
Timestamp t = Timestamp.ofTimeMicroseconds(TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()) + TimeUnit.HOURS.toMicros(28));
Backup backup = Backup.newBuilder().setName(BK_NAME).setExpireTime(t.toProto()).build();
when(rpc.updateBackup(backup, FieldMask.newBuilder().addPaths("expire_time").build())).thenReturn(Backup.newBuilder().setName(BK_NAME).setDatabase(DB_NAME).setExpireTime(t.toProto()).build());
com.google.cloud.spanner.Backup updatedBackup = client.updateBackup(INSTANCE_ID, BK_ID, t);
assertThat(updatedBackup.getExpireTime()).isEqualTo(t);
}
Aggregations