/** * Adds an arbitrary label to the instance. * * <p>Labels are key-value pairs that you can use to group related instances and store metadata * about an instance. * * @see <a href="https://cloud.google.com/bigtable/docs/creating-managing-labels">For more * details</a> */ @SuppressWarnings("WeakerAccess") public CreateInstanceRequest addLabel(@Nonnull String key, @Nonnull String value) { Preconditions.checkNotNull(key, "Key can't be null"); Preconditions.checkNotNull(value, "Value can't be null"); builder.getInstanceBuilder().putLabels(key, value); return this; }
@Test public void testFromProto() { com.google.bigtable.admin.v2.Instance proto = com.google.bigtable.admin.v2.Instance.newBuilder() .setName("projects/my-project/instances/my-instance") .setDisplayName("my display name") .setType(com.google.bigtable.admin.v2.Instance.Type.PRODUCTION) .setState(com.google.bigtable.admin.v2.Instance.State.READY) .putLabels("label1", "value1") .putLabels("label2", "value2") .build(); Instance result = Instance.fromProto(proto); assertThat(result.getId()).isEqualTo("my-instance"); assertThat(result.getDisplayName()).isEqualTo("my display name"); assertThat(result.getType()).isEqualTo(Instance.Type.PRODUCTION); assertThat(result.getState()).isEqualTo(Instance.State.READY); assertThat(result.getLabels()) .containsExactly( "label1", "value1", "label2", "value2"); }
@Test public void testLabels() { UpdateInstanceRequest input = UpdateInstanceRequest.of("my-instance") .setAllLabels( ImmutableMap.of( "label1", "value1", "label2", "value2")); PartialUpdateInstanceRequest actual = input.toProto("my-project"); PartialUpdateInstanceRequest expected = PartialUpdateInstanceRequest.newBuilder() .setUpdateMask(FieldMask.newBuilder().addPaths("labels")) .setInstance( Instance.newBuilder() .setName("projects/my-project/instances/my-instance") .putLabels("label1", "value1") .putLabels("label2", "value2")) .build(); assertThat(actual).isEqualTo(expected); }
/** * Adds an arbitrary label to the instance. * * <p>Labels are key-value pairs that you can use to group related instances and store metadata * about an instance. * * @see <a href="https://cloud.google.com/bigtable/docs/creating-managing-labels">For more * details</a> */ @SuppressWarnings("WeakerAccess") public CreateInstanceRequest addLabel(@Nonnull String key, @Nonnull String value) { Preconditions.checkNotNull(key, "Key can't be null"); Preconditions.checkNotNull(value, "Value can't be null"); builder.getInstanceBuilder().putLabels(key, value); return this; }
@Test public void testRequiresName() { com.google.bigtable.admin.v2.Instance proto = com.google.bigtable.admin.v2.Instance.newBuilder() .setDisplayName("my display name") .setType(com.google.bigtable.admin.v2.Instance.Type.PRODUCTION) .setState(com.google.bigtable.admin.v2.Instance.State.READY) .putLabels("label1", "value1") .putLabels("label2", "value2") .build(); Exception actualException = null; try { Instance.fromProto(proto); } catch (Exception e) { actualException = e; } assertThat(actualException).isInstanceOf(IllegalArgumentException.class); }