Search in sources :

Example 21 with Instance

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

the class BaseBigtableInstanceAdminClientTest method updateInstanceExceptionTest.

@Test
public void updateInstanceExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableInstanceAdmin.addException(exception);
    try {
        Instance request = Instance.newBuilder().setName(InstanceName.of("[PROJECT]", "[INSTANCE]").toString()).setDisplayName("displayName1714148973").putAllLabels(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).build();
        client.updateInstance(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) Instance(com.google.bigtable.admin.v2.Instance) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 22 with Instance

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

the class BaseBigtableInstanceAdminClientTest method updateInstanceTest.

@Test
public void updateInstanceTest() throws Exception {
    Instance expectedResponse = Instance.newBuilder().setName(InstanceName.of("[PROJECT]", "[INSTANCE]").toString()).setDisplayName("displayName1714148973").putAllLabels(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).build();
    mockBigtableInstanceAdmin.addResponse(expectedResponse);
    Instance request = Instance.newBuilder().setName(InstanceName.of("[PROJECT]", "[INSTANCE]").toString()).setDisplayName("displayName1714148973").putAllLabels(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).build();
    Instance actualResponse = client.updateInstance(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    Instance actualRequest = ((Instance) actualRequests.get(0));
    Assert.assertEquals(request.getName(), actualRequest.getName());
    Assert.assertEquals(request.getDisplayName(), actualRequest.getDisplayName());
    Assert.assertEquals(request.getState(), actualRequest.getState());
    Assert.assertEquals(request.getType(), actualRequest.getType());
    Assert.assertEquals(request.getLabelsMap(), actualRequest.getLabelsMap());
    Assert.assertEquals(request.getCreateTime(), actualRequest.getCreateTime());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Instance(com.google.bigtable.admin.v2.Instance) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 23 with Instance

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

the class BaseBigtableInstanceAdminClientTest method createInstanceTest.

@Test
public void createInstanceTest() throws Exception {
    Instance expectedResponse = Instance.newBuilder().setName(InstanceName.of("[PROJECT]", "[INSTANCE]").toString()).setDisplayName("displayName1714148973").putAllLabels(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).build();
    Operation resultOperation = Operation.newBuilder().setName("createInstanceTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockBigtableInstanceAdmin.addResponse(resultOperation);
    ProjectName parent = ProjectName.of("[PROJECT]");
    String instanceId = "instanceId902024336";
    Instance instance = Instance.newBuilder().build();
    Map<String, Cluster> clusters = new HashMap<>();
    Instance actualResponse = client.createInstanceAsync(parent, instanceId, instance, clusters).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateInstanceRequest actualRequest = ((CreateInstanceRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(instanceId, actualRequest.getInstanceId());
    Assert.assertEquals(instance, actualRequest.getInstance());
    Assert.assertEquals(clusters, actualRequest.getClustersMap());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Instance(com.google.bigtable.admin.v2.Instance) ProjectName(com.google.bigtable.admin.v2.ProjectName) HashMap(java.util.HashMap) Cluster(com.google.bigtable.admin.v2.Cluster) ByteString(com.google.protobuf.ByteString) Operation(com.google.longrunning.Operation) CreateInstanceRequest(com.google.bigtable.admin.v2.CreateInstanceRequest) Test(org.junit.Test)

Example 24 with Instance

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

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

Aggregations

Test (org.junit.Test)50 AbstractMessage (com.google.protobuf.AbstractMessage)19 ByteString (com.google.protobuf.ByteString)17 ExecutionException (java.util.concurrent.ExecutionException)16 Instance (com.google.cloud.spanner.Instance)15 StatusRuntimeException (io.grpc.StatusRuntimeException)14 Instance (com.google.cloud.compute.v1.Instance)11 InstancesClient (com.google.cloud.compute.v1.InstancesClient)11 CreateInstanceMetadata (com.google.spanner.admin.instance.v1.CreateInstanceMetadata)11 Instance (com.google.spanner.admin.instance.v1.Instance)11 Instance (com.google.bigtable.admin.v2.Instance)10 InstanceAdminClient (com.google.cloud.spanner.InstanceAdminClient)10 InstanceInfo (com.google.cloud.spanner.InstanceInfo)10 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)9 Instance (com.google.cloud.notebooks.v1beta1.Instance)9 Spanner (com.google.cloud.spanner.Spanner)8 ArrayList (java.util.ArrayList)8 Operation (com.google.cloud.compute.v1.Operation)7 FieldMask (com.google.protobuf.FieldMask)7 InstanceName (com.google.spanner.admin.instance.v1.InstanceName)7