GRPC C++  1.39.1
fake_resolver.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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 #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_FAKE_FAKE_RESOLVER_H
18 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_FAKE_FAKE_RESOLVER_H
19 
21 
26 
27 #define GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR \
28  "grpc.fake_resolver.response_generator"
29 
30 namespace grpc_core {
31 
32 class FakeResolver;
33 
38 // TODO(roth): I would ideally like this to be InternallyRefCounted
39 // instead of RefCounted, but external refs are currently needed to
40 // encode this in channel args. Once channel_args are converted to C++,
41 // see if we can find a way to fix this.
43  : public RefCounted<FakeResolverResponseGenerator> {
44  public:
46 
49 
50  // Instructs the fake resolver associated with the response generator
51  // instance to trigger a new resolution with the specified result. If the
52  // resolver is not available yet, delays response setting until it is. This
53  // can be called at most once before the resolver is available.
54  void SetResponse(Resolver::Result result);
55 
56  // Sets the re-resolution response, which is returned by the fake resolver
57  // when re-resolution is requested (via \a RequestReresolutionLocked()).
58  // The new re-resolution response replaces any previous re-resolution
59  // response that may have been set by a previous call.
61 
62  // Unsets the re-resolution response. After this, the fake resolver will
63  // not return anything when \a RequestReresolutionLocked() is called.
65 
66  // Tells the resolver to return a transient failure.
67  void SetFailure();
68 
69  // Same as SetFailure(), but instead of returning the error
70  // immediately, waits for the next call to RequestReresolutionLocked().
72 
73  // Returns a channel arg containing \a generator.
74  // TODO(roth): When we have time, make this a non-static method.
76 
77  // Returns the response generator in \a args, or null if not found.
79  const grpc_channel_args* args);
80 
81  private:
82  friend class FakeResolver;
83  // Set the corresponding FakeResolver to this generator.
84  void SetFakeResolver(RefCountedPtr<FakeResolver> resolver);
85 
86  // Mutex protecting the members below.
87  Mutex mu_;
88  RefCountedPtr<FakeResolver> resolver_ ABSL_GUARDED_BY(mu_);
89  Resolver::Result result_ ABSL_GUARDED_BY(mu_);
90  bool has_result_ ABSL_GUARDED_BY(mu_) = false;
91 };
92 
93 } // namespace grpc_core
94 
95 #endif // GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_FAKE_FAKE_RESOLVER_H
Definition: fake_resolver.cc:50
A mechanism for generating responses for the fake resolver.
Definition: fake_resolver.h:43
void SetResponse(Resolver::Result result)
Definition: fake_resolver.cc:229
static RefCountedPtr< FakeResolverResponseGenerator > GetFromArgs(const grpc_channel_args *args)
Definition: fake_resolver.cc:344
void SetFailure()
Definition: fake_resolver.cc:273
void UnsetReresolutionResponse()
Definition: fake_resolver.cc:260
void SetFailureOnReresolution()
Definition: fake_resolver.cc:286
static grpc_arg MakeChannelArg(FakeResolverResponseGenerator *generator)
Definition: fake_resolver.cc:336
void SetReresolutionResponse(Resolver::Result result)
Definition: fake_resolver.cc:246
~FakeResolverResponseGenerator() override
Definition: fake_resolver.cc:227
FakeResolverResponseGenerator()
Definition: fake_resolver.cc:225
static const grpc_arg_pointer_vtable kChannelArgPointerVtable
Definition: fake_resolver.h:45
Definition: sync.h:59
Definition: ref_counted.h:282
Definition: ref_counted_ptr.h:35
Round Robin Policy.
Definition: backend_metric.cc:26
Definition: grpc_types.h:85
A single argument...
Definition: grpc_types.h:103
An array of arguments that can be passed around.
Definition: grpc_types.h:132
Results returned by the resolver.
Definition: resolver.h:55