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

grpc / grpc-java / #19863

13 Jun 2025 03:20PM UTC coverage: 88.555% (-0.02%) from 88.578%
#19863

push

github

ejona86
core: Remove RetryingNR.RESOLUTION_RESULT_LISTENER_KEY

It was introduced in fcb5c54e4 because at the time we didn't change the
API to communicate the status. When onResult2() was introduced in
90d0fabb1 this hack stopped being necessary.

34539 of 39003 relevant lines covered (88.55%)

0.89 hits per line

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

92.59
/../core/src/main/java/io/grpc/internal/RetryingNameResolver.java
1
/*
2
 * Copyright 2023 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 com.google.common.annotations.VisibleForTesting;
20
import io.grpc.NameResolver;
21
import io.grpc.Status;
22
import io.grpc.SynchronizationContext;
23

24
/**
25
 * This wrapper class can add retry capability to any polling {@link NameResolver} implementation
26
 * that supports calling {@link ResolutionResultListener}s with the outcome of each resolution.
27
 *
28
 * <p>The {@link NameResolver} used with this
29
 */
30
final class RetryingNameResolver extends ForwardingNameResolver {
31

32
  private final NameResolver retriedNameResolver;
33
  private final RetryScheduler retryScheduler;
34
  private final SynchronizationContext syncContext;
35

36

37
  /**
38
   * Creates a new {@link RetryingNameResolver}.
39
   *
40
   * @param retriedNameResolver A {@link NameResolver} that will have failed attempt retried.
41
   * @param retryScheduler Used to schedule the retry attempts.
42
   */
43
  RetryingNameResolver(NameResolver retriedNameResolver, RetryScheduler retryScheduler,
44
      SynchronizationContext syncContext) {
45
    super(retriedNameResolver);
1✔
46
    this.retriedNameResolver = retriedNameResolver;
1✔
47
    this.retryScheduler = retryScheduler;
1✔
48
    this.syncContext = syncContext;
1✔
49
  }
1✔
50

51
  @Override
52
  public void start(Listener2 listener) {
53
    super.start(new RetryingListener(listener));
1✔
54
  }
1✔
55

56
  @Override
57
  public void shutdown() {
58
    super.shutdown();
1✔
59
    retryScheduler.reset();
1✔
60
  }
1✔
61

62
  /**
63
   * Used to get the underlying {@link NameResolver} that is getting its failed attempts retried.
64
   */
65
  @VisibleForTesting
66
  NameResolver getRetriedNameResolver() {
67
    return retriedNameResolver;
1✔
68
  }
69

70
  @VisibleForTesting
71
  class DelayedNameResolverRefresh implements Runnable {
1✔
72
    @Override
73
    public void run() {
74
      refresh();
×
75
    }
×
76
  }
77

78
  private class RetryingListener extends Listener2 {
79
    private Listener2 delegateListener;
80

81
    RetryingListener(Listener2 delegateListener) {
1✔
82
      this.delegateListener = delegateListener;
1✔
83
    }
1✔
84

85
    @Override
86
    public void onResult(ResolutionResult resolutionResult) {
87
      syncContext.execute(() -> onResult2(resolutionResult));
1✔
88
    }
1✔
89

90
    @Override
91
    public Status onResult2(ResolutionResult resolutionResult) {
92
      Status status = delegateListener.onResult2(resolutionResult);
1✔
93
      if (status.isOk()) {
1✔
94
        retryScheduler.reset();
1✔
95
      } else {
96
        retryScheduler.schedule(new DelayedNameResolverRefresh());
1✔
97
      }
98
      return status;
1✔
99
    }
100

101
    @Override
102
    public void onError(Status error) {
103
      delegateListener.onError(error);
1✔
104
      syncContext.execute(() -> retryScheduler.schedule(new DelayedNameResolverRefresh()));
1✔
105
    }
1✔
106
  }
107
}
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