Skip to content

Commit 58e6ad7

Browse files
authored
xds: fix style (#6834)
1 parent 9922382 commit 58e6ad7

7 files changed

+22
-25
lines changed

xds/src/main/java/io/grpc/xds/WeightedTargetLoadBalancer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private void updateOverallBalancingState() {
157157
}
158158

159159
@Nullable
160-
private ConnectivityState aggregateState(
160+
private static ConnectivityState aggregateState(
161161
@Nullable ConnectivityState overallState, ConnectivityState childState) {
162162
if (overallState == null) {
163163
return childState;

xds/src/main/java/io/grpc/xds/WeightedTargetLoadBalancerProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public boolean equals(Object o) {
185185

186186
@Override
187187
public int hashCode() {
188-
return Objects.hash(targets);
188+
return Objects.hashCode(targets);
189189
}
190190

191191
@Override

xds/src/main/java/io/grpc/xds/XdsClientImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ final class XdsClientImpl extends XdsClient {
9393
"type.googleapis.com/envoy.api.v2.ClusterLoadAssignment";
9494

9595
// For now we do not support path matching unless enabled manually.
96-
private static boolean enablePathMatching = Boolean.parseBoolean(
96+
private static final boolean ENABLE_PATH_MATCHING = Boolean.parseBoolean(
9797
System.getenv("ENABLE_EXPERIMENTAL_PATH_MATCHING"));
9898

9999
private final MessagePrinter respPrinter = new MessagePrinter();
@@ -641,7 +641,7 @@ private void handleLdsResponseForConfigUpdate(DiscoveryResponse ldsResponse) {
641641
if (routes != null) {
642642
// Found clusterName in the in-lined RouteConfiguration.
643643
String clusterName = routes.get(routes.size() - 1).getRouteAction().get().getCluster();
644-
if (!enablePathMatching) {
644+
if (!ENABLE_PATH_MATCHING) {
645645
logger.log(
646646
XdsLogLevel.INFO,
647647
"Found cluster name (inlined in route config): {0}", clusterName);
@@ -812,7 +812,7 @@ private void handleRdsResponse(DiscoveryResponse rdsResponse) {
812812

813813
// Found clusterName in the in-lined RouteConfiguration.
814814
String clusterName = routes.get(routes.size() - 1).getRouteAction().get().getCluster();
815-
if (!enablePathMatching) {
815+
if (!ENABLE_PATH_MATCHING) {
816816
logger.log(XdsLogLevel.INFO, "Found cluster name: {0}", clusterName);
817817
} else {
818818
logger.log(XdsLogLevel.INFO, "Found {0} routes", routes.size());
@@ -893,7 +893,7 @@ private static String validateRoutes(List<EnvoyProtoData.Route> routes) {
893893
}
894894

895895
// We only validate the default route unless path matching is enabled.
896-
if (!enablePathMatching) {
896+
if (!ENABLE_PATH_MATCHING) {
897897
EnvoyProtoData.Route route = routes.get(routes.size() - 1);
898898
RouteMatch routeMatch = route.getRouteMatch();
899899
if (!routeMatch.getPath().isEmpty() || !routeMatch.getPrefix().isEmpty()

xds/src/test/java/io/grpc/xds/LocalityStoreTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,8 @@ public PickResult pickSubchannel(PickSubchannelArgs args) {
488488
assertThat(interLocalityPicker.weightedChildPickers).hasSize(2);
489489

490490
Set<Subchannel> pickedReadySubchannels = new HashSet<>();
491-
for (int i = 0; i < interLocalityPicker.weightedChildPickers.size(); i++) {
492-
PickResult result = interLocalityPicker.weightedChildPickers.get(i).getPicker()
493-
.pickSubchannel(pickSubchannelArgs);
491+
for (WeightedChildPicker weightedPicker : interLocalityPicker.weightedChildPickers) {
492+
PickResult result = weightedPicker.getPicker().pickSubchannel(pickSubchannelArgs);
494493
pickedReadySubchannels.add(result.getSubchannel());
495494
}
496495
assertThat(pickedReadySubchannels).containsExactly(subchannel31, subchannel12);
@@ -916,9 +915,7 @@ public PickResult pickSubchannel(PickSubchannelArgs args) {
916915
WeightedRandomPicker interLocalityPicker =
917916
(WeightedRandomPicker) subchannelPickerCaptor.getValue();
918917
assertThat(interLocalityPicker.weightedChildPickers).hasSize(3);
919-
for (int i = 0; i < interLocalityPicker.weightedChildPickers.size(); i++) {
920-
WeightedChildPicker weightedChildPicker
921-
= interLocalityPicker.weightedChildPickers.get(i);
918+
for (WeightedChildPicker weightedChildPicker : interLocalityPicker.weightedChildPickers) {
922919
Subchannel subchannel
923920
= weightedChildPicker.getPicker().pickSubchannel(pickSubchannelArgs).getSubchannel();
924921
assertThat(weightedChildPicker.getWeight())

xds/src/test/java/io/grpc/xds/WeightedTargetLoadBalancerProviderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public ConfigOrError parseLoadBalancingPolicyConfig(Map<String, ?> rawConfig) {
118118
+ " ]"
119119
+ " }"
120120
+ " }"
121-
+ "}").replace("'", "\"");
121+
+ "}").replace('\'', '"');
122122

123123
@SuppressWarnings("unchecked")
124124
Map<String, ?> rawLbConfigMap = (Map<String, ?>) JsonParser.parse(weightedTargetConfigJson);

xds/src/test/java/io/grpc/xds/WeightedTargetLoadBalancerTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -305,36 +305,36 @@ public void balancingStateUpdatedFromChildBalancers() {
305305
verify(helper).updateBalancingState(eq(READY), pickerCaptor.capture());
306306
assertThat(pickerCaptor.getValue()).isInstanceOf(WeightedRandomPicker.class);
307307
WeightedRandomPicker overallPicker = (WeightedRandomPicker) pickerCaptor.getValue();
308-
assertThat(overallPicker.weightedChildPickers).isEqualTo(
309-
ImmutableList.of(new WeightedChildPicker(weights[2], subchannelPickers[2])));
308+
assertThat(overallPicker.weightedChildPickers)
309+
.containsExactly(new WeightedChildPicker(weights[2], subchannelPickers[2]));
310310

311311
// Another child balancer goes to READY.
312312
childHelpers.get(3).updateBalancingState(READY, subchannelPickers[3]);
313313
verify(helper, times(2)).updateBalancingState(eq(READY), pickerCaptor.capture());
314314
overallPicker = (WeightedRandomPicker) pickerCaptor.getValue();
315-
assertThat(overallPicker.weightedChildPickers).isEqualTo(
316-
ImmutableList.of(
315+
assertThat(overallPicker.weightedChildPickers)
316+
.containsExactly(
317317
new WeightedChildPicker(weights[2], subchannelPickers[2]),
318-
new WeightedChildPicker(weights[3], subchannelPickers[3])));
318+
new WeightedChildPicker(weights[3], subchannelPickers[3]));
319319

320320
// Another child balancer goes to READY.
321321
childHelpers.get(0).updateBalancingState(READY, subchannelPickers[0]);
322322
verify(helper, times(3)).updateBalancingState(eq(READY), pickerCaptor.capture());
323323
overallPicker = (WeightedRandomPicker) pickerCaptor.getValue();
324-
assertThat(overallPicker.weightedChildPickers).isEqualTo(
325-
ImmutableList.of(
324+
assertThat(overallPicker.weightedChildPickers)
325+
.containsExactly(
326326
new WeightedChildPicker(weights[0], subchannelPickers[0]),
327327
new WeightedChildPicker(weights[2], subchannelPickers[2]),
328-
new WeightedChildPicker(weights[3], subchannelPickers[3])));
328+
new WeightedChildPicker(weights[3], subchannelPickers[3]));
329329

330330
// One of READY child balancers goes to TRANSIENT_FAILURE.
331331
childHelpers.get(2).updateBalancingState(TRANSIENT_FAILURE, new ErrorPicker(Status.DATA_LOSS));
332332
verify(helper, times(4)).updateBalancingState(eq(READY), pickerCaptor.capture());
333333
overallPicker = (WeightedRandomPicker) pickerCaptor.getValue();
334-
assertThat(overallPicker.weightedChildPickers).isEqualTo(
335-
ImmutableList.of(
334+
assertThat(overallPicker.weightedChildPickers)
335+
.containsExactly(
336336
new WeightedChildPicker(weights[0], subchannelPickers[0]),
337-
new WeightedChildPicker(weights[3], subchannelPickers[3])));
337+
new WeightedChildPicker(weights[3], subchannelPickers[3]));
338338

339339
// All child balancers go to TRANSIENT_FAILURE.
340340
childHelpers.get(3).updateBalancingState(TRANSIENT_FAILURE, new ErrorPicker(Status.DATA_LOSS));

xds/src/test/java/io/grpc/xds/XdsClientImplTestForListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public void tearDown() {
226226
assertThat(fakeClock.getPendingTasks()).isEmpty();
227227
}
228228

229-
private Node getNodeToVerify() {
229+
private static Node getNodeToVerify() {
230230
Struct newMetadata = NODE.getMetadata().toBuilder()
231231
.putFields("listener_inbound_port",
232232
Value.newBuilder().setStringValue("" + PORT).build())

0 commit comments

Comments
 (0)