From b18d5ca1915bc70807966e39939e270440a5e3ff Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Mon, 16 Sep 2024 15:27:22 -0400 Subject: [PATCH 1/9] Create of methods, add unit tests Change-Id: I7cdd6c9ce85f9132c0fa3db3aa8c70abac26f12b --- .../bigtable/admin/v2/models/AppProfile.java | 30 +++++++++++++ .../admin/v2/models/AppProfileTest.java | 44 +++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/AppProfile.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/AppProfile.java index bd7a534640..f2c1cf3cd4 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/AppProfile.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/AppProfile.java @@ -69,6 +69,10 @@ private AppProfile(@Nonnull com.google.bigtable.admin.v2.AppProfile proto) { @SuppressWarnings("WeakerAccess") public RoutingPolicy getPolicy() { if (proto.hasMultiClusterRoutingUseAny()) { + if (proto.getMultiClusterRoutingUseAny().hasRowAffinity()) { + return MultiClusterRoutingPolicy.ofWithRowAffinity( + ImmutableSet.copyOf(proto.getMultiClusterRoutingUseAny().getClusterIdsList())); + } return MultiClusterRoutingPolicy.of( ImmutableSet.copyOf(proto.getMultiClusterRoutingUseAny().getClusterIdsList())); } else if (proto.hasSingleClusterRouting()) { @@ -267,6 +271,32 @@ public static MultiClusterRoutingPolicy of(Set clusterIds) { MultiClusterRoutingUseAny.newBuilder().addAllClusterIds(clusterIds).build()); } + /** Creates a new instance of {@link MultiClusterRoutingPolicy}. */ + public static MultiClusterRoutingPolicy ofWithRowAffinity() { + return new MultiClusterRoutingPolicy(MultiClusterRoutingUseAny.newBuilder() + .setRowAffinity(MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()).build()); + } + + /** + * Creates a new instance of {@link MultiClusterRoutingPolicy} with row affinity enabled and specified cluster ids to + * route to. + */ + public static MultiClusterRoutingPolicy ofWithRowAffinity(String... clusterIds) { + return ofWithRowAffinity(ImmutableSet.copyOf(clusterIds)); + } + + /** + * Creates a new instance of {@link MultiClusterRoutingPolicy} with specified cluster ids to + * route to. + */ + public static MultiClusterRoutingPolicy ofWithRowAffinity(Set clusterIds) { + return new MultiClusterRoutingPolicy( + MultiClusterRoutingUseAny.newBuilder() + .addAllClusterIds(clusterIds) + .setRowAffinity(MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()) + .build()); + } + /* * Returns the set of clusters to route to. The order is ignored; clusters will be * tried in order of distance. If empty, all clusters are eligible. diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/AppProfileTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/AppProfileTest.java index 8215e5f8fc..2e6f0c5203 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/AppProfileTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/AppProfileTest.java @@ -291,4 +291,48 @@ public void testFromProtoWithDataBoostIsolation() { AppProfile.DataBoostIsolationReadOnlyPolicy.of( AppProfile.ComputeBillingOwner.UNSPECIFIED)); } + + @Test + public void testFromProtoWithRowAffinityNoClusterGroup() { + AppProfile profile = + AppProfile.fromProto( + com.google.bigtable.admin.v2.AppProfile.newBuilder() + .setName(AppProfileName.of("my-project", "my-instance", "my-profile").toString()) + .setDescription("my description") + .setMultiClusterRoutingUseAny( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() + .setRowAffinity(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()) + .build()) + .setEtag("my-etag") + .build()); + + assertThat(profile.getInstanceId()).isEqualTo("my-instance"); + assertThat(profile.getId()).isEqualTo("my-profile"); + assertThat(profile.getDescription()).isEqualTo("my description"); + System.out.println(profile.getPolicy()); + System.out.println(AppProfile.MultiClusterRoutingPolicy.ofWithRowAffinity()); + assertThat(profile.getPolicy()) + .isEqualTo(AppProfile.MultiClusterRoutingPolicy.ofWithRowAffinity()); + } + @Test + public void testFromProtoWithRowAffinityClusterGroup() { + AppProfile profile = + AppProfile.fromProto( + com.google.bigtable.admin.v2.AppProfile.newBuilder() + .setName(AppProfileName.of("my-project", "my-instance", "my-profile").toString()) + .setDescription("my description") + .setMultiClusterRoutingUseAny( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() + .addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2")) + .setRowAffinity(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()) + .build()) + .setEtag("my-etag") + .build()); + + assertThat(profile.getInstanceId()).isEqualTo("my-instance"); + assertThat(profile.getId()).isEqualTo("my-profile"); + assertThat(profile.getDescription()).isEqualTo("my description"); + assertThat(profile.getPolicy()) + .isEqualTo(AppProfile.MultiClusterRoutingPolicy.ofWithRowAffinity("cluster-id-1", "cluster-id-2")); + } } From e3be203d5836e14dba9d67d227ec2ee0c72d1ad2 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Mon, 16 Sep 2024 15:42:36 -0400 Subject: [PATCH 2/9] Add unit tests for BigtableInstanceAdminClientTests Change-Id: Id2cedefd90c52c249b2b15734eb1fbbcc5db2bf4 --- .../v2/BigtableInstanceAdminClientTests.java | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java index d8522db71a..bf3223a19f 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java @@ -1034,6 +1034,135 @@ public void testCreateAppProfileAddPriority() { assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse)); } + @Test + public void testCreateAppProfileAddRowAffinity() { + // Setup + Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable); + + com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = + com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder() + .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) + .setAppProfileId(APP_PROFILE_ID) + .setAppProfile( + com.google.bigtable.admin.v2.AppProfile.newBuilder() + .setDescription("my description") + .setMultiClusterRoutingUseAny( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny + .newBuilder() + .setRowAffinity(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()))) + .build(); + + com.google.bigtable.admin.v2.AppProfile expectedResponse = + com.google.bigtable.admin.v2.AppProfile.newBuilder() + .setName(APP_PROFILE_NAME) + .setDescription("my description") + .setMultiClusterRoutingUseAny( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() + .setRowAffinity(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance())) + .build(); + + Mockito.when(mockCreateAppProfileCallable.futureCall(expectedRequest)) + .thenReturn(ApiFutures.immediateFuture(expectedResponse)); + + // Execute + AppProfile actualResult = + adminClient.createAppProfile( + CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID) + .setDescription("my description") + .setRoutingPolicy(MultiClusterRoutingPolicy.ofWithRowAffinity())); + + // Verify + assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse)); + } + + @Test + public void testCreateAppProfileAddRowAffinityAddMultipleClusterIds() { + // Setup + Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable); + + com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = + com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder() + .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) + .setAppProfileId(APP_PROFILE_ID) + .setAppProfile( + com.google.bigtable.admin.v2.AppProfile.newBuilder() + .setDescription("my description") + .setMultiClusterRoutingUseAny( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny + .newBuilder() + .addClusterIds("cluster-id-1") + .addClusterIds("cluster-id-2") + .setRowAffinity(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()))) + .build(); + + com.google.bigtable.admin.v2.AppProfile expectedResponse = + com.google.bigtable.admin.v2.AppProfile.newBuilder() + .setName(APP_PROFILE_NAME) + .setDescription("my description") + .setMultiClusterRoutingUseAny( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() + .addClusterIds("cluster-id-1") + .addClusterIds("cluster-id-2") + .setRowAffinity(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance())) + .build(); + + Mockito.when(mockCreateAppProfileCallable.futureCall(expectedRequest)) + .thenReturn(ApiFutures.immediateFuture(expectedResponse)); + + // Execute + AppProfile actualResult = + adminClient.createAppProfile( + CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID) + .setDescription("my description") + .setRoutingPolicy(MultiClusterRoutingPolicy.ofWithRowAffinity("cluster-id-1", "cluster-id-2"))); + + // Verify + assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse)); + } + + @Test + public void testCreateAppProfileAddRowAffinityAddMultipleClusterIdsWithList() { + // Setup + Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable); + + com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = + com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder() + .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) + .setAppProfileId(APP_PROFILE_ID) + .setAppProfile( + com.google.bigtable.admin.v2.AppProfile.newBuilder() + .setDescription("my description") + .setMultiClusterRoutingUseAny( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny + .newBuilder() + .addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2")) + .setRowAffinity(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()))) + .build(); + + com.google.bigtable.admin.v2.AppProfile expectedResponse = + com.google.bigtable.admin.v2.AppProfile.newBuilder() + .setName(APP_PROFILE_NAME) + .setDescription("my description") + .setMultiClusterRoutingUseAny( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() + .addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2")) + .setRowAffinity(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance())) + .build(); + + Mockito.when(mockCreateAppProfileCallable.futureCall(expectedRequest)) + .thenReturn(ApiFutures.immediateFuture(expectedResponse)); + + // Execute + AppProfile actualResult = + adminClient.createAppProfile( + CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID) + .setDescription("my description") + .setRoutingPolicy(MultiClusterRoutingPolicy.ofWithRowAffinity("cluster-id-1", "cluster-id-2"))); + + // Verify + assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse)); + } + @Test public void testGetAppProfile() { // Setup From 8019c29fa7070bca7c593935f45f3c116ec85af6 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Mon, 16 Sep 2024 16:00:08 -0400 Subject: [PATCH 3/9] Add tests for Create and Update App Profile Change-Id: I01ef72617d391bdb956ae9f469f1fd5af208a2e1 --- .../models/CreateAppProfileRequestTest.java | 10 ++++++++ .../models/UpdateAppProfileRequestTest.java | 23 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateAppProfileRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateAppProfileRequestTest.java index 088dc2bcfe..e42b79bc39 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateAppProfileRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateAppProfileRequestTest.java @@ -101,4 +101,14 @@ public void testDataBoostIsolationReadOnly() { .setComputeBillingOwner(DataBoostIsolationReadOnly.ComputeBillingOwner.HOST_PAYS) .build()); } + + @Test + public void testRowAffinity() { + CreateAppProfileRequest wrapper = + CreateAppProfileRequest.of("my-instance", "my-profile") + .setRoutingPolicy(MultiClusterRoutingPolicy.ofWithRowAffinity()); + + assertThat(wrapper.toProto("my-project").getAppProfile().getMultiClusterRoutingUseAny()) + .isEqualTo(MultiClusterRoutingUseAny.newBuilder().setRowAffinity(MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()).build()); + } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateAppProfileRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateAppProfileRequestTest.java index 04cf3f0813..e33bbe1980 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateAppProfileRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateAppProfileRequestTest.java @@ -146,4 +146,27 @@ public void testUpdateExistingDataBoostIsolationReadOnly() { .setUpdateMask(FieldMask.newBuilder().addPaths("data_boost_isolation_read_only")) .build()); } + + @Test + public void testUpdateRowAffinity() { + com.google.bigtable.admin.v2.AppProfile existingProto = + com.google.bigtable.admin.v2.AppProfile.newBuilder() + .setName("projects/my-project/instances/my-instance/appProfiles/my-profile") + .setEtag("my-etag") + .setDescription("description") + .setMultiClusterRoutingUseAny(MultiClusterRoutingUseAny.getDefaultInstance()) + .build(); + + AppProfile existingWrapper = AppProfile.fromProto(existingProto); + + UpdateAppProfileRequest updateWrapper = + UpdateAppProfileRequest.of(existingWrapper).setRoutingPolicy(AppProfile.MultiClusterRoutingPolicy.ofWithRowAffinity()); + + assertThat(updateWrapper.toProto("my-project")) + .isEqualTo( + com.google.bigtable.admin.v2.UpdateAppProfileRequest.newBuilder() + .setAppProfile(existingProto.toBuilder().setMultiClusterRoutingUseAny(MultiClusterRoutingUseAny.newBuilder().setRowAffinity(MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()))) + .setUpdateMask(FieldMask.newBuilder().addPaths("multi_cluster_routing_use_any")) + .build()); + } } From d10c5cfb2f6bafb28ec025b91598c744b3336e68 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Mon, 16 Sep 2024 16:11:36 -0400 Subject: [PATCH 4/9] Add integration test Change-Id: I9f18991cb61d99f30b811cea0988963d9e2577cd --- .../v2/it/BigtableInstanceAdminClientIT.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java index 76413165bd..8e06f3a661 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java @@ -279,6 +279,40 @@ public void appProfileTestDataBoost() { } } + @Test + public void appProfileTestRowAffinity() { + String newInstanceId = prefixGenerator.newPrefix(); + String newClusterId = newInstanceId + "-c1"; + String newClusterId2 = newInstanceId + "-c2"; + + client.createInstance( + CreateInstanceRequest.of(newInstanceId) + .addCluster(newClusterId, testEnvRule.env().getPrimaryZone(), 1, StorageType.SSD) + .addCluster(newClusterId2, testEnvRule.env().getSecondaryZone(), 1, StorageType.SSD) + .setDisplayName("Row-Affinity-Instance-Test") + .addLabel("state", "readytodelete") + .setType(Type.PRODUCTION)); + + try { + assertThat(client.exists(newInstanceId)).isTrue(); + + String testAppProfile = prefixGenerator.newPrefix(); + + CreateAppProfileRequest request = + CreateAppProfileRequest.of(newInstanceId, testAppProfile) + .setRoutingPolicy(AppProfile.MultiClusterRoutingPolicy.ofWithRowAffinity(newClusterId, newClusterId2)) + .setDescription("row affinity app profile"); + + AppProfile newlyCreateAppProfile = client.createAppProfile(request); + AppProfile.RoutingPolicy routingPolicy = newlyCreateAppProfile.getPolicy(); + assertThat(routingPolicy).isEqualTo(AppProfile.MultiClusterRoutingPolicy.ofWithRowAffinity(newClusterId, newClusterId2)); + } finally { + if (client.exists(newInstanceId)) { + client.deleteInstance(newInstanceId); + } + } + } + @Test public void iamUpdateTest() { Policy policy = client.getIamPolicy(instanceId); From 047b046b507df8c5078257b1bb2366ad7b3310d4 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Tue, 1 Oct 2024 11:15:22 -0400 Subject: [PATCH 5/9] Rename ofWithRowAffinity to withRowAffinity Change-Id: I9f88209e04cde4f628c878fbdb659c7344aa1c3c --- .../cloud/bigtable/admin/v2/models/AppProfile.java | 11 +++++------ .../admin/v2/BigtableInstanceAdminClientTests.java | 6 +++--- .../admin/v2/it/BigtableInstanceAdminClientIT.java | 4 ++-- .../bigtable/admin/v2/models/AppProfileTest.java | 6 +++--- .../admin/v2/models/CreateAppProfileRequestTest.java | 2 +- .../admin/v2/models/UpdateAppProfileRequestTest.java | 2 +- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/AppProfile.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/AppProfile.java index f2c1cf3cd4..4ee58bc47a 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/AppProfile.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/AppProfile.java @@ -18,7 +18,6 @@ import com.google.api.core.InternalApi; import com.google.bigtable.admin.v2.AppProfile.DataBoostIsolationReadOnly; import com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny; -import com.google.bigtable.admin.v2.AppProfile.Priority; import com.google.bigtable.admin.v2.AppProfile.StandardIsolation; import com.google.bigtable.admin.v2.AppProfileName; import com.google.common.base.Objects; @@ -70,7 +69,7 @@ private AppProfile(@Nonnull com.google.bigtable.admin.v2.AppProfile proto) { public RoutingPolicy getPolicy() { if (proto.hasMultiClusterRoutingUseAny()) { if (proto.getMultiClusterRoutingUseAny().hasRowAffinity()) { - return MultiClusterRoutingPolicy.ofWithRowAffinity( + return MultiClusterRoutingPolicy.withRowAffinity( ImmutableSet.copyOf(proto.getMultiClusterRoutingUseAny().getClusterIdsList())); } return MultiClusterRoutingPolicy.of( @@ -272,7 +271,7 @@ public static MultiClusterRoutingPolicy of(Set clusterIds) { } /** Creates a new instance of {@link MultiClusterRoutingPolicy}. */ - public static MultiClusterRoutingPolicy ofWithRowAffinity() { + public static MultiClusterRoutingPolicy withRowAffinity() { return new MultiClusterRoutingPolicy(MultiClusterRoutingUseAny.newBuilder() .setRowAffinity(MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()).build()); } @@ -281,15 +280,15 @@ public static MultiClusterRoutingPolicy ofWithRowAffinity() { * Creates a new instance of {@link MultiClusterRoutingPolicy} with row affinity enabled and specified cluster ids to * route to. */ - public static MultiClusterRoutingPolicy ofWithRowAffinity(String... clusterIds) { - return ofWithRowAffinity(ImmutableSet.copyOf(clusterIds)); + public static MultiClusterRoutingPolicy withRowAffinity(String... clusterIds) { + return withRowAffinity(ImmutableSet.copyOf(clusterIds)); } /** * Creates a new instance of {@link MultiClusterRoutingPolicy} with specified cluster ids to * route to. */ - public static MultiClusterRoutingPolicy ofWithRowAffinity(Set clusterIds) { + public static MultiClusterRoutingPolicy withRowAffinity(Set clusterIds) { return new MultiClusterRoutingPolicy( MultiClusterRoutingUseAny.newBuilder() .addAllClusterIds(clusterIds) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java index bf3223a19f..7310448865 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java @@ -1069,7 +1069,7 @@ public void testCreateAppProfileAddRowAffinity() { adminClient.createAppProfile( CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID) .setDescription("my description") - .setRoutingPolicy(MultiClusterRoutingPolicy.ofWithRowAffinity())); + .setRoutingPolicy(MultiClusterRoutingPolicy.withRowAffinity())); // Verify assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse)); @@ -1114,7 +1114,7 @@ public void testCreateAppProfileAddRowAffinityAddMultipleClusterIds() { adminClient.createAppProfile( CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID) .setDescription("my description") - .setRoutingPolicy(MultiClusterRoutingPolicy.ofWithRowAffinity("cluster-id-1", "cluster-id-2"))); + .setRoutingPolicy(MultiClusterRoutingPolicy.withRowAffinity("cluster-id-1", "cluster-id-2"))); // Verify assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse)); @@ -1157,7 +1157,7 @@ public void testCreateAppProfileAddRowAffinityAddMultipleClusterIdsWithList() { adminClient.createAppProfile( CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID) .setDescription("my description") - .setRoutingPolicy(MultiClusterRoutingPolicy.ofWithRowAffinity("cluster-id-1", "cluster-id-2"))); + .setRoutingPolicy(MultiClusterRoutingPolicy.withRowAffinity("cluster-id-1", "cluster-id-2"))); // Verify assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse)); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java index 8e06f3a661..2ab26134ee 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java @@ -300,12 +300,12 @@ public void appProfileTestRowAffinity() { CreateAppProfileRequest request = CreateAppProfileRequest.of(newInstanceId, testAppProfile) - .setRoutingPolicy(AppProfile.MultiClusterRoutingPolicy.ofWithRowAffinity(newClusterId, newClusterId2)) + .setRoutingPolicy(AppProfile.MultiClusterRoutingPolicy.withRowAffinity(newClusterId, newClusterId2)) .setDescription("row affinity app profile"); AppProfile newlyCreateAppProfile = client.createAppProfile(request); AppProfile.RoutingPolicy routingPolicy = newlyCreateAppProfile.getPolicy(); - assertThat(routingPolicy).isEqualTo(AppProfile.MultiClusterRoutingPolicy.ofWithRowAffinity(newClusterId, newClusterId2)); + assertThat(routingPolicy).isEqualTo(AppProfile.MultiClusterRoutingPolicy.withRowAffinity(newClusterId, newClusterId2)); } finally { if (client.exists(newInstanceId)) { client.deleteInstance(newInstanceId); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/AppProfileTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/AppProfileTest.java index 2e6f0c5203..d56bdf2f52 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/AppProfileTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/AppProfileTest.java @@ -310,9 +310,9 @@ public void testFromProtoWithRowAffinityNoClusterGroup() { assertThat(profile.getId()).isEqualTo("my-profile"); assertThat(profile.getDescription()).isEqualTo("my description"); System.out.println(profile.getPolicy()); - System.out.println(AppProfile.MultiClusterRoutingPolicy.ofWithRowAffinity()); + System.out.println(AppProfile.MultiClusterRoutingPolicy.withRowAffinity()); assertThat(profile.getPolicy()) - .isEqualTo(AppProfile.MultiClusterRoutingPolicy.ofWithRowAffinity()); + .isEqualTo(AppProfile.MultiClusterRoutingPolicy.withRowAffinity()); } @Test public void testFromProtoWithRowAffinityClusterGroup() { @@ -333,6 +333,6 @@ public void testFromProtoWithRowAffinityClusterGroup() { assertThat(profile.getId()).isEqualTo("my-profile"); assertThat(profile.getDescription()).isEqualTo("my description"); assertThat(profile.getPolicy()) - .isEqualTo(AppProfile.MultiClusterRoutingPolicy.ofWithRowAffinity("cluster-id-1", "cluster-id-2")); + .isEqualTo(AppProfile.MultiClusterRoutingPolicy.withRowAffinity("cluster-id-1", "cluster-id-2")); } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateAppProfileRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateAppProfileRequestTest.java index e42b79bc39..bf8495f259 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateAppProfileRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateAppProfileRequestTest.java @@ -106,7 +106,7 @@ public void testDataBoostIsolationReadOnly() { public void testRowAffinity() { CreateAppProfileRequest wrapper = CreateAppProfileRequest.of("my-instance", "my-profile") - .setRoutingPolicy(MultiClusterRoutingPolicy.ofWithRowAffinity()); + .setRoutingPolicy(MultiClusterRoutingPolicy.withRowAffinity()); assertThat(wrapper.toProto("my-project").getAppProfile().getMultiClusterRoutingUseAny()) .isEqualTo(MultiClusterRoutingUseAny.newBuilder().setRowAffinity(MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()).build()); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateAppProfileRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateAppProfileRequestTest.java index e33bbe1980..e50d1c46a2 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateAppProfileRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateAppProfileRequestTest.java @@ -160,7 +160,7 @@ public void testUpdateRowAffinity() { AppProfile existingWrapper = AppProfile.fromProto(existingProto); UpdateAppProfileRequest updateWrapper = - UpdateAppProfileRequest.of(existingWrapper).setRoutingPolicy(AppProfile.MultiClusterRoutingPolicy.ofWithRowAffinity()); + UpdateAppProfileRequest.of(existingWrapper).setRoutingPolicy(AppProfile.MultiClusterRoutingPolicy.withRowAffinity()); assertThat(updateWrapper.toProto("my-project")) .isEqualTo( From 4f197d4f35f1664d4694e7366b9ff68aead1bb46 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Fri, 11 Oct 2024 12:39:44 -0400 Subject: [PATCH 6/9] Run mvn com.coveo:fmt-maven-plugin:format Change-Id: Ieda39f0d9825fae649755350b4f228fe0e8985e5 --- .../bigtable/admin/v2/models/AppProfile.java | 20 ++- .../v2/BigtableInstanceAdminClientTests.java | 164 ++++++++++-------- .../v2/it/BigtableInstanceAdminClientIT.java | 23 +-- .../admin/v2/models/AppProfileTest.java | 52 +++--- .../models/CreateAppProfileRequestTest.java | 9 +- .../models/UpdateAppProfileRequestTest.java | 31 ++-- 6 files changed, 167 insertions(+), 132 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/AppProfile.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/AppProfile.java index 4ee58bc47a..2507ef4dd3 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/AppProfile.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/AppProfile.java @@ -70,7 +70,7 @@ public RoutingPolicy getPolicy() { if (proto.hasMultiClusterRoutingUseAny()) { if (proto.getMultiClusterRoutingUseAny().hasRowAffinity()) { return MultiClusterRoutingPolicy.withRowAffinity( - ImmutableSet.copyOf(proto.getMultiClusterRoutingUseAny().getClusterIdsList())); + ImmutableSet.copyOf(proto.getMultiClusterRoutingUseAny().getClusterIdsList())); } return MultiClusterRoutingPolicy.of( ImmutableSet.copyOf(proto.getMultiClusterRoutingUseAny().getClusterIdsList())); @@ -272,13 +272,15 @@ public static MultiClusterRoutingPolicy of(Set clusterIds) { /** Creates a new instance of {@link MultiClusterRoutingPolicy}. */ public static MultiClusterRoutingPolicy withRowAffinity() { - return new MultiClusterRoutingPolicy(MultiClusterRoutingUseAny.newBuilder() - .setRowAffinity(MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()).build()); + return new MultiClusterRoutingPolicy( + MultiClusterRoutingUseAny.newBuilder() + .setRowAffinity(MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()) + .build()); } /** - * Creates a new instance of {@link MultiClusterRoutingPolicy} with row affinity enabled and specified cluster ids to - * route to. + * Creates a new instance of {@link MultiClusterRoutingPolicy} with row affinity enabled and + * specified cluster ids to route to. */ public static MultiClusterRoutingPolicy withRowAffinity(String... clusterIds) { return withRowAffinity(ImmutableSet.copyOf(clusterIds)); @@ -290,10 +292,10 @@ public static MultiClusterRoutingPolicy withRowAffinity(String... clusterIds) { */ public static MultiClusterRoutingPolicy withRowAffinity(Set clusterIds) { return new MultiClusterRoutingPolicy( - MultiClusterRoutingUseAny.newBuilder() - .addAllClusterIds(clusterIds) - .setRowAffinity(MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()) - .build()); + MultiClusterRoutingUseAny.newBuilder() + .addAllClusterIds(clusterIds) + .setRowAffinity(MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()) + .build()); } /* diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java index 7310448865..2dd90f461a 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java @@ -1040,36 +1040,40 @@ public void testCreateAppProfileAddRowAffinity() { Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable); com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = - com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder() - .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) - .setAppProfileId(APP_PROFILE_ID) - .setAppProfile( - com.google.bigtable.admin.v2.AppProfile.newBuilder() - .setDescription("my description") - .setMultiClusterRoutingUseAny( - com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny - .newBuilder() - .setRowAffinity(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()))) - .build(); - - com.google.bigtable.admin.v2.AppProfile expectedResponse = - com.google.bigtable.admin.v2.AppProfile.newBuilder() - .setName(APP_PROFILE_NAME) + com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder() + .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) + .setAppProfileId(APP_PROFILE_ID) + .setAppProfile( + com.google.bigtable.admin.v2.AppProfile.newBuilder() .setDescription("my description") .setMultiClusterRoutingUseAny( - com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() - .setRowAffinity(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance())) - .build(); + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny + .newBuilder() + .setRowAffinity( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny + .RowAffinity.getDefaultInstance()))) + .build(); + + com.google.bigtable.admin.v2.AppProfile expectedResponse = + com.google.bigtable.admin.v2.AppProfile.newBuilder() + .setName(APP_PROFILE_NAME) + .setDescription("my description") + .setMultiClusterRoutingUseAny( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() + .setRowAffinity( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny + .RowAffinity.getDefaultInstance())) + .build(); Mockito.when(mockCreateAppProfileCallable.futureCall(expectedRequest)) - .thenReturn(ApiFutures.immediateFuture(expectedResponse)); + .thenReturn(ApiFutures.immediateFuture(expectedResponse)); // Execute AppProfile actualResult = - adminClient.createAppProfile( - CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID) - .setDescription("my description") - .setRoutingPolicy(MultiClusterRoutingPolicy.withRowAffinity())); + adminClient.createAppProfile( + CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID) + .setDescription("my description") + .setRoutingPolicy(MultiClusterRoutingPolicy.withRowAffinity())); // Verify assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse)); @@ -1081,40 +1085,45 @@ public void testCreateAppProfileAddRowAffinityAddMultipleClusterIds() { Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable); com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = - com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder() - .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) - .setAppProfileId(APP_PROFILE_ID) - .setAppProfile( - com.google.bigtable.admin.v2.AppProfile.newBuilder() - .setDescription("my description") - .setMultiClusterRoutingUseAny( - com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny - .newBuilder() - .addClusterIds("cluster-id-1") - .addClusterIds("cluster-id-2") - .setRowAffinity(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()))) - .build(); - - com.google.bigtable.admin.v2.AppProfile expectedResponse = - com.google.bigtable.admin.v2.AppProfile.newBuilder() - .setName(APP_PROFILE_NAME) + com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder() + .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) + .setAppProfileId(APP_PROFILE_ID) + .setAppProfile( + com.google.bigtable.admin.v2.AppProfile.newBuilder() .setDescription("my description") .setMultiClusterRoutingUseAny( - com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() - .addClusterIds("cluster-id-1") - .addClusterIds("cluster-id-2") - .setRowAffinity(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance())) - .build(); + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny + .newBuilder() + .addClusterIds("cluster-id-1") + .addClusterIds("cluster-id-2") + .setRowAffinity( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny + .RowAffinity.getDefaultInstance()))) + .build(); + + com.google.bigtable.admin.v2.AppProfile expectedResponse = + com.google.bigtable.admin.v2.AppProfile.newBuilder() + .setName(APP_PROFILE_NAME) + .setDescription("my description") + .setMultiClusterRoutingUseAny( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() + .addClusterIds("cluster-id-1") + .addClusterIds("cluster-id-2") + .setRowAffinity( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny + .RowAffinity.getDefaultInstance())) + .build(); Mockito.when(mockCreateAppProfileCallable.futureCall(expectedRequest)) - .thenReturn(ApiFutures.immediateFuture(expectedResponse)); + .thenReturn(ApiFutures.immediateFuture(expectedResponse)); // Execute AppProfile actualResult = - adminClient.createAppProfile( - CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID) - .setDescription("my description") - .setRoutingPolicy(MultiClusterRoutingPolicy.withRowAffinity("cluster-id-1", "cluster-id-2"))); + adminClient.createAppProfile( + CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID) + .setDescription("my description") + .setRoutingPolicy( + MultiClusterRoutingPolicy.withRowAffinity("cluster-id-1", "cluster-id-2"))); // Verify assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse)); @@ -1126,38 +1135,43 @@ public void testCreateAppProfileAddRowAffinityAddMultipleClusterIdsWithList() { Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable); com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = - com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder() - .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) - .setAppProfileId(APP_PROFILE_ID) - .setAppProfile( - com.google.bigtable.admin.v2.AppProfile.newBuilder() - .setDescription("my description") - .setMultiClusterRoutingUseAny( - com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny - .newBuilder() - .addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2")) - .setRowAffinity(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()))) - .build(); - - com.google.bigtable.admin.v2.AppProfile expectedResponse = - com.google.bigtable.admin.v2.AppProfile.newBuilder() - .setName(APP_PROFILE_NAME) + com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder() + .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) + .setAppProfileId(APP_PROFILE_ID) + .setAppProfile( + com.google.bigtable.admin.v2.AppProfile.newBuilder() .setDescription("my description") .setMultiClusterRoutingUseAny( - com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() - .addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2")) - .setRowAffinity(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance())) - .build(); + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny + .newBuilder() + .addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2")) + .setRowAffinity( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny + .RowAffinity.getDefaultInstance()))) + .build(); + + com.google.bigtable.admin.v2.AppProfile expectedResponse = + com.google.bigtable.admin.v2.AppProfile.newBuilder() + .setName(APP_PROFILE_NAME) + .setDescription("my description") + .setMultiClusterRoutingUseAny( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() + .addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2")) + .setRowAffinity( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny + .RowAffinity.getDefaultInstance())) + .build(); Mockito.when(mockCreateAppProfileCallable.futureCall(expectedRequest)) - .thenReturn(ApiFutures.immediateFuture(expectedResponse)); + .thenReturn(ApiFutures.immediateFuture(expectedResponse)); // Execute AppProfile actualResult = - adminClient.createAppProfile( - CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID) - .setDescription("my description") - .setRoutingPolicy(MultiClusterRoutingPolicy.withRowAffinity("cluster-id-1", "cluster-id-2"))); + adminClient.createAppProfile( + CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID) + .setDescription("my description") + .setRoutingPolicy( + MultiClusterRoutingPolicy.withRowAffinity("cluster-id-1", "cluster-id-2"))); // Verify assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse)); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java index 2ab26134ee..6e9f82b5b4 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java @@ -286,12 +286,12 @@ public void appProfileTestRowAffinity() { String newClusterId2 = newInstanceId + "-c2"; client.createInstance( - CreateInstanceRequest.of(newInstanceId) - .addCluster(newClusterId, testEnvRule.env().getPrimaryZone(), 1, StorageType.SSD) - .addCluster(newClusterId2, testEnvRule.env().getSecondaryZone(), 1, StorageType.SSD) - .setDisplayName("Row-Affinity-Instance-Test") - .addLabel("state", "readytodelete") - .setType(Type.PRODUCTION)); + CreateInstanceRequest.of(newInstanceId) + .addCluster(newClusterId, testEnvRule.env().getPrimaryZone(), 1, StorageType.SSD) + .addCluster(newClusterId2, testEnvRule.env().getSecondaryZone(), 1, StorageType.SSD) + .setDisplayName("Row-Affinity-Instance-Test") + .addLabel("state", "readytodelete") + .setType(Type.PRODUCTION)); try { assertThat(client.exists(newInstanceId)).isTrue(); @@ -299,13 +299,16 @@ public void appProfileTestRowAffinity() { String testAppProfile = prefixGenerator.newPrefix(); CreateAppProfileRequest request = - CreateAppProfileRequest.of(newInstanceId, testAppProfile) - .setRoutingPolicy(AppProfile.MultiClusterRoutingPolicy.withRowAffinity(newClusterId, newClusterId2)) - .setDescription("row affinity app profile"); + CreateAppProfileRequest.of(newInstanceId, testAppProfile) + .setRoutingPolicy( + AppProfile.MultiClusterRoutingPolicy.withRowAffinity(newClusterId, newClusterId2)) + .setDescription("row affinity app profile"); AppProfile newlyCreateAppProfile = client.createAppProfile(request); AppProfile.RoutingPolicy routingPolicy = newlyCreateAppProfile.getPolicy(); - assertThat(routingPolicy).isEqualTo(AppProfile.MultiClusterRoutingPolicy.withRowAffinity(newClusterId, newClusterId2)); + assertThat(routingPolicy) + .isEqualTo( + AppProfile.MultiClusterRoutingPolicy.withRowAffinity(newClusterId, newClusterId2)); } finally { if (client.exists(newInstanceId)) { client.deleteInstance(newInstanceId); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/AppProfileTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/AppProfileTest.java index d56bdf2f52..d6e6e410e8 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/AppProfileTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/AppProfileTest.java @@ -295,16 +295,18 @@ public void testFromProtoWithDataBoostIsolation() { @Test public void testFromProtoWithRowAffinityNoClusterGroup() { AppProfile profile = - AppProfile.fromProto( - com.google.bigtable.admin.v2.AppProfile.newBuilder() - .setName(AppProfileName.of("my-project", "my-instance", "my-profile").toString()) - .setDescription("my description") - .setMultiClusterRoutingUseAny( - com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() - .setRowAffinity(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()) - .build()) - .setEtag("my-etag") - .build()); + AppProfile.fromProto( + com.google.bigtable.admin.v2.AppProfile.newBuilder() + .setName(AppProfileName.of("my-project", "my-instance", "my-profile").toString()) + .setDescription("my description") + .setMultiClusterRoutingUseAny( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() + .setRowAffinity( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny + .RowAffinity.getDefaultInstance()) + .build()) + .setEtag("my-etag") + .build()); assertThat(profile.getInstanceId()).isEqualTo("my-instance"); assertThat(profile.getId()).isEqualTo("my-profile"); @@ -312,27 +314,31 @@ public void testFromProtoWithRowAffinityNoClusterGroup() { System.out.println(profile.getPolicy()); System.out.println(AppProfile.MultiClusterRoutingPolicy.withRowAffinity()); assertThat(profile.getPolicy()) - .isEqualTo(AppProfile.MultiClusterRoutingPolicy.withRowAffinity()); + .isEqualTo(AppProfile.MultiClusterRoutingPolicy.withRowAffinity()); } + @Test public void testFromProtoWithRowAffinityClusterGroup() { AppProfile profile = - AppProfile.fromProto( - com.google.bigtable.admin.v2.AppProfile.newBuilder() - .setName(AppProfileName.of("my-project", "my-instance", "my-profile").toString()) - .setDescription("my description") - .setMultiClusterRoutingUseAny( - com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() - .addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2")) - .setRowAffinity(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()) - .build()) - .setEtag("my-etag") - .build()); + AppProfile.fromProto( + com.google.bigtable.admin.v2.AppProfile.newBuilder() + .setName(AppProfileName.of("my-project", "my-instance", "my-profile").toString()) + .setDescription("my description") + .setMultiClusterRoutingUseAny( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() + .addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2")) + .setRowAffinity( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny + .RowAffinity.getDefaultInstance()) + .build()) + .setEtag("my-etag") + .build()); assertThat(profile.getInstanceId()).isEqualTo("my-instance"); assertThat(profile.getId()).isEqualTo("my-profile"); assertThat(profile.getDescription()).isEqualTo("my description"); assertThat(profile.getPolicy()) - .isEqualTo(AppProfile.MultiClusterRoutingPolicy.withRowAffinity("cluster-id-1", "cluster-id-2")); + .isEqualTo( + AppProfile.MultiClusterRoutingPolicy.withRowAffinity("cluster-id-1", "cluster-id-2")); } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateAppProfileRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateAppProfileRequestTest.java index bf8495f259..7e9cc81541 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateAppProfileRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateAppProfileRequestTest.java @@ -105,10 +105,13 @@ public void testDataBoostIsolationReadOnly() { @Test public void testRowAffinity() { CreateAppProfileRequest wrapper = - CreateAppProfileRequest.of("my-instance", "my-profile") - .setRoutingPolicy(MultiClusterRoutingPolicy.withRowAffinity()); + CreateAppProfileRequest.of("my-instance", "my-profile") + .setRoutingPolicy(MultiClusterRoutingPolicy.withRowAffinity()); assertThat(wrapper.toProto("my-project").getAppProfile().getMultiClusterRoutingUseAny()) - .isEqualTo(MultiClusterRoutingUseAny.newBuilder().setRowAffinity(MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()).build()); + .isEqualTo( + MultiClusterRoutingUseAny.newBuilder() + .setRowAffinity(MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()) + .build()); } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateAppProfileRequestTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateAppProfileRequestTest.java index e50d1c46a2..603943c533 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateAppProfileRequestTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateAppProfileRequestTest.java @@ -150,23 +150,30 @@ public void testUpdateExistingDataBoostIsolationReadOnly() { @Test public void testUpdateRowAffinity() { com.google.bigtable.admin.v2.AppProfile existingProto = - com.google.bigtable.admin.v2.AppProfile.newBuilder() - .setName("projects/my-project/instances/my-instance/appProfiles/my-profile") - .setEtag("my-etag") - .setDescription("description") - .setMultiClusterRoutingUseAny(MultiClusterRoutingUseAny.getDefaultInstance()) - .build(); + com.google.bigtable.admin.v2.AppProfile.newBuilder() + .setName("projects/my-project/instances/my-instance/appProfiles/my-profile") + .setEtag("my-etag") + .setDescription("description") + .setMultiClusterRoutingUseAny(MultiClusterRoutingUseAny.getDefaultInstance()) + .build(); AppProfile existingWrapper = AppProfile.fromProto(existingProto); UpdateAppProfileRequest updateWrapper = - UpdateAppProfileRequest.of(existingWrapper).setRoutingPolicy(AppProfile.MultiClusterRoutingPolicy.withRowAffinity()); + UpdateAppProfileRequest.of(existingWrapper) + .setRoutingPolicy(AppProfile.MultiClusterRoutingPolicy.withRowAffinity()); assertThat(updateWrapper.toProto("my-project")) - .isEqualTo( - com.google.bigtable.admin.v2.UpdateAppProfileRequest.newBuilder() - .setAppProfile(existingProto.toBuilder().setMultiClusterRoutingUseAny(MultiClusterRoutingUseAny.newBuilder().setRowAffinity(MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()))) - .setUpdateMask(FieldMask.newBuilder().addPaths("multi_cluster_routing_use_any")) - .build()); + .isEqualTo( + com.google.bigtable.admin.v2.UpdateAppProfileRequest.newBuilder() + .setAppProfile( + existingProto + .toBuilder() + .setMultiClusterRoutingUseAny( + MultiClusterRoutingUseAny.newBuilder() + .setRowAffinity( + MultiClusterRoutingUseAny.RowAffinity.getDefaultInstance()))) + .setUpdateMask(FieldMask.newBuilder().addPaths("multi_cluster_routing_use_any")) + .build()); } } From c6f6a7858491d00771b717c15bc41ada6ea53edd Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Fri, 11 Oct 2024 14:02:30 -0400 Subject: [PATCH 7/9] Remove extra test for cluster IDs - one is enough Change-Id: I6d8e7bd644ce2cd8f098c8ee37b4eec1a0d642e2 --- .../v2/BigtableInstanceAdminClientTests.java | 48 ------------------- 1 file changed, 48 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java index 2dd90f461a..724f75bc98 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java @@ -1129,54 +1129,6 @@ public void testCreateAppProfileAddRowAffinityAddMultipleClusterIds() { assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse)); } - @Test - public void testCreateAppProfileAddRowAffinityAddMultipleClusterIdsWithList() { - // Setup - Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable); - - com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = - com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder() - .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) - .setAppProfileId(APP_PROFILE_ID) - .setAppProfile( - com.google.bigtable.admin.v2.AppProfile.newBuilder() - .setDescription("my description") - .setMultiClusterRoutingUseAny( - com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny - .newBuilder() - .addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2")) - .setRowAffinity( - com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny - .RowAffinity.getDefaultInstance()))) - .build(); - - com.google.bigtable.admin.v2.AppProfile expectedResponse = - com.google.bigtable.admin.v2.AppProfile.newBuilder() - .setName(APP_PROFILE_NAME) - .setDescription("my description") - .setMultiClusterRoutingUseAny( - com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() - .addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2")) - .setRowAffinity( - com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny - .RowAffinity.getDefaultInstance())) - .build(); - - Mockito.when(mockCreateAppProfileCallable.futureCall(expectedRequest)) - .thenReturn(ApiFutures.immediateFuture(expectedResponse)); - - // Execute - AppProfile actualResult = - adminClient.createAppProfile( - CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID) - .setDescription("my description") - .setRoutingPolicy( - MultiClusterRoutingPolicy.withRowAffinity("cluster-id-1", "cluster-id-2"))); - - // Verify - assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse)); - } - @Test public void testGetAppProfile() { // Setup From fecd6ea8baa6bfbf924e5ac51ee4a2eb7b200338 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Fri, 11 Oct 2024 17:17:10 -0400 Subject: [PATCH 8/9] Add unit test for row affinity with set of strings Change-Id: I7b072214c8b38646058d0ec668bbb469bf16f23e --- .../v2/BigtableInstanceAdminClientTests.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java index 724f75bc98..6faa65ddbd 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java @@ -65,7 +65,10 @@ import com.google.protobuf.FieldMask; import io.grpc.Status; import io.grpc.Status.Code; + +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Before; @@ -1129,6 +1132,59 @@ public void testCreateAppProfileAddRowAffinityAddMultipleClusterIds() { assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse)); } + @Test + public void testCreateAppProfileAddRowAffinityAddSetOfClusterIds() { + // Setup + Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable); + + com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = + com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder() + .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) + .setAppProfileId(APP_PROFILE_ID) + .setAppProfile( + com.google.bigtable.admin.v2.AppProfile.newBuilder() + .setDescription("my description") + .setMultiClusterRoutingUseAny( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny + .newBuilder() + .addClusterIds("cluster-id-1") + .addClusterIds("cluster-id-2") + .setRowAffinity( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny + .RowAffinity.getDefaultInstance()))) + .build(); + + com.google.bigtable.admin.v2.AppProfile expectedResponse = + com.google.bigtable.admin.v2.AppProfile.newBuilder() + .setName(APP_PROFILE_NAME) + .setDescription("my description") + .setMultiClusterRoutingUseAny( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() + .addClusterIds("cluster-id-1") + .addClusterIds("cluster-id-2") + .setRowAffinity( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny + .RowAffinity.getDefaultInstance())) + .build(); + + Mockito.when(mockCreateAppProfileCallable.futureCall(expectedRequest)) + .thenReturn(ApiFutures.immediateFuture(expectedResponse)); + + // Execute + Set clusterIds = new HashSet(); + clusterIds.add("cluster-id-1"); + clusterIds.add("cluster-id-2"); + AppProfile actualResult = + adminClient.createAppProfile( + CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID) + .setDescription("my description") + .setRoutingPolicy( + MultiClusterRoutingPolicy.withRowAffinity(clusterIds))); + + // Verify + assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse)); + } + @Test public void testGetAppProfile() { // Setup From 7ba35f859cb7fc75967dd7393813149af6f57d83 Mon Sep 17 00:00:00 2001 From: Derek Yau Date: Mon, 14 Oct 2024 10:40:30 -0400 Subject: [PATCH 9/9] Run formatter Change-Id: Ieb04b2141c8843ff59cc4d756d736b4c00609ee2 --- .../v2/BigtableInstanceAdminClientTests.java | 64 +++++++++---------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java index 6faa65ddbd..388631d93a 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java @@ -65,7 +65,6 @@ import com.google.protobuf.FieldMask; import io.grpc.Status; import io.grpc.Status.Code; - import java.util.HashSet; import java.util.List; import java.util.Set; @@ -1138,48 +1137,47 @@ public void testCreateAppProfileAddRowAffinityAddSetOfClusterIds() { Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable); com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = - com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder() - .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) - .setAppProfileId(APP_PROFILE_ID) - .setAppProfile( - com.google.bigtable.admin.v2.AppProfile.newBuilder() - .setDescription("my description") - .setMultiClusterRoutingUseAny( - com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny - .newBuilder() - .addClusterIds("cluster-id-1") - .addClusterIds("cluster-id-2") - .setRowAffinity( - com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny - .RowAffinity.getDefaultInstance()))) - .build(); - - com.google.bigtable.admin.v2.AppProfile expectedResponse = - com.google.bigtable.admin.v2.AppProfile.newBuilder() - .setName(APP_PROFILE_NAME) + com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder() + .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) + .setAppProfileId(APP_PROFILE_ID) + .setAppProfile( + com.google.bigtable.admin.v2.AppProfile.newBuilder() .setDescription("my description") .setMultiClusterRoutingUseAny( - com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() - .addClusterIds("cluster-id-1") - .addClusterIds("cluster-id-2") - .setRowAffinity( - com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny - .RowAffinity.getDefaultInstance())) - .build(); + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny + .newBuilder() + .addClusterIds("cluster-id-1") + .addClusterIds("cluster-id-2") + .setRowAffinity( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny + .RowAffinity.getDefaultInstance()))) + .build(); + + com.google.bigtable.admin.v2.AppProfile expectedResponse = + com.google.bigtable.admin.v2.AppProfile.newBuilder() + .setName(APP_PROFILE_NAME) + .setDescription("my description") + .setMultiClusterRoutingUseAny( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() + .addClusterIds("cluster-id-1") + .addClusterIds("cluster-id-2") + .setRowAffinity( + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny + .RowAffinity.getDefaultInstance())) + .build(); Mockito.when(mockCreateAppProfileCallable.futureCall(expectedRequest)) - .thenReturn(ApiFutures.immediateFuture(expectedResponse)); + .thenReturn(ApiFutures.immediateFuture(expectedResponse)); // Execute Set clusterIds = new HashSet(); clusterIds.add("cluster-id-1"); clusterIds.add("cluster-id-2"); AppProfile actualResult = - adminClient.createAppProfile( - CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID) - .setDescription("my description") - .setRoutingPolicy( - MultiClusterRoutingPolicy.withRowAffinity(clusterIds))); + adminClient.createAppProfile( + CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID) + .setDescription("my description") + .setRoutingPolicy(MultiClusterRoutingPolicy.withRowAffinity(clusterIds))); // Verify assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse));