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

Commit

Permalink
update by code review
Browse files Browse the repository at this point in the history
  • Loading branch information
hycdong committed Dec 23, 2020
1 parent d40b4ba commit 8a1a98b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
9 changes: 5 additions & 4 deletions src/meta/meta_http_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ void meta_http_service::start_compaction_handler(const http_request &req, http_r
// validate parameters
manual_compaction_info info;
bool ret = json::json_forwarder<manual_compaction_info>::decode(req.body, info);

if (!ret) {
resp.body = "invalid request structure";
resp.status_code = http_status_code::bad_request;
Expand All @@ -720,23 +721,23 @@ void meta_http_service::start_compaction_handler(const http_request &req, http_r
return;
}
if (info.type.empty() || (info.type != "once" && info.type != "periodic")) {
resp.body = "type should ony be once or periodic";
resp.body = "type should ony be 'once' or 'periodic'";
resp.status_code = http_status_code::bad_request;
return;
}
if (info.target_level < -1) {
resp.body = "target_level should be greater than -1";
resp.body = "target_level should be >= -1";
resp.status_code = http_status_code::bad_request;
return;
}
if (info.bottommost_level_compaction.empty() || (info.bottommost_level_compaction != "skip" &&
info.bottommost_level_compaction != "force")) {
resp.body = "bottommost_level_compaction should ony be skip or force";
resp.body = "bottommost_level_compaction should ony be 'skip' or 'force'";
resp.status_code = http_status_code::bad_request;
return;
}
if (info.max_concurrent_running_count < 0) {
resp.body = "max_running_count should be greater than 0";
resp.body = "max_running_count should be >= 0";
resp.status_code = http_status_code::bad_request;
return;
}
Expand Down
31 changes: 11 additions & 20 deletions src/meta/test/meta_http_service_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// This source code is licensed under the Apache License Version 2.0, which
// can be found in the LICENSE file in the root directory of this source tree.

#include <iostream>
#include <gtest/gtest.h>
#include <dsn/dist/fmt_logging.h>
#include <dsn/http/http_server.h>
Expand Down Expand Up @@ -317,32 +318,22 @@ TEST_F(meta_bulk_load_http_test, start_compaction_test)
http_status_code expected_code;
std::string expected_response_json;
} tests[] = {
{"{\"app_name\":\"test_bulk_load\",\"type\":\"once\",\"target_level\":-1,\"bottommost_"
"level_compaction\":\"skip\",\"max_concurrent_running_count\":\"0\"}",
{R"({"app_name":"test_bulk_load","type":"once","target_level":-1,"bottommost_level_compaction":"skip","max_concurrent_running_count":"0"})",
http_status_code::bad_request,
"invalid request structure"},

{"{\"app_name\":\"test_bulk_load\",\"type\":\"wrong\",\"target_level\":-1,\"bottommost_"
"level_compaction\":\"skip\",\"max_concurrent_running_count\":0,\"trigger_time\":\"\"}",
{R"({"app_name":"test_bulk_load","type":"wrong","target_level":-1,"bottommost_level_compaction":"skip","max_concurrent_running_count":0,"trigger_time":""})",
http_status_code::bad_request,
"type should ony be once or periodic"},

{"{\"app_name\":\"test_bulk_load\",\"type\":\"once\",\"target_level\":-3,\"bottommost_"
"level_compaction\":\"skip\",\"max_concurrent_running_count\":0,\"trigger_time\":\"\"}",
"type should ony be 'once' or 'periodic'"},
{R"({"app_name":"test_bulk_load","type":"once","target_level":-3,"bottommost_level_compaction":"skip","max_concurrent_running_count":0,"trigger_time":""})",
http_status_code::bad_request,
"target_level should be greater than -1"},

{"{\"app_name\":\"test_bulk_load\",\"type\":\"once\",\"target_level\":-1,\"bottommost_"
"level_compaction\":\"wrong\",\"max_concurrent_running_count\":0,\"trigger_time\":\"\"}",
"target_level should be >= -1"},
{R"({"app_name":"test_bulk_load","type":"once","target_level":-1,"bottommost_level_compaction":"wrong","max_concurrent_running_count":0,"trigger_time":""})",
http_status_code::bad_request,
"bottommost_level_compaction should ony be skip or force"},
{"{\"app_name\":\"test_bulk_load\",\"type\":\"once\",\"target_level\":-1,\"bottommost_"
"level_compaction\":\"skip\",\"max_concurrent_running_count\":-2,\"trigger_time\":\"\"}",
"bottommost_level_compaction should ony be 'skip' or 'force'"},
{R"({"app_name":"test_bulk_load","type":"once","target_level":-1,"bottommost_level_compaction":"skip","max_concurrent_running_count":-2,"trigger_time":""})",
http_status_code::bad_request,
"max_running_count should be greater than 0"},

{"{\"app_name\":\"test_bulk_load\",\"type\":\"once\",\"target_level\":-1,\"bottommost_"
"level_compaction\":\"skip\",\"max_concurrent_running_count\":0,\"trigger_time\":\"\"}",
"max_running_count should be >= 0"},
{R"({"app_name":"test_bulk_load","type":"once","target_level":-1,"bottommost_level_compaction":"skip","max_concurrent_running_count":0,"trigger_time":""})",
http_status_code::ok,
"{\"error\":\"ERR_OK\",\"hint_message\":\"\"}\n"}};

Expand Down

0 comments on commit 8a1a98b

Please sign in to comment.