Skip to content

Commit

Permalink
remove TestOnlyCopyToVector() from LB metadata API
Browse files Browse the repository at this point in the history
  • Loading branch information
markdroth committed Jun 20, 2024
1 parent 5fe11aa commit 2765da6
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/core/client_channel/lb_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ absl::optional<absl::string_view> LbMetadata::Lookup(
}

std::vector<std::pair<std::string, std::string>>
LbMetadata::TestOnlyCopyToVector() {
LbMetadata::TestOnlyCopyToVector() const {
if (batch_ == nullptr) return {};
Encoder encoder;
batch_->Encode(&encoder);
Expand Down
3 changes: 1 addition & 2 deletions src/core/client_channel/lb_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class LbMetadata : public LoadBalancingPolicy::MetadataInterface {
absl::optional<absl::string_view> Lookup(absl::string_view key,
std::string* buffer) const override;

std::vector<std::pair<std::string, std::string>> TestOnlyCopyToVector()
override;
std::vector<std::pair<std::string, std::string>> TestOnlyCopyToVector() const;

private:
grpc_metadata_batch* batch_;
Expand Down
5 changes: 0 additions & 5 deletions src/core/load_balancing/lb_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "absl/base/thread_annotations.h"
#include "absl/container/inlined_vector.h"
Expand Down Expand Up @@ -120,10 +119,6 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {

virtual absl::optional<absl::string_view> Lookup(
absl::string_view key, std::string* buffer) const = 0;

/// Produce a vector of metadata key/value strings for tests.
virtual std::vector<std::pair<std::string, std::string>>
TestOnlyCopyToVector() = 0;
};

/// A list of metadata mutations to be returned along with a PickResult.
Expand Down
5 changes: 0 additions & 5 deletions test/core/load_balancing/lb_policy_test_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,6 @@ class LoadBalancingPolicyTest : public ::testing::Test {
return it->second;
}

std::vector<std::pair<std::string, std::string>> TestOnlyCopyToVector()
override {
return {}; // Not used.
}

std::map<std::string, std::string> metadata_;
};

Expand Down
2 changes: 2 additions & 0 deletions test/core/test_util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 6 additions & 2 deletions test/core/test_util/test_lb_policies.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
#include <grpc/grpc.h>
#include <grpc/support/json.h>

#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"
Expand Down Expand Up @@ -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<LbMetadata*>(args.initial_metadata)->TestOnlyCopyToVector();
cb_(args_seen);
// Do pick.
return delegate_picker_->Pick(args);
Expand Down Expand Up @@ -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<LbMetadata*>(args.trailing_metadata)->TestOnlyCopyToVector();
cb_(args_seen);
}

Expand Down

0 comments on commit 2765da6

Please sign in to comment.