@java.lang.Override public Builder newBuilderForType() { return newBuilder(); }
/** * * * <pre> * The instance being created. * </pre> * * <code>.google.spanner.admin.instance.v1.Instance instance = 1;</code> */ public Builder mergeInstance(com.google.spanner.admin.instance.v1.Instance value) { if (instanceBuilder_ == null) { if (instance_ != null) { instance_ = com.google.spanner.admin.instance.v1.Instance.newBuilder(instance_) .mergeFrom(value) .buildPartial(); } else { instance_ = value; } onChanged(); } else { instanceBuilder_.mergeFrom(value); } return this; } /**
/** * * * <pre> * Required. The instance to create. The name may be omitted, but if * specified must be `<parent>/instances/<instance_id>`. * </pre> * * <code>.google.spanner.admin.instance.v1.Instance instance = 3;</code> */ public Builder mergeInstance(com.google.spanner.admin.instance.v1.Instance value) { if (instanceBuilder_ == null) { if (instance_ != null) { instance_ = com.google.spanner.admin.instance.v1.Instance.newBuilder(instance_) .mergeFrom(value) .buildPartial(); } else { instance_ = value; } onChanged(); } else { instanceBuilder_.mergeFrom(value); } return this; } /**
/** * * * <pre> * Required. The instance to update, which must always include the instance * name. Otherwise, only fields mentioned in [][google.spanner.admin.instance.v1.UpdateInstanceRequest.field_mask] need be included. * </pre> * * <code>.google.spanner.admin.instance.v1.Instance instance = 1;</code> */ public Builder mergeInstance(com.google.spanner.admin.instance.v1.Instance value) { if (instanceBuilder_ == null) { if (instance_ != null) { instance_ = com.google.spanner.admin.instance.v1.Instance.newBuilder(instance_) .mergeFrom(value) .buildPartial(); } else { instance_ = value; } onChanged(); } else { instanceBuilder_.mergeFrom(value); } return this; } /**
/** * * * <pre> * The desired end state of the update. * </pre> * * <code>.google.spanner.admin.instance.v1.Instance instance = 1;</code> */ public Builder mergeInstance(com.google.spanner.admin.instance.v1.Instance value) { if (instanceBuilder_ == null) { if (instance_ != null) { instance_ = com.google.spanner.admin.instance.v1.Instance.newBuilder(instance_) .mergeFrom(value) .buildPartial(); } else { instance_ = value; } onChanged(); } else { instanceBuilder_.mergeFrom(value); } return this; } /**
private com.google.spanner.admin.instance.v1.Instance getInstanceProto() { return com.google.spanner.admin.instance.v1.Instance.newBuilder() .setConfig(CONFIG_NAME) .setName(INSTANCE_NAME) .setNodeCount(1) .build(); }
private com.google.spanner.admin.instance.v1.Instance getAnotherInstanceProto() { return com.google.spanner.admin.instance.v1.Instance.newBuilder() .setConfig(CONFIG_NAME) .setName(INSTANCE_NAME2) .setNodeCount(1) .build(); }
@Test @SuppressWarnings("all") public void updateInstanceExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockInstanceAdmin.addException(exception); try { Instance instance = Instance.newBuilder().build(); FieldMask fieldMask = FieldMask.newBuilder().build(); client.updateInstanceAsync(instance, fieldMask).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } }
@Test @SuppressWarnings("all") public void createInstanceExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockInstanceAdmin.addException(exception); try { ProjectName parent = ProjectName.of("[PROJECT]"); InstanceName instanceId = InstanceName.of("[PROJECT]", "[INSTANCE]"); Instance instance = Instance.newBuilder().build(); client.createInstanceAsync(parent, instanceId, instance).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } }
com.google.spanner.admin.instance.v1.Instance toProto() { com.google.spanner.admin.instance.v1.Instance.Builder builder = com.google.spanner.admin.instance.v1.Instance.newBuilder() .setName(getId().getName()) .setNodeCount(getNodeCount()) .putAllLabels(getLabels()); if (getDisplayName() != null) { builder.setDisplayName(getDisplayName()); } if (getInstanceConfigId() != null) { builder.setConfig(getInstanceConfigId().getName()); } return builder.build(); }
@Test @SuppressWarnings("all") public void listInstancesTest() { String nextPageToken = ""; Instance instancesElement = Instance.newBuilder().build(); List<Instance> instances = Arrays.asList(instancesElement); ListInstancesResponse expectedResponse = ListInstancesResponse.newBuilder() .setNextPageToken(nextPageToken) .addAllInstances(instances) .build(); mockInstanceAdmin.addResponse(expectedResponse); ProjectName parent = ProjectName.of("[PROJECT]"); ListInstancesPagedResponse pagedListResponse = client.listInstances(parent); List<Instance> resources = Lists.newArrayList(pagedListResponse.iterateAll()); Assert.assertEquals(1, resources.size()); Assert.assertEquals(expectedResponse.getInstancesList().get(0), resources.get(0)); List<GeneratedMessageV3> actualRequests = mockInstanceAdmin.getRequests(); Assert.assertEquals(1, actualRequests.size()); ListInstancesRequest actualRequest = (ListInstancesRequest) actualRequests.get(0); Assert.assertEquals(parent, ProjectName.parse(actualRequest.getParent())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Test public void updateInstanceMetadata() throws Exception { com.google.spanner.admin.instance.v1.Instance instance = com.google.spanner.admin.instance.v1.Instance.newBuilder() .setName(INSTANCE_NAME) .setConfig(CONFIG_NAME) .setNodeCount(2) .build(); OperationFuture<com.google.spanner.admin.instance.v1.Instance, UpdateInstanceMetadata> rawOperationFuture = OperationFutureUtil.immediateOperationFuture( "updateInstance", getInstanceProto(), UpdateInstanceMetadata.getDefaultInstance()); when(rpc.updateInstance(instance, FieldMask.newBuilder().addPaths("node_count").build())) .thenReturn(rawOperationFuture); InstanceInfo instanceInfo = InstanceInfo.newBuilder(InstanceId.of(INSTANCE_NAME)) .setInstanceConfigId(InstanceConfigId.of(CONFIG_NAME)) .setNodeCount(2) .build(); OperationFuture<Instance, UpdateInstanceMetadata> op = client.updateInstance(instanceInfo, InstanceInfo.InstanceField.NODE_COUNT); assertThat(op.isDone()).isTrue(); assertThat(op.get().getId().getName()).isEqualTo(INSTANCE_NAME); }
@Test @SuppressWarnings("all") public void getInstanceTest() { InstanceName name2 = InstanceName.of("[PROJECT]", "[INSTANCE]"); InstanceConfigName config = InstanceConfigName.of("[PROJECT]", "[INSTANCE_CONFIG]"); String displayName = "displayName1615086568"; int nodeCount = 1539922066; Instance expectedResponse = Instance.newBuilder() .setName(name2.toString()) .setConfig(config.toString()) .setDisplayName(displayName) .setNodeCount(nodeCount) .build(); mockInstanceAdmin.addResponse(expectedResponse); InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]"); Instance actualResponse = client.getInstance(name); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockInstanceAdmin.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetInstanceRequest actualRequest = (GetInstanceRequest) actualRequests.get(0); Assert.assertEquals(name, InstanceName.parse(actualRequest.getName())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
int nodeCount = 1539922066; Instance expectedResponse = Instance.newBuilder() .setName(name.toString()) .setConfig(config.toString()) mockInstanceAdmin.addResponse(resultOperation); Instance instance = Instance.newBuilder().build(); FieldMask fieldMask = FieldMask.newBuilder().build();
int nodeCount = 1539922066; Instance expectedResponse = Instance.newBuilder() .setName(name.toString()) .setConfig(config.toString()) Instance instance = Instance.newBuilder().build();
@java.lang.Override public Builder newBuilderForType() { return newBuilder(); }
/** * * * <pre> * Required. The instance to update, which must always include the instance * name. Otherwise, only fields mentioned in [][google.spanner.admin.instance.v1.UpdateInstanceRequest.field_mask] need be included. * </pre> * * <code>.google.spanner.admin.instance.v1.Instance instance = 1;</code> */ public Builder mergeInstance(com.google.spanner.admin.instance.v1.Instance value) { if (instanceBuilder_ == null) { if (instance_ != null) { instance_ = com.google.spanner.admin.instance.v1.Instance.newBuilder(instance_) .mergeFrom(value) .buildPartial(); } else { instance_ = value; } onChanged(); } else { instanceBuilder_.mergeFrom(value); } return this; } /**
/** * * * <pre> * Required. The instance to create. The name may be omitted, but if * specified must be `<parent>/instances/<instance_id>`. * </pre> * * <code>.google.spanner.admin.instance.v1.Instance instance = 3;</code> */ public Builder mergeInstance(com.google.spanner.admin.instance.v1.Instance value) { if (instanceBuilder_ == null) { if (instance_ != null) { instance_ = com.google.spanner.admin.instance.v1.Instance.newBuilder(instance_) .mergeFrom(value) .buildPartial(); } else { instance_ = value; } onChanged(); } else { instanceBuilder_.mergeFrom(value); } return this; } /**
/** * * * <pre> * The instance being created. * </pre> * * <code>.google.spanner.admin.instance.v1.Instance instance = 1;</code> */ public Builder mergeInstance(com.google.spanner.admin.instance.v1.Instance value) { if (instanceBuilder_ == null) { if (instance_ != null) { instance_ = com.google.spanner.admin.instance.v1.Instance.newBuilder(instance_) .mergeFrom(value) .buildPartial(); } else { instance_ = value; } onChanged(); } else { instanceBuilder_.mergeFrom(value); } return this; } /**
com.google.spanner.admin.instance.v1.Instance toProto() { com.google.spanner.admin.instance.v1.Instance.Builder builder = com.google.spanner.admin.instance.v1.Instance.newBuilder() .setName(getId().getName()) .setNodeCount(getNodeCount()) .putAllLabels(getLabels()); if (getDisplayName() != null) { builder.setDisplayName(getDisplayName()); } if (getInstanceConfigId() != null) { builder.setConfig(getInstanceConfigId().getName()); } return builder.build(); }