use of com.google.spanner.admin.instance.v1.ListInstanceConfigsRequest 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()));
}
use of com.google.spanner.admin.instance.v1.ListInstanceConfigsRequest 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());
}
use of com.google.spanner.admin.instance.v1.ListInstanceConfigsRequest in project java-spanner by googleapis.
the class InstanceAdminGaxTest method listInstanceConfigsTest.
@Test
public void listInstanceConfigsTest() {
Exception exception = setupException();
String nextPageToken = "token%d";
List<InstanceConfig> configs = new ArrayList<>(2);
for (int i = 0; i < 2; i++) {
configs.add(InstanceConfig.newBuilder().setDisplayName(String.format("TEST%d", i)).setName(String.format("projects/%s/instanceConfigs/test%d", PROJECT, i)).build());
}
if (exceptionAtCall == 0) {
mockInstanceAdmin.addException(exception);
}
for (int i = 0; i < 2; i++) {
ListInstanceConfigsResponse.Builder builder = ListInstanceConfigsResponse.newBuilder().addAllInstanceConfigs(Collections.singletonList(configs.get(i)));
if (i < (configs.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<com.google.cloud.spanner.InstanceConfig> pagedListResponse = client.listInstanceConfigs();
List<com.google.cloud.spanner.InstanceConfig> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(2, resources.size());
List<AbstractMessage> actualRequests = mockInstanceAdmin.getRequests();
Assert.assertEquals(2, actualRequests.size());
ListInstanceConfigsRequest actualRequest = (ListInstanceConfigsRequest) actualRequests.get(0);
Assert.assertEquals(parent, ProjectName.parse(actualRequest.getParent()));
}
use of com.google.spanner.admin.instance.v1.ListInstanceConfigsRequest 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()));
}
Aggregations