diff options
author | heretic <heretic@yandex-team.ru> | 2022-02-10 16:45:43 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:43 +0300 |
commit | 397cbe258b9e064f49c4ca575279f02f39fef76e (patch) | |
tree | a0b0eb3cca6a14e4e8ea715393637672fa651284 /contrib/libs/grpc/test/cpp/util | |
parent | 43f5a35593ebc9f6bcea619bb170394ea7ae468e (diff) | |
download | ydb-397cbe258b9e064f49c4ca575279f02f39fef76e.tar.gz |
Restoring authorship annotation for <heretic@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/grpc/test/cpp/util')
37 files changed, 1448 insertions, 1448 deletions
diff --git a/contrib/libs/grpc/test/cpp/util/.yandex_meta/licenses.list.txt b/contrib/libs/grpc/test/cpp/util/.yandex_meta/licenses.list.txt index d2dadabed9..d41622f4e5 100644 --- a/contrib/libs/grpc/test/cpp/util/.yandex_meta/licenses.list.txt +++ b/contrib/libs/grpc/test/cpp/util/.yandex_meta/licenses.list.txt @@ -1,32 +1,32 @@ -====================Apache-2.0==================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - - -====================COPYRIGHT==================== - * Copyright 2015 gRPC authors. - - -====================COPYRIGHT==================== - * Copyright 2015-2016 gRPC authors. - - -====================COPYRIGHT==================== - * Copyright 2016 gRPC authors. - - -====================COPYRIGHT==================== - * Copyright 2017 gRPC authors. - - -====================COPYRIGHT==================== - * Copyright 2018 gRPC authors. +====================Apache-2.0==================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + + +====================COPYRIGHT==================== + * Copyright 2015 gRPC authors. + + +====================COPYRIGHT==================== + * Copyright 2015-2016 gRPC authors. + + +====================COPYRIGHT==================== + * Copyright 2016 gRPC authors. + + +====================COPYRIGHT==================== + * Copyright 2017 gRPC authors. + + +====================COPYRIGHT==================== + * Copyright 2018 gRPC authors. diff --git a/contrib/libs/grpc/test/cpp/util/byte_buffer_proto_helper.cc b/contrib/libs/grpc/test/cpp/util/byte_buffer_proto_helper.cc index 5971b53075..cad822c1f9 100644 --- a/contrib/libs/grpc/test/cpp/util/byte_buffer_proto_helper.cc +++ b/contrib/libs/grpc/test/cpp/util/byte_buffer_proto_helper.cc @@ -24,7 +24,7 @@ namespace testing { bool ParseFromByteBuffer(ByteBuffer* buffer, grpc::protobuf::Message* message) { std::vector<Slice> slices; (void)buffer->Dump(&slices); - TString buf; + TString buf; buf.reserve(buffer->Length()); for (auto s = slices.begin(); s != slices.end(); s++) { buf.append(reinterpret_cast<const char*>(s->begin()), s->size()); @@ -34,7 +34,7 @@ bool ParseFromByteBuffer(ByteBuffer* buffer, grpc::protobuf::Message* message) { std::unique_ptr<ByteBuffer> SerializeToByteBuffer( grpc::protobuf::Message* message) { - TString buf; + TString buf; message->SerializeToString(&buf); Slice slice(buf); return std::unique_ptr<ByteBuffer>(new ByteBuffer(&slice, 1)); @@ -42,7 +42,7 @@ std::unique_ptr<ByteBuffer> SerializeToByteBuffer( bool SerializeToByteBufferInPlace(grpc::protobuf::Message* message, ByteBuffer* buffer) { - TString buf; + TString buf; if (!message->SerializeToString(&buf)) { return false; } diff --git a/contrib/libs/grpc/test/cpp/util/byte_buffer_test.cc b/contrib/libs/grpc/test/cpp/util/byte_buffer_test.cc index c63f351a8f..39f80086bd 100644 --- a/contrib/libs/grpc/test/cpp/util/byte_buffer_test.cc +++ b/contrib/libs/grpc/test/cpp/util/byte_buffer_test.cc @@ -27,8 +27,8 @@ #include <grpcpp/support/slice.h> #include <gtest/gtest.h> -#include "test/core/util/test_config.h" - +#include "test/core/util/test_config.h" + namespace grpc { static internal::GrpcLibraryInitializer g_gli_initializer; @@ -127,7 +127,7 @@ TEST_F(ByteBufferTest, SerializationMakesCopy) { } // namespace grpc int main(int argc, char** argv) { - grpc::testing::TestEnvironment env(argc, argv); + grpc::testing::TestEnvironment env(argc, argv); ::testing::InitGoogleTest(&argc, argv); int ret = RUN_ALL_TESTS(); return ret; diff --git a/contrib/libs/grpc/test/cpp/util/channel_trace_proto_helper.cc b/contrib/libs/grpc/test/cpp/util/channel_trace_proto_helper.cc index d4b4026774..78ed41c18c 100644 --- a/contrib/libs/grpc/test/cpp/util/channel_trace_proto_helper.cc +++ b/contrib/libs/grpc/test/cpp/util/channel_trace_proto_helper.cc @@ -26,8 +26,8 @@ #include <grpcpp/impl/codegen/config_protobuf.h> #include <gtest/gtest.h> -#include "src/core/lib/iomgr/error.h" -#include "src/core/lib/json/json.h" +#include "src/core/lib/iomgr/error.h" +#include "src/core/lib/json/json.h" #include "src/proto/grpc/channelz/channelz.pb.h" namespace grpc { @@ -38,7 +38,7 @@ namespace { // then back to json. This ensures that the json string was correctly formatted // according to https://developers.google.com/protocol-buffers/docs/proto3#json template <typename Message> -void VaidateProtoJsonTranslation(const TString& json_str) { +void VaidateProtoJsonTranslation(const TString& json_str) { Message msg; grpc::protobuf::json::JsonParseOptions parse_options; // If the following line is failing, then uncomment the last line of the @@ -49,21 +49,21 @@ void VaidateProtoJsonTranslation(const TString& json_str) { grpc::protobuf::util::Status s = grpc::protobuf::json::JsonStringToMessage(json_str, &msg, parse_options); EXPECT_TRUE(s.ok()); - TString proto_json_str; + TString proto_json_str; grpc::protobuf::json::JsonPrintOptions print_options; // We usually do not want this to be true, however it can be helpful to // uncomment and see the output produced then all fields are printed. // print_options.always_print_primitive_fields = true; s = grpc::protobuf::json::MessageToJsonString(msg, &proto_json_str); EXPECT_TRUE(s.ok()); - // Parse JSON and re-dump to string, to make sure formatting is the - // same as what would be generated by our JSON library. - grpc_error* error = GRPC_ERROR_NONE; - grpc_core::Json parsed_json = - grpc_core::Json::Parse(proto_json_str.c_str(), &error); - ASSERT_EQ(error, GRPC_ERROR_NONE) << grpc_error_string(error); - ASSERT_EQ(parsed_json.type(), grpc_core::Json::Type::OBJECT); - proto_json_str = parsed_json.Dump(); + // Parse JSON and re-dump to string, to make sure formatting is the + // same as what would be generated by our JSON library. + grpc_error* error = GRPC_ERROR_NONE; + grpc_core::Json parsed_json = + grpc_core::Json::Parse(proto_json_str.c_str(), &error); + ASSERT_EQ(error, GRPC_ERROR_NONE) << grpc_error_string(error); + ASSERT_EQ(parsed_json.type(), grpc_core::Json::Type::OBJECT); + proto_json_str = parsed_json.Dump(); // uncomment these to compare the json strings. // gpr_log(GPR_ERROR, "tracer json: %s", json_str.c_str()); // gpr_log(GPR_ERROR, "proto json: %s", proto_json_str.c_str()); @@ -74,39 +74,39 @@ void VaidateProtoJsonTranslation(const TString& json_str) { namespace testing { -void ValidateChannelTraceProtoJsonTranslation(const char* json_c_str) { +void ValidateChannelTraceProtoJsonTranslation(const char* json_c_str) { VaidateProtoJsonTranslation<grpc::channelz::v1::ChannelTrace>(json_c_str); } -void ValidateChannelProtoJsonTranslation(const char* json_c_str) { +void ValidateChannelProtoJsonTranslation(const char* json_c_str) { VaidateProtoJsonTranslation<grpc::channelz::v1::Channel>(json_c_str); } -void ValidateGetTopChannelsResponseProtoJsonTranslation( - const char* json_c_str) { +void ValidateGetTopChannelsResponseProtoJsonTranslation( + const char* json_c_str) { VaidateProtoJsonTranslation<grpc::channelz::v1::GetTopChannelsResponse>( json_c_str); } -void ValidateGetChannelResponseProtoJsonTranslation(const char* json_c_str) { +void ValidateGetChannelResponseProtoJsonTranslation(const char* json_c_str) { VaidateProtoJsonTranslation<grpc::channelz::v1::GetChannelResponse>( json_c_str); } -void ValidateGetServerResponseProtoJsonTranslation(const char* json_c_str) { +void ValidateGetServerResponseProtoJsonTranslation(const char* json_c_str) { VaidateProtoJsonTranslation<grpc::channelz::v1::GetServerResponse>( json_c_str); } -void ValidateSubchannelProtoJsonTranslation(const char* json_c_str) { +void ValidateSubchannelProtoJsonTranslation(const char* json_c_str) { VaidateProtoJsonTranslation<grpc::channelz::v1::Subchannel>(json_c_str); } -void ValidateServerProtoJsonTranslation(const char* json_c_str) { +void ValidateServerProtoJsonTranslation(const char* json_c_str) { VaidateProtoJsonTranslation<grpc::channelz::v1::Server>(json_c_str); } -void ValidateGetServersResponseProtoJsonTranslation(const char* json_c_str) { +void ValidateGetServersResponseProtoJsonTranslation(const char* json_c_str) { VaidateProtoJsonTranslation<grpc::channelz::v1::GetServersResponse>( json_c_str); } diff --git a/contrib/libs/grpc/test/cpp/util/channel_trace_proto_helper.h b/contrib/libs/grpc/test/cpp/util/channel_trace_proto_helper.h index 664e899deb..7424182d09 100644 --- a/contrib/libs/grpc/test/cpp/util/channel_trace_proto_helper.h +++ b/contrib/libs/grpc/test/cpp/util/channel_trace_proto_helper.h @@ -22,14 +22,14 @@ namespace grpc { namespace testing { -void ValidateChannelTraceProtoJsonTranslation(const char* json_c_str); -void ValidateChannelProtoJsonTranslation(const char* json_c_str); -void ValidateGetTopChannelsResponseProtoJsonTranslation(const char* json_c_str); -void ValidateGetChannelResponseProtoJsonTranslation(const char* json_c_str); -void ValidateGetServerResponseProtoJsonTranslation(const char* json_c_str); -void ValidateSubchannelProtoJsonTranslation(const char* json_c_str); -void ValidateServerProtoJsonTranslation(const char* json_c_str); -void ValidateGetServersResponseProtoJsonTranslation(const char* json_c_str); +void ValidateChannelTraceProtoJsonTranslation(const char* json_c_str); +void ValidateChannelProtoJsonTranslation(const char* json_c_str); +void ValidateGetTopChannelsResponseProtoJsonTranslation(const char* json_c_str); +void ValidateGetChannelResponseProtoJsonTranslation(const char* json_c_str); +void ValidateGetServerResponseProtoJsonTranslation(const char* json_c_str); +void ValidateSubchannelProtoJsonTranslation(const char* json_c_str); +void ValidateServerProtoJsonTranslation(const char* json_c_str); +void ValidateGetServersResponseProtoJsonTranslation(const char* json_c_str); } // namespace testing } // namespace grpc diff --git a/contrib/libs/grpc/test/cpp/util/channelz_sampler.cc b/contrib/libs/grpc/test/cpp/util/channelz_sampler.cc index e6bde68556..0a7627271f 100644 --- a/contrib/libs/grpc/test/cpp/util/channelz_sampler.cc +++ b/contrib/libs/grpc/test/cpp/util/channelz_sampler.cc @@ -1,588 +1,588 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include <unistd.h> - -#include <cstdlib> -#include <fstream> -#include <iostream> -#include <memory> -#include <ostream> -#include <queue> -#include <util/generic/string.h> - -#include "y_absl/strings/str_format.h" -#include "y_absl/strings/str_join.h" -#include "gflags/gflags.h" -#include "google/protobuf/text_format.h" -#include "grpc/grpc.h" -#include "grpc/support/port_platform.h" -#include "grpcpp/channel.h" -#include "grpcpp/client_context.h" -#include "grpcpp/create_channel.h" -#include "grpcpp/ext/channelz_service_plugin.h" -#include "grpcpp/grpcpp.h" -#include "grpcpp/security/credentials.h" -#include "grpcpp/security/server_credentials.h" -#include "grpcpp/server.h" -#include "grpcpp/server_builder.h" -#include "grpcpp/server_context.h" -#include "src/core/lib/json/json.h" -#include "src/cpp/server/channelz/channelz_service.h" -#include "src/proto/grpc/channelz/channelz.pb.h" -#include "test/core/util/test_config.h" -#include "test/cpp/util/test_config.h" -#include "test/cpp/util/test_credentials_provider.h" - -DEFINE_string(server_address, "", "channelz server address"); -DEFINE_string(custom_credentials_type, "", "custom credentials type"); -DEFINE_int64(sampling_times, 1, "number of sampling"); -DEFINE_int64(sampling_interval_seconds, 0, "sampling interval in seconds"); -DEFINE_string(output_json, "", "output filename in json format"); - -namespace { -using grpc::ClientContext; -using grpc::Status; -using grpc::StatusCode; -using grpc::channelz::v1::GetChannelRequest; -using grpc::channelz::v1::GetChannelResponse; -using grpc::channelz::v1::GetServerRequest; -using grpc::channelz::v1::GetServerResponse; -using grpc::channelz::v1::GetServerSocketsRequest; -using grpc::channelz::v1::GetServerSocketsResponse; -using grpc::channelz::v1::GetServersRequest; -using grpc::channelz::v1::GetServersResponse; -using grpc::channelz::v1::GetSocketRequest; -using grpc::channelz::v1::GetSocketResponse; -using grpc::channelz::v1::GetSubchannelRequest; -using grpc::channelz::v1::GetSubchannelResponse; -using grpc::channelz::v1::GetTopChannelsRequest; -using grpc::channelz::v1::GetTopChannelsResponse; -} // namespace - -class ChannelzSampler final { - public: - // Get server_id of a server - int64_t GetServerID(const grpc::channelz::v1::Server& server) { - return server.ref().server_id(); - } - - // Get channel_id of a channel - inline int64_t GetChannelID(const grpc::channelz::v1::Channel& channel) { - return channel.ref().channel_id(); - } - - // Get subchannel_id of a subchannel - inline int64_t GetSubchannelID( - const grpc::channelz::v1::Subchannel& subchannel) { - return subchannel.ref().subchannel_id(); - } - - // Get socket_id of a socket - inline int64_t GetSocketID(const grpc::channelz::v1::Socket& socket) { - return socket.ref().socket_id(); - } - - // Get name of a server - inline TString GetServerName(const grpc::channelz::v1::Server& server) { - return server.ref().name(); - } - - // Get name of a channel - inline TString GetChannelName( - const grpc::channelz::v1::Channel& channel) { - return channel.ref().name(); - } - - // Get name of a subchannel - inline TString GetSubchannelName( - const grpc::channelz::v1::Subchannel& subchannel) { - return subchannel.ref().name(); - } - - // Get name of a socket - inline TString GetSocketName(const grpc::channelz::v1::Socket& socket) { - return socket.ref().name(); - } - - // Get a channel based on channel_id - grpc::channelz::v1::Channel GetChannelRPC(int64_t channel_id) { - GetChannelRequest get_channel_request; - get_channel_request.set_channel_id(channel_id); - GetChannelResponse get_channel_response; - ClientContext get_channel_context; - get_channel_context.set_deadline( - grpc_timeout_seconds_to_deadline(rpc_timeout_seconds_)); - Status status = channelz_stub_->GetChannel( - &get_channel_context, get_channel_request, &get_channel_response); - if (!status.ok()) { - gpr_log(GPR_ERROR, "GetChannelRPC failed: %s", - get_channel_context.debug_error_string().c_str()); - GPR_ASSERT(0); - } - return get_channel_response.channel(); - } - - // Get a subchannel based on subchannel_id - grpc::channelz::v1::Subchannel GetSubchannelRPC(int64_t subchannel_id) { - GetSubchannelRequest get_subchannel_request; - get_subchannel_request.set_subchannel_id(subchannel_id); - GetSubchannelResponse get_subchannel_response; - ClientContext get_subchannel_context; - get_subchannel_context.set_deadline( - grpc_timeout_seconds_to_deadline(rpc_timeout_seconds_)); - Status status = channelz_stub_->GetSubchannel(&get_subchannel_context, - get_subchannel_request, - &get_subchannel_response); - if (!status.ok()) { - gpr_log(GPR_ERROR, "GetSubchannelRPC failed: %s", - get_subchannel_context.debug_error_string().c_str()); - GPR_ASSERT(0); - } - return get_subchannel_response.subchannel(); - } - - // get a socket based on socket_id - grpc::channelz::v1::Socket GetSocketRPC(int64_t socket_id) { - GetSocketRequest get_socket_request; - get_socket_request.set_socket_id(socket_id); - GetSocketResponse get_socket_response; - ClientContext get_socket_context; - get_socket_context.set_deadline( - grpc_timeout_seconds_to_deadline(rpc_timeout_seconds_)); - Status status = channelz_stub_->GetSocket( - &get_socket_context, get_socket_request, &get_socket_response); - if (!status.ok()) { - gpr_log(GPR_ERROR, "GetSocketRPC failed: %s", - get_socket_context.debug_error_string().c_str()); - GPR_ASSERT(0); - } - return get_socket_response.socket(); - } - - // get the descedent channels/subchannels/sockets of a channel - // push descedent channels/subchannels to queue for layer traverse - // store descedent channels/subchannels/sockets for dumping data - void GetChannelDescedence( - const grpc::channelz::v1::Channel& channel, - std::queue<grpc::channelz::v1::Channel>& channel_queue, - std::queue<grpc::channelz::v1::Subchannel>& subchannel_queue) { - std::cout << " Channel ID" << GetChannelID(channel) << "_" - << GetChannelName(channel) << " descendence - "; - if (channel.channel_ref_size() > 0 || channel.subchannel_ref_size() > 0) { - if (channel.channel_ref_size() > 0) { - std::cout << "channel: "; - for (const auto& _channelref : channel.channel_ref()) { - int64_t ch_id = _channelref.channel_id(); - std::cout << "ID" << ch_id << "_" << _channelref.name() << " "; - grpc::channelz::v1::Channel ch = GetChannelRPC(ch_id); - channel_queue.push(ch); - if (CheckID(ch_id)) { - all_channels_.push_back(ch); - StoreChannelInJson(ch); - } - } - if (channel.subchannel_ref_size() > 0) { - std::cout << ", "; - } - } - if (channel.subchannel_ref_size() > 0) { - std::cout << "subchannel: "; - for (const auto& _subchannelref : channel.subchannel_ref()) { - int64_t subch_id = _subchannelref.subchannel_id(); - std::cout << "ID" << subch_id << "_" << _subchannelref.name() << " "; - grpc::channelz::v1::Subchannel subch = GetSubchannelRPC(subch_id); - subchannel_queue.push(subch); - if (CheckID(subch_id)) { - all_subchannels_.push_back(subch); - StoreSubchannelInJson(subch); - } - } - } - } else if (channel.socket_ref_size() > 0) { - std::cout << "socket: "; - for (const auto& _socketref : channel.socket_ref()) { - int64_t so_id = _socketref.socket_id(); - std::cout << "ID" << so_id << "_" << _socketref.name() << " "; - grpc::channelz::v1::Socket so = GetSocketRPC(so_id); - if (CheckID(so_id)) { - all_sockets_.push_back(so); - StoreSocketInJson(so); - } - } - } - std::cout << std::endl; - } - - // get the descedent channels/subchannels/sockets of a subchannel - // push descedent channels/subchannels to queue for layer traverse - // store descedent channels/subchannels/sockets for dumping data - void GetSubchannelDescedence( - grpc::channelz::v1::Subchannel& subchannel, - std::queue<grpc::channelz::v1::Channel>& channel_queue, - std::queue<grpc::channelz::v1::Subchannel>& subchannel_queue) { - std::cout << " Subchannel ID" << GetSubchannelID(subchannel) << "_" - << GetSubchannelName(subchannel) << " descendence - "; - if (subchannel.channel_ref_size() > 0 || - subchannel.subchannel_ref_size() > 0) { - if (subchannel.channel_ref_size() > 0) { - std::cout << "channel: "; - for (const auto& _channelref : subchannel.channel_ref()) { - int64_t ch_id = _channelref.channel_id(); - std::cout << "ID" << ch_id << "_" << _channelref.name() << " "; - grpc::channelz::v1::Channel ch = GetChannelRPC(ch_id); - channel_queue.push(ch); - if (CheckID(ch_id)) { - all_channels_.push_back(ch); - StoreChannelInJson(ch); - } - } - if (subchannel.subchannel_ref_size() > 0) { - std::cout << ", "; - } - } - if (subchannel.subchannel_ref_size() > 0) { - std::cout << "subchannel: "; - for (const auto& _subchannelref : subchannel.subchannel_ref()) { - int64_t subch_id = _subchannelref.subchannel_id(); - std::cout << "ID" << subch_id << "_" << _subchannelref.name() << " "; - grpc::channelz::v1::Subchannel subch = GetSubchannelRPC(subch_id); - subchannel_queue.push(subch); - if (CheckID(subch_id)) { - all_subchannels_.push_back(subch); - StoreSubchannelInJson(subch); - } - } - } - } else if (subchannel.socket_ref_size() > 0) { - std::cout << "socket: "; - for (const auto& _socketref : subchannel.socket_ref()) { - int64_t so_id = _socketref.socket_id(); - std::cout << "ID" << so_id << "_" << _socketref.name() << " "; - grpc::channelz::v1::Socket so = GetSocketRPC(so_id); - if (CheckID(so_id)) { - all_sockets_.push_back(so); - StoreSocketInJson(so); - } - } - } - std::cout << std::endl; - } - - // Set up the channelz sampler client - // Initialize json as an array - void Setup(const TString& custom_credentials_type, - const TString& server_address) { - json_ = grpc_core::Json::Array(); - rpc_timeout_seconds_ = 20; - grpc::ChannelArguments channel_args; - std::shared_ptr<grpc::ChannelCredentials> channel_creds = - grpc::testing::GetCredentialsProvider()->GetChannelCredentials( - custom_credentials_type, &channel_args); - if (!channel_creds) { - gpr_log(GPR_ERROR, - "Wrong user credential type: %s. Allowed credential types: " - "INSECURE_CREDENTIALS, ssl, alts, google_default_credentials.", - custom_credentials_type.c_str()); - GPR_ASSERT(0); - } - std::shared_ptr<grpc::Channel> channel = - CreateChannel(server_address, channel_creds); - channelz_stub_ = grpc::channelz::v1::Channelz::NewStub(channel); - } - - // Get all servers, keep querying until getting all - // Store servers for dumping data - // Need to check id repeating for servers - void GetServersRPC() { - int64_t server_start_id = 0; - while (true) { - GetServersRequest get_servers_request; - GetServersResponse get_servers_response; - ClientContext get_servers_context; - get_servers_context.set_deadline( - grpc_timeout_seconds_to_deadline(rpc_timeout_seconds_)); - get_servers_request.set_start_server_id(server_start_id); - Status status = channelz_stub_->GetServers( - &get_servers_context, get_servers_request, &get_servers_response); - if (!status.ok()) { - if (status.error_code() == StatusCode::UNIMPLEMENTED) { - gpr_log(GPR_ERROR, - "Error status UNIMPLEMENTED. Please check and make sure " - "channelz has been registered on the server being queried."); - } else { - gpr_log(GPR_ERROR, - "GetServers RPC with GetServersRequest.server_start_id=%d, " - "failed: %s", - int(server_start_id), - get_servers_context.debug_error_string().c_str()); - } - GPR_ASSERT(0); - } - for (const auto& _server : get_servers_response.server()) { - all_servers_.push_back(_server); - StoreServerInJson(_server); - } - if (!get_servers_response.end()) { - server_start_id = GetServerID(all_servers_.back()) + 1; - } else { - break; - } - } - std::cout << "Number of servers = " << all_servers_.size() << std::endl; - } - - // Get sockets that belongs to servers - // Store sockets for dumping data - void GetSocketsOfServers() { - for (const auto& _server : all_servers_) { - std::cout << "Server ID" << GetServerID(_server) << "_" - << GetServerName(_server) << " listen_socket - "; - for (const auto& _socket : _server.listen_socket()) { - int64_t so_id = _socket.socket_id(); - std::cout << "ID" << so_id << "_" << _socket.name() << " "; - if (CheckID(so_id)) { - grpc::channelz::v1::Socket so = GetSocketRPC(so_id); - all_sockets_.push_back(so); - StoreSocketInJson(so); - } - } - std::cout << std::endl; - } - } - - // Get all top channels, keep querying until getting all - // Store channels for dumping data - // No need to check id repeating for top channels - void GetTopChannelsRPC() { - int64_t channel_start_id = 0; - while (true) { - GetTopChannelsRequest get_top_channels_request; - GetTopChannelsResponse get_top_channels_response; - ClientContext get_top_channels_context; - get_top_channels_context.set_deadline( - grpc_timeout_seconds_to_deadline(rpc_timeout_seconds_)); - get_top_channels_request.set_start_channel_id(channel_start_id); - Status status = channelz_stub_->GetTopChannels( - &get_top_channels_context, get_top_channels_request, - &get_top_channels_response); - if (!status.ok()) { - gpr_log(GPR_ERROR, - "GetTopChannels RPC with " - "GetTopChannelsRequest.channel_start_id=%d failed: %s", - int(channel_start_id), - get_top_channels_context.debug_error_string().c_str()); - GPR_ASSERT(0); - } - for (const auto& _topchannel : get_top_channels_response.channel()) { - top_channels_.push_back(_topchannel); - all_channels_.push_back(_topchannel); - StoreChannelInJson(_topchannel); - } - if (!get_top_channels_response.end()) { - channel_start_id = GetChannelID(top_channels_.back()) + 1; - } else { - break; - } - } - std::cout << std::endl - << "Number of top channels = " << top_channels_.size() - << std::endl; - } - - // layer traverse for each top channel - void TraverseTopChannels() { - for (const auto& _topchannel : top_channels_) { - int tree_depth = 0; - std::queue<grpc::channelz::v1::Channel> channel_queue; - std::queue<grpc::channelz::v1::Subchannel> subchannel_queue; - std::cout << "Tree depth = " << tree_depth << std::endl; - GetChannelDescedence(_topchannel, channel_queue, subchannel_queue); - while (!channel_queue.empty() || !subchannel_queue.empty()) { - ++tree_depth; - std::cout << "Tree depth = " << tree_depth << std::endl; - int ch_q_size = channel_queue.size(); - int subch_q_size = subchannel_queue.size(); - for (int i = 0; i < ch_q_size; ++i) { - grpc::channelz::v1::Channel ch = channel_queue.front(); - channel_queue.pop(); - GetChannelDescedence(ch, channel_queue, subchannel_queue); - } - for (int i = 0; i < subch_q_size; ++i) { - grpc::channelz::v1::Subchannel subch = subchannel_queue.front(); - subchannel_queue.pop(); - GetSubchannelDescedence(subch, channel_queue, subchannel_queue); - } - } - std::cout << std::endl; - } - } - - // dump data of all entities to stdout - void DumpStdout() { - TString data_str; - for (const auto& _channel : all_channels_) { - std::cout << "channel ID" << GetChannelID(_channel) << "_" - << GetChannelName(_channel) << " data:" << std::endl; - // TODO(mohanli): TextFormat::PrintToString records time as seconds and - // nanos. Need a more human readable way. - ::google::protobuf::TextFormat::PrintToString(_channel.data(), &data_str); - printf("%s\n", data_str.c_str()); - } - for (const auto& _subchannel : all_subchannels_) { - std::cout << "subchannel ID" << GetSubchannelID(_subchannel) << "_" - << GetSubchannelName(_subchannel) << " data:" << std::endl; - ::google::protobuf::TextFormat::PrintToString(_subchannel.data(), - &data_str); - printf("%s\n", data_str.c_str()); - } - for (const auto& _server : all_servers_) { - std::cout << "server ID" << GetServerID(_server) << "_" - << GetServerName(_server) << " data:" << std::endl; - ::google::protobuf::TextFormat::PrintToString(_server.data(), &data_str); - printf("%s\n", data_str.c_str()); - } - for (const auto& _socket : all_sockets_) { - std::cout << "socket ID" << GetSocketID(_socket) << "_" - << GetSocketName(_socket) << " data:" << std::endl; - ::google::protobuf::TextFormat::PrintToString(_socket.data(), &data_str); - printf("%s\n", data_str.c_str()); - } - } - - // Store a channel in Json - void StoreChannelInJson(const grpc::channelz::v1::Channel& channel) { - TString id = grpc::to_string(GetChannelID(channel)); - TString type = "Channel"; - TString description; - ::google::protobuf::TextFormat::PrintToString(channel.data(), &description); - grpc_core::Json description_json = grpc_core::Json(description); - StoreEntityInJson(id, type, description_json); - } - - // Store a subchannel in Json - void StoreSubchannelInJson(const grpc::channelz::v1::Subchannel& subchannel) { - TString id = grpc::to_string(GetSubchannelID(subchannel)); - TString type = "Subchannel"; - TString description; - ::google::protobuf::TextFormat::PrintToString(subchannel.data(), - &description); - grpc_core::Json description_json = grpc_core::Json(description); - StoreEntityInJson(id, type, description_json); - } - - // Store a server in Json - void StoreServerInJson(const grpc::channelz::v1::Server& server) { - TString id = grpc::to_string(GetServerID(server)); - TString type = "Server"; - TString description; - ::google::protobuf::TextFormat::PrintToString(server.data(), &description); - grpc_core::Json description_json = grpc_core::Json(description); - StoreEntityInJson(id, type, description_json); - } - - // Store a socket in Json - void StoreSocketInJson(const grpc::channelz::v1::Socket& socket) { - TString id = grpc::to_string(GetSocketID(socket)); - TString type = "Socket"; - TString description; - ::google::protobuf::TextFormat::PrintToString(socket.data(), &description); - grpc_core::Json description_json = grpc_core::Json(description); - StoreEntityInJson(id, type, description_json); - } - - // Store an entity in Json - void StoreEntityInJson(TString& id, TString& type, - const grpc_core::Json& description) { - TString start, finish; - gpr_timespec ago = gpr_time_sub( - now_, - gpr_time_from_seconds(FLAGS_sampling_interval_seconds, GPR_TIMESPAN)); - std::stringstream ss; - const time_t time_now = now_.tv_sec; - ss << std::put_time(std::localtime(&time_now), "%F %T"); - finish = ss.str(); // example: "2019-02-01 12:12:18" - ss.str(""); - const time_t time_ago = ago.tv_sec; - ss << std::put_time(std::localtime(&time_ago), "%F %T"); - start = ss.str(); - grpc_core::Json obj = - grpc_core::Json::Object{{"Task", y_absl::StrFormat("%s_ID%s", type, id)}, - {"Start", start}, - {"Finish", finish}, - {"ID", id}, - {"Type", type}, - {"Description", description}}; - json_.mutable_array()->push_back(obj); - } - - // Dump data in json - TString DumpJson() { return json_.Dump(); } - - // Check if one entity has been recorded - bool CheckID(int64_t id) { - if (id_set_.count(id) == 0) { - id_set_.insert(id); - return true; - } else { - return false; - } - } - - // Record current time - void RecordNow() { now_ = gpr_now(GPR_CLOCK_REALTIME); } - - private: - std::unique_ptr<grpc::channelz::v1::Channelz::Stub> channelz_stub_; - std::vector<grpc::channelz::v1::Channel> top_channels_; - std::vector<grpc::channelz::v1::Server> all_servers_; - std::vector<grpc::channelz::v1::Channel> all_channels_; - std::vector<grpc::channelz::v1::Subchannel> all_subchannels_; - std::vector<grpc::channelz::v1::Socket> all_sockets_; - std::unordered_set<int64_t> id_set_; - grpc_core::Json json_; - int64_t rpc_timeout_seconds_; - gpr_timespec now_; -}; - -int main(int argc, char** argv) { - grpc::testing::TestEnvironment env(argc, argv); - grpc::testing::InitTest(&argc, &argv, true); - std::ofstream output_file(FLAGS_output_json); - for (int i = 0; i < FLAGS_sampling_times; ++i) { - ChannelzSampler channelz_sampler; - channelz_sampler.Setup(FLAGS_custom_credentials_type, FLAGS_server_address); - std::cout << "Wait for sampling interval " - << FLAGS_sampling_interval_seconds << "s..." << std::endl; - const gpr_timespec kDelay = gpr_time_add( - gpr_now(GPR_CLOCK_MONOTONIC), - gpr_time_from_seconds(FLAGS_sampling_interval_seconds, GPR_TIMESPAN)); - gpr_sleep_until(kDelay); - std::cout << "##### " << i << "th sampling #####" << std::endl; - channelz_sampler.RecordNow(); - channelz_sampler.GetServersRPC(); - channelz_sampler.GetSocketsOfServers(); - channelz_sampler.GetTopChannelsRPC(); - channelz_sampler.TraverseTopChannels(); - channelz_sampler.DumpStdout(); - if (!FLAGS_output_json.empty()) { - output_file << channelz_sampler.DumpJson() << "\n" << std::flush; - } - } - output_file.close(); - return 0; -} +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include <unistd.h> + +#include <cstdlib> +#include <fstream> +#include <iostream> +#include <memory> +#include <ostream> +#include <queue> +#include <util/generic/string.h> + +#include "y_absl/strings/str_format.h" +#include "y_absl/strings/str_join.h" +#include "gflags/gflags.h" +#include "google/protobuf/text_format.h" +#include "grpc/grpc.h" +#include "grpc/support/port_platform.h" +#include "grpcpp/channel.h" +#include "grpcpp/client_context.h" +#include "grpcpp/create_channel.h" +#include "grpcpp/ext/channelz_service_plugin.h" +#include "grpcpp/grpcpp.h" +#include "grpcpp/security/credentials.h" +#include "grpcpp/security/server_credentials.h" +#include "grpcpp/server.h" +#include "grpcpp/server_builder.h" +#include "grpcpp/server_context.h" +#include "src/core/lib/json/json.h" +#include "src/cpp/server/channelz/channelz_service.h" +#include "src/proto/grpc/channelz/channelz.pb.h" +#include "test/core/util/test_config.h" +#include "test/cpp/util/test_config.h" +#include "test/cpp/util/test_credentials_provider.h" + +DEFINE_string(server_address, "", "channelz server address"); +DEFINE_string(custom_credentials_type, "", "custom credentials type"); +DEFINE_int64(sampling_times, 1, "number of sampling"); +DEFINE_int64(sampling_interval_seconds, 0, "sampling interval in seconds"); +DEFINE_string(output_json, "", "output filename in json format"); + +namespace { +using grpc::ClientContext; +using grpc::Status; +using grpc::StatusCode; +using grpc::channelz::v1::GetChannelRequest; +using grpc::channelz::v1::GetChannelResponse; +using grpc::channelz::v1::GetServerRequest; +using grpc::channelz::v1::GetServerResponse; +using grpc::channelz::v1::GetServerSocketsRequest; +using grpc::channelz::v1::GetServerSocketsResponse; +using grpc::channelz::v1::GetServersRequest; +using grpc::channelz::v1::GetServersResponse; +using grpc::channelz::v1::GetSocketRequest; +using grpc::channelz::v1::GetSocketResponse; +using grpc::channelz::v1::GetSubchannelRequest; +using grpc::channelz::v1::GetSubchannelResponse; +using grpc::channelz::v1::GetTopChannelsRequest; +using grpc::channelz::v1::GetTopChannelsResponse; +} // namespace + +class ChannelzSampler final { + public: + // Get server_id of a server + int64_t GetServerID(const grpc::channelz::v1::Server& server) { + return server.ref().server_id(); + } + + // Get channel_id of a channel + inline int64_t GetChannelID(const grpc::channelz::v1::Channel& channel) { + return channel.ref().channel_id(); + } + + // Get subchannel_id of a subchannel + inline int64_t GetSubchannelID( + const grpc::channelz::v1::Subchannel& subchannel) { + return subchannel.ref().subchannel_id(); + } + + // Get socket_id of a socket + inline int64_t GetSocketID(const grpc::channelz::v1::Socket& socket) { + return socket.ref().socket_id(); + } + + // Get name of a server + inline TString GetServerName(const grpc::channelz::v1::Server& server) { + return server.ref().name(); + } + + // Get name of a channel + inline TString GetChannelName( + const grpc::channelz::v1::Channel& channel) { + return channel.ref().name(); + } + + // Get name of a subchannel + inline TString GetSubchannelName( + const grpc::channelz::v1::Subchannel& subchannel) { + return subchannel.ref().name(); + } + + // Get name of a socket + inline TString GetSocketName(const grpc::channelz::v1::Socket& socket) { + return socket.ref().name(); + } + + // Get a channel based on channel_id + grpc::channelz::v1::Channel GetChannelRPC(int64_t channel_id) { + GetChannelRequest get_channel_request; + get_channel_request.set_channel_id(channel_id); + GetChannelResponse get_channel_response; + ClientContext get_channel_context; + get_channel_context.set_deadline( + grpc_timeout_seconds_to_deadline(rpc_timeout_seconds_)); + Status status = channelz_stub_->GetChannel( + &get_channel_context, get_channel_request, &get_channel_response); + if (!status.ok()) { + gpr_log(GPR_ERROR, "GetChannelRPC failed: %s", + get_channel_context.debug_error_string().c_str()); + GPR_ASSERT(0); + } + return get_channel_response.channel(); + } + + // Get a subchannel based on subchannel_id + grpc::channelz::v1::Subchannel GetSubchannelRPC(int64_t subchannel_id) { + GetSubchannelRequest get_subchannel_request; + get_subchannel_request.set_subchannel_id(subchannel_id); + GetSubchannelResponse get_subchannel_response; + ClientContext get_subchannel_context; + get_subchannel_context.set_deadline( + grpc_timeout_seconds_to_deadline(rpc_timeout_seconds_)); + Status status = channelz_stub_->GetSubchannel(&get_subchannel_context, + get_subchannel_request, + &get_subchannel_response); + if (!status.ok()) { + gpr_log(GPR_ERROR, "GetSubchannelRPC failed: %s", + get_subchannel_context.debug_error_string().c_str()); + GPR_ASSERT(0); + } + return get_subchannel_response.subchannel(); + } + + // get a socket based on socket_id + grpc::channelz::v1::Socket GetSocketRPC(int64_t socket_id) { + GetSocketRequest get_socket_request; + get_socket_request.set_socket_id(socket_id); + GetSocketResponse get_socket_response; + ClientContext get_socket_context; + get_socket_context.set_deadline( + grpc_timeout_seconds_to_deadline(rpc_timeout_seconds_)); + Status status = channelz_stub_->GetSocket( + &get_socket_context, get_socket_request, &get_socket_response); + if (!status.ok()) { + gpr_log(GPR_ERROR, "GetSocketRPC failed: %s", + get_socket_context.debug_error_string().c_str()); + GPR_ASSERT(0); + } + return get_socket_response.socket(); + } + + // get the descedent channels/subchannels/sockets of a channel + // push descedent channels/subchannels to queue for layer traverse + // store descedent channels/subchannels/sockets for dumping data + void GetChannelDescedence( + const grpc::channelz::v1::Channel& channel, + std::queue<grpc::channelz::v1::Channel>& channel_queue, + std::queue<grpc::channelz::v1::Subchannel>& subchannel_queue) { + std::cout << " Channel ID" << GetChannelID(channel) << "_" + << GetChannelName(channel) << " descendence - "; + if (channel.channel_ref_size() > 0 || channel.subchannel_ref_size() > 0) { + if (channel.channel_ref_size() > 0) { + std::cout << "channel: "; + for (const auto& _channelref : channel.channel_ref()) { + int64_t ch_id = _channelref.channel_id(); + std::cout << "ID" << ch_id << "_" << _channelref.name() << " "; + grpc::channelz::v1::Channel ch = GetChannelRPC(ch_id); + channel_queue.push(ch); + if (CheckID(ch_id)) { + all_channels_.push_back(ch); + StoreChannelInJson(ch); + } + } + if (channel.subchannel_ref_size() > 0) { + std::cout << ", "; + } + } + if (channel.subchannel_ref_size() > 0) { + std::cout << "subchannel: "; + for (const auto& _subchannelref : channel.subchannel_ref()) { + int64_t subch_id = _subchannelref.subchannel_id(); + std::cout << "ID" << subch_id << "_" << _subchannelref.name() << " "; + grpc::channelz::v1::Subchannel subch = GetSubchannelRPC(subch_id); + subchannel_queue.push(subch); + if (CheckID(subch_id)) { + all_subchannels_.push_back(subch); + StoreSubchannelInJson(subch); + } + } + } + } else if (channel.socket_ref_size() > 0) { + std::cout << "socket: "; + for (const auto& _socketref : channel.socket_ref()) { + int64_t so_id = _socketref.socket_id(); + std::cout << "ID" << so_id << "_" << _socketref.name() << " "; + grpc::channelz::v1::Socket so = GetSocketRPC(so_id); + if (CheckID(so_id)) { + all_sockets_.push_back(so); + StoreSocketInJson(so); + } + } + } + std::cout << std::endl; + } + + // get the descedent channels/subchannels/sockets of a subchannel + // push descedent channels/subchannels to queue for layer traverse + // store descedent channels/subchannels/sockets for dumping data + void GetSubchannelDescedence( + grpc::channelz::v1::Subchannel& subchannel, + std::queue<grpc::channelz::v1::Channel>& channel_queue, + std::queue<grpc::channelz::v1::Subchannel>& subchannel_queue) { + std::cout << " Subchannel ID" << GetSubchannelID(subchannel) << "_" + << GetSubchannelName(subchannel) << " descendence - "; + if (subchannel.channel_ref_size() > 0 || + subchannel.subchannel_ref_size() > 0) { + if (subchannel.channel_ref_size() > 0) { + std::cout << "channel: "; + for (const auto& _channelref : subchannel.channel_ref()) { + int64_t ch_id = _channelref.channel_id(); + std::cout << "ID" << ch_id << "_" << _channelref.name() << " "; + grpc::channelz::v1::Channel ch = GetChannelRPC(ch_id); + channel_queue.push(ch); + if (CheckID(ch_id)) { + all_channels_.push_back(ch); + StoreChannelInJson(ch); + } + } + if (subchannel.subchannel_ref_size() > 0) { + std::cout << ", "; + } + } + if (subchannel.subchannel_ref_size() > 0) { + std::cout << "subchannel: "; + for (const auto& _subchannelref : subchannel.subchannel_ref()) { + int64_t subch_id = _subchannelref.subchannel_id(); + std::cout << "ID" << subch_id << "_" << _subchannelref.name() << " "; + grpc::channelz::v1::Subchannel subch = GetSubchannelRPC(subch_id); + subchannel_queue.push(subch); + if (CheckID(subch_id)) { + all_subchannels_.push_back(subch); + StoreSubchannelInJson(subch); + } + } + } + } else if (subchannel.socket_ref_size() > 0) { + std::cout << "socket: "; + for (const auto& _socketref : subchannel.socket_ref()) { + int64_t so_id = _socketref.socket_id(); + std::cout << "ID" << so_id << "_" << _socketref.name() << " "; + grpc::channelz::v1::Socket so = GetSocketRPC(so_id); + if (CheckID(so_id)) { + all_sockets_.push_back(so); + StoreSocketInJson(so); + } + } + } + std::cout << std::endl; + } + + // Set up the channelz sampler client + // Initialize json as an array + void Setup(const TString& custom_credentials_type, + const TString& server_address) { + json_ = grpc_core::Json::Array(); + rpc_timeout_seconds_ = 20; + grpc::ChannelArguments channel_args; + std::shared_ptr<grpc::ChannelCredentials> channel_creds = + grpc::testing::GetCredentialsProvider()->GetChannelCredentials( + custom_credentials_type, &channel_args); + if (!channel_creds) { + gpr_log(GPR_ERROR, + "Wrong user credential type: %s. Allowed credential types: " + "INSECURE_CREDENTIALS, ssl, alts, google_default_credentials.", + custom_credentials_type.c_str()); + GPR_ASSERT(0); + } + std::shared_ptr<grpc::Channel> channel = + CreateChannel(server_address, channel_creds); + channelz_stub_ = grpc::channelz::v1::Channelz::NewStub(channel); + } + + // Get all servers, keep querying until getting all + // Store servers for dumping data + // Need to check id repeating for servers + void GetServersRPC() { + int64_t server_start_id = 0; + while (true) { + GetServersRequest get_servers_request; + GetServersResponse get_servers_response; + ClientContext get_servers_context; + get_servers_context.set_deadline( + grpc_timeout_seconds_to_deadline(rpc_timeout_seconds_)); + get_servers_request.set_start_server_id(server_start_id); + Status status = channelz_stub_->GetServers( + &get_servers_context, get_servers_request, &get_servers_response); + if (!status.ok()) { + if (status.error_code() == StatusCode::UNIMPLEMENTED) { + gpr_log(GPR_ERROR, + "Error status UNIMPLEMENTED. Please check and make sure " + "channelz has been registered on the server being queried."); + } else { + gpr_log(GPR_ERROR, + "GetServers RPC with GetServersRequest.server_start_id=%d, " + "failed: %s", + int(server_start_id), + get_servers_context.debug_error_string().c_str()); + } + GPR_ASSERT(0); + } + for (const auto& _server : get_servers_response.server()) { + all_servers_.push_back(_server); + StoreServerInJson(_server); + } + if (!get_servers_response.end()) { + server_start_id = GetServerID(all_servers_.back()) + 1; + } else { + break; + } + } + std::cout << "Number of servers = " << all_servers_.size() << std::endl; + } + + // Get sockets that belongs to servers + // Store sockets for dumping data + void GetSocketsOfServers() { + for (const auto& _server : all_servers_) { + std::cout << "Server ID" << GetServerID(_server) << "_" + << GetServerName(_server) << " listen_socket - "; + for (const auto& _socket : _server.listen_socket()) { + int64_t so_id = _socket.socket_id(); + std::cout << "ID" << so_id << "_" << _socket.name() << " "; + if (CheckID(so_id)) { + grpc::channelz::v1::Socket so = GetSocketRPC(so_id); + all_sockets_.push_back(so); + StoreSocketInJson(so); + } + } + std::cout << std::endl; + } + } + + // Get all top channels, keep querying until getting all + // Store channels for dumping data + // No need to check id repeating for top channels + void GetTopChannelsRPC() { + int64_t channel_start_id = 0; + while (true) { + GetTopChannelsRequest get_top_channels_request; + GetTopChannelsResponse get_top_channels_response; + ClientContext get_top_channels_context; + get_top_channels_context.set_deadline( + grpc_timeout_seconds_to_deadline(rpc_timeout_seconds_)); + get_top_channels_request.set_start_channel_id(channel_start_id); + Status status = channelz_stub_->GetTopChannels( + &get_top_channels_context, get_top_channels_request, + &get_top_channels_response); + if (!status.ok()) { + gpr_log(GPR_ERROR, + "GetTopChannels RPC with " + "GetTopChannelsRequest.channel_start_id=%d failed: %s", + int(channel_start_id), + get_top_channels_context.debug_error_string().c_str()); + GPR_ASSERT(0); + } + for (const auto& _topchannel : get_top_channels_response.channel()) { + top_channels_.push_back(_topchannel); + all_channels_.push_back(_topchannel); + StoreChannelInJson(_topchannel); + } + if (!get_top_channels_response.end()) { + channel_start_id = GetChannelID(top_channels_.back()) + 1; + } else { + break; + } + } + std::cout << std::endl + << "Number of top channels = " << top_channels_.size() + << std::endl; + } + + // layer traverse for each top channel + void TraverseTopChannels() { + for (const auto& _topchannel : top_channels_) { + int tree_depth = 0; + std::queue<grpc::channelz::v1::Channel> channel_queue; + std::queue<grpc::channelz::v1::Subchannel> subchannel_queue; + std::cout << "Tree depth = " << tree_depth << std::endl; + GetChannelDescedence(_topchannel, channel_queue, subchannel_queue); + while (!channel_queue.empty() || !subchannel_queue.empty()) { + ++tree_depth; + std::cout << "Tree depth = " << tree_depth << std::endl; + int ch_q_size = channel_queue.size(); + int subch_q_size = subchannel_queue.size(); + for (int i = 0; i < ch_q_size; ++i) { + grpc::channelz::v1::Channel ch = channel_queue.front(); + channel_queue.pop(); + GetChannelDescedence(ch, channel_queue, subchannel_queue); + } + for (int i = 0; i < subch_q_size; ++i) { + grpc::channelz::v1::Subchannel subch = subchannel_queue.front(); + subchannel_queue.pop(); + GetSubchannelDescedence(subch, channel_queue, subchannel_queue); + } + } + std::cout << std::endl; + } + } + + // dump data of all entities to stdout + void DumpStdout() { + TString data_str; + for (const auto& _channel : all_channels_) { + std::cout << "channel ID" << GetChannelID(_channel) << "_" + << GetChannelName(_channel) << " data:" << std::endl; + // TODO(mohanli): TextFormat::PrintToString records time as seconds and + // nanos. Need a more human readable way. + ::google::protobuf::TextFormat::PrintToString(_channel.data(), &data_str); + printf("%s\n", data_str.c_str()); + } + for (const auto& _subchannel : all_subchannels_) { + std::cout << "subchannel ID" << GetSubchannelID(_subchannel) << "_" + << GetSubchannelName(_subchannel) << " data:" << std::endl; + ::google::protobuf::TextFormat::PrintToString(_subchannel.data(), + &data_str); + printf("%s\n", data_str.c_str()); + } + for (const auto& _server : all_servers_) { + std::cout << "server ID" << GetServerID(_server) << "_" + << GetServerName(_server) << " data:" << std::endl; + ::google::protobuf::TextFormat::PrintToString(_server.data(), &data_str); + printf("%s\n", data_str.c_str()); + } + for (const auto& _socket : all_sockets_) { + std::cout << "socket ID" << GetSocketID(_socket) << "_" + << GetSocketName(_socket) << " data:" << std::endl; + ::google::protobuf::TextFormat::PrintToString(_socket.data(), &data_str); + printf("%s\n", data_str.c_str()); + } + } + + // Store a channel in Json + void StoreChannelInJson(const grpc::channelz::v1::Channel& channel) { + TString id = grpc::to_string(GetChannelID(channel)); + TString type = "Channel"; + TString description; + ::google::protobuf::TextFormat::PrintToString(channel.data(), &description); + grpc_core::Json description_json = grpc_core::Json(description); + StoreEntityInJson(id, type, description_json); + } + + // Store a subchannel in Json + void StoreSubchannelInJson(const grpc::channelz::v1::Subchannel& subchannel) { + TString id = grpc::to_string(GetSubchannelID(subchannel)); + TString type = "Subchannel"; + TString description; + ::google::protobuf::TextFormat::PrintToString(subchannel.data(), + &description); + grpc_core::Json description_json = grpc_core::Json(description); + StoreEntityInJson(id, type, description_json); + } + + // Store a server in Json + void StoreServerInJson(const grpc::channelz::v1::Server& server) { + TString id = grpc::to_string(GetServerID(server)); + TString type = "Server"; + TString description; + ::google::protobuf::TextFormat::PrintToString(server.data(), &description); + grpc_core::Json description_json = grpc_core::Json(description); + StoreEntityInJson(id, type, description_json); + } + + // Store a socket in Json + void StoreSocketInJson(const grpc::channelz::v1::Socket& socket) { + TString id = grpc::to_string(GetSocketID(socket)); + TString type = "Socket"; + TString description; + ::google::protobuf::TextFormat::PrintToString(socket.data(), &description); + grpc_core::Json description_json = grpc_core::Json(description); + StoreEntityInJson(id, type, description_json); + } + + // Store an entity in Json + void StoreEntityInJson(TString& id, TString& type, + const grpc_core::Json& description) { + TString start, finish; + gpr_timespec ago = gpr_time_sub( + now_, + gpr_time_from_seconds(FLAGS_sampling_interval_seconds, GPR_TIMESPAN)); + std::stringstream ss; + const time_t time_now = now_.tv_sec; + ss << std::put_time(std::localtime(&time_now), "%F %T"); + finish = ss.str(); // example: "2019-02-01 12:12:18" + ss.str(""); + const time_t time_ago = ago.tv_sec; + ss << std::put_time(std::localtime(&time_ago), "%F %T"); + start = ss.str(); + grpc_core::Json obj = + grpc_core::Json::Object{{"Task", y_absl::StrFormat("%s_ID%s", type, id)}, + {"Start", start}, + {"Finish", finish}, + {"ID", id}, + {"Type", type}, + {"Description", description}}; + json_.mutable_array()->push_back(obj); + } + + // Dump data in json + TString DumpJson() { return json_.Dump(); } + + // Check if one entity has been recorded + bool CheckID(int64_t id) { + if (id_set_.count(id) == 0) { + id_set_.insert(id); + return true; + } else { + return false; + } + } + + // Record current time + void RecordNow() { now_ = gpr_now(GPR_CLOCK_REALTIME); } + + private: + std::unique_ptr<grpc::channelz::v1::Channelz::Stub> channelz_stub_; + std::vector<grpc::channelz::v1::Channel> top_channels_; + std::vector<grpc::channelz::v1::Server> all_servers_; + std::vector<grpc::channelz::v1::Channel> all_channels_; + std::vector<grpc::channelz::v1::Subchannel> all_subchannels_; + std::vector<grpc::channelz::v1::Socket> all_sockets_; + std::unordered_set<int64_t> id_set_; + grpc_core::Json json_; + int64_t rpc_timeout_seconds_; + gpr_timespec now_; +}; + +int main(int argc, char** argv) { + grpc::testing::TestEnvironment env(argc, argv); + grpc::testing::InitTest(&argc, &argv, true); + std::ofstream output_file(FLAGS_output_json); + for (int i = 0; i < FLAGS_sampling_times; ++i) { + ChannelzSampler channelz_sampler; + channelz_sampler.Setup(FLAGS_custom_credentials_type, FLAGS_server_address); + std::cout << "Wait for sampling interval " + << FLAGS_sampling_interval_seconds << "s..." << std::endl; + const gpr_timespec kDelay = gpr_time_add( + gpr_now(GPR_CLOCK_MONOTONIC), + gpr_time_from_seconds(FLAGS_sampling_interval_seconds, GPR_TIMESPAN)); + gpr_sleep_until(kDelay); + std::cout << "##### " << i << "th sampling #####" << std::endl; + channelz_sampler.RecordNow(); + channelz_sampler.GetServersRPC(); + channelz_sampler.GetSocketsOfServers(); + channelz_sampler.GetTopChannelsRPC(); + channelz_sampler.TraverseTopChannels(); + channelz_sampler.DumpStdout(); + if (!FLAGS_output_json.empty()) { + output_file << channelz_sampler.DumpJson() << "\n" << std::flush; + } + } + output_file.close(); + return 0; +} diff --git a/contrib/libs/grpc/test/cpp/util/channelz_sampler_test.cc b/contrib/libs/grpc/test/cpp/util/channelz_sampler_test.cc index d81dbb0d05..02e44f7931 100644 --- a/contrib/libs/grpc/test/cpp/util/channelz_sampler_test.cc +++ b/contrib/libs/grpc/test/cpp/util/channelz_sampler_test.cc @@ -1,176 +1,176 @@ -/* - * - * Copyright 2016 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include <stdlib.h> -#include <unistd.h> - -#include <cstdlib> -#include <iostream> -#include <memory> -#include <util/generic/string.h> -#include <thread> - -#include "grpc/grpc.h" -#include "grpc/support/alloc.h" -#include "grpc/support/port_platform.h" -#include "grpcpp/channel.h" -#include "grpcpp/client_context.h" -#include "grpcpp/create_channel.h" -#include "grpcpp/ext/channelz_service_plugin.h" -#include "grpcpp/grpcpp.h" -#include "grpcpp/security/credentials.h" -#include "grpcpp/security/server_credentials.h" -#include "grpcpp/server.h" -#include "grpcpp/server_builder.h" -#include "grpcpp/server_context.h" -#include "gtest/gtest.h" -#include "src/core/lib/gpr/env.h" -#include "src/cpp/server/channelz/channelz_service.h" -#include "src/proto/grpc/testing/test.grpc.pb.h" -#include "test/core/util/test_config.h" -#include "test/cpp/util/subprocess.h" -#include "test/cpp/util/test_credentials_provider.h" - -static TString g_root; - -namespace { -using grpc::ClientContext; -using grpc::Server; -using grpc::ServerBuilder; -using grpc::ServerContext; -using grpc::Status; -} // namespace - -// Test variables -TString server_address("0.0.0.0:10000"); -TString custom_credentials_type("INSECURE_CREDENTIALS"); -TString sampling_times = "2"; -TString sampling_interval_seconds = "3"; -TString output_json("output.json"); - -// Creata an echo server -class EchoServerImpl final : public grpc::testing::TestService::Service { - Status EmptyCall(::grpc::ServerContext* context, - const grpc::testing::Empty* request, - grpc::testing::Empty* response) { - return Status::OK; - } -}; - -// Run client in a thread -void RunClient(const TString& client_id, gpr_event* done_ev) { - grpc::ChannelArguments channel_args; - std::shared_ptr<grpc::ChannelCredentials> channel_creds = - grpc::testing::GetCredentialsProvider()->GetChannelCredentials( - custom_credentials_type, &channel_args); - std::unique_ptr<grpc::testing::TestService::Stub> stub = - grpc::testing::TestService::NewStub( - grpc::CreateChannel(server_address, channel_creds)); - gpr_log(GPR_INFO, "Client %s is echoing!", client_id.c_str()); - while (true) { - if (gpr_event_wait(done_ev, grpc_timeout_seconds_to_deadline(1)) != - nullptr) { - return; - } - grpc::testing::Empty request; - grpc::testing::Empty response; - ClientContext context; - Status status = stub->EmptyCall(&context, request, &response); - if (!status.ok()) { - gpr_log(GPR_ERROR, "Client echo failed."); - GPR_ASSERT(0); - } - } -} - -// Create the channelz to test the connection to the server -bool WaitForConnection(int wait_server_seconds) { - grpc::ChannelArguments channel_args; - std::shared_ptr<grpc::ChannelCredentials> channel_creds = - grpc::testing::GetCredentialsProvider()->GetChannelCredentials( - custom_credentials_type, &channel_args); - auto channel = grpc::CreateChannel(server_address, channel_creds); - return channel->WaitForConnected( - grpc_timeout_seconds_to_deadline(wait_server_seconds)); -} - -// Test the channelz sampler -TEST(ChannelzSamplerTest, SimpleTest) { - // start server - ::grpc::channelz::experimental::InitChannelzService(); - EchoServerImpl service; - grpc::ServerBuilder builder; - auto server_creds = - grpc::testing::GetCredentialsProvider()->GetServerCredentials( - custom_credentials_type); - builder.AddListeningPort(server_address, server_creds); - builder.RegisterService(&service); - std::unique_ptr<Server> server(builder.BuildAndStart()); - gpr_log(GPR_INFO, "Server listening on %s", server_address.c_str()); - const int kWaitForServerSeconds = 10; - ASSERT_TRUE(WaitForConnection(kWaitForServerSeconds)); - // client threads - gpr_event done_ev1, done_ev2; - gpr_event_init(&done_ev1); - gpr_event_init(&done_ev2); - std::thread client_thread_1(RunClient, "1", &done_ev1); - std::thread client_thread_2(RunClient, "2", &done_ev2); - // Run the channelz sampler - grpc::SubProcess* test_driver = new grpc::SubProcess( - {g_root + "/channelz_sampler", "--server_address=" + server_address, - "--custom_credentials_type=" + custom_credentials_type, - "--sampling_times=" + sampling_times, - "--sampling_interval_seconds=" + sampling_interval_seconds, - "--output_json=" + output_json}); - int status = test_driver->Join(); - if (WIFEXITED(status)) { - if (WEXITSTATUS(status)) { - gpr_log(GPR_ERROR, - "Channelz sampler test test-runner exited with code %d", - WEXITSTATUS(status)); - GPR_ASSERT(0); // log the line number of the assertion failure - } - } else if (WIFSIGNALED(status)) { - gpr_log(GPR_ERROR, "Channelz sampler test test-runner ended from signal %d", - WTERMSIG(status)); - GPR_ASSERT(0); - } else { - gpr_log(GPR_ERROR, - "Channelz sampler test test-runner ended with unknown status %d", - status); - GPR_ASSERT(0); - } - delete test_driver; - gpr_event_set(&done_ev1, (void*)1); - gpr_event_set(&done_ev2, (void*)1); - client_thread_1.join(); - client_thread_2.join(); -} - -int main(int argc, char** argv) { - grpc::testing::TestEnvironment env(argc, argv); - ::testing::InitGoogleTest(&argc, argv); - TString me = argv[0]; - auto lslash = me.rfind('/'); - if (lslash != TString::npos) { - g_root = me.substr(0, lslash); - } else { - g_root = "."; - } - int ret = RUN_ALL_TESTS(); - return ret; -} +/* + * + * Copyright 2016 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include <stdlib.h> +#include <unistd.h> + +#include <cstdlib> +#include <iostream> +#include <memory> +#include <util/generic/string.h> +#include <thread> + +#include "grpc/grpc.h" +#include "grpc/support/alloc.h" +#include "grpc/support/port_platform.h" +#include "grpcpp/channel.h" +#include "grpcpp/client_context.h" +#include "grpcpp/create_channel.h" +#include "grpcpp/ext/channelz_service_plugin.h" +#include "grpcpp/grpcpp.h" +#include "grpcpp/security/credentials.h" +#include "grpcpp/security/server_credentials.h" +#include "grpcpp/server.h" +#include "grpcpp/server_builder.h" +#include "grpcpp/server_context.h" +#include "gtest/gtest.h" +#include "src/core/lib/gpr/env.h" +#include "src/cpp/server/channelz/channelz_service.h" +#include "src/proto/grpc/testing/test.grpc.pb.h" +#include "test/core/util/test_config.h" +#include "test/cpp/util/subprocess.h" +#include "test/cpp/util/test_credentials_provider.h" + +static TString g_root; + +namespace { +using grpc::ClientContext; +using grpc::Server; +using grpc::ServerBuilder; +using grpc::ServerContext; +using grpc::Status; +} // namespace + +// Test variables +TString server_address("0.0.0.0:10000"); +TString custom_credentials_type("INSECURE_CREDENTIALS"); +TString sampling_times = "2"; +TString sampling_interval_seconds = "3"; +TString output_json("output.json"); + +// Creata an echo server +class EchoServerImpl final : public grpc::testing::TestService::Service { + Status EmptyCall(::grpc::ServerContext* context, + const grpc::testing::Empty* request, + grpc::testing::Empty* response) { + return Status::OK; + } +}; + +// Run client in a thread +void RunClient(const TString& client_id, gpr_event* done_ev) { + grpc::ChannelArguments channel_args; + std::shared_ptr<grpc::ChannelCredentials> channel_creds = + grpc::testing::GetCredentialsProvider()->GetChannelCredentials( + custom_credentials_type, &channel_args); + std::unique_ptr<grpc::testing::TestService::Stub> stub = + grpc::testing::TestService::NewStub( + grpc::CreateChannel(server_address, channel_creds)); + gpr_log(GPR_INFO, "Client %s is echoing!", client_id.c_str()); + while (true) { + if (gpr_event_wait(done_ev, grpc_timeout_seconds_to_deadline(1)) != + nullptr) { + return; + } + grpc::testing::Empty request; + grpc::testing::Empty response; + ClientContext context; + Status status = stub->EmptyCall(&context, request, &response); + if (!status.ok()) { + gpr_log(GPR_ERROR, "Client echo failed."); + GPR_ASSERT(0); + } + } +} + +// Create the channelz to test the connection to the server +bool WaitForConnection(int wait_server_seconds) { + grpc::ChannelArguments channel_args; + std::shared_ptr<grpc::ChannelCredentials> channel_creds = + grpc::testing::GetCredentialsProvider()->GetChannelCredentials( + custom_credentials_type, &channel_args); + auto channel = grpc::CreateChannel(server_address, channel_creds); + return channel->WaitForConnected( + grpc_timeout_seconds_to_deadline(wait_server_seconds)); +} + +// Test the channelz sampler +TEST(ChannelzSamplerTest, SimpleTest) { + // start server + ::grpc::channelz::experimental::InitChannelzService(); + EchoServerImpl service; + grpc::ServerBuilder builder; + auto server_creds = + grpc::testing::GetCredentialsProvider()->GetServerCredentials( + custom_credentials_type); + builder.AddListeningPort(server_address, server_creds); + builder.RegisterService(&service); + std::unique_ptr<Server> server(builder.BuildAndStart()); + gpr_log(GPR_INFO, "Server listening on %s", server_address.c_str()); + const int kWaitForServerSeconds = 10; + ASSERT_TRUE(WaitForConnection(kWaitForServerSeconds)); + // client threads + gpr_event done_ev1, done_ev2; + gpr_event_init(&done_ev1); + gpr_event_init(&done_ev2); + std::thread client_thread_1(RunClient, "1", &done_ev1); + std::thread client_thread_2(RunClient, "2", &done_ev2); + // Run the channelz sampler + grpc::SubProcess* test_driver = new grpc::SubProcess( + {g_root + "/channelz_sampler", "--server_address=" + server_address, + "--custom_credentials_type=" + custom_credentials_type, + "--sampling_times=" + sampling_times, + "--sampling_interval_seconds=" + sampling_interval_seconds, + "--output_json=" + output_json}); + int status = test_driver->Join(); + if (WIFEXITED(status)) { + if (WEXITSTATUS(status)) { + gpr_log(GPR_ERROR, + "Channelz sampler test test-runner exited with code %d", + WEXITSTATUS(status)); + GPR_ASSERT(0); // log the line number of the assertion failure + } + } else if (WIFSIGNALED(status)) { + gpr_log(GPR_ERROR, "Channelz sampler test test-runner ended from signal %d", + WTERMSIG(status)); + GPR_ASSERT(0); + } else { + gpr_log(GPR_ERROR, + "Channelz sampler test test-runner ended with unknown status %d", + status); + GPR_ASSERT(0); + } + delete test_driver; + gpr_event_set(&done_ev1, (void*)1); + gpr_event_set(&done_ev2, (void*)1); + client_thread_1.join(); + client_thread_2.join(); +} + +int main(int argc, char** argv) { + grpc::testing::TestEnvironment env(argc, argv); + ::testing::InitGoogleTest(&argc, argv); + TString me = argv[0]; + auto lslash = me.rfind('/'); + if (lslash != TString::npos) { + g_root = me.substr(0, lslash); + } else { + g_root = "."; + } + int ret = RUN_ALL_TESTS(); + return ret; +} diff --git a/contrib/libs/grpc/test/cpp/util/cli_call.cc b/contrib/libs/grpc/test/cpp/util/cli_call.cc index 5b3631667f..722ad88970 100644 --- a/contrib/libs/grpc/test/cpp/util/cli_call.cc +++ b/contrib/libs/grpc/test/cpp/util/cli_call.cc @@ -25,23 +25,23 @@ #include <grpcpp/client_context.h> #include <grpcpp/support/byte_buffer.h> -#include <cmath> -#include <iostream> -#include <utility> - +#include <cmath> +#include <iostream> +#include <utility> + namespace grpc { namespace testing { namespace { void* tag(int i) { return (void*)static_cast<intptr_t>(i); } } // namespace -Status CliCall::Call(const std::shared_ptr<grpc::Channel>& channel, - const TString& method, const TString& request, - TString* response, +Status CliCall::Call(const std::shared_ptr<grpc::Channel>& channel, + const TString& method, const TString& request, + TString* response, const OutgoingMetadataContainer& metadata, IncomingMetadataContainer* server_initial_metadata, IncomingMetadataContainer* server_trailing_metadata) { - CliCall call(channel, method, metadata); + CliCall call(channel, method, metadata); call.Write(request); call.WritesDone(); if (!call.Read(response, server_initial_metadata)) { @@ -51,8 +51,8 @@ Status CliCall::Call(const std::shared_ptr<grpc::Channel>& channel, } CliCall::CliCall(const std::shared_ptr<grpc::Channel>& channel, - const TString& method, - const OutgoingMetadataContainer& metadata, CliArgs args) + const TString& method, + const OutgoingMetadataContainer& metadata, CliArgs args) : stub_(new grpc::GenericStub(channel)) { gpr_mu_init(&write_mu_); gpr_cv_init(&write_cv_); @@ -62,22 +62,22 @@ CliCall::CliCall(const std::shared_ptr<grpc::Channel>& channel, ctx_.AddMetadata(iter->first, iter->second); } } - - // Set deadline if timeout > 0 (default value -1 if no timeout specified) - if (args.timeout > 0) { - int64_t timeout_in_ns = ceil(args.timeout * 1e9); - - // Convert timeout (in nanoseconds) to a deadline - auto deadline = - gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), - gpr_time_from_nanos(timeout_in_ns, GPR_TIMESPAN)); - ctx_.set_deadline(deadline); - } else if (args.timeout != -1) { - fprintf( - stderr, - "WARNING: Non-positive timeout value, skipping setting deadline.\n"); - } - + + // Set deadline if timeout > 0 (default value -1 if no timeout specified) + if (args.timeout > 0) { + int64_t timeout_in_ns = ceil(args.timeout * 1e9); + + // Convert timeout (in nanoseconds) to a deadline + auto deadline = + gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), + gpr_time_from_nanos(timeout_in_ns, GPR_TIMESPAN)); + ctx_.set_deadline(deadline); + } else if (args.timeout != -1) { + fprintf( + stderr, + "WARNING: Non-positive timeout value, skipping setting deadline.\n"); + } + call_ = stub_->PrepareCall(&ctx_, method, &cq_); call_->StartCall(tag(1)); void* got_tag; @@ -91,7 +91,7 @@ CliCall::~CliCall() { gpr_mu_destroy(&write_mu_); } -void CliCall::Write(const TString& request) { +void CliCall::Write(const TString& request) { void* got_tag; bool ok; @@ -103,7 +103,7 @@ void CliCall::Write(const TString& request) { GPR_ASSERT(ok); } -bool CliCall::Read(TString* response, +bool CliCall::Read(TString* response, IncomingMetadataContainer* server_initial_metadata) { void* got_tag; bool ok; @@ -137,7 +137,7 @@ void CliCall::WritesDone() { GPR_ASSERT(ok); } -void CliCall::WriteAndWait(const TString& request) { +void CliCall::WriteAndWait(const TString& request) { grpc::Slice req_slice(request); grpc::ByteBuffer send_buffer(&req_slice, 1); @@ -161,7 +161,7 @@ void CliCall::WritesDoneAndWait() { } bool CliCall::ReadAndMaybeNotifyWrite( - TString* response, IncomingMetadataContainer* server_initial_metadata) { + TString* response, IncomingMetadataContainer* server_initial_metadata) { void* got_tag; bool ok; grpc::ByteBuffer recv_buffer; diff --git a/contrib/libs/grpc/test/cpp/util/cli_call.h b/contrib/libs/grpc/test/cpp/util/cli_call.h index 79d00d99f4..a01279cb74 100644 --- a/contrib/libs/grpc/test/cpp/util/cli_call.h +++ b/contrib/libs/grpc/test/cpp/util/cli_call.h @@ -25,16 +25,16 @@ #include <grpcpp/support/status.h> #include <grpcpp/support/string_ref.h> -#include <map> +#include <map> namespace grpc { -class ClientContext; - -struct CliArgs { - double timeout = -1; -}; - +class ClientContext; + +struct CliArgs { + double timeout = -1; +}; + namespace testing { // CliCall handles the sending and receiving of generic messages given the name @@ -42,40 +42,40 @@ namespace testing { // and thread-unsafe methods should not be used together. class CliCall final { public: - typedef std::multimap<TString, TString> OutgoingMetadataContainer; + typedef std::multimap<TString, TString> OutgoingMetadataContainer; typedef std::multimap<grpc::string_ref, grpc::string_ref> IncomingMetadataContainer; CliCall(const std::shared_ptr<grpc::Channel>& channel, - const TString& method, const OutgoingMetadataContainer& metadata, - CliArgs args); - CliCall(const std::shared_ptr<grpc::Channel>& channel, - const TString& method, const OutgoingMetadataContainer& metadata) - : CliCall(channel, method, metadata, CliArgs{}) {} - + const TString& method, const OutgoingMetadataContainer& metadata, + CliArgs args); + CliCall(const std::shared_ptr<grpc::Channel>& channel, + const TString& method, const OutgoingMetadataContainer& metadata) + : CliCall(channel, method, metadata, CliArgs{}) {} + ~CliCall(); // Perform an unary generic RPC. - static Status Call(const std::shared_ptr<grpc::Channel>& channel, - const TString& method, const TString& request, - TString* response, + static Status Call(const std::shared_ptr<grpc::Channel>& channel, + const TString& method, const TString& request, + TString* response, const OutgoingMetadataContainer& metadata, IncomingMetadataContainer* server_initial_metadata, IncomingMetadataContainer* server_trailing_metadata); // Send a generic request message in a synchronous manner. NOT thread-safe. - void Write(const TString& request); + void Write(const TString& request); // Send a generic request message in a synchronous manner. NOT thread-safe. void WritesDone(); // Receive a generic response message in a synchronous manner.NOT thread-safe. - bool Read(TString* response, + bool Read(TString* response, IncomingMetadataContainer* server_initial_metadata); // Thread-safe write. Must be used with ReadAndMaybeNotifyWrite. Send out a // generic request message and wait for ReadAndMaybeNotifyWrite to finish it. - void WriteAndWait(const TString& request); + void WriteAndWait(const TString& request); // Thread-safe WritesDone. Must be used with ReadAndMaybeNotifyWrite. Send out // WritesDone for gereneric request messages and wait for @@ -85,17 +85,17 @@ class CliCall final { // Thread-safe Read. Blockingly receive a generic response message. Notify // writes if they are finished when this read is waiting for a resposne. bool ReadAndMaybeNotifyWrite( - TString* response, + TString* response, IncomingMetadataContainer* server_initial_metadata); // Finish the RPC. Status Finish(IncomingMetadataContainer* server_trailing_metadata); - TString peer() const { return ctx_.peer(); } - + TString peer() const { return ctx_.peer(); } + private: std::unique_ptr<grpc::GenericStub> stub_; - grpc::ClientContext ctx_; + grpc::ClientContext ctx_; std::unique_ptr<grpc::GenericClientAsyncReaderWriter> call_; grpc::CompletionQueue cq_; gpr_mu write_mu_; diff --git a/contrib/libs/grpc/test/cpp/util/cli_call_test.cc b/contrib/libs/grpc/test/cpp/util/cli_call_test.cc index 4f0544b2e5..4bde83facd 100644 --- a/contrib/libs/grpc/test/cpp/util/cli_call_test.cc +++ b/contrib/libs/grpc/test/cpp/util/cli_call_test.cc @@ -100,14 +100,14 @@ TEST_F(CliCallTest, SimpleRpc) { EXPECT_EQ(response.message(), request.message()); EXPECT_TRUE(s.ok()); - const TString kMethod("/grpc.testing.EchoTestService/Echo"); - TString request_bin, response_bin, expected_response_bin; + const TString kMethod("/grpc.testing.EchoTestService/Echo"); + TString request_bin, response_bin, expected_response_bin; EXPECT_TRUE(request.SerializeToString(&request_bin)); EXPECT_TRUE(response.SerializeToString(&expected_response_bin)); - std::multimap<TString, TString> client_metadata; + std::multimap<TString, TString> client_metadata; std::multimap<grpc::string_ref, grpc::string_ref> server_initial_metadata, server_trailing_metadata; - client_metadata.insert(std::pair<TString, TString>("key1", "val1")); + client_metadata.insert(std::pair<TString, TString>("key1", "val1")); Status s2 = CliCall::Call(channel_, kMethod, request_bin, &response_bin, client_metadata, &server_initial_metadata, &server_trailing_metadata); diff --git a/contrib/libs/grpc/test/cpp/util/cli_credentials.cc b/contrib/libs/grpc/test/cpp/util/cli_credentials.cc index efd548eb9b..c377cb6b80 100644 --- a/contrib/libs/grpc/test/cpp/util/cli_credentials.cc +++ b/contrib/libs/grpc/test/cpp/util/cli_credentials.cc @@ -48,13 +48,13 @@ DEFINE_string( "If not empty, load this PEM formatted private key. Requires use of " "--ssl_client_cert"); DEFINE_string( - local_connect_type, "local_tcp", - "The type of local connections for which local channel credentials will " - "be applied. Should be local_tcp or uds."); -DEFINE_string( + local_connect_type, "local_tcp", + "The type of local connections for which local channel credentials will " + "be applied. Should be local_tcp or uds."); +DEFINE_string( channel_creds_type, "", - "The channel creds type: insecure, ssl, gdc (Google Default Credentials), " - "alts, or local."); + "The channel creds type: insecure, ssl, gdc (Google Default Credentials), " + "alts, or local."); DEFINE_string( call_creds, "", "Call credentials to use: none (default), or access_token=<token>. If " @@ -69,21 +69,21 @@ const char ACCESS_TOKEN_PREFIX[] = "access_token="; constexpr int ACCESS_TOKEN_PREFIX_LEN = sizeof(ACCESS_TOKEN_PREFIX) / sizeof(*ACCESS_TOKEN_PREFIX) - 1; -bool IsAccessToken(const TString& auth) { +bool IsAccessToken(const TString& auth) { return auth.length() > ACCESS_TOKEN_PREFIX_LEN && auth.compare(0, ACCESS_TOKEN_PREFIX_LEN, ACCESS_TOKEN_PREFIX) == 0; } -TString AccessToken(const TString& auth) { +TString AccessToken(const TString& auth) { if (!IsAccessToken(auth)) { return ""; } - return TString(auth.c_str(), ACCESS_TOKEN_PREFIX_LEN); + return TString(auth.c_str(), ACCESS_TOKEN_PREFIX_LEN); } } // namespace -TString CliCredentials::GetDefaultChannelCredsType() const { +TString CliCredentials::GetDefaultChannelCredsType() const { // Compatibility logic for --enable_ssl. if (FLAGS_enable_ssl) { fprintf(stderr, @@ -101,12 +101,12 @@ TString CliCredentials::GetDefaultChannelCredsType() const { return "insecure"; } -TString CliCredentials::GetDefaultCallCreds() const { +TString CliCredentials::GetDefaultCallCreds() const { if (!FLAGS_access_token.empty()) { fprintf(stderr, "warning: --access_token is deprecated. Use " "--call_creds=access_token=<token>.\n"); - return TString("access_token=") + FLAGS_access_token; + return TString("access_token=") + FLAGS_access_token; } return "none"; } @@ -142,28 +142,28 @@ CliCredentials::GetChannelCredentials() const { } else if (FLAGS_channel_creds_type.compare("alts") == 0) { return grpc::experimental::AltsCredentials( grpc::experimental::AltsCredentialsOptions()); - } else if (FLAGS_channel_creds_type.compare("local") == 0) { - if (FLAGS_local_connect_type.compare("local_tcp") == 0) { - return grpc::experimental::LocalCredentials(LOCAL_TCP); - } else if (FLAGS_local_connect_type.compare("uds") == 0) { - return grpc::experimental::LocalCredentials(UDS); - } else { - fprintf(stderr, - "--local_connect_type=%s invalid; must be local_tcp or uds.\n", - FLAGS_local_connect_type.c_str()); - } + } else if (FLAGS_channel_creds_type.compare("local") == 0) { + if (FLAGS_local_connect_type.compare("local_tcp") == 0) { + return grpc::experimental::LocalCredentials(LOCAL_TCP); + } else if (FLAGS_local_connect_type.compare("uds") == 0) { + return grpc::experimental::LocalCredentials(UDS); + } else { + fprintf(stderr, + "--local_connect_type=%s invalid; must be local_tcp or uds.\n", + FLAGS_local_connect_type.c_str()); + } } fprintf(stderr, - "--channel_creds_type=%s invalid; must be insecure, ssl, gdc, " - "alts, or local.\n", + "--channel_creds_type=%s invalid; must be insecure, ssl, gdc, " + "alts, or local.\n", FLAGS_channel_creds_type.c_str()); return std::shared_ptr<grpc::ChannelCredentials>(); } std::shared_ptr<grpc::CallCredentials> CliCredentials::GetCallCredentials() const { - if (IsAccessToken(FLAGS_call_creds.c_str())) { - return grpc::AccessTokenCredentials(AccessToken(FLAGS_call_creds.c_str())); + if (IsAccessToken(FLAGS_call_creds.c_str())) { + return grpc::AccessTokenCredentials(AccessToken(FLAGS_call_creds.c_str())); } if (FLAGS_call_creds.compare("none") == 0) { // Nothing to do; creds, if any, are baked into the channel. @@ -180,7 +180,7 @@ std::shared_ptr<grpc::ChannelCredentials> CliCredentials::GetCredentials() const { if (FLAGS_call_creds.empty()) { FLAGS_call_creds = GetDefaultCallCreds(); - } else if (!FLAGS_access_token.empty() && !IsAccessToken(FLAGS_call_creds.c_str())) { + } else if (!FLAGS_access_token.empty() && !IsAccessToken(FLAGS_call_creds.c_str())) { fprintf(stderr, "warning: ignoring --access_token because --call_creds " "already set to %s.\n", @@ -200,7 +200,7 @@ std::shared_ptr<grpc::ChannelCredentials> CliCredentials::GetCredentials() FLAGS_channel_creds_type.c_str()); } // Legacy transport upgrade logic for insecure requests. - if (IsAccessToken(FLAGS_call_creds.c_str()) && + if (IsAccessToken(FLAGS_call_creds.c_str()) && FLAGS_channel_creds_type.compare("insecure") == 0) { fprintf(stderr, "warning: --channel_creds_type=insecure upgraded to ssl because " @@ -216,9 +216,9 @@ std::shared_ptr<grpc::ChannelCredentials> CliCredentials::GetCredentials() : grpc::CompositeChannelCredentials(channel_creds, call_creds); } -const TString CliCredentials::GetCredentialUsage() const { - return " --enable_ssl ; Set whether to use ssl " - "(deprecated)\n" +const TString CliCredentials::GetCredentialUsage() const { + return " --enable_ssl ; Set whether to use ssl " + "(deprecated)\n" " --use_auth ; Set whether to create default google" " credentials\n" " ; (deprecated)\n" @@ -228,14 +228,14 @@ const TString CliCredentials::GetCredentialUsage() const { " --ssl_target ; Set server host for ssl validation\n" " --ssl_client_cert ; Client cert for ssl\n" " --ssl_client_key ; Client private key for ssl\n" - " --local_connect_type ; Set to local_tcp or uds\n" - " --channel_creds_type ; Set to insecure, ssl, gdc, alts, or " - "local\n" + " --local_connect_type ; Set to local_tcp or uds\n" + " --channel_creds_type ; Set to insecure, ssl, gdc, alts, or " + "local\n" " --call_creds ; Set to none, or" " access_token=<token>\n"; } -const TString CliCredentials::GetSslTargetNameOverride() const { +const TString CliCredentials::GetSslTargetNameOverride() const { bool use_ssl = FLAGS_channel_creds_type.compare("ssl") == 0 || FLAGS_channel_creds_type.compare("gdc") == 0; return use_ssl ? FLAGS_ssl_target : ""; diff --git a/contrib/libs/grpc/test/cpp/util/cli_credentials.h b/contrib/libs/grpc/test/cpp/util/cli_credentials.h index 3e695692fa..43f098f245 100644 --- a/contrib/libs/grpc/test/cpp/util/cli_credentials.h +++ b/contrib/libs/grpc/test/cpp/util/cli_credentials.h @@ -29,16 +29,16 @@ class CliCredentials { public: virtual ~CliCredentials() {} std::shared_ptr<grpc::ChannelCredentials> GetCredentials() const; - virtual const TString GetCredentialUsage() const; - virtual const TString GetSslTargetNameOverride() const; + virtual const TString GetCredentialUsage() const; + virtual const TString GetSslTargetNameOverride() const; protected: // Returns the appropriate channel_creds_type value for the set of legacy // flag arguments. - virtual TString GetDefaultChannelCredsType() const; + virtual TString GetDefaultChannelCredsType() const; // Returns the appropriate call_creds value for the set of legacy flag // arguments. - virtual TString GetDefaultCallCreds() const; + virtual TString GetDefaultCallCreds() const; // Returns the base transport channel credentials. Child classes can override // to support additional channel_creds_types unknown to this base class. virtual std::shared_ptr<grpc::ChannelCredentials> GetChannelCredentials() diff --git a/contrib/libs/grpc/test/cpp/util/create_test_channel.cc b/contrib/libs/grpc/test/cpp/util/create_test_channel.cc index 86d8e22af1..faeb6d3171 100644 --- a/contrib/libs/grpc/test/cpp/util/create_test_channel.cc +++ b/contrib/libs/grpc/test/cpp/util/create_test_channel.cc @@ -18,21 +18,21 @@ #include "test/cpp/util/create_test_channel.h" -#include <gflags/gflags.h> - +#include <gflags/gflags.h> + #include <grpc/support/log.h> #include <grpcpp/create_channel.h> #include <grpcpp/security/credentials.h> #include "test/cpp/util/test_credentials_provider.h" -DEFINE_string( - grpc_test_use_grpclb_with_child_policy, "", - "If non-empty, set a static service config on channels created by " - "grpc::CreateTestChannel, that configures the grpclb LB policy " - "with a child policy being the value of this flag (e.g. round_robin " - "or pick_first)."); - +DEFINE_string( + grpc_test_use_grpclb_with_child_policy, "", + "If non-empty, set a static service config on channels created by " + "grpc::CreateTestChannel, that configures the grpclb LB policy " + "with a child policy being the value of this flag (e.g. round_robin " + "or pick_first)."); + namespace grpc { namespace { @@ -58,16 +58,16 @@ void AddProdSslType() { new SslCredentialProvider)); } -void MaybeSetCustomChannelArgs(grpc::ChannelArguments* args) { - if (FLAGS_grpc_test_use_grpclb_with_child_policy.size() > 0) { - args->SetString("grpc.service_config", - "{\"loadBalancingConfig\":[{\"grpclb\":{\"childPolicy\":[{" - "\"" + - FLAGS_grpc_test_use_grpclb_with_child_policy + - "\":{}}]}}]}"); - } -} - +void MaybeSetCustomChannelArgs(grpc::ChannelArguments* args) { + if (FLAGS_grpc_test_use_grpclb_with_child_policy.size() > 0) { + args->SetString("grpc.service_config", + "{\"loadBalancingConfig\":[{\"grpclb\":{\"childPolicy\":[{" + "\"" + + FLAGS_grpc_test_use_grpclb_with_child_policy + + "\":{}}]}}]}"); + } +} + } // namespace // When cred_type is 'ssl', if server is empty, override_hostname is used to @@ -86,8 +86,8 @@ void MaybeSetCustomChannelArgs(grpc::ChannelArguments* args) { // same as above // CreateTestChannel("", "ssl", "test.google.com:443", true, creds); std::shared_ptr<Channel> CreateTestChannel( - const TString& server, const TString& cred_type, - const TString& override_hostname, bool use_prod_roots, + const TString& server, const TString& cred_type, + const TString& override_hostname, bool use_prod_roots, const std::shared_ptr<CallCredentials>& creds, const ChannelArguments& args) { return CreateTestChannel(server, cred_type, override_hostname, use_prod_roots, @@ -96,7 +96,7 @@ std::shared_ptr<Channel> CreateTestChannel( } std::shared_ptr<Channel> CreateTestChannel( - const TString& server, const TString& override_hostname, + const TString& server, const TString& override_hostname, testing::transport_security security_type, bool use_prod_roots, const std::shared_ptr<CallCredentials>& creds, const ChannelArguments& args) { @@ -106,7 +106,7 @@ std::shared_ptr<Channel> CreateTestChannel( } std::shared_ptr<Channel> CreateTestChannel( - const TString& server, const TString& override_hostname, + const TString& server, const TString& override_hostname, testing::transport_security security_type, bool use_prod_roots, const std::shared_ptr<CallCredentials>& creds) { return CreateTestChannel(server, override_hostname, security_type, @@ -114,7 +114,7 @@ std::shared_ptr<Channel> CreateTestChannel( } std::shared_ptr<Channel> CreateTestChannel( - const TString& server, const TString& override_hostname, + const TString& server, const TString& override_hostname, testing::transport_security security_type, bool use_prod_roots) { return CreateTestChannel(server, override_hostname, security_type, use_prod_roots, std::shared_ptr<CallCredentials>()); @@ -122,15 +122,15 @@ std::shared_ptr<Channel> CreateTestChannel( // Shortcut for end2end and interop tests. std::shared_ptr<Channel> CreateTestChannel( - const TString& server, testing::transport_security security_type) { + const TString& server, testing::transport_security security_type) { return CreateTestChannel(server, "foo.test.google.fr", security_type, false); } std::shared_ptr<Channel> CreateTestChannel( - const TString& server, const TString& credential_type, + const TString& server, const TString& credential_type, const std::shared_ptr<CallCredentials>& creds) { ChannelArguments channel_args; - MaybeSetCustomChannelArgs(&channel_args); + MaybeSetCustomChannelArgs(&channel_args); std::shared_ptr<ChannelCredentials> channel_creds = testing::GetCredentialsProvider()->GetChannelCredentials(credential_type, &channel_args); @@ -142,22 +142,22 @@ std::shared_ptr<Channel> CreateTestChannel( } std::shared_ptr<Channel> CreateTestChannel( - const TString& server, const TString& cred_type, - const TString& override_hostname, bool use_prod_roots, + const TString& server, const TString& cred_type, + const TString& override_hostname, bool use_prod_roots, const std::shared_ptr<CallCredentials>& creds, const ChannelArguments& args, std::vector< std::unique_ptr<experimental::ClientInterceptorFactoryInterface>> interceptor_creators) { ChannelArguments channel_args(args); - MaybeSetCustomChannelArgs(&channel_args); + MaybeSetCustomChannelArgs(&channel_args); std::shared_ptr<ChannelCredentials> channel_creds; if (cred_type.empty()) { if (interceptor_creators.empty()) { return ::grpc::CreateCustomChannel(server, InsecureChannelCredentials(), - channel_args); + channel_args); } else { return experimental::CreateCustomChannelWithInterceptors( - server, InsecureChannelCredentials(), channel_args, + server, InsecureChannelCredentials(), channel_args, std::move(interceptor_creators)); } } else if (cred_type == testing::kTlsCredentialsType) { // cred_type == "ssl" @@ -175,7 +175,7 @@ std::shared_ptr<Channel> CreateTestChannel( } GPR_ASSERT(channel_creds != nullptr); - const TString& connect_to = server.empty() ? override_hostname : server; + const TString& connect_to = server.empty() ? override_hostname : server; if (creds.get()) { channel_creds = grpc::CompositeChannelCredentials(channel_creds, creds); } @@ -193,22 +193,22 @@ std::shared_ptr<Channel> CreateTestChannel( GPR_ASSERT(channel_creds != nullptr); if (interceptor_creators.empty()) { - return ::grpc::CreateCustomChannel(server, channel_creds, channel_args); + return ::grpc::CreateCustomChannel(server, channel_creds, channel_args); } else { return experimental::CreateCustomChannelWithInterceptors( - server, channel_creds, channel_args, std::move(interceptor_creators)); + server, channel_creds, channel_args, std::move(interceptor_creators)); } } } std::shared_ptr<Channel> CreateTestChannel( - const TString& server, const TString& override_hostname, + const TString& server, const TString& override_hostname, testing::transport_security security_type, bool use_prod_roots, const std::shared_ptr<CallCredentials>& creds, const ChannelArguments& args, std::vector< std::unique_ptr<experimental::ClientInterceptorFactoryInterface>> interceptor_creators) { - TString credential_type = + TString credential_type = security_type == testing::ALTS ? testing::kAltsCredentialsType : (security_type == testing::TLS ? testing::kTlsCredentialsType @@ -219,7 +219,7 @@ std::shared_ptr<Channel> CreateTestChannel( } std::shared_ptr<Channel> CreateTestChannel( - const TString& server, const TString& override_hostname, + const TString& server, const TString& override_hostname, testing::transport_security security_type, bool use_prod_roots, const std::shared_ptr<CallCredentials>& creds, std::vector< @@ -231,13 +231,13 @@ std::shared_ptr<Channel> CreateTestChannel( } std::shared_ptr<Channel> CreateTestChannel( - const TString& server, const TString& credential_type, + const TString& server, const TString& credential_type, const std::shared_ptr<CallCredentials>& creds, std::vector< std::unique_ptr<experimental::ClientInterceptorFactoryInterface>> interceptor_creators) { ChannelArguments channel_args; - MaybeSetCustomChannelArgs(&channel_args); + MaybeSetCustomChannelArgs(&channel_args); std::shared_ptr<ChannelCredentials> channel_creds = testing::GetCredentialsProvider()->GetChannelCredentials(credential_type, &channel_args); diff --git a/contrib/libs/grpc/test/cpp/util/create_test_channel.h b/contrib/libs/grpc/test/cpp/util/create_test_channel.h index ed4ce6c11b..a4ea9d999d 100644 --- a/contrib/libs/grpc/test/cpp/util/create_test_channel.h +++ b/contrib/libs/grpc/test/cpp/util/create_test_channel.h @@ -26,7 +26,7 @@ #include <grpcpp/security/credentials.h> #include <grpcpp/support/channel_arguments.h> -namespace grpc { +namespace grpc { class Channel; namespace testing { @@ -36,35 +36,35 @@ typedef enum { INSECURE = 0, TLS, ALTS } transport_security; } // namespace testing std::shared_ptr<Channel> CreateTestChannel( - const TString& server, testing::transport_security security_type); + const TString& server, testing::transport_security security_type); std::shared_ptr<Channel> CreateTestChannel( - const TString& server, const TString& override_hostname, + const TString& server, const TString& override_hostname, testing::transport_security security_type, bool use_prod_roots); std::shared_ptr<Channel> CreateTestChannel( - const TString& server, const TString& override_hostname, + const TString& server, const TString& override_hostname, testing::transport_security security_type, bool use_prod_roots, const std::shared_ptr<CallCredentials>& creds); std::shared_ptr<Channel> CreateTestChannel( - const TString& server, const TString& override_hostname, + const TString& server, const TString& override_hostname, testing::transport_security security_type, bool use_prod_roots, const std::shared_ptr<CallCredentials>& creds, const ChannelArguments& args); std::shared_ptr<Channel> CreateTestChannel( - const TString& server, const TString& cred_type, - const TString& override_hostname, bool use_prod_roots, + const TString& server, const TString& cred_type, + const TString& override_hostname, bool use_prod_roots, const std::shared_ptr<CallCredentials>& creds, const ChannelArguments& args); std::shared_ptr<Channel> CreateTestChannel( - const TString& server, const TString& credential_type, + const TString& server, const TString& credential_type, const std::shared_ptr<CallCredentials>& creds); std::shared_ptr<Channel> CreateTestChannel( - const TString& server, const TString& override_hostname, + const TString& server, const TString& override_hostname, testing::transport_security security_type, bool use_prod_roots, const std::shared_ptr<CallCredentials>& creds, std::vector< @@ -72,7 +72,7 @@ std::shared_ptr<Channel> CreateTestChannel( interceptor_creators); std::shared_ptr<Channel> CreateTestChannel( - const TString& server, const TString& override_hostname, + const TString& server, const TString& override_hostname, testing::transport_security security_type, bool use_prod_roots, const std::shared_ptr<CallCredentials>& creds, const ChannelArguments& args, std::vector< @@ -80,15 +80,15 @@ std::shared_ptr<Channel> CreateTestChannel( interceptor_creators); std::shared_ptr<Channel> CreateTestChannel( - const TString& server, const TString& cred_type, - const TString& override_hostname, bool use_prod_roots, + const TString& server, const TString& cred_type, + const TString& override_hostname, bool use_prod_roots, const std::shared_ptr<CallCredentials>& creds, const ChannelArguments& args, std::vector< std::unique_ptr<experimental::ClientInterceptorFactoryInterface>> interceptor_creators); std::shared_ptr<Channel> CreateTestChannel( - const TString& server, const TString& credential_type, + const TString& server, const TString& credential_type, const std::shared_ptr<CallCredentials>& creds, std::vector< std::unique_ptr<experimental::ClientInterceptorFactoryInterface>> diff --git a/contrib/libs/grpc/test/cpp/util/error_details_test.cc b/contrib/libs/grpc/test/cpp/util/error_details_test.cc index 630ab1d98f..2482a6bf2e 100644 --- a/contrib/libs/grpc/test/cpp/util/error_details_test.cc +++ b/contrib/libs/grpc/test/cpp/util/error_details_test.cc @@ -21,7 +21,7 @@ #include "src/proto/grpc/status/status.pb.h" #include "src/proto/grpc/testing/echo_messages.pb.h" -#include "test/core/util/test_config.h" +#include "test/core/util/test_config.h" namespace grpc { namespace { @@ -31,11 +31,11 @@ TEST(ExtractTest, Success) { expected.set_code(13); // INTERNAL expected.set_message("I am an error message"); testing::EchoRequest expected_details; - expected_details.set_message(TString(100, '\0')); + expected_details.set_message(TString(100, '\0')); expected.add_details()->PackFrom(expected_details); google::rpc::Status to; - TString error_details = expected.SerializeAsString(); + TString error_details = expected.SerializeAsString(); Status from(static_cast<StatusCode>(expected.code()), expected.message(), error_details); EXPECT_TRUE(ExtractErrorDetails(from, &to).ok()); @@ -53,7 +53,7 @@ TEST(ExtractTest, NullInput) { } TEST(ExtractTest, Unparsable) { - TString error_details("I am not a status object"); + TString error_details("I am not a status object"); Status from(StatusCode::INTERNAL, "", error_details); google::rpc::Status to; EXPECT_EQ(StatusCode::INVALID_ARGUMENT, @@ -65,7 +65,7 @@ TEST(SetTest, Success) { expected.set_code(13); // INTERNAL expected.set_message("I am an error message"); testing::EchoRequest expected_details; - expected_details.set_message(TString(100, '\0')); + expected_details.set_message(TString(100, '\0')); expected.add_details()->PackFrom(expected_details); Status to; @@ -86,7 +86,7 @@ TEST(SetTest, OutOfScopeErrorCode) { expected.set_code(17); // Out of scope (UNAUTHENTICATED is 16). expected.set_message("I am an error message"); testing::EchoRequest expected_details; - expected_details.set_message(TString(100, '\0')); + expected_details.set_message(TString(100, '\0')); expected.add_details()->PackFrom(expected_details); Status to; @@ -103,7 +103,7 @@ TEST(SetTest, ValidScopeErrorCode) { expected.set_code(c); expected.set_message("I am an error message"); testing::EchoRequest expected_details; - expected_details.set_message(TString(100, '\0')); + expected_details.set_message(TString(100, '\0')); expected.add_details()->PackFrom(expected_details); Status to; @@ -119,7 +119,7 @@ TEST(SetTest, ValidScopeErrorCode) { } // namespace grpc int main(int argc, char** argv) { - grpc::testing::TestEnvironment env(argc, argv); + grpc::testing::TestEnvironment env(argc, argv); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/contrib/libs/grpc/test/cpp/util/grpc_cli.cc b/contrib/libs/grpc/test/cpp/util/grpc_cli.cc index 45c6b94f84..45e509658e 100644 --- a/contrib/libs/grpc/test/cpp/util/grpc_cli.cc +++ b/contrib/libs/grpc/test/cpp/util/grpc_cli.cc @@ -51,11 +51,11 @@ --decode=grpc.testing.SimpleResponse \ src/proto/grpc/testing/messages.proto \ < output.bin > output.txt - 10. --default_service_config, optional default service config to use - on the channel. Note that this may be ignored if the name resolver - returns a service config. - 11. --display_peer_address, on CallMethod commands, log the peer socket - address of the connection that each RPC is made on to stderr. + 10. --default_service_config, optional default service config to use + on the channel. Note that this may be ignored if the name resolver + returns a service config. + 11. --display_peer_address, on CallMethod commands, log the peer socket + address of the connection that each RPC is made on to stderr. */ #include <fstream> @@ -70,12 +70,12 @@ DEFINE_string(outfile, "", "Output file (default is stdout)"); -static bool SimplePrint(const TString& outfile, const TString& output) { +static bool SimplePrint(const TString& outfile, const TString& output) { if (outfile.empty()) { - std::cout << output << std::flush; + std::cout << output << std::flush; } else { std::ofstream output_file(outfile, std::ios::app | std::ios::binary); - output_file << output << std::flush; + output_file << output << std::flush; output_file.close(); } return true; @@ -86,5 +86,5 @@ int main(int argc, char** argv) { return grpc::testing::GrpcToolMainLib( argc, (const char**)argv, grpc::testing::CliCredentials(), - std::bind(SimplePrint, TString(FLAGS_outfile.c_str()), std::placeholders::_1)); + std::bind(SimplePrint, TString(FLAGS_outfile.c_str()), std::placeholders::_1)); } diff --git a/contrib/libs/grpc/test/cpp/util/grpc_tool.cc b/contrib/libs/grpc/test/cpp/util/grpc_tool.cc index 30f3024e25..aaa5ef3f5d 100644 --- a/contrib/libs/grpc/test/cpp/util/grpc_tool.cc +++ b/contrib/libs/grpc/test/cpp/util/grpc_tool.cc @@ -27,14 +27,14 @@ #include <grpcpp/security/credentials.h> #include <grpcpp/support/string_ref.h> -#include <cstdio> -#include <fstream> -#include <iostream> -#include <memory> -#include <sstream> -#include <util/generic/string.h> -#include <thread> - +#include <cstdio> +#include <fstream> +#include <iostream> +#include <memory> +#include <sstream> +#include <util/generic/string.h> +#include <thread> + #include "test/cpp/util/cli_call.h" #include "test/cpp/util/proto_file_parser.h" #include "test/cpp/util/proto_reflection_descriptor_database.h" @@ -57,15 +57,15 @@ DEFINE_string(proto_path, ".", "Path to look for the proto file."); DEFINE_string(protofiles, "", "Name of the proto file."); DEFINE_bool(binary_input, false, "Input in binary format"); DEFINE_bool(binary_output, false, "Output in binary format"); -DEFINE_string( - default_service_config, "", - "Default service config to use on the channel, if non-empty. Note " - "that this will be ignored if the name resolver returns a service " - "config."); -DEFINE_bool( - display_peer_address, false, - "Log the peer socket address of the connection that each RPC is made " - "on to stderr."); +DEFINE_string( + default_service_config, "", + "Default service config to use on the channel, if non-empty. Note " + "that this will be ignored if the name resolver returns a service " + "config."); +DEFINE_bool( + display_peer_address, false, + "Log the peer socket address of the connection that each RPC is made " + "on to stderr."); DEFINE_bool(json_input, false, "Input in json format"); DEFINE_bool(json_output, false, "Output in json format"); DEFINE_string(infile, "", "Input file (default is stdin)"); @@ -74,9 +74,9 @@ DEFINE_bool(batch, false, "more than a few RPCs. gRPC CLI has very different performance " "characteristics compared with normal RPC calls which make it " "unsuitable for loadtesting or significant production traffic."); -DEFINE_double(timeout, -1, - "Specify timeout in seconds, used to set the deadline for all " - "RPCs. The default value of -1 means no deadline has been set."); +DEFINE_double(timeout, -1, + "Specify timeout in seconds, used to set the deadline for all " + "RPCs. The default value of -1 means no deadline has been set."); namespace { @@ -113,10 +113,10 @@ class GrpcTool { } private: - void CommandUsage(const TString& usage) const; + void CommandUsage(const TString& usage) const; bool print_command_usage_; int usage_exit_status_; - const TString cred_usage_; + const TString cred_usage_; }; template <typename T> @@ -135,11 +135,11 @@ size_t ArraySize(T& a) { } void ParseMetadataFlag( - std::multimap<TString, TString>* client_metadata) { + std::multimap<TString, TString>* client_metadata) { if (FLAGS_metadata.empty()) { return; } - std::vector<TString> fields; + std::vector<TString> fields; const char delim = ':'; const char escape = '\\'; size_t cur = -1; @@ -172,17 +172,17 @@ void ParseMetadataFlag( } for (size_t i = 0; i < fields.size(); i += 2) { client_metadata->insert( - std::pair<TString, TString>(fields[i], fields[i + 1])); + std::pair<TString, TString>(fields[i], fields[i + 1])); } } template <typename T> -void PrintMetadata(const T& m, const TString& message) { +void PrintMetadata(const T& m, const TString& message) { if (m.empty()) { return; } fprintf(stderr, "%s\n", message.c_str()); - TString pair; + TString pair; for (typename T::const_iterator iter = m.begin(); iter != m.end(); ++iter) { pair.clear(); pair.append(iter->first.data(), iter->first.size()); @@ -192,10 +192,10 @@ void PrintMetadata(const T& m, const TString& message) { } } -void ReadResponse(CliCall* call, const TString& method_name, +void ReadResponse(CliCall* call, const TString& method_name, GrpcToolOutputCallback callback, ProtoFileParser* parser, gpr_mu* parser_mu, bool print_mode) { - TString serialized_response_proto; + TString serialized_response_proto; std::multimap<grpc::string_ref, grpc::string_ref> server_initial_metadata; for (bool receive_initial_metadata = true; call->ReadAndMaybeNotifyWrite( @@ -224,15 +224,15 @@ void ReadResponse(CliCall* call, const TString& method_name, } std::shared_ptr<grpc::Channel> CreateCliChannel( - const TString& server_address, const CliCredentials& cred) { + const TString& server_address, const CliCredentials& cred) { grpc::ChannelArguments args; if (!cred.GetSslTargetNameOverride().empty()) { args.SetSslTargetNameOverride(cred.GetSslTargetNameOverride()); } - if (!FLAGS_default_service_config.empty()) { - args.SetString(GRPC_ARG_SERVICE_CONFIG, - FLAGS_default_service_config.c_str()); - } + if (!FLAGS_default_service_config.empty()) { + args.SetString(GRPC_ARG_SERVICE_CONFIG, + FLAGS_default_service_config.c_str()); + } return ::grpc::CreateCustomChannel(server_address, cred.GetCredentials(), args); } @@ -258,7 +258,7 @@ const Command ops[] = { {"tojson", BindWith5Args(&GrpcTool::ToJson), 2, 3}, }; -void Usage(const TString& msg) { +void Usage(const TString& msg) { fprintf( stderr, "%s\n" @@ -276,7 +276,7 @@ void Usage(const TString& msg) { exit(1); } -const Command* FindCommand(const TString& name) { +const Command* FindCommand(const TString& name) { for (int i = 0; i < (int)ArraySize(ops); i++) { if (name == ops[i].command) { return &ops[i]; @@ -292,7 +292,7 @@ int GrpcToolMainLib(int argc, const char** argv, const CliCredentials& cred, Usage("No command specified"); } - TString command = argv[1]; + TString command = argv[1]; argc -= 2; argv += 2; @@ -308,14 +308,14 @@ int GrpcToolMainLib(int argc, const char** argv, const CliCredentials& cred, const bool ok = cmd->function(&grpc_tool, argc, argv, cred, callback); return ok ? 0 : 1; } else { - Usage("Invalid command '" + TString(command.c_str()) + "'"); + Usage("Invalid command '" + TString(command.c_str()) + "'"); } return 1; } GrpcTool::GrpcTool() : print_command_usage_(false), usage_exit_status_(0) {} -void GrpcTool::CommandUsage(const TString& usage) const { +void GrpcTool::CommandUsage(const TString& usage) const { if (print_command_usage_) { fprintf(stderr, "\n%s%s\n", usage.c_str(), (usage.empty() || usage[usage.size() - 1] != '\n') ? "\n" : ""); @@ -334,7 +334,7 @@ bool GrpcTool::Help(int argc, const char** argv, const CliCredentials& cred, } else { const Command* cmd = FindCommand(argv[0]); if (cmd == nullptr) { - Usage("Unknown command '" + TString(argv[0]) + "'"); + Usage("Unknown command '" + TString(argv[0]) + "'"); } SetPrintCommandMode(0); cmd->function(this, -1, nullptr, cred, callback); @@ -355,20 +355,20 @@ bool GrpcTool::ListServices(int argc, const char** argv, " --outfile ; Output filename (defaults to stdout)\n" + cred.GetCredentialUsage()); - TString server_address(argv[0]); + TString server_address(argv[0]); std::shared_ptr<grpc::Channel> channel = CreateCliChannel(server_address, cred); grpc::ProtoReflectionDescriptorDatabase desc_db(channel); grpc::protobuf::DescriptorPool desc_pool(&desc_db); - std::vector<TString> service_list; + std::vector<TString> service_list; if (!desc_db.GetServices(&service_list)) { fprintf(stderr, "Received an error when querying services endpoint.\n"); return false; } // If no service is specified, dump the list of services. - TString output; + TString output; if (argc < 2) { // List all services, if --l is passed, then include full description, // otherwise include a summarized list only. @@ -382,8 +382,8 @@ bool GrpcTool::ListServices(int argc, const char** argv, } } } else { - std::string service_name; - std::string method_name; + std::string service_name; + std::string method_name; std::stringstream ss(argv[1]); // Remove leading slashes. @@ -453,13 +453,13 @@ bool GrpcTool::PrintType(int /*argc*/, const char** argv, " <type> ; Protocol buffer type name\n" + cred.GetCredentialUsage()); - TString server_address(argv[0]); + TString server_address(argv[0]); std::shared_ptr<grpc::Channel> channel = CreateCliChannel(server_address, cred); grpc::ProtoReflectionDescriptorDatabase desc_db(channel); grpc::protobuf::DescriptorPool desc_pool(&desc_db); - TString output; + TString output; const grpc::protobuf::Descriptor* descriptor = desc_pool.FindMessageTypeByName(argv[1]); if (descriptor != nullptr) { @@ -493,21 +493,21 @@ bool GrpcTool::CallMethod(int argc, const char** argv, " --binary_input ; Input in binary format\n" " --binary_output ; Output in binary format\n" " --json_input ; Input in json format\n" - " --json_output ; Output in json format\n" - " --timeout ; Specify timeout (in seconds), used to " - "set the deadline for RPCs. The default value of -1 means no " - "deadline has been set.\n" + + " --json_output ; Output in json format\n" + " --timeout ; Specify timeout (in seconds), used to " + "set the deadline for RPCs. The default value of -1 means no " + "deadline has been set.\n" + cred.GetCredentialUsage()); std::stringstream output_ss; - TString request_text; - TString server_address(argv[0]); - TString method_name(argv[1]); - TString formatted_method_name; + TString request_text; + TString server_address(argv[0]); + TString method_name(argv[1]); + TString formatted_method_name; std::unique_ptr<ProtoFileParser> parser; - TString serialized_request_proto; - CliArgs cli_args; - cli_args.timeout = FLAGS_timeout; + TString serialized_request_proto; + CliArgs cli_args; + cli_args.timeout = FLAGS_timeout; bool print_mode = false; std::shared_ptr<grpc::Channel> channel = @@ -516,7 +516,7 @@ bool GrpcTool::CallMethod(int argc, const char** argv, if (!FLAGS_binary_input || !FLAGS_binary_output) { parser.reset( new grpc::testing::ProtoFileParser(FLAGS_remotedb ? channel : nullptr, - FLAGS_proto_path.c_str(), FLAGS_protofiles.c_str())); + FLAGS_proto_path.c_str(), FLAGS_protofiles.c_str())); if (parser->HasError()) { fprintf( stderr, @@ -548,15 +548,15 @@ bool GrpcTool::CallMethod(int argc, const char** argv, return false; } - std::multimap<TString, TString> client_metadata; + std::multimap<TString, TString> client_metadata; ParseMetadataFlag(&client_metadata); PrintMetadata(client_metadata, "Sending client initial metadata:"); - CliCall call(channel, formatted_method_name, client_metadata, cli_args); - if (FLAGS_display_peer_address) { - fprintf(stderr, "New call for method_name:%s has peer address:|%s|\n", - formatted_method_name.c_str(), call.peer().c_str()); - } + CliCall call(channel, formatted_method_name, client_metadata, cli_args); + if (FLAGS_display_peer_address) { + fprintf(stderr, "New call for method_name:%s has peer address:|%s|\n", + formatted_method_name.c_str(), call.peer().c_str()); + } if (FLAGS_infile.empty()) { if (isatty(fileno(stdin))) { @@ -575,7 +575,7 @@ bool GrpcTool::CallMethod(int argc, const char** argv, parser.get(), &parser_mu, print_mode); std::stringstream request_ss; - std::string line; + std::string line; while (!request_text.empty() || (!input_stream->eof() && getline(*input_stream, line))) { if (!request_text.empty()) { @@ -605,7 +605,7 @@ bool GrpcTool::CallMethod(int argc, const char** argv, } else { if (line.length() == 0) { request_text = request_ss.str(); - request_ss.str(TString()); + request_ss.str(TString()); request_ss.clear(); } else { request_ss << line << ' '; @@ -655,14 +655,14 @@ bool GrpcTool::CallMethod(int argc, const char** argv, input_stream = &input_file; } - std::multimap<TString, TString> client_metadata; + std::multimap<TString, TString> client_metadata; ParseMetadataFlag(&client_metadata); if (print_mode) { PrintMetadata(client_metadata, "Sending client initial metadata:"); } std::stringstream request_ss; - std::string line; + std::string line; while (!request_text.empty() || (!input_stream->eof() && getline(*input_stream, line))) { if (!request_text.empty()) { @@ -682,16 +682,16 @@ bool GrpcTool::CallMethod(int argc, const char** argv, } } - TString serialized_response_proto; + TString serialized_response_proto; std::multimap<grpc::string_ref, grpc::string_ref> server_initial_metadata, server_trailing_metadata; - CliCall call(channel, formatted_method_name, client_metadata, - cli_args); - if (FLAGS_display_peer_address) { - fprintf(stderr, - "New call for method_name:%s has peer address:|%s|\n", - formatted_method_name.c_str(), call.peer().c_str()); - } + CliCall call(channel, formatted_method_name, client_metadata, + cli_args); + if (FLAGS_display_peer_address) { + fprintf(stderr, + "New call for method_name:%s has peer address:|%s|\n", + formatted_method_name.c_str(), call.peer().c_str()); + } call.Write(serialized_request_proto); call.WritesDone(); if (!call.Read(&serialized_response_proto, @@ -714,7 +714,7 @@ bool GrpcTool::CallMethod(int argc, const char** argv, break; } } else { - TString response_text = parser->GetFormattedStringFromMethod( + TString response_text = parser->GetFormattedStringFromMethod( method_name, serialized_response_proto, false /* is_request */, FLAGS_json_output); @@ -736,7 +736,7 @@ bool GrpcTool::CallMethod(int argc, const char** argv, } else { if (line.length() == 0) { request_text = request_ss.str(); - request_ss.str(TString()); + request_ss.str(TString()); request_ss.clear(); } else { request_ss << line << ' '; @@ -782,18 +782,18 @@ bool GrpcTool::CallMethod(int argc, const char** argv, } fprintf(stderr, "connecting to %s\n", server_address.c_str()); - TString serialized_response_proto; - std::multimap<TString, TString> client_metadata; + TString serialized_response_proto; + std::multimap<TString, TString> client_metadata; std::multimap<grpc::string_ref, grpc::string_ref> server_initial_metadata, server_trailing_metadata; ParseMetadataFlag(&client_metadata); PrintMetadata(client_metadata, "Sending client initial metadata:"); - CliCall call(channel, formatted_method_name, client_metadata, cli_args); - if (FLAGS_display_peer_address) { - fprintf(stderr, "New call for method_name:%s has peer address:|%s|\n", - formatted_method_name.c_str(), call.peer().c_str()); - } + CliCall call(channel, formatted_method_name, client_metadata, cli_args); + if (FLAGS_display_peer_address) { + fprintf(stderr, "New call for method_name:%s has peer address:|%s|\n", + formatted_method_name.c_str(), call.peer().c_str()); + } call.Write(serialized_request_proto); call.WritesDone(); @@ -858,11 +858,11 @@ bool GrpcTool::ParseMessage(int argc, const char** argv, cred.GetCredentialUsage()); std::stringstream output_ss; - TString message_text; - TString server_address(argv[0]); - TString type_name(argv[1]); + TString message_text; + TString server_address(argv[0]); + TString type_name(argv[1]); std::unique_ptr<grpc::testing::ProtoFileParser> parser; - TString serialized_request_proto; + TString serialized_request_proto; if (argc == 3) { message_text = argv[2]; @@ -889,7 +889,7 @@ bool GrpcTool::ParseMessage(int argc, const char** argv, CreateCliChannel(server_address, cred); parser.reset( new grpc::testing::ProtoFileParser(FLAGS_remotedb ? channel : nullptr, - FLAGS_proto_path.c_str(), FLAGS_protofiles.c_str())); + FLAGS_proto_path.c_str(), FLAGS_protofiles.c_str())); if (parser->HasError()) { fprintf( stderr, @@ -912,7 +912,7 @@ bool GrpcTool::ParseMessage(int argc, const char** argv, if (FLAGS_binary_output) { output_ss << serialized_request_proto; } else { - TString output_text; + TString output_text; output_text = parser->GetFormattedStringFromMessageType( type_name, serialized_request_proto, FLAGS_json_output); if (parser->HasError()) { diff --git a/contrib/libs/grpc/test/cpp/util/grpc_tool.h b/contrib/libs/grpc/test/cpp/util/grpc_tool.h index 5bb43430d3..7ee0bc9dbe 100644 --- a/contrib/libs/grpc/test/cpp/util/grpc_tool.h +++ b/contrib/libs/grpc/test/cpp/util/grpc_tool.h @@ -28,7 +28,7 @@ namespace grpc { namespace testing { -typedef std::function<bool(const TString&)> GrpcToolOutputCallback; +typedef std::function<bool(const TString&)> GrpcToolOutputCallback; int GrpcToolMainLib(int argc, const char** argv, const CliCredentials& cred, GrpcToolOutputCallback callback); diff --git a/contrib/libs/grpc/test/cpp/util/grpc_tool_test.cc b/contrib/libs/grpc/test/cpp/util/grpc_tool_test.cc index ff610daadd..95d78fa778 100644 --- a/contrib/libs/grpc/test/cpp/util/grpc_tool_test.cc +++ b/contrib/libs/grpc/test/cpp/util/grpc_tool_test.cc @@ -30,11 +30,11 @@ #include <grpcpp/server_context.h> #include <gtest/gtest.h> -#include <chrono> -#include <sstream> - +#include <chrono> +#include <sstream> + #include "src/core/lib/gpr/env.h" -#include "src/core/lib/iomgr/load_file.h" +#include "src/core/lib/iomgr/load_file.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "src/proto/grpc/testing/echo.pb.h" #include "test/core/util/port.h" @@ -42,10 +42,10 @@ #include "test/cpp/util/cli_credentials.h" #include "test/cpp/util/string_ref_helper.h" -#define CA_CERT_PATH "src/core/tsi/test_creds/ca.pem" -#define SERVER_CERT_PATH "src/core/tsi/test_creds/server1.pem" -#define SERVER_KEY_PATH "src/core/tsi/test_creds/server1.key" - +#define CA_CERT_PATH "src/core/tsi/test_creds/ca.pem" +#define SERVER_CERT_PATH "src/core/tsi/test_creds/server1.pem" +#define SERVER_KEY_PATH "src/core/tsi/test_creds/server1.key" + using grpc::testing::EchoRequest; using grpc::testing::EchoResponse; @@ -53,41 +53,41 @@ using grpc::testing::EchoResponse; #define ECHO_TEST_SERVICE_SUMMARY \ "Echo\n" \ - "Echo1\n" \ - "Echo2\n" \ - "CheckDeadlineUpperBound\n" \ - "CheckDeadlineSet\n" \ + "Echo1\n" \ + "Echo2\n" \ + "CheckDeadlineUpperBound\n" \ + "CheckDeadlineSet\n" \ "CheckClientInitialMetadata\n" \ "RequestStream\n" \ "ResponseStream\n" \ "BidiStream\n" \ "Unimplemented\n" -#define ECHO_TEST_SERVICE_DESCRIPTION \ - "filename: src/proto/grpc/testing/echo.proto\n" \ - "package: grpc.testing;\n" \ - "service EchoTestService {\n" \ - " rpc Echo(grpc.testing.EchoRequest) returns (grpc.testing.EchoResponse) " \ - "{}\n" \ - " rpc Echo1(grpc.testing.EchoRequest) returns (grpc.testing.EchoResponse) " \ - "{}\n" \ - " rpc Echo2(grpc.testing.EchoRequest) returns (grpc.testing.EchoResponse) " \ - "{}\n" \ - " rpc CheckDeadlineUpperBound(grpc.testing.SimpleRequest) returns " \ - "(grpc.testing.StringValue) {}\n" \ - " rpc CheckDeadlineSet(grpc.testing.SimpleRequest) returns " \ - "(grpc.testing.StringValue) {}\n" \ - " rpc CheckClientInitialMetadata(grpc.testing.SimpleRequest) returns " \ - "(grpc.testing.SimpleResponse) {}\n" \ - " rpc RequestStream(stream grpc.testing.EchoRequest) returns " \ - "(grpc.testing.EchoResponse) {}\n" \ - " rpc ResponseStream(grpc.testing.EchoRequest) returns (stream " \ - "grpc.testing.EchoResponse) {}\n" \ - " rpc BidiStream(stream grpc.testing.EchoRequest) returns (stream " \ - "grpc.testing.EchoResponse) {}\n" \ - " rpc Unimplemented(grpc.testing.EchoRequest) returns " \ - "(grpc.testing.EchoResponse) {}\n" \ - "}\n" \ +#define ECHO_TEST_SERVICE_DESCRIPTION \ + "filename: src/proto/grpc/testing/echo.proto\n" \ + "package: grpc.testing;\n" \ + "service EchoTestService {\n" \ + " rpc Echo(grpc.testing.EchoRequest) returns (grpc.testing.EchoResponse) " \ + "{}\n" \ + " rpc Echo1(grpc.testing.EchoRequest) returns (grpc.testing.EchoResponse) " \ + "{}\n" \ + " rpc Echo2(grpc.testing.EchoRequest) returns (grpc.testing.EchoResponse) " \ + "{}\n" \ + " rpc CheckDeadlineUpperBound(grpc.testing.SimpleRequest) returns " \ + "(grpc.testing.StringValue) {}\n" \ + " rpc CheckDeadlineSet(grpc.testing.SimpleRequest) returns " \ + "(grpc.testing.StringValue) {}\n" \ + " rpc CheckClientInitialMetadata(grpc.testing.SimpleRequest) returns " \ + "(grpc.testing.SimpleResponse) {}\n" \ + " rpc RequestStream(stream grpc.testing.EchoRequest) returns " \ + "(grpc.testing.EchoResponse) {}\n" \ + " rpc ResponseStream(grpc.testing.EchoRequest) returns (stream " \ + "grpc.testing.EchoResponse) {}\n" \ + " rpc BidiStream(stream grpc.testing.EchoRequest) returns (stream " \ + "grpc.testing.EchoResponse) {}\n" \ + " rpc Unimplemented(grpc.testing.EchoRequest) returns " \ + "(grpc.testing.EchoResponse) {}\n" \ + "}\n" \ "\n" #define ECHO_METHOD_DESCRIPTION \ @@ -125,8 +125,8 @@ DECLARE_bool(batch); DECLARE_string(metadata); DECLARE_string(protofiles); DECLARE_string(proto_path); -DECLARE_string(default_service_config); -DECLARE_double(timeout); +DECLARE_string(default_service_config); +DECLARE_double(timeout); namespace { @@ -140,24 +140,24 @@ class TestCliCredentials final : public grpc::testing::CliCredentials { if (!secure_) { return InsecureChannelCredentials(); } - grpc_slice ca_slice; - GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file", - grpc_load_file(CA_CERT_PATH, 1, &ca_slice))); - const char* test_root_cert = - reinterpret_cast<const char*> GRPC_SLICE_START_PTR(ca_slice); + grpc_slice ca_slice; + GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file", + grpc_load_file(CA_CERT_PATH, 1, &ca_slice))); + const char* test_root_cert = + reinterpret_cast<const char*> GRPC_SLICE_START_PTR(ca_slice); SslCredentialsOptions ssl_opts = {test_root_cert, "", ""}; - std::shared_ptr<grpc::ChannelCredentials> credential_ptr = - grpc::SslCredentials(grpc::SslCredentialsOptions(ssl_opts)); - grpc_slice_unref(ca_slice); - return credential_ptr; + std::shared_ptr<grpc::ChannelCredentials> credential_ptr = + grpc::SslCredentials(grpc::SslCredentialsOptions(ssl_opts)); + grpc_slice_unref(ca_slice); + return credential_ptr; } - const TString GetCredentialUsage() const override { return ""; } + const TString GetCredentialUsage() const override { return ""; } private: const bool secure_; }; -bool PrintStream(std::stringstream* ss, const TString& output) { +bool PrintStream(std::stringstream* ss, const TString& output) { (*ss) << output; return true; } @@ -185,29 +185,29 @@ class TestServiceImpl : public ::grpc::testing::EchoTestService::Service { return Status::OK; } - Status CheckDeadlineSet(ServerContext* context, const SimpleRequest* request, - StringValue* response) override { - response->set_message(context->deadline() != - std::chrono::system_clock::time_point::max() - ? "true" - : "false"); - return Status::OK; - } - - // Check if deadline - current time <= timeout - // If deadline set, timeout + current time should be an upper bound for it - Status CheckDeadlineUpperBound(ServerContext* context, - const SimpleRequest* request, - StringValue* response) override { - auto seconds = std::chrono::duration_cast<std::chrono::seconds>( - context->deadline() - std::chrono::system_clock::now()); - - // Returning string instead of bool to avoid using embedded messages in - // proto3 - response->set_message(seconds.count() <= FLAGS_timeout ? "true" : "false"); - return Status::OK; - } - + Status CheckDeadlineSet(ServerContext* context, const SimpleRequest* request, + StringValue* response) override { + response->set_message(context->deadline() != + std::chrono::system_clock::time_point::max() + ? "true" + : "false"); + return Status::OK; + } + + // Check if deadline - current time <= timeout + // If deadline set, timeout + current time should be an upper bound for it + Status CheckDeadlineUpperBound(ServerContext* context, + const SimpleRequest* request, + StringValue* response) override { + auto seconds = std::chrono::duration_cast<std::chrono::seconds>( + context->deadline() - std::chrono::system_clock::now()); + + // Returning string instead of bool to avoid using embedded messages in + // proto3 + response->set_message(seconds.count() <= FLAGS_timeout ? "true" : "false"); + return Status::OK; + } + Status RequestStream(ServerContext* context, ServerReader<EchoRequest>* reader, EchoResponse* response) override { @@ -243,7 +243,7 @@ class TestServiceImpl : public ::grpc::testing::EchoTestService::Service { EchoResponse response; for (int i = 0; i < kServerDefaultResponseStreamsToSend; i++) { - response.set_message(request->message() + ToString(i)); + response.set_message(request->message() + ToString(i)); writer->Write(response); } @@ -283,24 +283,24 @@ class GrpcToolTest : public ::testing::Test { // SetUpServer cannot be used with EXPECT_EXIT. grpc_pick_unused_port_or_die() // uses atexit() to free chosen ports, and it will spawn a new thread in // resolve_address_posix.c:192 at exit time. - const TString SetUpServer(bool secure = false) { + const TString SetUpServer(bool secure = false) { std::ostringstream server_address; int port = grpc_pick_unused_port_or_die(); server_address << "localhost:" << port; // Setup server ServerBuilder builder; std::shared_ptr<grpc::ServerCredentials> creds; - grpc_slice cert_slice, key_slice; - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "load_file", grpc_load_file(SERVER_CERT_PATH, 1, &cert_slice))); - GPR_ASSERT(GRPC_LOG_IF_ERROR( - "load_file", grpc_load_file(SERVER_KEY_PATH, 1, &key_slice))); - const char* server_cert = - reinterpret_cast<const char*> GRPC_SLICE_START_PTR(cert_slice); - const char* server_key = - reinterpret_cast<const char*> GRPC_SLICE_START_PTR(key_slice); - SslServerCredentialsOptions::PemKeyCertPair pkcp = {server_key, - server_cert}; + grpc_slice cert_slice, key_slice; + GPR_ASSERT(GRPC_LOG_IF_ERROR( + "load_file", grpc_load_file(SERVER_CERT_PATH, 1, &cert_slice))); + GPR_ASSERT(GRPC_LOG_IF_ERROR( + "load_file", grpc_load_file(SERVER_KEY_PATH, 1, &key_slice))); + const char* server_cert = + reinterpret_cast<const char*> GRPC_SLICE_START_PTR(cert_slice); + const char* server_key = + reinterpret_cast<const char*> GRPC_SLICE_START_PTR(key_slice); + SslServerCredentialsOptions::PemKeyCertPair pkcp = {server_key, + server_cert}; if (secure) { SslServerCredentialsOptions ssl_opts; ssl_opts.pem_root_certs = ""; @@ -312,8 +312,8 @@ class GrpcToolTest : public ::testing::Test { builder.AddListeningPort(server_address.str(), creds); builder.RegisterService(&service_); server_ = builder.BuildAndStart(); - grpc_slice_unref(cert_slice); - grpc_slice_unref(key_slice); + grpc_slice_unref(cert_slice); + grpc_slice_unref(key_slice); return server_address.str(); } @@ -369,7 +369,7 @@ TEST_F(GrpcToolTest, ListCommand) { // Test input "grpc_cli list localhost:<port>" std::stringstream output_stream; - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "ls", server_address.c_str()}; FLAGS_l = false; @@ -387,7 +387,7 @@ TEST_F(GrpcToolTest, ListOneService) { // Test input "grpc_cli list localhost:<port> grpc.testing.EchoTestService" std::stringstream output_stream; - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "ls", server_address.c_str(), "grpc.testing.EchoTestService"}; // without -l flag @@ -400,7 +400,7 @@ TEST_F(GrpcToolTest, ListOneService) { strcmp(output_stream.str().c_str(), ECHO_TEST_SERVICE_SUMMARY)); // with -l flag - output_stream.str(TString()); + output_stream.str(TString()); output_stream.clear(); FLAGS_l = true; EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), @@ -417,7 +417,7 @@ TEST_F(GrpcToolTest, TypeCommand) { // Test input "grpc_cli type localhost:<port> grpc.testing.EchoRequest" std::stringstream output_stream; - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "type", server_address.c_str(), "grpc.testing.EchoRequest"}; @@ -438,7 +438,7 @@ TEST_F(GrpcToolTest, ListOneMethod) { // Test input "grpc_cli list localhost:<port> grpc.testing.EchoTestService" std::stringstream output_stream; - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "ls", server_address.c_str(), "grpc.testing.EchoTestService.Echo"}; // without -l flag @@ -450,7 +450,7 @@ TEST_F(GrpcToolTest, ListOneMethod) { EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), "Echo\n")); // with -l flag - output_stream.str(TString()); + output_stream.str(TString()); output_stream.clear(); FLAGS_l = true; EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), @@ -467,7 +467,7 @@ TEST_F(GrpcToolTest, TypeNotFound) { // Test input "grpc_cli type localhost:<port> grpc.testing.DummyRequest" std::stringstream output_stream; - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "type", server_address.c_str(), "grpc.testing.DummyRequest"}; @@ -481,7 +481,7 @@ TEST_F(GrpcToolTest, CallCommand) { // Test input "grpc_cli call localhost:<port> Echo "message: 'Hello'" std::stringstream output_stream; - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "Echo", "message: 'Hello'"}; @@ -493,7 +493,7 @@ TEST_F(GrpcToolTest, CallCommand) { strstr(output_stream.str().c_str(), "message: \"Hello\"")); // with json_output - output_stream.str(TString()); + output_stream.str(TString()); output_stream.clear(); FLAGS_json_output = true; @@ -516,7 +516,7 @@ TEST_F(GrpcToolTest, CallCommandJsonInput) { // Test input "grpc_cli call localhost:<port> Echo "{ \"message\": \"Hello\"}" std::stringstream output_stream; - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "Echo", "{ \"message\": \"Hello\"}"}; @@ -529,7 +529,7 @@ TEST_F(GrpcToolTest, CallCommandJsonInput) { strstr(output_stream.str().c_str(), "message: \"Hello\"")); // with json_output - output_stream.str(TString()); + output_stream.str(TString()); output_stream.clear(); FLAGS_json_output = true; @@ -553,7 +553,7 @@ TEST_F(GrpcToolTest, CallCommandBatch) { // Test input "grpc_cli call Echo" std::stringstream output_stream; - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "Echo", "message: 'Hello0'"}; @@ -574,7 +574,7 @@ TEST_F(GrpcToolTest, CallCommandBatch) { "message: \"Hello0\"\nmessage: " "\"Hello1\"\nmessage: \"Hello2\"\n")); // with json_output - output_stream.str(TString()); + output_stream.str(TString()); output_stream.clear(); ss.clear(); ss.seekg(0); @@ -613,7 +613,7 @@ TEST_F(GrpcToolTest, CallCommandBatchJsonInput) { // Test input "grpc_cli call Echo" std::stringstream output_stream; - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "Echo", "{\"message\": \"Hello0\"}"}; @@ -636,7 +636,7 @@ TEST_F(GrpcToolTest, CallCommandBatchJsonInput) { "message: \"Hello0\"\nmessage: " "\"Hello1\"\nmessage: \"Hello2\"\n")); // with json_output - output_stream.str(TString()); + output_stream.str(TString()); output_stream.clear(); ss.clear(); ss.seekg(0); @@ -676,7 +676,7 @@ TEST_F(GrpcToolTest, CallCommandBatchWithBadRequest) { // Test input "grpc_cli call Echo" std::stringstream output_stream; - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "Echo", "message: 'Hello0'"}; @@ -696,7 +696,7 @@ TEST_F(GrpcToolTest, CallCommandBatchWithBadRequest) { "message: \"Hello0\"\nmessage: \"Hello2\"\n")); // with json_output - output_stream.str(TString()); + output_stream.str(TString()); output_stream.clear(); ss.clear(); ss.seekg(0); @@ -731,7 +731,7 @@ TEST_F(GrpcToolTest, CallCommandBatchJsonInputWithBadRequest) { // Test input "grpc_cli call Echo" std::stringstream output_stream; - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "Echo", "{ \"message\": \"Hello0\"}"}; @@ -754,7 +754,7 @@ TEST_F(GrpcToolTest, CallCommandBatchJsonInputWithBadRequest) { "message: \"Hello0\"\nmessage: \"Hello2\"\n")); // with json_output - output_stream.str(TString()); + output_stream.str(TString()); output_stream.clear(); ss.clear(); ss.seekg(0); @@ -792,7 +792,7 @@ TEST_F(GrpcToolTest, CallCommandRequestStream) { // 'Hello0'" std::stringstream output_stream; - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "RequestStream", "message: 'Hello0'"}; @@ -817,7 +817,7 @@ TEST_F(GrpcToolTest, CallCommandRequestStreamJsonInput) { // \"Hello0\"}" std::stringstream output_stream; - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "RequestStream", "{ \"message\": \"Hello0\" }"}; @@ -845,7 +845,7 @@ TEST_F(GrpcToolTest, CallCommandRequestStreamWithBadRequest) { // 'Hello0'" std::stringstream output_stream; - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "RequestStream", "message: 'Hello0'"}; @@ -870,7 +870,7 @@ TEST_F(GrpcToolTest, CallCommandRequestStreamWithBadRequestJsonInput) { // 'Hello0'" std::stringstream output_stream; - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "RequestStream", "{ \"message\": \"Hello0\" }"}; @@ -893,99 +893,99 @@ TEST_F(GrpcToolTest, CallCommandRequestStreamWithBadRequestJsonInput) { ShutdownServer(); } -TEST_F(GrpcToolTest, CallCommandWithTimeoutDeadlineSet) { - // Test input "grpc_cli call CheckDeadlineSet --timeout=5000.25" - std::stringstream output_stream; - - const TString server_address = SetUpServer(); - const char* argv[] = {"grpc_cli", "call", server_address.c_str(), - "CheckDeadlineSet"}; - - // Set timeout to 5000.25 seconds - FLAGS_timeout = 5000.25; - - EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), - std::bind(PrintStream, &output_stream, - std::placeholders::_1))); - - // Expected output: "message: "true"", deadline set - EXPECT_TRUE(nullptr != - strstr(output_stream.str().c_str(), "message: \"true\"")); - ShutdownServer(); -} - -TEST_F(GrpcToolTest, CallCommandWithTimeoutDeadlineUpperBound) { - // Test input "grpc_cli call CheckDeadlineUpperBound --timeout=900" - std::stringstream output_stream; - - const TString server_address = SetUpServer(); - const char* argv[] = {"grpc_cli", "call", server_address.c_str(), - "CheckDeadlineUpperBound"}; - - // Set timeout to 900 seconds - FLAGS_timeout = 900; - - EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), - std::bind(PrintStream, &output_stream, - std::placeholders::_1))); - - // Expected output: "message: "true"" - // deadline not greater than timeout + current time - EXPECT_TRUE(nullptr != - strstr(output_stream.str().c_str(), "message: \"true\"")); - ShutdownServer(); -} - -TEST_F(GrpcToolTest, CallCommandWithNegativeTimeoutValue) { - // Test input "grpc_cli call CheckDeadlineSet --timeout=-5" - std::stringstream output_stream; - - const TString server_address = SetUpServer(); - const char* argv[] = {"grpc_cli", "call", server_address.c_str(), - "CheckDeadlineSet"}; - - // Set timeout to -5 (deadline not set) - FLAGS_timeout = -5; - - EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), - std::bind(PrintStream, &output_stream, - std::placeholders::_1))); - - // Expected output: "message: "false"", deadline not set - EXPECT_TRUE(nullptr != - strstr(output_stream.str().c_str(), "message: \"false\"")); - - ShutdownServer(); -} - -TEST_F(GrpcToolTest, CallCommandWithDefaultTimeoutValue) { - // Test input "grpc_cli call CheckDeadlineSet --timeout=-1" - std::stringstream output_stream; - - const TString server_address = SetUpServer(); - const char* argv[] = {"grpc_cli", "call", server_address.c_str(), - "CheckDeadlineSet"}; - - // Set timeout to -1 (default value, deadline not set) - FLAGS_timeout = -1; - - EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), - std::bind(PrintStream, &output_stream, - std::placeholders::_1))); - - // Expected output: "message: "false"", deadline not set - EXPECT_TRUE(nullptr != - strstr(output_stream.str().c_str(), "message: \"false\"")); - - ShutdownServer(); -} - +TEST_F(GrpcToolTest, CallCommandWithTimeoutDeadlineSet) { + // Test input "grpc_cli call CheckDeadlineSet --timeout=5000.25" + std::stringstream output_stream; + + const TString server_address = SetUpServer(); + const char* argv[] = {"grpc_cli", "call", server_address.c_str(), + "CheckDeadlineSet"}; + + // Set timeout to 5000.25 seconds + FLAGS_timeout = 5000.25; + + EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), + std::bind(PrintStream, &output_stream, + std::placeholders::_1))); + + // Expected output: "message: "true"", deadline set + EXPECT_TRUE(nullptr != + strstr(output_stream.str().c_str(), "message: \"true\"")); + ShutdownServer(); +} + +TEST_F(GrpcToolTest, CallCommandWithTimeoutDeadlineUpperBound) { + // Test input "grpc_cli call CheckDeadlineUpperBound --timeout=900" + std::stringstream output_stream; + + const TString server_address = SetUpServer(); + const char* argv[] = {"grpc_cli", "call", server_address.c_str(), + "CheckDeadlineUpperBound"}; + + // Set timeout to 900 seconds + FLAGS_timeout = 900; + + EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), + std::bind(PrintStream, &output_stream, + std::placeholders::_1))); + + // Expected output: "message: "true"" + // deadline not greater than timeout + current time + EXPECT_TRUE(nullptr != + strstr(output_stream.str().c_str(), "message: \"true\"")); + ShutdownServer(); +} + +TEST_F(GrpcToolTest, CallCommandWithNegativeTimeoutValue) { + // Test input "grpc_cli call CheckDeadlineSet --timeout=-5" + std::stringstream output_stream; + + const TString server_address = SetUpServer(); + const char* argv[] = {"grpc_cli", "call", server_address.c_str(), + "CheckDeadlineSet"}; + + // Set timeout to -5 (deadline not set) + FLAGS_timeout = -5; + + EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), + std::bind(PrintStream, &output_stream, + std::placeholders::_1))); + + // Expected output: "message: "false"", deadline not set + EXPECT_TRUE(nullptr != + strstr(output_stream.str().c_str(), "message: \"false\"")); + + ShutdownServer(); +} + +TEST_F(GrpcToolTest, CallCommandWithDefaultTimeoutValue) { + // Test input "grpc_cli call CheckDeadlineSet --timeout=-1" + std::stringstream output_stream; + + const TString server_address = SetUpServer(); + const char* argv[] = {"grpc_cli", "call", server_address.c_str(), + "CheckDeadlineSet"}; + + // Set timeout to -1 (default value, deadline not set) + FLAGS_timeout = -1; + + EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), + std::bind(PrintStream, &output_stream, + std::placeholders::_1))); + + // Expected output: "message: "false"", deadline not set + EXPECT_TRUE(nullptr != + strstr(output_stream.str().c_str(), "message: \"false\"")); + + ShutdownServer(); +} + TEST_F(GrpcToolTest, CallCommandResponseStream) { // Test input: grpc_cli call localhost:<port> ResponseStream "message: // 'Hello'" std::stringstream output_stream; - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "ResponseStream", "message: 'Hello'"}; @@ -995,14 +995,14 @@ TEST_F(GrpcToolTest, CallCommandResponseStream) { // Expected output: "message: \"Hello{n}\"" for (int i = 0; i < kServerDefaultResponseStreamsToSend; i++) { - TString expected_response_text = - "message: \"Hello" + ToString(i) + "\"\n"; + TString expected_response_text = + "message: \"Hello" + ToString(i) + "\"\n"; EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), expected_response_text.c_str())); } // with json_output - output_stream.str(TString()); + output_stream.str(TString()); output_stream.clear(); FLAGS_json_output = true; @@ -1013,8 +1013,8 @@ TEST_F(GrpcToolTest, CallCommandResponseStream) { // Expected output: "{\n \"message\": \"Hello{n}\"\n}\n" for (int i = 0; i < kServerDefaultResponseStreamsToSend; i++) { - TString expected_response_text = - "{\n \"message\": \"Hello" + ToString(i) + "\"\n}\n"; + TString expected_response_text = + "{\n \"message\": \"Hello" + ToString(i) + "\"\n}\n"; EXPECT_TRUE(nullptr != strstr(output_stream.str().c_str(), expected_response_text.c_str())); } @@ -1026,7 +1026,7 @@ TEST_F(GrpcToolTest, CallCommandBidiStream) { // Test input: grpc_cli call localhost:<port> BidiStream "message: 'Hello0'" std::stringstream output_stream; - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "BidiStream", "message: 'Hello0'"}; @@ -1052,7 +1052,7 @@ TEST_F(GrpcToolTest, CallCommandBidiStreamWithBadRequest) { // Test input: grpc_cli call localhost:<port> BidiStream "message: 'Hello0'" std::stringstream output_stream; - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "BidiStream", "message: 'Hello0'"}; @@ -1080,7 +1080,7 @@ TEST_F(GrpcToolTest, ParseCommand) { std::stringstream output_stream; std::stringstream binary_output_stream; - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "parse", server_address.c_str(), "grpc.testing.EchoResponse", ECHO_RESPONSE_MESSAGE_TEXT_FORMAT}; @@ -1095,7 +1095,7 @@ TEST_F(GrpcToolTest, ParseCommand) { ECHO_RESPONSE_MESSAGE_TEXT_FORMAT)); // with json_output - output_stream.str(TString()); + output_stream.str(TString()); output_stream.clear(); FLAGS_json_output = true; @@ -1109,14 +1109,14 @@ TEST_F(GrpcToolTest, ParseCommand) { ECHO_RESPONSE_MESSAGE_JSON_FORMAT)); // Parse text message to binary message and then parse it back to text message - output_stream.str(TString()); + output_stream.str(TString()); output_stream.clear(); FLAGS_binary_output = true; EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), std::bind(PrintStream, &output_stream, std::placeholders::_1))); - TString binary_data = output_stream.str(); - output_stream.str(TString()); + TString binary_data = output_stream.str(); + output_stream.str(TString()); output_stream.clear(); argv[4] = binary_data.c_str(); FLAGS_binary_input = true; @@ -1140,7 +1140,7 @@ TEST_F(GrpcToolTest, ParseCommandJsonFormat) { std::stringstream output_stream; std::stringstream binary_output_stream; - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "parse", server_address.c_str(), "grpc.testing.EchoResponse", ECHO_RESPONSE_MESSAGE_JSON_FORMAT}; @@ -1155,7 +1155,7 @@ TEST_F(GrpcToolTest, ParseCommandJsonFormat) { ECHO_RESPONSE_MESSAGE_TEXT_FORMAT)); // with json_output - output_stream.str(TString()); + output_stream.str(TString()); output_stream.clear(); FLAGS_json_output = true; @@ -1205,7 +1205,7 @@ TEST_F(GrpcToolTest, TooManyArguments) { TEST_F(GrpcToolTest, CallCommandWithMetadata) { // Test input "grpc_cli call localhost:<port> Echo "message: 'Hello'" - const TString server_address = SetUpServer(); + const TString server_address = SetUpServer(); const char* argv[] = {"grpc_cli", "call", server_address.c_str(), "Echo", "message: 'Hello'"}; @@ -1251,13 +1251,13 @@ TEST_F(GrpcToolTest, CallCommandWithMetadata) { TEST_F(GrpcToolTest, CallCommandWithBadMetadata) { // Test input "grpc_cli call localhost:10000 Echo "message: 'Hello'" - const char* argv[] = {"grpc_cli", "call", "localhost:10000", - "grpc.testing.EchoTestService.Echo", + const char* argv[] = {"grpc_cli", "call", "localhost:10000", + "grpc.testing.EchoTestService.Echo", "message: 'Hello'"}; FLAGS_protofiles = "src/proto/grpc/testing/echo.proto"; char* test_srcdir = gpr_getenv("TEST_SRCDIR"); if (test_srcdir != nullptr) { - FLAGS_proto_path = test_srcdir + TString("/com_github_grpc_grpc"); + FLAGS_proto_path = test_srcdir + TString("/com_github_grpc_grpc"); } { @@ -1289,7 +1289,7 @@ TEST_F(GrpcToolTest, CallCommandWithBadMetadata) { } TEST_F(GrpcToolTest, ListCommand_OverrideSslHostName) { - const TString server_address = SetUpServer(true); + const TString server_address = SetUpServer(true); // Test input "grpc_cli ls localhost:<port> --channel_creds_type=ssl // --ssl_target=z.test.google.fr" @@ -1311,28 +1311,28 @@ TEST_F(GrpcToolTest, ListCommand_OverrideSslHostName) { ShutdownServer(); } -TEST_F(GrpcToolTest, ConfiguringDefaultServiceConfig) { - // Test input "grpc_cli list localhost:<port> - // --default_service_config={\"loadBalancingConfig\":[{\"pick_first\":{}}]}" - std::stringstream output_stream; - const TString server_address = SetUpServer(); - const char* argv[] = {"grpc_cli", "ls", server_address.c_str()}; - // Just check that the tool is still operational when --default_service_config - // is configured. This particular service config is in reality redundant with - // the channel's default configuration. - FLAGS_l = false; - FLAGS_default_service_config = - "{\"loadBalancingConfig\":[{\"pick_first\":{}}]}"; - EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), - std::bind(PrintStream, &output_stream, - std::placeholders::_1))); - FLAGS_default_service_config = ""; - EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), - "grpc.testing.EchoTestService\n" - "grpc.reflection.v1alpha.ServerReflection\n")); - ShutdownServer(); -} - +TEST_F(GrpcToolTest, ConfiguringDefaultServiceConfig) { + // Test input "grpc_cli list localhost:<port> + // --default_service_config={\"loadBalancingConfig\":[{\"pick_first\":{}}]}" + std::stringstream output_stream; + const TString server_address = SetUpServer(); + const char* argv[] = {"grpc_cli", "ls", server_address.c_str()}; + // Just check that the tool is still operational when --default_service_config + // is configured. This particular service config is in reality redundant with + // the channel's default configuration. + FLAGS_l = false; + FLAGS_default_service_config = + "{\"loadBalancingConfig\":[{\"pick_first\":{}}]}"; + EXPECT_TRUE(0 == GrpcToolMainLib(ArraySize(argv), argv, TestCliCredentials(), + std::bind(PrintStream, &output_stream, + std::placeholders::_1))); + FLAGS_default_service_config = ""; + EXPECT_TRUE(0 == strcmp(output_stream.str().c_str(), + "grpc.testing.EchoTestService\n" + "grpc.reflection.v1alpha.ServerReflection\n")); + ShutdownServer(); +} + } // namespace testing } // namespace grpc diff --git a/contrib/libs/grpc/test/cpp/util/metrics_server.cc b/contrib/libs/grpc/test/cpp/util/metrics_server.cc index 0493da053e..aa212fd4f1 100644 --- a/contrib/libs/grpc/test/cpp/util/metrics_server.cc +++ b/contrib/libs/grpc/test/cpp/util/metrics_server.cc @@ -81,7 +81,7 @@ grpc::Status MetricsServiceImpl::GetGauge(ServerContext* /*context*/, } std::shared_ptr<QpsGauge> MetricsServiceImpl::CreateQpsGauge( - const TString& name, bool* already_present) { + const TString& name, bool* already_present) { std::lock_guard<std::mutex> lock(mu_); std::shared_ptr<QpsGauge> qps_gauge(new QpsGauge()); @@ -100,7 +100,7 @@ std::shared_ptr<QpsGauge> MetricsServiceImpl::CreateQpsGauge( std::unique_ptr<grpc::Server> MetricsServiceImpl::StartServer(int port) { gpr_log(GPR_INFO, "Building metrics server.."); - const TString address = "0.0.0.0:" + ToString(port); + const TString address = "0.0.0.0:" + ToString(port); ServerBuilder builder; builder.AddListeningPort(address, grpc::InsecureServerCredentials()); diff --git a/contrib/libs/grpc/test/cpp/util/metrics_server.h b/contrib/libs/grpc/test/cpp/util/metrics_server.h index 10ffa7b4dd..98e727597d 100644 --- a/contrib/libs/grpc/test/cpp/util/metrics_server.h +++ b/contrib/libs/grpc/test/cpp/util/metrics_server.h @@ -82,7 +82,7 @@ class MetricsServiceImpl final : public MetricsService::Service { // is already present in the map. // NOTE: CreateQpsGauge can be called anytime (i.e before or after calling // StartServer). - std::shared_ptr<QpsGauge> CreateQpsGauge(const TString& name, + std::shared_ptr<QpsGauge> CreateQpsGauge(const TString& name, bool* already_present); std::unique_ptr<grpc::Server> StartServer(int port); diff --git a/contrib/libs/grpc/test/cpp/util/proto_file_parser.cc b/contrib/libs/grpc/test/cpp/util/proto_file_parser.cc index b0912a712c..f4be2477f6 100644 --- a/contrib/libs/grpc/test/cpp/util/proto_file_parser.cc +++ b/contrib/libs/grpc/test/cpp/util/proto_file_parser.cc @@ -30,9 +30,9 @@ namespace testing { namespace { // Match the user input method string to the full_name from method descriptor. -bool MethodNameMatch(const TString& full_name, const TString& input) { - TString clean_input = input; - std::replace(clean_input.begin(), clean_input.vend(), '/', '.'); +bool MethodNameMatch(const TString& full_name, const TString& input) { + TString clean_input = input; + std::replace(clean_input.begin(), clean_input.vend(), '/', '.'); if (clean_input.size() > full_name.size()) { return false; } @@ -64,27 +64,27 @@ class ErrorPrinter : public protobuf::compiler::MultiFileErrorCollector { }; ProtoFileParser::ProtoFileParser(const std::shared_ptr<grpc::Channel>& channel, - const TString& proto_path, - const TString& protofiles) + const TString& proto_path, + const TString& protofiles) : has_error_(false), dynamic_factory_(new protobuf::DynamicMessageFactory()) { - std::vector<TString> service_list; + std::vector<TString> service_list; if (channel) { reflection_db_.reset(new grpc::ProtoReflectionDescriptorDatabase(channel)); reflection_db_->GetServices(&service_list); } - std::unordered_set<TString> known_services; + std::unordered_set<TString> known_services; if (!protofiles.empty()) { source_tree_.MapPath("", google::protobuf::string(proto_path)); error_printer_.reset(new ErrorPrinter(this)); importer_.reset( new protobuf::compiler::Importer(&source_tree_, error_printer_.get())); - std::string file_name; + std::string file_name; std::stringstream ss(protofiles); while (std::getline(ss, file_name, ',')) { - const auto* file_desc = importer_->Import(google::protobuf::string(file_name.c_str())); + const auto* file_desc = importer_->Import(google::protobuf::string(file_name.c_str())); if (file_desc) { for (int i = 0; i < file_desc->service_count(); i++) { service_desc_list_.push_back(file_desc->service(i)); @@ -127,7 +127,7 @@ ProtoFileParser::ProtoFileParser(const std::shared_ptr<grpc::Channel>& channel, ProtoFileParser::~ProtoFileParser() {} -TString ProtoFileParser::GetFullMethodName(const TString& method) { +TString ProtoFileParser::GetFullMethodName(const TString& method) { has_error_ = false; if (known_methods_.find(method) != known_methods_.end()) { @@ -164,24 +164,24 @@ TString ProtoFileParser::GetFullMethodName(const TString& method) { return method_descriptor->full_name(); } -TString ProtoFileParser::GetFormattedMethodName(const TString& method) { +TString ProtoFileParser::GetFormattedMethodName(const TString& method) { has_error_ = false; - TString formatted_method_name = GetFullMethodName(method); + TString formatted_method_name = GetFullMethodName(method); if (has_error_) { return ""; } size_t last_dot = formatted_method_name.find_last_of('.'); - if (last_dot != TString::npos) { + if (last_dot != TString::npos) { formatted_method_name[last_dot] = '/'; } formatted_method_name.insert(formatted_method_name.begin(), '/'); return formatted_method_name; } -TString ProtoFileParser::GetMessageTypeFromMethod(const TString& method, - bool is_request) { +TString ProtoFileParser::GetMessageTypeFromMethod(const TString& method, + bool is_request) { has_error_ = false; - TString full_method_name = GetFullMethodName(method); + TString full_method_name = GetFullMethodName(method); if (has_error_) { return ""; } @@ -196,10 +196,10 @@ TString ProtoFileParser::GetMessageTypeFromMethod(const TString& method, : method_desc->output_type()->full_name(); } -bool ProtoFileParser::IsStreaming(const TString& method, bool is_request) { +bool ProtoFileParser::IsStreaming(const TString& method, bool is_request) { has_error_ = false; - TString full_method_name = GetFullMethodName(method); + TString full_method_name = GetFullMethodName(method); if (has_error_) { return false; } @@ -215,11 +215,11 @@ bool ProtoFileParser::IsStreaming(const TString& method, bool is_request) { : method_desc->server_streaming(); } -TString ProtoFileParser::GetSerializedProtoFromMethod( - const TString& method, const TString& formatted_proto, +TString ProtoFileParser::GetSerializedProtoFromMethod( + const TString& method, const TString& formatted_proto, bool is_request, bool is_json_format) { has_error_ = false; - TString message_type_name = GetMessageTypeFromMethod(method, is_request); + TString message_type_name = GetMessageTypeFromMethod(method, is_request); if (has_error_) { return ""; } @@ -227,11 +227,11 @@ TString ProtoFileParser::GetSerializedProtoFromMethod( is_json_format); } -TString ProtoFileParser::GetFormattedStringFromMethod( - const TString& method, const TString& serialized_proto, +TString ProtoFileParser::GetFormattedStringFromMethod( + const TString& method, const TString& serialized_proto, bool is_request, bool is_json_format) { has_error_ = false; - TString message_type_name = GetMessageTypeFromMethod(method, is_request); + TString message_type_name = GetMessageTypeFromMethod(method, is_request); if (has_error_) { return ""; } @@ -239,8 +239,8 @@ TString ProtoFileParser::GetFormattedStringFromMethod( is_json_format); } -TString ProtoFileParser::GetSerializedProtoFromMessageType( - const TString& message_type_name, const TString& formatted_proto, +TString ProtoFileParser::GetSerializedProtoFromMessageType( + const TString& message_type_name, const TString& formatted_proto, bool is_json_format) { has_error_ = false; google::protobuf::string serialized; @@ -276,8 +276,8 @@ TString ProtoFileParser::GetSerializedProtoFromMessageType( return serialized; } -TString ProtoFileParser::GetFormattedStringFromMessageType( - const TString& message_type_name, const TString& serialized_proto, +TString ProtoFileParser::GetFormattedStringFromMessageType( + const TString& message_type_name, const TString& serialized_proto, bool is_json_format) { has_error_ = false; const protobuf::Descriptor* desc = @@ -312,7 +312,7 @@ TString ProtoFileParser::GetFormattedStringFromMessageType( return formatted_string; } -void ProtoFileParser::LogError(const TString& error_msg) { +void ProtoFileParser::LogError(const TString& error_msg) { if (!error_msg.empty()) { std::cerr << error_msg << std::endl; } diff --git a/contrib/libs/grpc/test/cpp/util/proto_file_parser.h b/contrib/libs/grpc/test/cpp/util/proto_file_parser.h index c0445641c7..51df2c5d76 100644 --- a/contrib/libs/grpc/test/cpp/util/proto_file_parser.h +++ b/contrib/libs/grpc/test/cpp/util/proto_file_parser.h @@ -37,7 +37,7 @@ class ProtoFileParser { // provided on the given channel. The given protofiles in a source tree rooted // from proto_path will also be searched. ProtoFileParser(const std::shared_ptr<grpc::Channel>& channel, - const TString& proto_path, const TString& protofiles); + const TString& proto_path, const TString& protofiles); ~ProtoFileParser(); @@ -46,11 +46,11 @@ class ProtoFileParser { // there is ambiguity. // Full method name is in the form of Service.Method, it's good to be used in // descriptor database queries. - TString GetFullMethodName(const TString& method); + TString GetFullMethodName(const TString& method); // Formatted method name is in the form of /Service/Method, it's good to be // used as the argument of Stub::Call() - TString GetFormattedMethodName(const TString& method); + TString GetFormattedMethodName(const TString& method); /// Converts a text or json string to its binary proto representation for the /// given method's input or return type. @@ -63,18 +63,18 @@ class ProtoFileParser { /// json-formatted proto, otherwise it is treated as a text-formatted /// proto /// \return the serialised binary proto representation of \c formatted_proto - TString GetSerializedProtoFromMethod(const TString& method, - const TString& formatted_proto, - bool is_request, - bool is_json_format); + TString GetSerializedProtoFromMethod(const TString& method, + const TString& formatted_proto, + bool is_request, + bool is_json_format); /// Converts a text or json string to its proto representation for the given /// message type. /// \param formatted_proto the text- or json-formatted proto string /// \return the serialised binary proto representation of \c formatted_proto - TString GetSerializedProtoFromMessageType( - const TString& message_type_name, const TString& formatted_proto, - bool is_json_format); + TString GetSerializedProtoFromMessageType( + const TString& message_type_name, const TString& formatted_proto, + bool is_json_format); /// Converts a binary proto string to its text or json string representation /// for the given method's input or return type. @@ -83,32 +83,32 @@ class ProtoFileParser { /// \param the serialised binary proto representation of type /// \c message_type_name /// \return the text- or json-formatted proto string of \c serialized_proto - TString GetFormattedStringFromMethod(const TString& method, - const TString& serialized_proto, - bool is_request, - bool is_json_format); + TString GetFormattedStringFromMethod(const TString& method, + const TString& serialized_proto, + bool is_request, + bool is_json_format); /// Converts a binary proto string to its text or json string representation /// for the given message type. /// \param the serialised binary proto representation of type /// \c message_type_name /// \return the text- or json-formatted proto string of \c serialized_proto - TString GetFormattedStringFromMessageType( - const TString& message_type_name, const TString& serialized_proto, - bool is_json_format); + TString GetFormattedStringFromMessageType( + const TString& message_type_name, const TString& serialized_proto, + bool is_json_format); - bool IsStreaming(const TString& method, bool is_request); + bool IsStreaming(const TString& method, bool is_request); bool HasError() const { return has_error_; } - void LogError(const TString& error_msg); + void LogError(const TString& error_msg); private: - TString GetMessageTypeFromMethod(const TString& method, - bool is_request); + TString GetMessageTypeFromMethod(const TString& method, + bool is_request); bool has_error_; - TString request_text_; + TString request_text_; protobuf::compiler::DiskSourceTree source_tree_; std::unique_ptr<ErrorPrinter> error_printer_; std::unique_ptr<protobuf::compiler::Importer> importer_; @@ -119,7 +119,7 @@ class ProtoFileParser { std::unique_ptr<protobuf::DynamicMessageFactory> dynamic_factory_; std::unique_ptr<grpc::protobuf::Message> request_prototype_; std::unique_ptr<grpc::protobuf::Message> response_prototype_; - std::unordered_map<TString, TString> known_methods_; + std::unordered_map<TString, TString> known_methods_; std::vector<const protobuf::ServiceDescriptor*> service_desc_list_; }; diff --git a/contrib/libs/grpc/test/cpp/util/proto_reflection_descriptor_database.cc b/contrib/libs/grpc/test/cpp/util/proto_reflection_descriptor_database.cc index 27a4c1e4cf..dbc687e1ab 100644 --- a/contrib/libs/grpc/test/cpp/util/proto_reflection_descriptor_database.cc +++ b/contrib/libs/grpc/test/cpp/util/proto_reflection_descriptor_database.cc @@ -257,7 +257,7 @@ bool ProtoReflectionDescriptorDatabase::FindAllExtensionNumbers( } bool ProtoReflectionDescriptorDatabase::GetServices( - std::vector<TString>* output) { + std::vector<TString>* output) { ServerReflectionRequest request; request.set_list_services(""); ServerReflectionResponse response; @@ -292,7 +292,7 @@ bool ProtoReflectionDescriptorDatabase::GetServices( const protobuf::FileDescriptorProto ProtoReflectionDescriptorDatabase::ParseFileDescriptorProtoResponse( - const TString& byte_fd_proto) { + const TString& byte_fd_proto) { protobuf::FileDescriptorProto file_desc_proto; file_desc_proto.ParseFromString(google::protobuf::string(byte_fd_proto)); return file_desc_proto; diff --git a/contrib/libs/grpc/test/cpp/util/proto_reflection_descriptor_database.h b/contrib/libs/grpc/test/cpp/util/proto_reflection_descriptor_database.h index cdd6f0cccd..428044b1d6 100644 --- a/contrib/libs/grpc/test/cpp/util/proto_reflection_descriptor_database.h +++ b/contrib/libs/grpc/test/cpp/util/proto_reflection_descriptor_database.h @@ -74,7 +74,7 @@ class ProtoReflectionDescriptorDatabase : public protobuf::DescriptorDatabase { std::vector<int>* output) override; // Provide a list of full names of registered services - bool GetServices(std::vector<TString>* output); + bool GetServices(std::vector<TString>* output); private: typedef ClientReaderWriter< @@ -83,7 +83,7 @@ class ProtoReflectionDescriptorDatabase : public protobuf::DescriptorDatabase { ClientStream; const protobuf::FileDescriptorProto ParseFileDescriptorProtoResponse( - const TString& byte_fd_proto); + const TString& byte_fd_proto); void AddFileFromResponse( const grpc::reflection::v1alpha::FileDescriptorResponse& response); diff --git a/contrib/libs/grpc/test/cpp/util/service_describer.cc b/contrib/libs/grpc/test/cpp/util/service_describer.cc index 2af1104b97..399784751c 100644 --- a/contrib/libs/grpc/test/cpp/util/service_describer.cc +++ b/contrib/libs/grpc/test/cpp/util/service_describer.cc @@ -20,14 +20,14 @@ #include <iostream> #include <sstream> -#include <util/generic/string.h> +#include <util/generic/string.h> #include <vector> namespace grpc { namespace testing { -TString DescribeServiceList(std::vector<TString> service_list, - grpc::protobuf::DescriptorPool& desc_pool) { +TString DescribeServiceList(std::vector<TString> service_list, + grpc::protobuf::DescriptorPool& desc_pool) { std::stringstream result; for (auto it = service_list.begin(); it != service_list.end(); it++) { auto const& service = *it; @@ -40,16 +40,16 @@ TString DescribeServiceList(std::vector<TString> service_list, return result.str(); } -TString DescribeService(const grpc::protobuf::ServiceDescriptor* service) { - TString result; +TString DescribeService(const grpc::protobuf::ServiceDescriptor* service) { + TString result; if (service->options().deprecated()) { result.append("DEPRECATED\n"); } result.append("filename: " + service->file()->name() + "\n"); - TString package = service->full_name(); + TString package = service->full_name(); size_t pos = package.rfind("." + service->name()); - if (pos != TString::npos) { + if (pos != TString::npos) { package.erase(pos); result.append("package: " + package + ";\n"); } @@ -61,7 +61,7 @@ TString DescribeService(const grpc::protobuf::ServiceDescriptor* service) { return result; } -TString DescribeMethod(const grpc::protobuf::MethodDescriptor* method) { +TString DescribeMethod(const grpc::protobuf::MethodDescriptor* method) { std::stringstream result; result << " rpc " << method->name() << (method->client_streaming() ? "(stream " : "(") @@ -74,16 +74,16 @@ TString DescribeMethod(const grpc::protobuf::MethodDescriptor* method) { return result.str(); } -TString SummarizeService(const grpc::protobuf::ServiceDescriptor* service) { - TString result; +TString SummarizeService(const grpc::protobuf::ServiceDescriptor* service) { + TString result; for (int i = 0; i < service->method_count(); ++i) { result.append(SummarizeMethod(service->method(i))); } return result; } -TString SummarizeMethod(const grpc::protobuf::MethodDescriptor* method) { - TString result = method->name(); +TString SummarizeMethod(const grpc::protobuf::MethodDescriptor* method) { + TString result = method->name(); result.append("\n"); return result; } diff --git a/contrib/libs/grpc/test/cpp/util/service_describer.h b/contrib/libs/grpc/test/cpp/util/service_describer.h index a473f03744..352fe0f38c 100644 --- a/contrib/libs/grpc/test/cpp/util/service_describer.h +++ b/contrib/libs/grpc/test/cpp/util/service_describer.h @@ -25,16 +25,16 @@ namespace grpc { namespace testing { -TString DescribeServiceList(std::vector<TString> service_list, - grpc::protobuf::DescriptorPool& desc_pool); +TString DescribeServiceList(std::vector<TString> service_list, + grpc::protobuf::DescriptorPool& desc_pool); -TString DescribeService(const grpc::protobuf::ServiceDescriptor* service); +TString DescribeService(const grpc::protobuf::ServiceDescriptor* service); -TString DescribeMethod(const grpc::protobuf::MethodDescriptor* method); +TString DescribeMethod(const grpc::protobuf::MethodDescriptor* method); -TString SummarizeService(const grpc::protobuf::ServiceDescriptor* service); +TString SummarizeService(const grpc::protobuf::ServiceDescriptor* service); -TString SummarizeMethod(const grpc::protobuf::MethodDescriptor* method); +TString SummarizeMethod(const grpc::protobuf::MethodDescriptor* method); } // namespace testing } // namespace grpc diff --git a/contrib/libs/grpc/test/cpp/util/slice_test.cc b/contrib/libs/grpc/test/cpp/util/slice_test.cc index d7e945ae38..ec370aa799 100644 --- a/contrib/libs/grpc/test/cpp/util/slice_test.cc +++ b/contrib/libs/grpc/test/cpp/util/slice_test.cc @@ -23,8 +23,8 @@ #include <grpc/slice.h> #include <gtest/gtest.h> -#include "test/core/util/test_config.h" - +#include "test/core/util/test_config.h" + namespace grpc { static internal::GrpcLibraryInitializer g_gli_initializer; @@ -39,13 +39,13 @@ class SliceTest : public ::testing::Test { static void TearDownTestCase() { grpc_shutdown(); } - void CheckSliceSize(const Slice& s, const TString& content) { + void CheckSliceSize(const Slice& s, const TString& content) { EXPECT_EQ(content.size(), s.size()); } - void CheckSlice(const Slice& s, const TString& content) { + void CheckSlice(const Slice& s, const TString& content) { EXPECT_EQ(content.size(), s.size()); EXPECT_EQ(content, - TString(reinterpret_cast<const char*>(s.begin()), s.size())); + TString(reinterpret_cast<const char*>(s.begin()), s.size())); } }; @@ -137,7 +137,7 @@ TEST_F(SliceTest, Cslice) { } // namespace grpc int main(int argc, char** argv) { - grpc::testing::TestEnvironment env(argc, argv); + grpc::testing::TestEnvironment env(argc, argv); ::testing::InitGoogleTest(&argc, argv); int ret = RUN_ALL_TESTS(); return ret; diff --git a/contrib/libs/grpc/test/cpp/util/string_ref_helper.cc b/contrib/libs/grpc/test/cpp/util/string_ref_helper.cc index e573f5d33a..4da437abe9 100644 --- a/contrib/libs/grpc/test/cpp/util/string_ref_helper.cc +++ b/contrib/libs/grpc/test/cpp/util/string_ref_helper.cc @@ -21,8 +21,8 @@ namespace grpc { namespace testing { -TString ToString(const grpc::string_ref& r) { - return TString(r.data(), r.size()); +TString ToString(const grpc::string_ref& r) { + return TString(r.data(), r.size()); } } // namespace testing diff --git a/contrib/libs/grpc/test/cpp/util/string_ref_helper.h b/contrib/libs/grpc/test/cpp/util/string_ref_helper.h index e9e941f319..eab876aea8 100644 --- a/contrib/libs/grpc/test/cpp/util/string_ref_helper.h +++ b/contrib/libs/grpc/test/cpp/util/string_ref_helper.h @@ -24,7 +24,7 @@ namespace grpc { namespace testing { -TString ToString(const grpc::string_ref& r); +TString ToString(const grpc::string_ref& r); } // namespace testing } // namespace grpc diff --git a/contrib/libs/grpc/test/cpp/util/string_ref_test.cc b/contrib/libs/grpc/test/cpp/util/string_ref_test.cc index 8e3259b764..3cad17f0b4 100644 --- a/contrib/libs/grpc/test/cpp/util/string_ref_test.cc +++ b/contrib/libs/grpc/test/cpp/util/string_ref_test.cc @@ -22,8 +22,8 @@ #include <gtest/gtest.h> -#include "test/core/util/test_config.h" - +#include "test/core/util/test_config.h" + namespace grpc { namespace { @@ -199,7 +199,7 @@ TEST_F(StringRefTest, ComparisonOperators) { } // namespace grpc int main(int argc, char** argv) { - grpc::testing::TestEnvironment env(argc, argv); + grpc::testing::TestEnvironment env(argc, argv); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/contrib/libs/grpc/test/cpp/util/subprocess.cc b/contrib/libs/grpc/test/cpp/util/subprocess.cc index 648bd50274..a90802b5af 100644 --- a/contrib/libs/grpc/test/cpp/util/subprocess.cc +++ b/contrib/libs/grpc/test/cpp/util/subprocess.cc @@ -24,7 +24,7 @@ namespace grpc { -static gpr_subprocess* MakeProcess(const std::vector<TString>& args) { +static gpr_subprocess* MakeProcess(const std::vector<TString>& args) { std::vector<const char*> vargs; for (auto it = args.begin(); it != args.end(); ++it) { vargs.push_back(it->c_str()); @@ -32,7 +32,7 @@ static gpr_subprocess* MakeProcess(const std::vector<TString>& args) { return gpr_subprocess_create(vargs.size(), &vargs[0]); } -SubProcess::SubProcess(const std::vector<TString>& args) +SubProcess::SubProcess(const std::vector<TString>& args) : subprocess_(MakeProcess(args)) {} SubProcess::~SubProcess() { gpr_subprocess_destroy(subprocess_); } diff --git a/contrib/libs/grpc/test/cpp/util/subprocess.h b/contrib/libs/grpc/test/cpp/util/subprocess.h index 84dda31dd1..763c6eb185 100644 --- a/contrib/libs/grpc/test/cpp/util/subprocess.h +++ b/contrib/libs/grpc/test/cpp/util/subprocess.h @@ -20,7 +20,7 @@ #define GRPC_TEST_CPP_UTIL_SUBPROCESS_H #include <initializer_list> -#include <util/generic/string.h> +#include <util/generic/string.h> #include <vector> struct gpr_subprocess; @@ -29,7 +29,7 @@ namespace grpc { class SubProcess { public: - SubProcess(const std::vector<TString>& args); + SubProcess(const std::vector<TString>& args); ~SubProcess(); int Join(); diff --git a/contrib/libs/grpc/test/cpp/util/test_credentials_provider.cc b/contrib/libs/grpc/test/cpp/util/test_credentials_provider.cc index f7134b773f..63e5b95ada 100644 --- a/contrib/libs/grpc/test/cpp/util/test_credentials_provider.cc +++ b/contrib/libs/grpc/test/cpp/util/test_credentials_provider.cc @@ -40,11 +40,11 @@ namespace grpc { namespace testing { namespace { -TString ReadFile(const TString& src_path) { +TString ReadFile(const TString& src_path) { std::ifstream src; src.open(src_path, std::ifstream::in | std::ifstream::binary); - TString contents; + TString contents; src.seekg(0, std::ios::end); contents.reserve(src.tellg()); src.seekg(0, std::ios::beg); @@ -66,7 +66,7 @@ class DefaultCredentialsProvider : public CredentialsProvider { ~DefaultCredentialsProvider() override {} void AddSecureType( - const TString& type, + const TString& type, std::unique_ptr<CredentialTypeProvider> type_provider) override { // This clobbers any existing entry for type, except the defaults, which // can't be clobbered. @@ -83,7 +83,7 @@ class DefaultCredentialsProvider : public CredentialsProvider { } std::shared_ptr<ChannelCredentials> GetChannelCredentials( - const TString& type, ChannelArguments* args) override { + const TString& type, ChannelArguments* args) override { if (type == grpc::testing::kInsecureCredentialsType) { return InsecureChannelCredentials(); } else if (type == grpc::testing::kAltsCredentialsType) { @@ -109,7 +109,7 @@ class DefaultCredentialsProvider : public CredentialsProvider { } std::shared_ptr<ServerCredentials> GetServerCredentials( - const TString& type) override { + const TString& type) override { if (type == grpc::testing::kInsecureCredentialsType) { return InsecureServerCredentials(); } else if (type == grpc::testing::kAltsCredentialsType) { @@ -140,8 +140,8 @@ class DefaultCredentialsProvider : public CredentialsProvider { ->GetServerCredentials(); } } - std::vector<TString> GetSecureCredentialsTypeList() override { - std::vector<TString> types; + std::vector<TString> GetSecureCredentialsTypeList() override { + std::vector<TString> types; types.push_back(grpc::testing::kTlsCredentialsType); std::unique_lock<std::mutex> lock(mu_); for (auto it = added_secure_type_names_.begin(); @@ -153,11 +153,11 @@ class DefaultCredentialsProvider : public CredentialsProvider { private: std::mutex mu_; - std::vector<TString> added_secure_type_names_; + std::vector<TString> added_secure_type_names_; std::vector<std::unique_ptr<CredentialTypeProvider>> added_secure_type_providers_; - TString custom_server_key_; - TString custom_server_cert_; + TString custom_server_key_; + TString custom_server_cert_; }; CredentialsProvider* g_provider = nullptr; diff --git a/contrib/libs/grpc/test/cpp/util/test_credentials_provider.h b/contrib/libs/grpc/test/cpp/util/test_credentials_provider.h index acba277ada..6b5e7f4b99 100644 --- a/contrib/libs/grpc/test/cpp/util/test_credentials_provider.h +++ b/contrib/libs/grpc/test/cpp/util/test_credentials_provider.h @@ -53,21 +53,21 @@ class CredentialsProvider { // Add a secure type in addition to the defaults. The default provider has // (kInsecureCredentialsType, kTlsCredentialsType). virtual void AddSecureType( - const TString& type, + const TString& type, std::unique_ptr<CredentialTypeProvider> type_provider) = 0; // Provide channel credentials according to the given type. Alter the channel // arguments if needed. Return nullptr if type is not registered. virtual std::shared_ptr<ChannelCredentials> GetChannelCredentials( - const TString& type, ChannelArguments* args) = 0; + const TString& type, ChannelArguments* args) = 0; // Provide server credentials according to the given type. // Return nullptr if type is not registered. virtual std::shared_ptr<ServerCredentials> GetServerCredentials( - const TString& type) = 0; + const TString& type) = 0; // Provide a list of secure credentials type. - virtual std::vector<TString> GetSecureCredentialsTypeList() = 0; + virtual std::vector<TString> GetSecureCredentialsTypeList() = 0; }; // Get the current provider. Create a default one if not set. diff --git a/contrib/libs/grpc/test/cpp/util/time_test.cc b/contrib/libs/grpc/test/cpp/util/time_test.cc index bcbfa14f94..474458789f 100644 --- a/contrib/libs/grpc/test/cpp/util/time_test.cc +++ b/contrib/libs/grpc/test/cpp/util/time_test.cc @@ -20,8 +20,8 @@ #include <grpcpp/support/time.h> #include <gtest/gtest.h> -#include "test/core/util/test_config.h" - +#include "test/core/util/test_config.h" + using std::chrono::duration_cast; using std::chrono::microseconds; using std::chrono::system_clock; @@ -66,7 +66,7 @@ TEST_F(TimeTest, InfFuture) { } // namespace grpc int main(int argc, char** argv) { - grpc::testing::TestEnvironment env(argc, argv); + grpc::testing::TestEnvironment env(argc, argv); ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/contrib/libs/grpc/test/cpp/util/ya.make b/contrib/libs/grpc/test/cpp/util/ya.make index f043cc5b14..12d102d8a1 100644 --- a/contrib/libs/grpc/test/cpp/util/ya.make +++ b/contrib/libs/grpc/test/cpp/util/ya.make @@ -2,10 +2,10 @@ LIBRARY() LICENSE(Apache-2.0) -LICENSE_TEXTS(.yandex_meta/licenses.list.txt) - -OWNER(orivej) +LICENSE_TEXTS(.yandex_meta/licenses.list.txt) +OWNER(orivej) + PEERDIR( contrib/libs/gflags contrib/libs/protoc @@ -14,10 +14,10 @@ PEERDIR( contrib/restricted/googletest/googletest ) -ADDINCL( - ${ARCADIA_BUILD_ROOT}/contrib/libs/grpc - contrib/libs/grpc -) +ADDINCL( + ${ARCADIA_BUILD_ROOT}/contrib/libs/grpc + contrib/libs/grpc +) NO_COMPILER_WARNINGS() |