test_health_check_service_impl.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #include <map>
  21. #include <mutex>
  22. #include <grpcpp/server_context.h>
  23. #include <grpcpp/support/status.h>
  24. #include "src/proto/grpc/health/v1/health.grpc.pb.h"
  25. namespace grpc {
  26. namespace testing {
  27. // A sample sync implementation of the health checking service. This does the
  28. // same thing as the default one.
  29. class HealthCheckServiceImpl : public health::v1::Health::Service {
  30. public:
  31. Status Check(ServerContext* context,
  32. const health::v1::HealthCheckRequest* request,
  33. health::v1::HealthCheckResponse* response) override;
  34. Status Watch(ServerContext* context,
  35. const health::v1::HealthCheckRequest* request,
  36. ServerWriter<health::v1::HealthCheckResponse>* writer) override;
  37. void SetStatus(const std::string& service_name,
  38. health::v1::HealthCheckResponse::ServingStatus status);
  39. void SetAll(health::v1::HealthCheckResponse::ServingStatus status);
  40. void Shutdown();
  41. private:
  42. std::mutex mu_;
  43. bool shutdown_ = false;
  44. std::map<const std::string, health::v1::HealthCheckResponse::ServingStatus>
  45. status_map_;
  46. };
  47. } // namespace testing
  48. } // namespace grpc
  49. #endif // GRPC_TEST_CPP_END2END_TEST_HEALTH_CHECK_SERVICE_IMPL_H