• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

grpc / grpc-java / #19904

14 Jul 2025 02:05PM UTC coverage: 88.591% (+0.06%) from 88.53%
#19904

push

github

ejona86
xds: Check isHttp11ProxyAvailable in equals()

This fixes an equals/hashCode bug introduced in 12197065fe.

Discovered when investigating b/430347751

34672 of 39137 relevant lines covered (88.59%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.45
/../xds/src/main/java/io/grpc/xds/ClusterResolverLoadBalancerProvider.java
1
/*
2
 * Copyright 2020 The gRPC Authors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package io.grpc.xds;
18

19
import static com.google.common.base.Preconditions.checkNotNull;
20

21
import com.google.common.base.MoreObjects;
22
import com.google.common.collect.ImmutableMap;
23
import com.google.protobuf.Struct;
24
import io.grpc.Internal;
25
import io.grpc.LoadBalancer;
26
import io.grpc.LoadBalancer.Helper;
27
import io.grpc.LoadBalancerProvider;
28
import io.grpc.NameResolver.ConfigOrError;
29
import io.grpc.Status;
30
import io.grpc.xds.EnvoyServerProtoData.OutlierDetection;
31
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext;
32
import io.grpc.xds.client.Bootstrapper.ServerInfo;
33
import java.util.List;
34
import java.util.Map;
35
import java.util.Objects;
36
import javax.annotation.Nullable;
37

38
/**
39
 * The provider for the cluster_resolver load balancing policy. This class should not be directly
40
 * referenced in code.  The policy should be accessed through
41
 * {@link io.grpc.LoadBalancerRegistry#getProvider} with the name "cluster_resolver_experimental".
42
 */
43
@Internal
44
public final class ClusterResolverLoadBalancerProvider extends LoadBalancerProvider {
1✔
45

46
  @Override
47
  public boolean isAvailable() {
48
    return true;
1✔
49
  }
50

51
  @Override
52
  public int getPriority() {
53
    return 5;
1✔
54
  }
55

56
  @Override
57
  public String getPolicyName() {
58
    return XdsLbPolicies.CLUSTER_RESOLVER_POLICY_NAME;
1✔
59
  }
60

61
  @Override
62
  public ConfigOrError parseLoadBalancingPolicyConfig(Map<String, ?> rawLoadBalancingPolicyConfig) {
63
    return ConfigOrError.fromError(
×
64
        Status.INTERNAL.withDescription(getPolicyName() + " cannot be used from service config"));
×
65
  }
66

67
  @Override
68
  public LoadBalancer newLoadBalancer(Helper helper) {
69
    return new ClusterResolverLoadBalancer(helper);
1✔
70
  }
71

72
  static final class ClusterResolverConfig {
73
    // Ordered list of clusters to be resolved.
74
    final List<DiscoveryMechanism> discoveryMechanisms;
75
    // GracefulSwitch configuration
76
    final Object lbConfig;
77
    private final boolean isHttp11ProxyAvailable;
78

79
    ClusterResolverConfig(List<DiscoveryMechanism> discoveryMechanisms, Object lbConfig,
80
        boolean isHttp11ProxyAvailable) {
1✔
81
      this.discoveryMechanisms = checkNotNull(discoveryMechanisms, "discoveryMechanisms");
1✔
82
      this.lbConfig = checkNotNull(lbConfig, "lbConfig");
1✔
83
      this.isHttp11ProxyAvailable = isHttp11ProxyAvailable;
1✔
84
    }
1✔
85

86
    boolean isHttp11ProxyAvailable() {
87
      return isHttp11ProxyAvailable;
1✔
88
    }
89

90
    @Override
91
    public int hashCode() {
92
      return Objects.hash(discoveryMechanisms, lbConfig, isHttp11ProxyAvailable);
1✔
93
    }
94

95
    @Override
96
    public boolean equals(Object o) {
97
      if (this == o) {
1✔
98
        return true;
1✔
99
      }
100
      if (o == null || getClass() != o.getClass()) {
1✔
101
        return false;
1✔
102
      }
103
      ClusterResolverConfig that = (ClusterResolverConfig) o;
1✔
104
      return discoveryMechanisms.equals(that.discoveryMechanisms)
1✔
105
          && lbConfig.equals(that.lbConfig)
1✔
106
          && isHttp11ProxyAvailable == that.isHttp11ProxyAvailable;
107
    }
108

109
    @Override
110
    public String toString() {
111
      return MoreObjects.toStringHelper(this)
1✔
112
          .add("discoveryMechanisms", discoveryMechanisms)
1✔
113
          .add("lbConfig", lbConfig)
1✔
114
          .add("isHttp11ProxyAvailable", isHttp11ProxyAvailable)
1✔
115
          .toString();
1✔
116
    }
117

118
    // Describes the mechanism for a specific cluster.
119
    static final class DiscoveryMechanism {
120
      // Name of the cluster to resolve.
121
      final String cluster;
122
      // Type of the cluster.
123
      final Type type;
124
      // Load reporting server info. Null if not enabled.
125
      @Nullable
126
      final ServerInfo lrsServerInfo;
127
      // Cluster-level max concurrent request threshold. Null if not specified.
128
      @Nullable
129
      final Long maxConcurrentRequests;
130
      // TLS context for connections to endpoints in the cluster.
131
      @Nullable
132
      final UpstreamTlsContext tlsContext;
133
      // Resource name for resolving endpoints via EDS. Only valid for EDS clusters.
134
      @Nullable
135
      final String edsServiceName;
136
      // Hostname for resolving endpoints via DNS. Only valid for LOGICAL_DNS clusters.
137
      @Nullable
138
      final String dnsHostName;
139
      @Nullable
140
      final OutlierDetection outlierDetection;
141
      final Map<String, Struct> filterMetadata;
142

143
      enum Type {
1✔
144
        EDS,
1✔
145
        LOGICAL_DNS,
1✔
146
      }
147

148
      private DiscoveryMechanism(String cluster, Type type, @Nullable String edsServiceName,
149
          @Nullable String dnsHostName, @Nullable ServerInfo lrsServerInfo,
150
          @Nullable Long maxConcurrentRequests, @Nullable UpstreamTlsContext tlsContext,
151
          Map<String, Struct> filterMetadata, @Nullable OutlierDetection outlierDetection) {
1✔
152
        this.cluster = checkNotNull(cluster, "cluster");
1✔
153
        this.type = checkNotNull(type, "type");
1✔
154
        this.edsServiceName = edsServiceName;
1✔
155
        this.dnsHostName = dnsHostName;
1✔
156
        this.lrsServerInfo = lrsServerInfo;
1✔
157
        this.maxConcurrentRequests = maxConcurrentRequests;
1✔
158
        this.tlsContext = tlsContext;
1✔
159
        this.filterMetadata = ImmutableMap.copyOf(checkNotNull(filterMetadata, "filterMetadata"));
1✔
160
        this.outlierDetection = outlierDetection;
1✔
161
      }
1✔
162

163
      static DiscoveryMechanism forEds(String cluster, @Nullable String edsServiceName,
164
          @Nullable ServerInfo lrsServerInfo, @Nullable Long maxConcurrentRequests,
165
          @Nullable UpstreamTlsContext tlsContext, Map<String, Struct> filterMetadata,
166
          OutlierDetection outlierDetection) {
167
        return new DiscoveryMechanism(cluster, Type.EDS, edsServiceName, null, lrsServerInfo,
1✔
168
            maxConcurrentRequests, tlsContext, filterMetadata, outlierDetection);
169
      }
170

171
      static DiscoveryMechanism forLogicalDns(String cluster, String dnsHostName,
172
          @Nullable ServerInfo lrsServerInfo, @Nullable Long maxConcurrentRequests,
173
          @Nullable UpstreamTlsContext tlsContext, Map<String, Struct> filterMetadata) {
174
        return new DiscoveryMechanism(cluster, Type.LOGICAL_DNS, null, dnsHostName,
1✔
175
            lrsServerInfo, maxConcurrentRequests, tlsContext, filterMetadata, null);
176
      }
177

178
      @Override
179
      public int hashCode() {
180
        return Objects.hash(cluster, type, lrsServerInfo, maxConcurrentRequests, tlsContext,
1✔
181
            edsServiceName, dnsHostName, filterMetadata, outlierDetection);
182
      }
183

184
      @Override
185
      public boolean equals(Object o) {
186
        if (this == o) {
1✔
187
          return true;
1✔
188
        }
189
        if (o == null || getClass() != o.getClass()) {
1✔
190
          return false;
×
191
        }
192
        DiscoveryMechanism that = (DiscoveryMechanism) o;
1✔
193
        return cluster.equals(that.cluster)
1✔
194
            && type == that.type
195
            && Objects.equals(edsServiceName, that.edsServiceName)
1✔
196
            && Objects.equals(dnsHostName, that.dnsHostName)
1✔
197
            && Objects.equals(lrsServerInfo, that.lrsServerInfo)
1✔
198
            && Objects.equals(maxConcurrentRequests, that.maxConcurrentRequests)
1✔
199
            && Objects.equals(tlsContext, that.tlsContext)
1✔
200
            && Objects.equals(filterMetadata, that.filterMetadata)
1✔
201
            && Objects.equals(outlierDetection, that.outlierDetection);
1✔
202
      }
203

204
      @Override
205
      public String toString() {
206
        MoreObjects.ToStringHelper toStringHelper =
1✔
207
            MoreObjects.toStringHelper(this)
1✔
208
                .add("cluster", cluster)
1✔
209
                .add("type", type)
1✔
210
                .add("edsServiceName", edsServiceName)
1✔
211
                .add("dnsHostName", dnsHostName)
1✔
212
                .add("lrsServerInfo", lrsServerInfo)
1✔
213
                // Exclude tlsContext as its string representation is cumbersome.
214
                .add("maxConcurrentRequests", maxConcurrentRequests)
1✔
215
                .add("filterMetadata", filterMetadata)
1✔
216
                // Exclude outlierDetection as its string representation is long.
217
                ;
218
        return toStringHelper.toString();
1✔
219
      }
220
    }
221
  }
222
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc