Search in sources :

Example 46 with InstanceName

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

the class DatabaseAdminClientTest method createBackupExceptionTest.

@Test
public void createBackupExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDatabaseAdmin.addException(exception);
    try {
        InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
        Backup backup = Backup.newBuilder().build();
        String backupId = "backupId2121930365";
        client.createBackupAsync(parent, backup, backupId).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());
    }
}
Also used : InstanceName(com.google.spanner.admin.database.v1.InstanceName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) Backup(com.google.spanner.admin.database.v1.Backup) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 47 with InstanceName

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

the class DatabaseAdminClientTest method restoreDatabaseTest.

@Test
public void restoreDatabaseTest() 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";
    BackupName backup = BackupName.of("[PROJECT]", "[INSTANCE]", "[BACKUP]");
    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.toString(), 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) BackupName(com.google.spanner.admin.database.v1.BackupName) Test(org.junit.Test)

Example 48 with InstanceName

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

the class DatabaseAdminClientTest method listDatabasesExceptionTest.

@Test
public void listDatabasesExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDatabaseAdmin.addException(exception);
    try {
        InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
        client.listDatabases(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 49 with InstanceName

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

the class DatabaseAdminClientTest method createDatabaseExceptionTest.

@Test
public void createDatabaseExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDatabaseAdmin.addException(exception);
    try {
        InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
        String createStatement = "createStatement744686547";
        client.createDatabaseAsync(parent, createStatement).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());
    }
}
Also used : InstanceName(com.google.spanner.admin.database.v1.InstanceName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 50 with InstanceName

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

the class DatabaseAdminClientTest method listDatabasesTest.

@Test
public void listDatabasesTest() throws Exception {
    Database responsesElement = Database.newBuilder().build();
    ListDatabasesResponse expectedResponse = ListDatabasesResponse.newBuilder().setNextPageToken("").addAllDatabases(Arrays.asList(responsesElement)).build();
    mockDatabaseAdmin.addResponse(expectedResponse);
    InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
    ListDatabasesPagedResponse pagedListResponse = client.listDatabases(parent);
    List<Database> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getDatabasesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListDatabasesRequest actualRequest = ((ListDatabasesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : InstanceName(com.google.spanner.admin.database.v1.InstanceName) AbstractMessage(com.google.protobuf.AbstractMessage) ListDatabasesPagedResponse(com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabasesPagedResponse) Database(com.google.spanner.admin.database.v1.Database) ListDatabasesResponse(com.google.spanner.admin.database.v1.ListDatabasesResponse) ListDatabasesRequest(com.google.spanner.admin.database.v1.ListDatabasesRequest) 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 CloudRedisClient (com.google.cloud.redis.v1beta1.CloudRedisClient)6 Table (com.google.bigtable.admin.v2.Table)5 InstanceName (com.google.cloud.redis.v1beta1.InstanceName)5 Database (com.google.spanner.admin.database.v1.Database)5 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)4 Backup (com.google.spanner.admin.database.v1.Backup)4 InstanceConfigName (com.google.spanner.admin.instance.v1.InstanceConfigName)4 IOException (java.io.IOException)4 ExpectedException (org.junit.rules.ExpectedException)4