aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@users.noreply.github.com>2016-06-08 18:15:22 -0700
committerGravatar Jan Tattermusch <jtattermusch@users.noreply.github.com>2016-06-08 18:15:22 -0700
commitac48d1aafea394a3defd664911deb755d93b2f43 (patch)
treed400400b9b1ecae740a3e352f2676fffca9744f7 /test
parentd861b13aff7481b4901ab012cfd51c5887b11a2e (diff)
parente27d189f2165e904dbb3d61616edf3c643df71f0 (diff)
Merge pull request #6656 from dklempner/qps_report
Factor out json serialization code from qps report.cc
Diffstat (limited to 'test')
-rw-r--r--test/cpp/qps/parse_json.cc15
-rw-r--r--test/cpp/qps/parse_json.h3
-rw-r--r--test/cpp/qps/report.cc18
3 files changed, 21 insertions, 15 deletions
diff --git a/test/cpp/qps/parse_json.cc b/test/cpp/qps/parse_json.cc
index a90bf6153c..be804281f8 100644
--- a/test/cpp/qps/parse_json.cc
+++ b/test/cpp/qps/parse_json.cc
@@ -61,5 +61,20 @@ void ParseJson(const grpc::string& json, const grpc::string& type,
GPR_ASSERT(msg->ParseFromString(binary));
}
+grpc::string SerializeJson(const GRPC_CUSTOM_MESSAGE& msg,
+ const grpc::string& type) {
+ std::unique_ptr<google::protobuf::util::TypeResolver> type_resolver(
+ google::protobuf::util::NewTypeResolverForDescriptorPool(
+ "type.googleapis.com",
+ google::protobuf::DescriptorPool::generated_pool()));
+ grpc::string binary;
+ grpc::string json_string;
+ msg.SerializeToString(&binary);
+ auto status =
+ BinaryToJsonString(type_resolver.get(), type, binary, &json_string);
+ GPR_ASSERT(status.ok());
+ return json_string;
+}
+
} // testing
} // grpc
diff --git a/test/cpp/qps/parse_json.h b/test/cpp/qps/parse_json.h
index 42d7d22c53..ce1821f961 100644
--- a/test/cpp/qps/parse_json.h
+++ b/test/cpp/qps/parse_json.h
@@ -43,6 +43,9 @@ namespace testing {
void ParseJson(const grpc::string& json, const grpc::string& type,
GRPC_CUSTOM_MESSAGE* msg);
+grpc::string SerializeJson(const GRPC_CUSTOM_MESSAGE& msg,
+ const grpc::string& type);
+
} // testing
} // grpc
diff --git a/test/cpp/qps/report.cc b/test/cpp/qps/report.cc
index 3ae41399cf..2ec7d8676c 100644
--- a/test/cpp/qps/report.cc
+++ b/test/cpp/qps/report.cc
@@ -35,11 +35,9 @@
#include <fstream>
-#include <google/protobuf/util/json_util.h>
-#include <google/protobuf/util/type_resolver_util.h>
-
#include <grpc/support/log.h>
#include "test/cpp/qps/driver.h"
+#include "test/cpp/qps/parse_json.h"
#include "test/cpp/qps/stats.h"
namespace grpc {
@@ -104,18 +102,8 @@ void GprLogReporter::ReportTimes(const ScenarioResult& result) {
}
void JsonReporter::ReportQPS(const ScenarioResult& result) {
- std::unique_ptr<google::protobuf::util::TypeResolver> type_resolver(
- google::protobuf::util::NewTypeResolverForDescriptorPool(
- "type.googleapis.com",
- google::protobuf::DescriptorPool::generated_pool()));
- grpc::string binary;
- grpc::string json_string;
- result.SerializeToString(&binary);
- auto status = BinaryToJsonString(
- type_resolver.get(), "type.googleapis.com/grpc.testing.ScenarioResult",
- binary, &json_string);
- GPR_ASSERT(status.ok());
-
+ grpc::string json_string =
+ SerializeJson(result, "type.googleapis.com/grpc.testing.ScenarioResult");
std::ofstream output_file(report_file_);
output_file << json_string;
output_file.close();