Search in sources :

Example 1 with ListInstanceConfigsResponse

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

the class InstanceAdminClientTest method listInstanceConfigsTest.

@Test
public void listInstanceConfigsTest() throws Exception {
    InstanceConfig responsesElement = InstanceConfig.newBuilder().build();
    ListInstanceConfigsResponse expectedResponse = ListInstanceConfigsResponse.newBuilder().setNextPageToken("").addAllInstanceConfigs(Arrays.asList(responsesElement)).build();
    mockInstanceAdmin.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    ListInstanceConfigsPagedResponse pagedListResponse = client.listInstanceConfigs(parent);
    List<InstanceConfig> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getInstanceConfigsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListInstanceConfigsRequest actualRequest = ((ListInstanceConfigsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) InstanceConfig(com.google.spanner.admin.instance.v1.InstanceConfig) ProjectName(com.google.spanner.admin.instance.v1.ProjectName) ListInstanceConfigsPagedResponse(com.google.cloud.spanner.admin.instance.v1.InstanceAdminClient.ListInstanceConfigsPagedResponse) ListInstanceConfigsRequest(com.google.spanner.admin.instance.v1.ListInstanceConfigsRequest) ListInstanceConfigsResponse(com.google.spanner.admin.instance.v1.ListInstanceConfigsResponse) Test(org.junit.Test)

Example 2 with ListInstanceConfigsResponse

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

the class GapicSpannerRpc method listInstanceConfigs.

@Override
public Paginated<InstanceConfig> listInstanceConfigs(int pageSize, @Nullable String pageToken) throws SpannerException {
    ListInstanceConfigsRequest.Builder requestBuilder = ListInstanceConfigsRequest.newBuilder().setParent(projectName).setPageSize(pageSize);
    if (pageToken != null) {
        requestBuilder.setPageToken(pageToken);
    }
    ListInstanceConfigsRequest request = requestBuilder.build();
    GrpcCallContext context = newCallContext(null, projectName, request, InstanceAdminGrpc.getListInstanceConfigsMethod());
    ListInstanceConfigsResponse response = get(instanceAdminStub.listInstanceConfigsCallable().futureCall(request, context));
    return new Paginated<>(response.getInstanceConfigsList(), response.getNextPageToken());
}
Also used : GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) ListInstanceConfigsRequest(com.google.spanner.admin.instance.v1.ListInstanceConfigsRequest) ListInstanceConfigsResponse(com.google.spanner.admin.instance.v1.ListInstanceConfigsResponse)

Example 3 with ListInstanceConfigsResponse

use of com.google.spanner.admin.instance.v1.ListInstanceConfigsResponse in project google-cloud-java by GoogleCloudPlatform.

the class GrpcSpannerRpc method listInstanceConfigs.

@Override
public Paginated<InstanceConfig> listInstanceConfigs(int pageSize, @Nullable String pageToken) throws SpannerException {
    ListInstanceConfigsRequest.Builder request = ListInstanceConfigsRequest.newBuilder().setParent(projectName()).setPageSize(0);
    if (pageToken != null) {
        request.setPageToken(pageToken);
    }
    ListInstanceConfigsResponse response = get(doUnaryCall(InstanceAdminGrpc.METHOD_LIST_INSTANCE_CONFIGS, request.build(), projectName(), null));
    return new Paginated<>(response.getInstanceConfigsList(), response.getNextPageToken());
}
Also used : ListInstanceConfigsRequest(com.google.spanner.admin.instance.v1.ListInstanceConfigsRequest) ListInstanceConfigsResponse(com.google.spanner.admin.instance.v1.ListInstanceConfigsResponse)

Example 4 with ListInstanceConfigsResponse

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

the class InstanceAdminClientTest method listInstanceConfigsTest2.

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

Aggregations

ListInstanceConfigsRequest (com.google.spanner.admin.instance.v1.ListInstanceConfigsRequest)4 ListInstanceConfigsResponse (com.google.spanner.admin.instance.v1.ListInstanceConfigsResponse)4 ListInstanceConfigsPagedResponse (com.google.cloud.spanner.admin.instance.v1.InstanceAdminClient.ListInstanceConfigsPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 InstanceConfig (com.google.spanner.admin.instance.v1.InstanceConfig)2 Test (org.junit.Test)2 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)1 ByteString (com.google.protobuf.ByteString)1 ProjectName (com.google.spanner.admin.instance.v1.ProjectName)1