|
|
@ -29,7 +29,6 @@ |
|
|
|
namespace grpc { |
|
|
|
namespace grpc { |
|
|
|
namespace testing { |
|
|
|
namespace testing { |
|
|
|
namespace { |
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
|
|
AsyncClientCallResult BuildCallResult(int saved_request_id) { |
|
|
|
AsyncClientCallResult BuildCallResult(int saved_request_id) { |
|
|
|
AsyncClientCallResult result; |
|
|
|
AsyncClientCallResult result; |
|
|
|
result.saved_request_id = saved_request_id; |
|
|
|
result.saved_request_id = saved_request_id; |
|
|
@ -37,63 +36,25 @@ AsyncClientCallResult BuildCallResult(int saved_request_id) { |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LoadBalancerStatsResponse::MetadataByPeer BuildMetadatas( |
|
|
|
TEST(XdsStatsWatcherTest, CollectsMetadata) { |
|
|
|
const std::initializer_list< |
|
|
|
XdsStatsWatcher watcher(0, 3); |
|
|
|
std::initializer_list<std::pair<std::string, std::string>>>& values) { |
|
|
|
watcher.RpcCompleted(BuildCallResult(0), "peer1"); |
|
|
|
LoadBalancerStatsResponse::MetadataByPeer metadata_by_peer; |
|
|
|
watcher.RpcCompleted(BuildCallResult(1), "peer1"); |
|
|
|
for (const auto& per_rpc : values) { |
|
|
|
watcher.RpcCompleted(BuildCallResult(2), "peer2"); |
|
|
|
auto rpc_metadata = metadata_by_peer.add_rpc_metadata(); |
|
|
|
LoadBalancerStatsResponse lb_response; |
|
|
|
for (const auto& key_value : per_rpc) { |
|
|
|
watcher.WaitForRpcStatsResponse(&lb_response, 1); |
|
|
|
auto entry = rpc_metadata->add_metadata(); |
|
|
|
EXPECT_EQ( |
|
|
|
entry->set_key(key_value.first); |
|
|
|
(std::multimap<std::string, int32_t>(lb_response.rpcs_by_peer().begin(), |
|
|
|
entry->set_value(key_value.second); |
|
|
|
lb_response.rpcs_by_peer().end())), |
|
|
|
} |
|
|
|
(std::multimap<std::string, int32_t>({{"peer1", 2}, {"peer2", 1}}))); |
|
|
|
} |
|
|
|
EXPECT_EQ(lb_response.rpcs_by_method_size(), 1); |
|
|
|
return metadata_by_peer; |
|
|
|
auto rpcs = lb_response.rpcs_by_method().find("UnaryCall"); |
|
|
|
} |
|
|
|
EXPECT_NE(rpcs, lb_response.rpcs_by_method().end()); |
|
|
|
|
|
|
|
std::multimap<std::string, int32_t> by_peer( |
|
|
|
TEST(XdsStatsWatcherTest, WaitForRpcStatsResponse) { |
|
|
|
rpcs->second.rpcs_by_peer().begin(), rpcs->second.rpcs_by_peer().end()); |
|
|
|
// "k3" will be ignored
|
|
|
|
EXPECT_EQ( |
|
|
|
XdsStatsWatcher watcher(0, 3, {"k1", "k2"}); |
|
|
|
by_peer, |
|
|
|
watcher.RpcCompleted(BuildCallResult(0), "peer1", |
|
|
|
(std::multimap<std::string, int32_t>({{"peer1", 2}, {"peer2", 1}}))); |
|
|
|
{{"k1", "v1"}, {"k2", "v2"}, {"k3", "v3"}}); |
|
|
|
|
|
|
|
watcher.RpcCompleted(BuildCallResult(1), "peer1", {{"k1", "v4"}}); |
|
|
|
|
|
|
|
watcher.RpcCompleted(BuildCallResult(2), "peer2", |
|
|
|
|
|
|
|
{{"k1", "v5"}, {"k2", "v6"}, {"k3", "v7"}}); |
|
|
|
|
|
|
|
LoadBalancerStatsResponse expected; |
|
|
|
|
|
|
|
expected.mutable_rpcs_by_peer()->insert({{"peer1", 2}, {"peer2", 1}}); |
|
|
|
|
|
|
|
expected.mutable_metadatas_by_peer()->insert({ |
|
|
|
|
|
|
|
{"peer1", BuildMetadatas({{{"k1", "v1"}, {"k2", "v2"}}, {{"k1", "v4"}}})}, |
|
|
|
|
|
|
|
{"peer2", BuildMetadatas({{{"k1", "v5"}, {"k2", "v6"}}})}, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
(*expected.mutable_rpcs_by_method())["UnaryCall"] |
|
|
|
|
|
|
|
.mutable_rpcs_by_peer() |
|
|
|
|
|
|
|
->insert({{"peer1", 2}, {"peer2", 1}}); |
|
|
|
|
|
|
|
EXPECT_EQ(watcher.WaitForRpcStatsResponse(0).DebugString(), |
|
|
|
|
|
|
|
expected.DebugString()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST(XdsStatsWatcherTest, WaitForRpcStatsResponseIgnoresMetadata) { |
|
|
|
|
|
|
|
XdsStatsWatcher watcher(0, 3, {}); |
|
|
|
|
|
|
|
// RPC had metadata - but watcher should ignore it
|
|
|
|
|
|
|
|
watcher.RpcCompleted(BuildCallResult(0), "peer1", |
|
|
|
|
|
|
|
{{"k1", "v1"}, {"k2", "v2"}, {"k3", "v3"}}); |
|
|
|
|
|
|
|
// No metadata came with RPC
|
|
|
|
|
|
|
|
watcher.RpcCompleted(BuildCallResult(1), "peer1", {}); |
|
|
|
|
|
|
|
watcher.RpcCompleted(BuildCallResult(2), "peer2", |
|
|
|
|
|
|
|
{{"k1", "v5"}, {"k2", "v6"}, {"k3", "v7"}}); |
|
|
|
|
|
|
|
LoadBalancerStatsResponse expected; |
|
|
|
|
|
|
|
expected.mutable_rpcs_by_peer()->insert({{"peer1", 2}, {"peer2", 1}}); |
|
|
|
|
|
|
|
// There will still be an empty metadata collection for each RPC
|
|
|
|
|
|
|
|
expected.mutable_metadatas_by_peer()->insert({ |
|
|
|
|
|
|
|
{"peer1", BuildMetadatas({{}, {}})}, |
|
|
|
|
|
|
|
{"peer2", BuildMetadatas({{}})}, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
(*expected.mutable_rpcs_by_method())["UnaryCall"] |
|
|
|
|
|
|
|
.mutable_rpcs_by_peer() |
|
|
|
|
|
|
|
->insert({{"peer1", 2}, {"peer2", 1}}); |
|
|
|
|
|
|
|
EXPECT_EQ(watcher.WaitForRpcStatsResponse(0).DebugString(), |
|
|
|
|
|
|
|
expected.DebugString()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace
|
|
|
|