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

grpc / grpc-java / #18940

12 Dec 2023 10:50PM CUT coverage: 88.309% (+0.005%) from 88.304%
#18940

push

github

web-flow
core: de-expermentalize pick first config parsing (#10531) (#10742)

Co-authored-by: Terry Wilson <tmwilson@google.com>

30336 of 34352 relevant lines covered (88.31%)

0.88 hits per line

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

63.64
/../core/src/main/java/io/grpc/internal/PickFirstLoadBalancerProvider.java
1
/*
2
 * Copyright 2018 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.internal;
18

19
import io.grpc.LoadBalancer;
20
import io.grpc.LoadBalancerProvider;
21
import io.grpc.NameResolver;
22
import io.grpc.NameResolver.ConfigOrError;
23
import io.grpc.Status;
24
import io.grpc.internal.PickFirstLoadBalancer.PickFirstLoadBalancerConfig;
25
import java.util.Map;
26

27
/**
28
 * Provider for the "pick_first" balancing policy.
29
 *
30
 * <p>This provides no load-balancing over the addresses from the {@link NameResolver}.  It walks
31
 * down the address list and sticks to the first that works.
32
 */
33
public final class PickFirstLoadBalancerProvider extends LoadBalancerProvider {
1✔
34
  private static final String SHUFFLE_ADDRESS_LIST_KEY = "shuffleAddressList";
35

36
  @Override
37
  public boolean isAvailable() {
38
    return true;
1✔
39
  }
40

41
  @Override
42
  public int getPriority() {
43
    return 5;
1✔
44
  }
45

46
  @Override
47
  public String getPolicyName() {
48
    return "pick_first";
1✔
49
  }
50

51
  @Override
52
  public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) {
53
    return new PickFirstLoadBalancer(helper);
1✔
54
  }
55

56
  @Override
57
  public ConfigOrError parseLoadBalancingPolicyConfig(
58
      Map<String, ?> rawLoadBalancingPolicyConfig) {
59
    try {
60
      return ConfigOrError.fromConfig(
1✔
61
          new PickFirstLoadBalancerConfig(JsonUtil.getBoolean(rawLoadBalancingPolicyConfig,
1✔
62
              SHUFFLE_ADDRESS_LIST_KEY)));
63
    } catch (RuntimeException e) {
×
64
      return ConfigOrError.fromError(
×
65
          Status.UNAVAILABLE.withCause(e).withDescription(
×
66
              "Failed parsing configuration for " + getPolicyName()));
×
67
    }
68
  }
69
}
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

© 2025 Coveralls, Inc