Search in sources :

Example 11 with InstanceName

use of com.google.spanner.admin.instance.v1.InstanceName in project java-spanner by googleapis.

the class DatabaseAdminClientTest method listBackupsExceptionTest.

@Test
public void listBackupsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDatabaseAdmin.addException(exception);
    try {
        InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
        client.listBackups(parent);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InstanceName(com.google.spanner.admin.database.v1.InstanceName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 12 with InstanceName

use of com.google.spanner.admin.instance.v1.InstanceName in project java-spanner by googleapis.

the class DatabaseAdminClientTest method createBackupTest.

@Test
public void createBackupTest() 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);
    InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
    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.toString(), actualRequest.getParent());
    Assert.assertEquals(backup, actualRequest.getBackup());
    Assert.assertEquals(backupId, actualRequest.getBackupId());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : InstanceName(com.google.spanner.admin.database.v1.InstanceName) 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)

Example 13 with InstanceName

use of com.google.spanner.admin.instance.v1.InstanceName in project java-spanner by googleapis.

the class DatabaseAdminClientTest method restoreDatabaseTest2.

@Test
public void restoreDatabaseTest2() throws Exception {
    Database expectedResponse = Database.newBuilder().setName(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString()).setCreateTime(Timestamp.newBuilder().build()).setRestoreInfo(RestoreInfo.newBuilder().build()).setEncryptionConfig(EncryptionConfig.newBuilder().build()).addAllEncryptionInfo(new ArrayList<EncryptionInfo>()).setVersionRetentionPeriod("versionRetentionPeriod-629783929").setEarliestVersionTime(Timestamp.newBuilder().build()).setDefaultLeader("defaultLeader759009962").setDatabaseDialect(DatabaseDialect.forNumber(0)).build();
    Operation resultOperation = Operation.newBuilder().setName("restoreDatabaseTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockDatabaseAdmin.addResponse(resultOperation);
    InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
    String databaseId = "databaseId1688905718";
    String backup = "backup-1396673086";
    Database actualResponse = client.restoreDatabaseAsync(parent, databaseId, backup).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    RestoreDatabaseRequest actualRequest = ((RestoreDatabaseRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(databaseId, actualRequest.getDatabaseId());
    Assert.assertEquals(backup, actualRequest.getBackup());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : InstanceName(com.google.spanner.admin.database.v1.InstanceName) AbstractMessage(com.google.protobuf.AbstractMessage) RestoreDatabaseRequest(com.google.spanner.admin.database.v1.RestoreDatabaseRequest) Database(com.google.spanner.admin.database.v1.Database) ArrayList(java.util.ArrayList) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 14 with InstanceName

use of com.google.spanner.admin.instance.v1.InstanceName in project java-spanner by googleapis.

the class DatabaseAdminClientTest method listDatabaseOperationsExceptionTest.

@Test
public void listDatabaseOperationsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDatabaseAdmin.addException(exception);
    try {
        InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
        client.listDatabaseOperations(parent);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InstanceName(com.google.spanner.admin.database.v1.InstanceName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 15 with InstanceName

use of com.google.spanner.admin.instance.v1.InstanceName in project java-spanner by googleapis.

the class DatabaseAdminClientTest method createDatabaseTest.

@Test
public void createDatabaseTest() throws Exception {
    Database expectedResponse = Database.newBuilder().setName(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString()).setCreateTime(Timestamp.newBuilder().build()).setRestoreInfo(RestoreInfo.newBuilder().build()).setEncryptionConfig(EncryptionConfig.newBuilder().build()).addAllEncryptionInfo(new ArrayList<EncryptionInfo>()).setVersionRetentionPeriod("versionRetentionPeriod-629783929").setEarliestVersionTime(Timestamp.newBuilder().build()).setDefaultLeader("defaultLeader759009962").setDatabaseDialect(DatabaseDialect.forNumber(0)).build();
    Operation resultOperation = Operation.newBuilder().setName("createDatabaseTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockDatabaseAdmin.addResponse(resultOperation);
    InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
    String createStatement = "createStatement744686547";
    Database actualResponse = client.createDatabaseAsync(parent, createStatement).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateDatabaseRequest actualRequest = ((CreateDatabaseRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(createStatement, actualRequest.getCreateStatement());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : InstanceName(com.google.spanner.admin.database.v1.InstanceName) CreateDatabaseRequest(com.google.spanner.admin.database.v1.CreateDatabaseRequest) AbstractMessage(com.google.protobuf.AbstractMessage) Database(com.google.spanner.admin.database.v1.Database) ArrayList(java.util.ArrayList) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)44 AbstractMessage (com.google.protobuf.AbstractMessage)24 StatusRuntimeException (io.grpc.StatusRuntimeException)24 ByteString (com.google.protobuf.ByteString)21 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)20 InstanceName (com.google.bigtable.admin.v2.InstanceName)20 InstanceName (com.google.spanner.admin.database.v1.InstanceName)16 ExecutionException (java.util.concurrent.ExecutionException)11 Operation (com.google.longrunning.Operation)9 InstanceName (com.google.spanner.admin.instance.v1.InstanceName)9 ArrayList (java.util.ArrayList)7 Table (com.google.bigtable.admin.v2.Table)5 Database (com.google.spanner.admin.database.v1.Database)4 InstanceConfigName (com.google.spanner.admin.instance.v1.InstanceConfigName)4 IOException (java.io.IOException)4 ExpectedException (org.junit.rules.ExpectedException)4 AppProfile (com.google.bigtable.admin.v2.AppProfile)3 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)3 Backup (com.google.spanner.admin.database.v1.Backup)3 DeleteInstanceRequest (com.google.spanner.admin.instance.v1.DeleteInstanceRequest)3