use of com.google.spanner.admin.database.v1.CreateBackupRequest in project java-spanner by googleapis.
the class MockDatabaseAdminServiceImplTest method createTestBackup.
private Backup createTestBackup() {
CreateBackupRequest request = CreateBackupRequest.newBuilder().setBackupId("test-bck").setBackup(Backup.newBuilder().setDatabase(TEST_DB_NAME).setExpireTime(Timestamp.newBuilder().setSeconds(System.currentTimeMillis() * 1000L + TimeUnit.MILLISECONDS.convert(7, TimeUnit.DAYS))).build()).setParent(TEST_PARENT).build();
OperationFuture<Backup, CreateBackupMetadata> op = client.createBackupOperationCallable().futureCall(request);
try {
return op.get();
} catch (ExecutionException e) {
if (e.getCause() != null && e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new CancelledException(e, FakeStatusCode.of(Code.CANCELLED), false);
}
}
use of com.google.spanner.admin.database.v1.CreateBackupRequest 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()));
}
Aggregations