Search in sources :

Example 1 with ListInstancesRequest

use of com.google.bigtable.admin.v2.ListInstancesRequest in project java-bigtable by googleapis.

the class BaseBigtableInstanceAdminClientTest method listInstancesTest.

@Test
public void listInstancesTest() throws Exception {
    ListInstancesResponse expectedResponse = ListInstancesResponse.newBuilder().addAllInstances(new ArrayList<Instance>()).addAllFailedLocations(new ArrayList<String>()).setNextPageToken("nextPageToken-1386094857").build();
    mockBigtableInstanceAdmin.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    ListInstancesResponse actualResponse = client.listInstances(parent);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListInstancesRequest actualRequest = ((ListInstancesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListInstancesResponse(com.google.bigtable.admin.v2.ListInstancesResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ProjectName(com.google.bigtable.admin.v2.ProjectName) ListInstancesRequest(com.google.bigtable.admin.v2.ListInstancesRequest) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 2 with ListInstancesRequest

use of com.google.bigtable.admin.v2.ListInstancesRequest in project java-bigtable by googleapis.

the class BaseBigtableInstanceAdminClientTest method listInstancesTest2.

@Test
public void listInstancesTest2() throws Exception {
    ListInstancesResponse expectedResponse = ListInstancesResponse.newBuilder().addAllInstances(new ArrayList<Instance>()).addAllFailedLocations(new ArrayList<String>()).setNextPageToken("nextPageToken-1386094857").build();
    mockBigtableInstanceAdmin.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListInstancesResponse actualResponse = client.listInstances(parent);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListInstancesRequest actualRequest = ((ListInstancesRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListInstancesResponse(com.google.bigtable.admin.v2.ListInstancesResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ListInstancesRequest(com.google.bigtable.admin.v2.ListInstancesRequest) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 3 with ListInstancesRequest

use of com.google.bigtable.admin.v2.ListInstancesRequest in project java-spanner by googleapis.

the class GapicSpannerRpc method listInstances.

@Override
public Paginated<Instance> listInstances(int pageSize, @Nullable String pageToken, @Nullable String filter) throws SpannerException {
    ListInstancesRequest.Builder requestBuilder = ListInstancesRequest.newBuilder().setParent(projectName).setPageSize(pageSize);
    if (pageToken != null) {
        requestBuilder.setPageToken(pageToken);
    }
    if (filter != null) {
        requestBuilder.setFilter(filter);
    }
    ListInstancesRequest request = requestBuilder.build();
    GrpcCallContext context = newCallContext(null, projectName, request, InstanceAdminGrpc.getListInstancesMethod());
    ListInstancesResponse response = get(instanceAdminStub.listInstancesCallable().futureCall(request, context));
    return new Paginated<>(response.getInstancesList(), response.getNextPageToken());
}
Also used : ListInstancesResponse(com.google.spanner.admin.instance.v1.ListInstancesResponse) GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) ListInstancesRequest(com.google.spanner.admin.instance.v1.ListInstancesRequest)

Example 4 with ListInstancesRequest

use of com.google.bigtable.admin.v2.ListInstancesRequest in project java-spanner by googleapis.

the class InstanceAdminGaxTest method listInstancesTest.

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

Example 5 with ListInstancesRequest

use of com.google.bigtable.admin.v2.ListInstancesRequest in project java-spanner by googleapis.

the class InstanceAdminClientTest method listInstancesTest2.

@Test
public void listInstancesTest2() throws Exception {
    Instance responsesElement = Instance.newBuilder().build();
    ListInstancesResponse expectedResponse = ListInstancesResponse.newBuilder().setNextPageToken("").addAllInstances(Arrays.asList(responsesElement)).build();
    mockInstanceAdmin.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListInstancesPagedResponse pagedListResponse = client.listInstances(parent);
    List<Instance> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getInstancesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListInstancesRequest actualRequest = ((ListInstancesRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListInstancesResponse(com.google.spanner.admin.instance.v1.ListInstancesResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Instance(com.google.spanner.admin.instance.v1.Instance) ListInstancesRequest(com.google.spanner.admin.instance.v1.ListInstancesRequest) ListInstancesPagedResponse(com.google.cloud.spanner.admin.instance.v1.InstanceAdminClient.ListInstancesPagedResponse) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 AbstractMessage (com.google.protobuf.AbstractMessage)5 ListInstancesRequest (com.google.spanner.admin.instance.v1.ListInstancesRequest)4 ListInstancesResponse (com.google.spanner.admin.instance.v1.ListInstancesResponse)4 ByteString (com.google.protobuf.ByteString)3 ArrayList (java.util.ArrayList)3 ListInstancesRequest (com.google.bigtable.admin.v2.ListInstancesRequest)2 ListInstancesResponse (com.google.bigtable.admin.v2.ListInstancesResponse)2 ListInstancesPagedResponse (com.google.cloud.spanner.admin.instance.v1.InstanceAdminClient.ListInstancesPagedResponse)2 Instance (com.google.spanner.admin.instance.v1.Instance)2 ProjectName (com.google.spanner.admin.instance.v1.ProjectName)2 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)1 ProjectName (com.google.bigtable.admin.v2.ProjectName)1 Instance (com.google.cloud.notebooks.v1beta1.Instance)1 ListInstancesRequest (com.google.cloud.notebooks.v1beta1.ListInstancesRequest)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExpectedException (org.junit.rules.ExpectedException)1