test_lb_policies.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // Copyright 2018 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. #ifndef GRPC_TEST_CORE_UTIL_TEST_LB_POLICIES_H
  17. #define GRPC_TEST_CORE_UTIL_TEST_LB_POLICIES_H
  18. #include "src/core/ext/filters/client_channel/lb_policy.h"
  19. namespace grpc_core {
  20. using MetadataVector = std::vector<std::pair<std::string, std::string>>;
  21. struct PickArgsSeen {
  22. std::string path;
  23. MetadataVector metadata;
  24. };
  25. using TestPickArgsCallback = std::function<void(const PickArgsSeen&)>;
  26. // Registers an LB policy called "test_pick_args_lb" that passes the args
  27. // passed to SubchannelPicker::Pick() to cb.
  28. void RegisterTestPickArgsLoadBalancingPolicy(
  29. TestPickArgsCallback cb, const char* delegate_policy_name = "pick_first");
  30. struct TrailingMetadataArgsSeen {
  31. absl::Status status;
  32. const LoadBalancingPolicy::BackendMetricAccessor::BackendMetricData*
  33. backend_metric_data;
  34. MetadataVector metadata;
  35. };
  36. using InterceptRecvTrailingMetadataCallback =
  37. std::function<void(const TrailingMetadataArgsSeen&)>;
  38. // Registers an LB policy called "intercept_trailing_metadata_lb" that
  39. // invokes cb when trailing metadata is received for each call.
  40. void RegisterInterceptRecvTrailingMetadataLoadBalancingPolicy(
  41. InterceptRecvTrailingMetadataCallback cb);
  42. using AddressTestCallback = std::function<void(const ServerAddress&)>;
  43. // Registers an LB policy called "address_test_lb" that invokes cb for each
  44. // address used to create a subchannel.
  45. void RegisterAddressTestLoadBalancingPolicy(AddressTestCallback cb);
  46. // Registers an LB policy called "fixed_address_lb" that provides a
  47. // single subchannel whose address is in its configuration.
  48. void RegisterFixedAddressLoadBalancingPolicy();
  49. } // namespace grpc_core
  50. #endif // GRPC_TEST_CORE_UTIL_TEST_LB_POLICIES_H