From c215e8e3593b08ea6a81727f187a68efc2d30d1f Mon Sep 17 00:00:00 2001 From: ncteisen Date: Fri, 1 Feb 2019 12:14:06 -0800 Subject: [PATCH 1/4] Fix internal build --- test/cpp/util/channel_trace_proto_helper.cc | 40 +++++++-------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/test/cpp/util/channel_trace_proto_helper.cc b/test/cpp/util/channel_trace_proto_helper.cc index ff9d8873858..da858b6bb7e 100644 --- a/test/cpp/util/channel_trace_proto_helper.cc +++ b/test/cpp/util/channel_trace_proto_helper.cc @@ -16,53 +16,37 @@ * */ -#include "test/cpp/util/channel_trace_proto_helper.h" +#include -#include -#include +#include "test/cpp/util/channel_trace_proto_helper.h" #include #include +#include +#include #include #include "src/proto/grpc/channelz/channelz.pb.h" namespace grpc { -namespace testing { - -namespace { // Generic helper that takes in a json string, converts it to a proto, and // 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 void VaidateProtoJsonTranslation(char* json_c_str) { - std::string json_str(json_c_str); + grpc::string json_str(json_c_str); Message msg; - google::protobuf::util::JsonParseOptions parse_options; - // If the following line is failing, then uncomment the last line of the - // comment, and uncomment the lines that print the two strings. You can - // then compare the output, and determine what fields are missing. - // - // parse_options.ignore_unknown_fields = true; - EXPECT_EQ(google::protobuf::util::JsonStringToMessage(json_str, &msg, - parse_options), - google::protobuf::util::Status::OK); - std::string proto_json_str; - google::protobuf::util::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; - EXPECT_EQ(google::protobuf::util::MessageToJsonString(msg, &proto_json_str, - print_options), - google::protobuf::util::Status::OK); - // uncomment these to compare the 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()); + grpc::protobuf::util::Status s = + grpc::protobuf::json::JsonStringToMessage(json_str, &msg); + EXPECT_TRUE(s.ok()); + grpc::string proto_json_str; + s = grpc::protobuf::json::MessageToJsonString(msg, &proto_json_str); + EXPECT_TRUE(s.ok()); EXPECT_EQ(json_str, proto_json_str); } -} // namespace +namespace testing { void ValidateChannelTraceProtoJsonTranslation(char* json_c_str) { VaidateProtoJsonTranslation(json_c_str); From 632aa8125f8614a3ea68dec8d27d42cefcaf0237 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Fri, 1 Feb 2019 13:15:19 -0800 Subject: [PATCH 2/4] reintroduce anon namespace --- test/cpp/util/channel_trace_proto_helper.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/cpp/util/channel_trace_proto_helper.cc b/test/cpp/util/channel_trace_proto_helper.cc index da858b6bb7e..4cb1a5d0f44 100644 --- a/test/cpp/util/channel_trace_proto_helper.cc +++ b/test/cpp/util/channel_trace_proto_helper.cc @@ -29,6 +29,8 @@ #include "src/proto/grpc/channelz/channelz.pb.h" namespace grpc { + +namespace { // Generic helper that takes in a json string, converts it to a proto, and // then back to json. This ensures that the json string was correctly formatted @@ -46,6 +48,8 @@ void VaidateProtoJsonTranslation(char* json_c_str) { EXPECT_EQ(json_str, proto_json_str); } +} // namespace + namespace testing { void ValidateChannelTraceProtoJsonTranslation(char* json_c_str) { From fa74259769507e084795065627470f643acaaa34 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Fri, 1 Feb 2019 13:19:34 -0800 Subject: [PATCH 3/4] Reintroduce commented debugging tips --- test/cpp/util/channel_trace_proto_helper.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test/cpp/util/channel_trace_proto_helper.cc b/test/cpp/util/channel_trace_proto_helper.cc index 4cb1a5d0f44..80d084f585b 100644 --- a/test/cpp/util/channel_trace_proto_helper.cc +++ b/test/cpp/util/channel_trace_proto_helper.cc @@ -29,7 +29,7 @@ #include "src/proto/grpc/channelz/channelz.pb.h" namespace grpc { - + namespace { // Generic helper that takes in a json string, converts it to a proto, and @@ -39,12 +39,25 @@ template void VaidateProtoJsonTranslation(char* json_c_str) { grpc::string json_str(json_c_str); Message msg; + grpc::protobuf::json::JsonParseOptions parse_options; + // If the following line is failing, then uncomment the last line of the + // comment, and uncomment the lines that print the two strings. You can + // then compare the output, and determine what fields are missing. + // + // parse_options.ignore_unknown_fields = true; grpc::protobuf::util::Status s = - grpc::protobuf::json::JsonStringToMessage(json_str, &msg); + grpc::protobuf::json::JsonStringToMessage(json_str, &msg, parse_options); EXPECT_TRUE(s.ok()); grpc::string 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()); + // uncomment these to compare the 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()); EXPECT_EQ(json_str, proto_json_str); } From 82171553cfda63af93077de3e0d47223dfbc517f Mon Sep 17 00:00:00 2001 From: ncteisen Date: Fri, 1 Feb 2019 15:23:44 -0800 Subject: [PATCH 4/4] clang fmt --- test/cpp/util/channel_trace_proto_helper.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cpp/util/channel_trace_proto_helper.cc b/test/cpp/util/channel_trace_proto_helper.cc index 80d084f585b..b473b7d7aa5 100644 --- a/test/cpp/util/channel_trace_proto_helper.cc +++ b/test/cpp/util/channel_trace_proto_helper.cc @@ -61,7 +61,7 @@ void VaidateProtoJsonTranslation(char* json_c_str) { EXPECT_EQ(json_str, proto_json_str); } -} // namespace +} // namespace namespace testing {