Search in sources :

Example 11 with InstanceConfig

use of com.google.spanner.admin.instance.v1.InstanceConfig 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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ProjectName(com.google.spanner.admin.instance.v1.ProjectName) ArrayList(java.util.ArrayList) ListInstanceConfigsResponse(com.google.spanner.admin.instance.v1.ListInstanceConfigsResponse) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) InstanceConfig(com.google.spanner.admin.instance.v1.InstanceConfig) ListInstanceConfigsRequest(com.google.spanner.admin.instance.v1.ListInstanceConfigsRequest) Test(org.junit.Test)

Example 12 with InstanceConfig

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

the class InstanceAdminClientTest method getInstanceConfigTest2.

@Test
public void getInstanceConfigTest2() throws Exception {
    InstanceConfig expectedResponse = InstanceConfig.newBuilder().setName(InstanceConfigName.of("[PROJECT]", "[INSTANCE_CONFIG]").toString()).setDisplayName("displayName1714148973").addAllReplicas(new ArrayList<ReplicaInfo>()).addAllLeaderOptions(new ArrayList<String>()).build();
    mockInstanceAdmin.addResponse(expectedResponse);
    String name = "name3373707";
    InstanceConfig actualResponse = client.getInstanceConfig(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetInstanceConfigRequest actualRequest = ((GetInstanceConfigRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) InstanceConfig(com.google.spanner.admin.instance.v1.InstanceConfig) ReplicaInfo(com.google.spanner.admin.instance.v1.ReplicaInfo) GetInstanceConfigRequest(com.google.spanner.admin.instance.v1.GetInstanceConfigRequest) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 13 with InstanceConfig

use of com.google.spanner.admin.instance.v1.InstanceConfig 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

AbstractMessage (com.google.protobuf.AbstractMessage)6 InstanceConfig (com.google.spanner.admin.instance.v1.InstanceConfig)6 Test (org.junit.Test)6 ListInstanceConfigsRequest (com.google.spanner.admin.instance.v1.ListInstanceConfigsRequest)5 ListInstanceConfigsResponse (com.google.spanner.admin.instance.v1.ListInstanceConfigsResponse)5 Instance (com.google.cloud.spanner.Instance)4 InstanceConfig (com.google.cloud.spanner.InstanceConfig)4 CreateInstanceMetadata (com.google.spanner.admin.instance.v1.CreateInstanceMetadata)4 GetInstanceConfigRequest (com.google.spanner.admin.instance.v1.GetInstanceConfigRequest)3 StatusRuntimeException (io.grpc.StatusRuntimeException)3 ArrayList (java.util.ArrayList)3 ExecutionException (java.util.concurrent.ExecutionException)3 ExpectedException (org.junit.rules.ExpectedException)3 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)2 InstanceAdminClient (com.google.cloud.spanner.InstanceAdminClient)2 InstanceConfigId (com.google.cloud.spanner.InstanceConfigId)2 InstanceInfo (com.google.cloud.spanner.InstanceInfo)2 ListInstanceConfigsPagedResponse (com.google.cloud.spanner.admin.instance.v1.InstanceAdminClient.ListInstanceConfigsPagedResponse)2 ByteString (com.google.protobuf.ByteString)2 InstanceConfigName (com.google.spanner.admin.instance.v1.InstanceConfigName)2