xref: /aosp_15_r20/external/grpc-grpc/test/cpp/end2end/test_health_check_service_impl.h (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1 //
2 //
3 // Copyright 2018 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18 #ifndef GRPC_TEST_CPP_END2END_TEST_HEALTH_CHECK_SERVICE_IMPL_H
19 #define GRPC_TEST_CPP_END2END_TEST_HEALTH_CHECK_SERVICE_IMPL_H
20 
21 #include <map>
22 #include <mutex>
23 
24 #include <grpcpp/server_context.h>
25 #include <grpcpp/support/status.h>
26 
27 #include "src/proto/grpc/health/v1/health.grpc.pb.h"
28 
29 namespace grpc {
30 namespace testing {
31 
32 // A sample sync implementation of the health checking service. This does the
33 // same thing as the default one.
34 class HealthCheckServiceImpl : public health::v1::Health::Service {
35  public:
36   Status Check(ServerContext* context,
37                const health::v1::HealthCheckRequest* request,
38                health::v1::HealthCheckResponse* response) override;
39   Status Watch(ServerContext* context,
40                const health::v1::HealthCheckRequest* request,
41                ServerWriter<health::v1::HealthCheckResponse>* writer) override;
42   void SetStatus(const std::string& service_name,
43                  health::v1::HealthCheckResponse::ServingStatus status);
44   void SetAll(health::v1::HealthCheckResponse::ServingStatus status);
45 
46   void Shutdown();
47 
48  private:
49   std::mutex mu_;
50   bool shutdown_ = false;
51   std::map<const std::string, health::v1::HealthCheckResponse::ServingStatus>
52       status_map_;
53 };
54 
55 }  // namespace testing
56 }  // namespace grpc
57 
58 #endif  // GRPC_TEST_CPP_END2END_TEST_HEALTH_CHECK_SERVICE_IMPL_H
59