From 32a2975ce85b0a6d3aa47d6a5533a771167c867a Mon Sep 17 00:00:00 2001 From: Larry Safran Date: Thu, 9 Jan 2025 14:12:45 -0800 Subject: [PATCH] Errorprone --- .../io/grpc/xds/XdsDependencyManager.java | 3 ++- .../io/grpc/xds/XdsDependencyManagerTest.java | 21 +++++++------------ .../test/java/io/grpc/xds/XdsTestUtils.java | 3 ++- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/xds/src/main/java/io/grpc/xds/XdsDependencyManager.java b/xds/src/main/java/io/grpc/xds/XdsDependencyManager.java index 4292b087d58..05705c233e8 100644 --- a/xds/src/main/java/io/grpc/xds/XdsDependencyManager.java +++ b/xds/src/main/java/io/grpc/xds/XdsDependencyManager.java @@ -611,7 +611,8 @@ private void updateRoutes(List virtualHosts, String rdsName) { // Must be in SyncContext private void cleanUpRoutes() { // Remove RdsWatcher & CDS Watchers - TypeWatchers rdsResourceWatcher = resourceWatchers.get(XdsRouteConfigureResource.getInstance()); + TypeWatchers rdsResourceWatcher = + resourceWatchers.get(XdsRouteConfigureResource.getInstance()); if (rdsResourceWatcher == null) { return; } diff --git a/xds/src/test/java/io/grpc/xds/XdsDependencyManagerTest.java b/xds/src/test/java/io/grpc/xds/XdsDependencyManagerTest.java index bca49772e40..5ceb964b1d9 100644 --- a/xds/src/test/java/io/grpc/xds/XdsDependencyManagerTest.java +++ b/xds/src/test/java/io/grpc/xds/XdsDependencyManagerTest.java @@ -26,9 +26,7 @@ import static io.grpc.xds.XdsTestUtils.CLUSTER_NAME; import static io.grpc.xds.XdsTestUtils.ENDPOINT_HOSTNAME; import static io.grpc.xds.XdsTestUtils.ENDPOINT_PORT; -import static io.grpc.xds.XdsTestUtils.RDS_NAME; import static io.grpc.xds.XdsTestUtils.getEdsNameForCluster; -import static io.grpc.xds.client.CommonBootstrapperTestUtils.RDS_RESOURCE; import static io.grpc.xds.client.CommonBootstrapperTestUtils.SERVER_URI; import static org.mockito.AdditionalAnswers.delegatesTo; import static org.mockito.ArgumentMatchers.any; @@ -39,10 +37,8 @@ import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; +import com.google.common.collect.ImmutableSet; import com.google.protobuf.Any; import com.google.protobuf.Message; import io.envoyproxy.envoy.config.cluster.v3.Cluster; @@ -72,7 +68,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Queue; @@ -262,18 +257,17 @@ public void testComplexRegisteredAggregate() throws IOException { Closeable subscription2 = xdsDependencyManager.subscribeToCluster(rootName2); inOrder.verify(xdsConfigWatcher, timeout(1000)).onUpdate(xdsConfigCaptor.capture()); testWatcher.verifyStats(3, 0, 0); - Set expectedClusters = new HashSet<>(); - expectedClusters.addAll(ImmutableList.of(rootName1, rootName2, CLUSTER_NAME)); - expectedClusters.addAll(childNames); - expectedClusters.addAll(childNames2); + ImmutableSet.Builder builder = ImmutableSet.builder(); + Set expectedClusters = builder.add(rootName1).add(rootName2).add(CLUSTER_NAME) + .addAll(childNames).addAll(childNames2).build(); assertThat(xdsConfigCaptor.getValue().getClusters().keySet()).isEqualTo(expectedClusters); // Close 1 subscription shouldn't affect the other or RDS subscriptions subscription1.close(); inOrder.verify(xdsConfigWatcher, timeout(1000)).onUpdate(xdsConfigCaptor.capture()); - Set expectedClusters2 = new HashSet<>(); - expectedClusters.addAll(ImmutableList.of(rootName2, CLUSTER_NAME)); - expectedClusters.addAll(childNames2); + builder = ImmutableSet.builder(); + Set expectedClusters2 = + builder.add(rootName2).add(CLUSTER_NAME).addAll(childNames2).build(); assertThat(xdsConfigCaptor.getValue().getClusters().keySet()).isEqualTo(expectedClusters2); subscription2.close(); @@ -291,6 +285,7 @@ public void testDelayedSubscription() { List childNames = Arrays.asList("clusterC", "clusterB", "clusterA"); Closeable subscription1 = xdsDependencyManager.subscribeToCluster(rootName1); + assertThat(subscription1).isNotNull(); fakeClock.forwardTime(16, TimeUnit.SECONDS); inOrder.verify(xdsConfigWatcher).onUpdate(xdsConfigCaptor.capture()); assertThat(xdsConfigCaptor.getValue().getClusters().get(rootName1).toString()).isEqualTo( diff --git a/xds/src/test/java/io/grpc/xds/XdsTestUtils.java b/xds/src/test/java/io/grpc/xds/XdsTestUtils.java index 5157a4fd401..ecaf14eba75 100644 --- a/xds/src/test/java/io/grpc/xds/XdsTestUtils.java +++ b/xds/src/test/java/io/grpc/xds/XdsTestUtils.java @@ -186,7 +186,8 @@ static void setAggregateCdsConfig(XdsTestControlPlaneService service, String ser service.setXdsConfig(ADS_TYPE_URL_EDS, edsMap); } - static void addAggregateToExistingConfig(XdsTestControlPlaneService service, String rootName, List children) { + static void addAggregateToExistingConfig(XdsTestControlPlaneService service, String rootName, + List children) { Map clusterMap = new HashMap<>(service.getCurrentConfig(ADS_TYPE_URL_CDS)); if (clusterMap.containsKey(rootName)) { throw new IllegalArgumentException("Root cluster " + rootName + " already exists");