From 2765da61214f3ae63da3fdb8e362fac625b51c5a Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Thu, 20 Jun 2024 18:26:51 +0000 Subject: [PATCH] remove TestOnlyCopyToVector() from LB metadata API --- src/core/client_channel/lb_metadata.cc | 2 +- src/core/client_channel/lb_metadata.h | 3 +-- src/core/load_balancing/lb_policy.h | 5 ----- test/core/load_balancing/lb_policy_test_lib.h | 5 ----- test/core/test_util/BUILD | 2 ++ test/core/test_util/test_lb_policies.cc | 8 ++++++-- 6 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/core/client_channel/lb_metadata.cc b/src/core/client_channel/lb_metadata.cc index 20814e0918c..d66552d053a 100644 --- a/src/core/client_channel/lb_metadata.cc +++ b/src/core/client_channel/lb_metadata.cc @@ -61,7 +61,7 @@ absl::optional LbMetadata::Lookup( } std::vector> -LbMetadata::TestOnlyCopyToVector() { +LbMetadata::TestOnlyCopyToVector() const { if (batch_ == nullptr) return {}; Encoder encoder; batch_->Encode(&encoder); diff --git a/src/core/client_channel/lb_metadata.h b/src/core/client_channel/lb_metadata.h index bd73d393f0f..6c1fe7eeb7b 100644 --- a/src/core/client_channel/lb_metadata.h +++ b/src/core/client_channel/lb_metadata.h @@ -33,8 +33,7 @@ class LbMetadata : public LoadBalancingPolicy::MetadataInterface { absl::optional Lookup(absl::string_view key, std::string* buffer) const override; - std::vector> TestOnlyCopyToVector() - override; + std::vector> TestOnlyCopyToVector() const; private: grpc_metadata_batch* batch_; diff --git a/src/core/load_balancing/lb_policy.h b/src/core/load_balancing/lb_policy.h index c53795e1b51..600ef9f4498 100644 --- a/src/core/load_balancing/lb_policy.h +++ b/src/core/load_balancing/lb_policy.h @@ -23,7 +23,6 @@ #include #include #include -#include #include "absl/base/thread_annotations.h" #include "absl/container/inlined_vector.h" @@ -120,10 +119,6 @@ class LoadBalancingPolicy : public InternallyRefCounted { virtual absl::optional Lookup( absl::string_view key, std::string* buffer) const = 0; - - /// Produce a vector of metadata key/value strings for tests. - virtual std::vector> - TestOnlyCopyToVector() = 0; }; /// A list of metadata mutations to be returned along with a PickResult. diff --git a/test/core/load_balancing/lb_policy_test_lib.h b/test/core/load_balancing/lb_policy_test_lib.h index 5ff837a8a0a..fcd85c8928e 100644 --- a/test/core/load_balancing/lb_policy_test_lib.h +++ b/test/core/load_balancing/lb_policy_test_lib.h @@ -628,11 +628,6 @@ class LoadBalancingPolicyTest : public ::testing::Test { return it->second; } - std::vector> TestOnlyCopyToVector() - override { - return {}; // Not used. - } - std::map metadata_; }; diff --git a/test/core/test_util/BUILD b/test/core/test_util/BUILD index d2e935f75f4..e0962df86f3 100644 --- a/test/core/test_util/BUILD +++ b/test/core/test_util/BUILD @@ -333,10 +333,12 @@ grpc_cc_library( "//:uri_parser", "//src/core:channel_args", "//src/core:delegating_helper", + "//src/core:down_cast", "//src/core:error", "//src/core:grpc_backend_metric_data", "//src/core:json", "//src/core:json_util", + "//src/core:lb_metadata", "//src/core:lb_policy", "//src/core:lb_policy_factory", "//src/core:lb_policy_registry", diff --git a/test/core/test_util/test_lb_policies.cc b/test/core/test_util/test_lb_policies.cc index aea9e919414..2d674333b12 100644 --- a/test/core/test_util/test_lb_policies.cc +++ b/test/core/test_util/test_lb_policies.cc @@ -30,9 +30,11 @@ #include #include +#include "src/core/client_channel/lb_metadata.h" #include "src/core/lib/address_utils/parse_address.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/config/core_configuration.h" +#include "src/core/lib/gprpp/down_cast.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/status_helper.h" @@ -129,7 +131,8 @@ class TestPickArgsLb : public ForwardingLoadBalancingPolicy { // Report args seen. PickArgsSeen args_seen; args_seen.path = std::string(args.path); - args_seen.metadata = args.initial_metadata->TestOnlyCopyToVector(); + args_seen.metadata = + DownCast(args.initial_metadata)->TestOnlyCopyToVector(); cb_(args_seen); // Do pick. return delegate_picker_->Pick(args); @@ -269,7 +272,8 @@ class InterceptRecvTrailingMetadataLoadBalancingPolicy args_seen.status = args.status; args_seen.backend_metric_data = args.backend_metric_accessor->GetBackendMetricData(); - args_seen.metadata = args.trailing_metadata->TestOnlyCopyToVector(); + args_seen.metadata = + DownCast(args.trailing_metadata)->TestOnlyCopyToVector(); cb_(args_seen); }