Search in sources :

Example 6 with CreateBackupRequest

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);
    }
}
Also used : CreateBackupRequest(com.google.spanner.admin.database.v1.CreateBackupRequest) CancelledException(com.google.api.gax.rpc.CancelledException) Backup(com.google.spanner.admin.database.v1.Backup) CreateBackupMetadata(com.google.spanner.admin.database.v1.CreateBackupMetadata) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with CreateBackupRequest

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()));
}
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)

Aggregations

Operation (com.google.longrunning.Operation)5 AbstractMessage (com.google.protobuf.AbstractMessage)4 ByteString (com.google.protobuf.ByteString)4 Backup (com.google.spanner.admin.database.v1.Backup)4 CreateBackupRequest (com.google.spanner.admin.database.v1.CreateBackupRequest)4 Test (org.junit.Test)4 CreateBackupMetadata (com.google.spanner.admin.database.v1.CreateBackupMetadata)3 Backup (com.google.bigtable.admin.v2.Backup)2 CreateBackupRequest (com.google.bigtable.admin.v2.CreateBackupRequest)2 ArrayList (java.util.ArrayList)2 CancelledException (com.google.api.gax.rpc.CancelledException)1 ClusterName (com.google.bigtable.admin.v2.ClusterName)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 InstanceName (com.google.spanner.admin.database.v1.InstanceName)1 ExecutionException (java.util.concurrent.ExecutionException)1