empiredan commented on code in PR #1442:
URL: 
https://github.com/apache/incubator-pegasus/pull/1442#discussion_r1168131577


##########
src/test/function_test/utils/test_util.cpp:
##########
@@ -88,4 +99,38 @@ void test_util::run_cmd_from_project_root(const std::string 
&cmd)
     ASSERT_NO_FATAL_FAILURE(run_cmd(cmd));
 }
 
+int test_util::get_alive_replica_server_count()
+{
+    std::string json_filename = fmt::format("test_json_file.{}", 
dsn::rand::next_u32());

Review Comment:
   ```suggestion
       const auto json_filename = fmt::format("test_json_file.{}", 
dsn::rand::next_u32());
   ```



##########
src/test/function_test/utils/test_util.cpp:
##########
@@ -88,4 +99,38 @@ void test_util::run_cmd_from_project_root(const std::string 
&cmd)
     ASSERT_NO_FATAL_FAILURE(run_cmd(cmd));
 }
 
+int test_util::get_alive_replica_server_count()
+{
+    std::string json_filename = fmt::format("test_json_file.{}", 
dsn::rand::next_u32());
+    auto cleanup =
+        dsn::defer([json_filename]() { 
dsn::utils::filesystem::remove_path(json_filename); });
+    run_cmd_from_project_root(fmt::format("echo 'nodes -djo {}' | ./run.sh 
shell", json_filename));
+    std::ifstream f(json_filename);
+    json data = json::parse(f);
+    int replica_server_count = 0;
+    if (!dsn::buf2int32(data["summary"]["alive_node_count"], 
replica_server_count)) {
+        return -1;
+    }
+    return replica_server_count;
+}
+
+int test_util::get_leader_count(const std::string &table_name, int 
replica_server_index)
+{
+    std::string json_filename = fmt::format("test_json_file.{}", 
dsn::rand::next_u32());

Review Comment:
   ```suggestion
       const auto json_filename = fmt::format("test_json_file.{}", 
dsn::rand::next_u32());
   ```



##########
src/test/function_test/utils/test_util.cpp:
##########
@@ -88,4 +99,38 @@ void test_util::run_cmd_from_project_root(const std::string 
&cmd)
     ASSERT_NO_FATAL_FAILURE(run_cmd(cmd));
 }
 
+int test_util::get_alive_replica_server_count()
+{
+    std::string json_filename = fmt::format("test_json_file.{}", 
dsn::rand::next_u32());
+    auto cleanup =
+        dsn::defer([json_filename]() { 
dsn::utils::filesystem::remove_path(json_filename); });
+    run_cmd_from_project_root(fmt::format("echo 'nodes -djo {}' | ./run.sh 
shell", json_filename));
+    std::ifstream f(json_filename);
+    json data = json::parse(f);
+    int replica_server_count = 0;
+    if (!dsn::buf2int32(data["summary"]["alive_node_count"], 
replica_server_count)) {
+        return -1;
+    }
+    return replica_server_count;
+}
+
+int test_util::get_leader_count(const std::string &table_name, int 
replica_server_index)
+{
+    std::string json_filename = fmt::format("test_json_file.{}", 
dsn::rand::next_u32());
+    auto cleanup =
+        dsn::defer([json_filename]() { 
dsn::utils::filesystem::remove_path(json_filename); });
+    run_cmd_from_project_root(
+        fmt::format("echo 'app {} -djo {}' | ./run.sh shell", table_name, 
json_filename));
+    std::ifstream f(json_filename);
+    json data = json::parse(f);

Review Comment:
   ```suggestion
       const auto data = json::parse(f);
   ```



##########
src/test/function_test/utils/test_util.cpp:
##########
@@ -88,4 +99,38 @@ void test_util::run_cmd_from_project_root(const std::string 
&cmd)
     ASSERT_NO_FATAL_FAILURE(run_cmd(cmd));
 }
 
+int test_util::get_alive_replica_server_count()
+{
+    std::string json_filename = fmt::format("test_json_file.{}", 
dsn::rand::next_u32());
+    auto cleanup =
+        dsn::defer([json_filename]() { 
dsn::utils::filesystem::remove_path(json_filename); });
+    run_cmd_from_project_root(fmt::format("echo 'nodes -djo {}' | ./run.sh 
shell", json_filename));
+    std::ifstream f(json_filename);
+    json data = json::parse(f);

Review Comment:
   ```suggestion
       const auto data = json::parse(f);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to