Search in sources :

Example 31 with InstanceName

use of com.google.cloud.redis.v1beta1.InstanceName in project java-bigtable by googleapis.

the class BaseBigtableInstanceAdminClientTest method listClustersExceptionTest.

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

Example 32 with InstanceName

use of com.google.cloud.redis.v1beta1.InstanceName in project java-bigtable by googleapis.

the class BaseBigtableTableAdminClientTest method createTableTest.

@Test
public void createTableTest() throws Exception {
    Table expectedResponse = Table.newBuilder().setName(TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]").toString()).putAllClusterStates(new HashMap<String, Table.ClusterState>()).putAllColumnFamilies(new HashMap<String, ColumnFamily>()).setRestoreInfo(RestoreInfo.newBuilder().build()).build();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
    String tableId = "tableId-1552905847";
    Table table = Table.newBuilder().build();
    Table actualResponse = client.createTable(parent, tableId, table);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateTableRequest actualRequest = ((CreateTableRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(tableId, actualRequest.getTableId());
    Assert.assertEquals(table, actualRequest.getTable());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : InstanceName(com.google.bigtable.admin.v2.InstanceName) Table(com.google.bigtable.admin.v2.Table) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) CreateTableRequest(com.google.bigtable.admin.v2.CreateTableRequest) ColumnFamily(com.google.bigtable.admin.v2.ColumnFamily) Test(org.junit.Test)

Example 33 with InstanceName

use of com.google.cloud.redis.v1beta1.InstanceName in project java-bigtable by googleapis.

the class BaseBigtableTableAdminClientTest method createTableFromSnapshotTest2.

@Test
public void createTableFromSnapshotTest2() throws Exception {
    Table expectedResponse = Table.newBuilder().setName(TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]").toString()).putAllClusterStates(new HashMap<String, Table.ClusterState>()).putAllColumnFamilies(new HashMap<String, ColumnFamily>()).setRestoreInfo(RestoreInfo.newBuilder().build()).build();
    Operation resultOperation = Operation.newBuilder().setName("createTableFromSnapshotTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockBigtableTableAdmin.addResponse(resultOperation);
    InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
    String tableId = "tableId-1552905847";
    String sourceSnapshot = "sourceSnapshot-1078634753";
    Table actualResponse = client.createTableFromSnapshotAsync(parent, tableId, sourceSnapshot).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateTableFromSnapshotRequest actualRequest = ((CreateTableFromSnapshotRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(tableId, actualRequest.getTableId());
    Assert.assertEquals(sourceSnapshot, actualRequest.getSourceSnapshot());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : InstanceName(com.google.bigtable.admin.v2.InstanceName) Table(com.google.bigtable.admin.v2.Table) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) CreateTableFromSnapshotRequest(com.google.bigtable.admin.v2.CreateTableFromSnapshotRequest) ByteString(com.google.protobuf.ByteString) Operation(com.google.longrunning.Operation) ColumnFamily(com.google.bigtable.admin.v2.ColumnFamily) Test(org.junit.Test)

Example 34 with InstanceName

use of com.google.cloud.redis.v1beta1.InstanceName in project java-spanner by googleapis.

the class DatabaseAdminGaxTest method listDatabasesTest.

@Test
public void listDatabasesTest() {
    Exception exception = setupException();
    String nextPageToken = "token%d";
    List<com.google.spanner.admin.database.v1.Database> databases = new ArrayList<>(2);
    for (int i = 0; i < 2; i++) {
        databases.add(com.google.spanner.admin.database.v1.Database.newBuilder().setName(String.format("projects/%s/instances/%s/databases/test%d", PROJECT, INSTANCE, i)).build());
    }
    if (exceptionAtCall == 0) {
        mockDatabaseAdmin.addException(exception);
    }
    for (int i = 0; i < 2; i++) {
        ListDatabasesResponse.Builder builder = ListDatabasesResponse.newBuilder().addAllDatabases(Collections.singletonList(databases.get(i)));
        if (i < (databases.size() - 1)) {
            builder.setNextPageToken(String.format(nextPageToken, i));
        }
        if (exceptionAtCall == (i + 1)) {
            mockDatabaseAdmin.addException(exception);
        }
        mockDatabaseAdmin.addResponse(builder.build());
    }
    InstanceName parent = InstanceName.of(PROJECT, INSTANCE);
    Page<Database> pagedListResponse = client.listDatabases(INSTANCE);
    List<Database> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(2, resources.size());
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(2, actualRequests.size());
    ListDatabasesRequest actualRequest = (ListDatabasesRequest) actualRequests.get(0);
    Assert.assertEquals(parent, InstanceName.parse(actualRequest.getParent()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) InstanceName(com.google.spanner.admin.instance.v1.InstanceName) ListDatabasesResponse(com.google.spanner.admin.database.v1.ListDatabasesResponse) ListDatabasesRequest(com.google.spanner.admin.database.v1.ListDatabasesRequest) Test(org.junit.Test)

Example 35 with InstanceName

use of com.google.cloud.redis.v1beta1.InstanceName in project java-spanner by googleapis.

the class InstanceAdminGaxTest method getInstanceTest.

@Test
public void getInstanceTest() {
    Exception exception = setupException();
    InstanceName name2 = InstanceName.of(PROJECT, "INSTANCE");
    String displayName = "displayName1615086568";
    InstanceConfigName config = InstanceConfigName.of(PROJECT, "INSTANCE_CONFIG");
    com.google.spanner.admin.instance.v1.Instance expectedResponse = com.google.spanner.admin.instance.v1.Instance.newBuilder().setName(name2.toString()).setConfig(config.toString()).setDisplayName(displayName).setNodeCount(3).build();
    if (exceptionAtCall == 0) {
        mockInstanceAdmin.addException(exception);
    }
    mockInstanceAdmin.addResponse(expectedResponse);
    if (exceptionAtCall == 1) {
        mockInstanceAdmin.addException(exception);
    }
    mockInstanceAdmin.addResponse(expectedResponse);
    InstanceName name = InstanceName.of(PROJECT, "INSTANCE");
    for (int i = 0; i < 2; i++) {
        Instance actualResponse = client.getInstance(name.toString());
        Assert.assertEquals(displayName, actualResponse.getDisplayName());
    }
    List<AbstractMessage> actualRequests = mockInstanceAdmin.getRequests();
    Assert.assertEquals(2, actualRequests.size());
}
Also used : InstanceName(com.google.spanner.admin.instance.v1.InstanceName) AbstractMessage(com.google.protobuf.AbstractMessage) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) InstanceConfigName(com.google.spanner.admin.instance.v1.InstanceConfigName) 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 InstanceName (com.google.cloud.redis.v1beta1.InstanceName)6 Table (com.google.bigtable.admin.v2.Table)5 Instance (com.google.cloud.redis.v1beta1.Instance)4 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