counted_service.h
Go to the documentation of this file.
1 //
2 // Copyright 2017 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_TEST_CPP_END2END_COUNTED_SERVICE_H
18 #define GRPC_TEST_CPP_END2END_COUNTED_SERVICE_H
19 
21 
22 namespace grpc {
23 namespace testing {
24 
25 // A wrapper around an RPC service implementation that provides request and
26 // response counting.
27 template <typename ServiceType>
28 class CountedService : public ServiceType {
29  public:
30  size_t request_count() {
32  return request_count_;
33  }
34 
35  size_t response_count() {
37  return response_count_;
38  }
39 
42  ++response_count_;
43  }
47  }
48 
49  void ResetCounters() {
51  request_count_ = 0;
52  response_count_ = 0;
53  }
54 
55  private:
58  size_t response_count_ ABSL_GUARDED_BY(mu_) = 0;
59 };
60 
61 } // namespace testing
62 } // namespace grpc
63 
64 #endif // GRPC_TEST_CPP_END2END_COUNTED_SERVICE_H
grpc::testing::CountedService::request_count
size_t request_count()
Definition: counted_service.h:30
testing
Definition: aws_request_signer_test.cc:25
grpc
Definition: grpcpp/alarm.h:33
grpc_core::MutexLock
Definition: src/core/lib/gprpp/sync.h:88
grpc::testing::CountedService::IncreaseResponseCount
void IncreaseResponseCount()
Definition: counted_service.h:40
grpc::testing::CountedService::response_count
size_t response_count()
Definition: counted_service.h:35
grpc::testing::CountedService::IncreaseRequestCount
void IncreaseRequestCount()
Definition: counted_service.h:44
grpc::testing::CountedService::mu_
grpc_core::Mutex mu_
Definition: counted_service.h:56
grpc_core::Mutex
Definition: src/core/lib/gprpp/sync.h:61
request_count_
int request_count_
Definition: client_lb_end2end_test.cc:135
grpc::testing::CountedService
Definition: counted_service.h:28
grpc::testing::CountedService::ABSL_GUARDED_BY
size_t request_count_ ABSL_GUARDED_BY(mu_)=0
grpc::testing::CountedService::ResetCounters
void ResetCounters()
Definition: counted_service.h:49
sync.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:57