Skip to content

Commit

Permalink
Errorprone
Browse files Browse the repository at this point in the history
  • Loading branch information
larry-safran committed Jan 9, 2025
1 parent 2f4de7f commit 32a2975
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
3 changes: 2 additions & 1 deletion xds/src/main/java/io/grpc/xds/XdsDependencyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,8 @@ private void updateRoutes(List<VirtualHost> 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());

Check warning on line 615 in xds/src/main/java/io/grpc/xds/XdsDependencyManager.java

View check run for this annotation

Codecov / codecov/patch

xds/src/main/java/io/grpc/xds/XdsDependencyManager.java#L614-L615

Added lines #L614 - L615 were not covered by tests
if (rdsResourceWatcher == null) {
return;

Check warning on line 617 in xds/src/main/java/io/grpc/xds/XdsDependencyManager.java

View check run for this annotation

Codecov / codecov/patch

xds/src/main/java/io/grpc/xds/XdsDependencyManager.java#L617

Added line #L617 was not covered by tests
}
Expand Down
21 changes: 8 additions & 13 deletions xds/src/test/java/io/grpc/xds/XdsDependencyManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> expectedClusters = new HashSet<>();
expectedClusters.addAll(ImmutableList.of(rootName1, rootName2, CLUSTER_NAME));
expectedClusters.addAll(childNames);
expectedClusters.addAll(childNames2);
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
Set<String> 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<String> expectedClusters2 = new HashSet<>();
expectedClusters.addAll(ImmutableList.of(rootName2, CLUSTER_NAME));
expectedClusters.addAll(childNames2);
builder = ImmutableSet.builder();
Set<String> expectedClusters2 =
builder.add(rootName2).add(CLUSTER_NAME).addAll(childNames2).build();
assertThat(xdsConfigCaptor.getValue().getClusters().keySet()).isEqualTo(expectedClusters2);

subscription2.close();
Expand All @@ -291,6 +285,7 @@ public void testDelayedSubscription() {
List<String> 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(
Expand Down
3 changes: 2 additions & 1 deletion xds/src/test/java/io/grpc/xds/XdsTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> children) {
static void addAggregateToExistingConfig(XdsTestControlPlaneService service, String rootName,
List<String> children) {
Map<String, Message> clusterMap = new HashMap<>(service.getCurrentConfig(ADS_TYPE_URL_CDS));
if (clusterMap.containsKey(rootName)) {
throw new IllegalArgumentException("Root cluster " + rootName + " already exists");
Expand Down

0 comments on commit 32a2975

Please sign in to comment.