Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Commit

Permalink
feat(http): update query data version (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
hycdong authored and neverchanje committed Mar 31, 2021
1 parent e80a421 commit a7fa291
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
13 changes: 5 additions & 8 deletions src/replica/replica_http_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,14 @@ void replica_http_service::query_app_data_version_handler(const http_request &re
return;
}

dsn::utils::table_printer tp;
tp.add_title("pidx");
tp.add_column("data_version");
nlohmann::json json;
for (const auto &kv : version_map) {
tp.add_row(kv.first);
tp.append_data(kv.second);
json[std::to_string(kv.first)] = nlohmann::json{
{"data_version", std::to_string(kv.second)},
};
}
std::ostringstream out;
tp.output(out, dsn::utils::table_printer::output_format::kJsonCompact);
resp.body = out.str();
resp.status_code = http_status_code::ok;
resp.body = json.dump();
}

void replica_http_service::query_compaction_handler(const http_request &req, http_response &resp)
Expand Down
5 changes: 1 addition & 4 deletions src/replica/test/replica_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ TEST_F(replica_test, query_data_version_test)
{"wrong", http_status_code::bad_request, "invalid app_id=wrong"},
{"2",
http_status_code::ok,
R"({"1":{"pidx":"1","data_version":"1"}})"},
R"({"1":{"data_version":"1"}})"},
{"4", http_status_code::not_found, "app_id=4 not found"}};
for (const auto &test : tests) {
http_request req;
Expand All @@ -123,9 +123,6 @@ TEST_F(replica_test, query_data_version_test)
http_svc.query_app_data_version_handler(req, resp);
ASSERT_EQ(resp.status_code, test.expected_code);
std::string expected_json = test.expected_response_json;
if (test.expected_code == http_status_code::ok) {
expected_json += "\n";
}
ASSERT_EQ(resp.body, expected_json);
}
}
Expand Down

0 comments on commit a7fa291

Please sign in to comment.