Search in sources :

Example 1 with InstanceConfig

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

the class InstanceAdminGaxTest method getInstanceConfigTest.

@Test
public void getInstanceConfigTest() {
    Exception exception = setupException();
    for (int i = 0; i < 2; i++) {
        InstanceConfigName name2 = InstanceConfigName.of(PROJECT, "INSTANCE_CONFIG");
        String displayName = "displayName1615086568";
        List<String> leaderOptions = Arrays.asList("leader option 1", "leader option 2");
        InstanceConfig expectedResponse = InstanceConfig.newBuilder().setName(name2.toString()).setDisplayName(displayName).addAllLeaderOptions(leaderOptions).build();
        if (exceptionAtCall == 0) {
            mockInstanceAdmin.addException(exception);
        }
        mockInstanceAdmin.addResponse(expectedResponse);
        if (exceptionAtCall == 1) {
            mockInstanceAdmin.addException(exception);
        }
        InstanceConfigName name = InstanceConfigName.of(PROJECT, "INSTANCE_CONFIG");
        com.google.cloud.spanner.InstanceConfig actualResponse = client.getInstanceConfig(name.toString());
        Assert.assertEquals(displayName, actualResponse.getDisplayName());
        Assert.assertEquals(leaderOptions, actualResponse.getLeaderOptions());
        List<AbstractMessage> actualRequests = mockInstanceAdmin.getRequests();
        Assert.assertEquals(i + 1, actualRequests.size());
    }
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) InstanceConfig(com.google.spanner.admin.instance.v1.InstanceConfig) 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)

Example 2 with InstanceConfig

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

the class InstanceAdminClientTest method getInstanceConfigTest.

@Test
public void getInstanceConfigTest() 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);
    InstanceConfigName name = InstanceConfigName.of("[PROJECT]", "[INSTANCE_CONFIG]");
    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.toString(), 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) InstanceConfigName(com.google.spanner.admin.instance.v1.InstanceConfigName) Test(org.junit.Test)

Example 3 with InstanceConfig

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

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

the class GapicSpannerRpc method getInstanceConfig.

@Override
public InstanceConfig getInstanceConfig(String instanceConfigName) throws SpannerException {
    GetInstanceConfigRequest request = GetInstanceConfigRequest.newBuilder().setName(instanceConfigName).build();
    GrpcCallContext context = newCallContext(null, projectName, request, InstanceAdminGrpc.getGetInstanceConfigMethod());
    return get(instanceAdminStub.getInstanceConfigCallable().futureCall(request, context));
}
Also used : GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) GetInstanceConfigRequest(com.google.spanner.admin.instance.v1.GetInstanceConfigRequest)

Example 5 with InstanceConfig

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

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