From 6a1eb182ddf1558cc2ad88948509c815302982b2 Mon Sep 17 00:00:00 2001 From: Yingchun Lai Date: Sun, 18 Sep 2022 00:17:12 +0800 Subject: [PATCH] refacor(function_test): use test_util to reduce duplicate code --- run.sh | 6 - .../test_backup_and_restore.cpp | 2 + .../base_api_test/test_basic.cpp | 2678 ++++++++--------- .../base_api_test/test_batch_get.cpp | 7 +- .../base_api_test/test_check_and_mutate.cpp | 1715 +++++------ .../base_api_test/test_check_and_set.cpp | 1807 ++++++----- .../function_test/base_api_test/test_copy.cpp | 135 +- .../function_test/base_api_test/test_incr.cpp | 178 +- .../base_api_test/test_range_read.cpp | 105 +- .../base_api_test/test_recall.cpp | 80 +- .../function_test/base_api_test/test_scan.cpp | 274 +- .../function_test/base_api_test/test_ttl.cpp | 214 +- .../bulk_load_test/test_bulk_load.cpp | 254 +- .../test_detect_hotspot.cpp | 106 +- .../partition_split_test/test_split.cpp | 151 +- .../recovery_test/test_recovery.cpp | 239 +- .../restore_test/test_restore.cpp | 58 +- .../throttle_test/test_throttle.cpp | 730 ++--- src/test/function_test/utils/CMakeLists.txt | 1 + src/test/function_test/utils/global_env.cpp | 31 +- src/test/function_test/utils/test_util.cpp | 47 +- src/test/function_test/utils/test_util.h | 27 +- src/test/function_test/utils/utils.h | 17 +- 23 files changed, 4066 insertions(+), 4796 deletions(-) diff --git a/run.sh b/run.sh index b643c6dd00..1bf6710db4 100755 --- a/run.sh +++ b/run.sh @@ -765,7 +765,6 @@ function run_start_onebox() cd meta$i ln -s -f ${SERVER_PATH}/pegasus_server pegasus_server sed "s/@META_PORT@/$meta_port/;s/@REPLICA_PORT@/34800/;s/@PROMETHEUS_PORT@/$prometheus_port/" ${ROOT}/config-server.ini >config.ini - echo "cd `pwd` && $PWD/pegasus_server config.ini -app_list meta &>result &" $PWD/pegasus_server config.ini -app_list meta &>result & PID=$! ps -ef | grep '/pegasus_server config.ini' | grep "\<$PID\>" @@ -779,7 +778,6 @@ function run_start_onebox() cd replica$j ln -s -f ${SERVER_PATH}/pegasus_server pegasus_server sed "s/@META_PORT@/34600/;s/@REPLICA_PORT@/$replica_port/;s/@PROMETHEUS_PORT@/$prometheus_port/" ${ROOT}/config-server.ini >config.ini - echo "cd `pwd` && $PWD/pegasus_server config.ini -app_list replica &>result &" $PWD/pegasus_server config.ini -app_list replica &>result & PID=$! ps -ef | grep '/pegasus_server config.ini' | grep "\<$PID\>" @@ -791,7 +789,6 @@ function run_start_onebox() cd collector ln -s -f ${SERVER_PATH}/pegasus_server pegasus_server sed "s/@META_PORT@/34600/;s/@REPLICA_PORT@/34800/;s/@PROMETHEUS_PORT@/9091/" ${ROOT}/config-server.ini >config.ini - echo "cd `pwd` && $PWD/pegasus_server config.ini -app_list collector &>result &" $PWD/pegasus_server config.ini -app_list collector &>result & PID=$! ps -ef | grep '/pegasus_server config.ini' | grep "\<$PID\>" @@ -967,7 +964,6 @@ function run_start_onebox_instance() exit 1 fi cd $dir - echo "cd `pwd` && $PWD/pegasus_server config.ini -app_list meta &>result &" $PWD/pegasus_server config.ini -app_list meta &>result & PID=$! ps -ef | grep '/pegasus_server config.ini' | grep "\<$PID\>" @@ -985,7 +981,6 @@ function run_start_onebox_instance() exit 1 fi cd $dir - echo "cd `pwd` && $PWD/pegasus_server config.ini -app_list replica &>result &" $PWD/pegasus_server config.ini -app_list replica &>result & PID=$! ps -ef | grep '/pegasus_server config.ini' | grep "\<$PID\>" @@ -1003,7 +998,6 @@ function run_start_onebox_instance() exit 1 fi cd $dir - echo "cd `pwd` && $PWD/pegasus_server config.ini -app_list collector &>result &" $PWD/pegasus_server config.ini -app_list collector &>result & PID=$! ps -ef | grep '/pegasus_server config.ini' | grep "\<$PID\>" diff --git a/src/test/function_test/backup_restore_test/test_backup_and_restore.cpp b/src/test/function_test/backup_restore_test/test_backup_and_restore.cpp index 63aea7c1c2..4da286b910 100644 --- a/src/test/function_test/backup_restore_test/test_backup_and_restore.cpp +++ b/src/test/function_test/backup_restore_test/test_backup_and_restore.cpp @@ -30,6 +30,8 @@ using namespace dsn; using namespace dsn::replication; using namespace pegasus; +// TODO(yingchun): backup & restore festure is on refactoring, we can refactor the related function +// test later. class backup_restore_test : public testing::Test { public: diff --git a/src/test/function_test/base_api_test/test_basic.cpp b/src/test/function_test/base_api_test/test_basic.cpp index 03eef5ea86..4655cfd9e4 100644 --- a/src/test/function_test/base_api_test/test_basic.cpp +++ b/src/test/function_test/base_api_test/test_basic.cpp @@ -41,1624 +41,1594 @@ class basic : public test_util TEST_F(basic, set_get_del) { - ASSERT_STREQ("mycluster", client->get_cluster_name()); - // set - int ret = client->set("basic_test_hash_key_1", "basic_test_sort_key_1", "basic_test_value_1"); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->set("basic_test_hash_key_1", "basic_test_sort_key_1", "basic_test_value_1")); // exist - ret = client->exist("basic_test_hash_key_1", "basic_test_sort_key_1"); - ASSERT_EQ(PERR_OK, ret); - - ret = client->exist("basic_test_hash_key_1", "basic_test_sort_key_2"); - ASSERT_EQ(PERR_NOT_FOUND, ret); + ASSERT_EQ(PERR_OK, client_->exist("basic_test_hash_key_1", "basic_test_sort_key_1")); + ASSERT_EQ(PERR_NOT_FOUND, client_->exist("basic_test_hash_key_1", "basic_test_sort_key_2")); // sortkey_count int64_t count; - ret = client->sortkey_count("basic_test_hash_key_1", count); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->sortkey_count("basic_test_hash_key_1", count)); ASSERT_EQ(1, count); // get - std::string new_value_str; - ret = client->get("basic_test_hash_key_1", "basic_test_sort_key_1", new_value_str); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ("basic_test_value_1", new_value_str); + std::string new_value; + ASSERT_EQ(PERR_OK, client_->get("basic_test_hash_key_1", "basic_test_sort_key_1", new_value)); + ASSERT_EQ("basic_test_value_1", new_value); - ret = client->get("basic_test_hash_key_1", "basic_test_sort_key_2", new_value_str); - ASSERT_EQ(PERR_NOT_FOUND, ret); + ASSERT_EQ(PERR_NOT_FOUND, + client_->get("basic_test_hash_key_1", "basic_test_sort_key_2", new_value)); // del - ret = client->del("basic_test_hash_key_1", "basic_test_sort_key_1"); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->del("basic_test_hash_key_1", "basic_test_sort_key_1")); // exist - ret = client->exist("basic_test_hash_key_1", "basic_test_sort_key_1"); - ASSERT_EQ(PERR_NOT_FOUND, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->exist("basic_test_hash_key_1", "basic_test_sort_key_1")); // sortkey_count - ret = client->sortkey_count("basic_test_hash_key_1", count); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->sortkey_count("basic_test_hash_key_1", count)); ASSERT_EQ(0, count); // get - ret = client->get("basic_test_hash_key_1", "basic_test_sort_key_1", new_value_str); - ASSERT_EQ(PERR_NOT_FOUND, ret); + ASSERT_EQ(PERR_NOT_FOUND, + client_->get("basic_test_hash_key_1", "basic_test_sort_key_1", new_value)); } TEST_F(basic, multi_get) { + const std::map kvs({{"", "0"}, + {"1", "1"}, + {"1-abcdefg", "1-abcdefg"}, + {"2", "2"}, + {"2-abcdefg", "2-abcdefg"}, + {"3", "3"}, + {"3-efghijk", "3-efghijk"}, + {"4", "4"}, + {"4-hijklmn", "4-hijklmn"}, + {"5", "5"}, + {"5-hijklmn", "5-hijklmn"}, + {"6", "6"}, + {"7", "7"}}); + // multi_set - std::map kvs; - kvs[""] = "0"; - kvs["1"] = "1"; - kvs["1-abcdefg"] = "1-abcdefg"; - kvs["2"] = "2"; - kvs["2-abcdefg"] = "2-abcdefg"; - kvs["3"] = "3"; - kvs["3-efghijk"] = "3-efghijk"; - kvs["4"] = "4"; - kvs["4-hijklmn"] = "4-hijklmn"; - kvs["5"] = "5"; - kvs["5-hijklmn"] = "5-hijklmn"; - kvs["6"] = "6"; - kvs["7"] = "7"; - int ret = client->multi_set("basic_test_multi_get", kvs); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->multi_set("basic_test_multi_get", kvs)); // sortkey_count int64_t count; - ret = client->sortkey_count("basic_test_multi_get", count); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->sortkey_count("basic_test_multi_get", count)); ASSERT_EQ(13, count); // [null, null) - pegasus::pegasus_client::multi_get_options options; - ASSERT_TRUE(options.start_inclusive); - ASSERT_FALSE(options.stop_inclusive); - std::map new_values; - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(13, (int)new_values.size()); - ASSERT_EQ("0", new_values[""]); - ASSERT_EQ("1", new_values["1"]); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); - ASSERT_EQ("2", new_values["2"]); - ASSERT_EQ("2-abcdefg", new_values["2-abcdefg"]); - ASSERT_EQ("3", new_values["3"]); - ASSERT_EQ("3-efghijk", new_values["3-efghijk"]); - ASSERT_EQ("4", new_values["4"]); - ASSERT_EQ("4-hijklmn", new_values["4-hijklmn"]); - ASSERT_EQ("5", new_values["5"]); - ASSERT_EQ("5-hijklmn", new_values["5-hijklmn"]); - ASSERT_EQ("6", new_values["6"]); - ASSERT_EQ("7", new_values["7"]); + { + pegasus::pegasus_client::multi_get_options options; + ASSERT_TRUE(options.start_inclusive); + ASSERT_FALSE(options.stop_inclusive); + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + ASSERT_EQ(kvs, new_values); + } // [null, null] - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = true; - options.stop_inclusive = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(13, (int)new_values.size()); - ASSERT_EQ("0", new_values[""]); - ASSERT_EQ("1", new_values["1"]); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); - ASSERT_EQ("2", new_values["2"]); - ASSERT_EQ("2-abcdefg", new_values["2-abcdefg"]); - ASSERT_EQ("3", new_values["3"]); - ASSERT_EQ("3-efghijk", new_values["3-efghijk"]); - ASSERT_EQ("4", new_values["4"]); - ASSERT_EQ("4-hijklmn", new_values["4-hijklmn"]); - ASSERT_EQ("5", new_values["5"]); - ASSERT_EQ("5-hijklmn", new_values["5-hijklmn"]); - ASSERT_EQ("6", new_values["6"]); - ASSERT_EQ("7", new_values["7"]); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = true; + options.stop_inclusive = true; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + ASSERT_EQ(kvs, new_values); + } // (null, null) - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = false; - options.stop_inclusive = false; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(12, (int)new_values.size()); - ASSERT_EQ("1", new_values["1"]); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); - ASSERT_EQ("2", new_values["2"]); - ASSERT_EQ("2-abcdefg", new_values["2-abcdefg"]); - ASSERT_EQ("3", new_values["3"]); - ASSERT_EQ("3-efghijk", new_values["3-efghijk"]); - ASSERT_EQ("4", new_values["4"]); - ASSERT_EQ("4-hijklmn", new_values["4-hijklmn"]); - ASSERT_EQ("5", new_values["5"]); - ASSERT_EQ("5-hijklmn", new_values["5-hijklmn"]); - ASSERT_EQ("6", new_values["6"]); - ASSERT_EQ("7", new_values["7"]); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = false; + options.stop_inclusive = false; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + auto expect_kvs(kvs); + expect_kvs.erase(""); + ASSERT_EQ(expect_kvs, new_values); + } // (null, null] - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = false; - options.stop_inclusive = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(12, (int)new_values.size()); - ASSERT_EQ("1", new_values["1"]); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); - ASSERT_EQ("2", new_values["2"]); - ASSERT_EQ("2-abcdefg", new_values["2-abcdefg"]); - ASSERT_EQ("3", new_values["3"]); - ASSERT_EQ("3-efghijk", new_values["3-efghijk"]); - ASSERT_EQ("4", new_values["4"]); - ASSERT_EQ("4-hijklmn", new_values["4-hijklmn"]); - ASSERT_EQ("5", new_values["5"]); - ASSERT_EQ("5-hijklmn", new_values["5-hijklmn"]); - ASSERT_EQ("6", new_values["6"]); - ASSERT_EQ("7", new_values["7"]); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = false; + options.stop_inclusive = true; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + auto expect_kvs(kvs); + expect_kvs.erase(""); + ASSERT_EQ(expect_kvs, new_values); + } // [null, 1] - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = true; - options.stop_inclusive = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(2, (int)new_values.size()); - ASSERT_EQ("0", new_values[""]); - ASSERT_EQ("1", new_values["1"]); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = true; + options.stop_inclusive = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get", "", "1", options, new_values)); + std::map expect_kvs({{"", "0"}, {"1", "1"}}); + ASSERT_EQ(expect_kvs, new_values); + } // [null, 1) - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = true; - options.stop_inclusive = false; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("0", new_values[""]); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = true; + options.stop_inclusive = false; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get", "", "1", options, new_values)); + std::map expect_kvs({{"", "0"}}); + ASSERT_EQ(expect_kvs, new_values); + } // (null, 1] - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = false; - options.stop_inclusive = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("1", new_values["1"]); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = false; + options.stop_inclusive = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get", "", "1", options, new_values)); + std::map expect_kvs({{"1", "1"}}); + ASSERT_EQ(expect_kvs, new_values); + } // (null, 1) - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = false; - options.stop_inclusive = false; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = false; + options.stop_inclusive = false; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get", "", "1", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // [1, 1] - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = true; - options.stop_inclusive = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "1", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("1", new_values["1"]); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = true; + options.stop_inclusive = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get", "1", "1", options, new_values)); + std::map expect_kvs({{"1", "1"}}); + ASSERT_EQ(expect_kvs, new_values); + } // [1, 1) - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = true; - options.stop_inclusive = false; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "1", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = true; + options.stop_inclusive = false; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get", "1", "1", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // (1, 1] - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = false; - options.stop_inclusive = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "1", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = false; + options.stop_inclusive = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get", "1", "1", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // (1, 1) - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = false; - options.stop_inclusive = false; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "1", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = false; + options.stop_inclusive = false; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get", "1", "1", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // [2, 1] - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = true; - options.stop_inclusive = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "2", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = true; + options.stop_inclusive = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get", "2", "1", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-anywhere("-") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_ANYWHERE; - options.sort_key_filter_pattern = "-"; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(5, (int)new_values.size()); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); - ASSERT_EQ("2-abcdefg", new_values["2-abcdefg"]); - ASSERT_EQ("3-efghijk", new_values["3-efghijk"]); - ASSERT_EQ("4-hijklmn", new_values["4-hijklmn"]); - ASSERT_EQ("5-hijklmn", new_values["5-hijklmn"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_ANYWHERE; + options.sort_key_filter_pattern = "-"; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + std::map expect_kvs({ + {"1-abcdefg", "1-abcdefg"}, + {"2-abcdefg", "2-abcdefg"}, + {"3-efghijk", "3-efghijk"}, + {"4-hijklmn", "4-hijklmn"}, + {"5-hijklmn", "5-hijklmn"}, + }); + ASSERT_EQ(expect_kvs, new_values); + } // match-anywhere("1") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_ANYWHERE; - options.sort_key_filter_pattern = "1"; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(2, (int)new_values.size()); - ASSERT_EQ("1", new_values["1"]); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_ANYWHERE; + options.sort_key_filter_pattern = "1"; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + std::map expect_kvs({{"1", "1"}, {"1-abcdefg", "1-abcdefg"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-anywhere("1-") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_ANYWHERE; - options.sort_key_filter_pattern = "1-"; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_ANYWHERE; + options.sort_key_filter_pattern = "1-"; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + std::map expect_kvs({{"1-abcdefg", "1-abcdefg"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-anywhere("abc") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_ANYWHERE; - options.sort_key_filter_pattern = "abc"; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(2, (int)new_values.size()); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); - ASSERT_EQ("2-abcdefg", new_values["2-abcdefg"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_ANYWHERE; + options.sort_key_filter_pattern = "abc"; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + std::map expect_kvs( + {{"1-abcdefg", "1-abcdefg"}, {"2-abcdefg", "2-abcdefg"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-prefix("1") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "1"; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(2, (int)new_values.size()); - ASSERT_EQ("1", new_values["1"]); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "1"; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + std::map expect_kvs({ + {"1", "1"}, {"1-abcdefg", "1-abcdefg"}, + }); + ASSERT_EQ(expect_kvs, new_values); + } // match-prefix("1") in [0, 1) - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "1"; - options.start_inclusive = true; - options.stop_inclusive = false; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "0", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "1"; + options.start_inclusive = true; + options.stop_inclusive = false; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get", "0", "1", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-prefix("1") in [0, 1] - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "1"; - options.start_inclusive = true; - options.stop_inclusive = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "0", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("1", new_values["1"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "1"; + options.start_inclusive = true; + options.stop_inclusive = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get", "0", "1", options, new_values)); + std::map expect_kvs({{"1", "1"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-prefix("1") in [1, 2] - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "1"; - options.start_inclusive = true; - options.stop_inclusive = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "1", "2", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(2, (int)new_values.size()); - ASSERT_EQ("1", new_values["1"]); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "1"; + options.start_inclusive = true; + options.stop_inclusive = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get", "1", "2", options, new_values)); + std::map expect_kvs({{"1", "1"}, {"1-abcdefg", "1-abcdefg"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-prefix("1") in (1, 2] - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "1"; - options.start_inclusive = false; - options.stop_inclusive = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "1", "2", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "1"; + options.start_inclusive = false; + options.stop_inclusive = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get", "1", "2", options, new_values)); + std::map expect_kvs({{"1-abcdefg", "1-abcdefg"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-prefix("1") in (1-abcdefg, 2] - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "1"; - options.start_inclusive = false; - options.stop_inclusive = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "1-abcdefg", "2", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "1"; + options.start_inclusive = false; + options.stop_inclusive = true; + std::map new_values; + ASSERT_EQ( + PERR_OK, + client_->multi_get("basic_test_multi_get", "1-abcdefg", "2", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-prefix("1-") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "1-"; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "1-"; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + std::map expect_kvs({{"1-abcdefg", "1-abcdefg"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-prefix("1-x") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "1-x"; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "1-x"; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-prefix("abc") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "abc"; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "abc"; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-prefix("efg") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "efg"; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "efg"; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-prefix("ijk") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "ijk"; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "ijk"; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-prefix("lmn") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "lmn"; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "lmn"; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-prefix("5-hijklmn") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "5-hijklmn"; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("5-hijklmn", new_values["5-hijklmn"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "5-hijklmn"; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + std::map expect_kvs({{"5-hijklmn", "5-hijklmn"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-postfix("1") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; - options.sort_key_filter_pattern = "1"; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("1", new_values["1"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; + options.sort_key_filter_pattern = "1"; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + std::map expect_kvs({{"1", "1"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-postfix("1-") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; - options.sort_key_filter_pattern = "1-"; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; + options.sort_key_filter_pattern = "1-"; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-postfix("1-x") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; - options.sort_key_filter_pattern = "1-x"; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; + options.sort_key_filter_pattern = "1-x"; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-postfix("abc") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; - options.sort_key_filter_pattern = "abc"; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; + options.sort_key_filter_pattern = "abc"; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-postfix("efg") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; - options.sort_key_filter_pattern = "efg"; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(2, (int)new_values.size()); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); - ASSERT_EQ("2-abcdefg", new_values["2-abcdefg"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; + options.sort_key_filter_pattern = "efg"; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + std::map expect_kvs( + {{"1-abcdefg", "1-abcdefg"}, {"2-abcdefg", "2-abcdefg"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-postfix("ijk") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; - options.sort_key_filter_pattern = "ijk"; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("3-efghijk", new_values["3-efghijk"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; + options.sort_key_filter_pattern = "ijk"; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + std::map expect_kvs({{"3-efghijk", "3-efghijk"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-postfix("lmn") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; - options.sort_key_filter_pattern = "lmn"; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(2, (int)new_values.size()); - ASSERT_EQ("4-hijklmn", new_values["4-hijklmn"]); - ASSERT_EQ("5-hijklmn", new_values["5-hijklmn"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; + options.sort_key_filter_pattern = "lmn"; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + std::map expect_kvs( + {{"4-hijklmn", "4-hijklmn"}, {"5-hijklmn", "5-hijklmn"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-postfix("5-hijklmn") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; - options.sort_key_filter_pattern = "5-hijklmn"; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("5-hijklmn", new_values["5-hijklmn"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; + options.sort_key_filter_pattern = "5-hijklmn"; + std::map new_values; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_multi_get", "", "", options, new_values)); + std::map expect_kvs({{"5-hijklmn", "5-hijklmn"}}); + ASSERT_EQ(expect_kvs, new_values); + } // maxCount = 4 - options = pegasus::pegasus_client::multi_get_options(); - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values, 4, -1); - ASSERT_EQ(PERR_INCOMPLETE, ret); - ASSERT_EQ(4, (int)new_values.size()); - ASSERT_EQ("0", new_values[""]); - ASSERT_EQ("1", new_values["1"]); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); - ASSERT_EQ("2", new_values["2"]); + { + pegasus::pegasus_client::multi_get_options options; + std::map new_values; + ASSERT_EQ(PERR_INCOMPLETE, + client_->multi_get("basic_test_multi_get", "", "", options, new_values, 4, -1)); + std::map expect_kvs( + {{"", "0"}, {"1", "1"}, {"1-abcdefg", "1-abcdefg"}, {"2", "2"}}); + ASSERT_EQ(expect_kvs, new_values); + } // maxCount = 1 - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = true; - options.stop_inclusive = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "5", "6", options, new_values, 1, -1); - ASSERT_EQ(PERR_INCOMPLETE, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("5", new_values["5"]); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = true; + options.stop_inclusive = true; + std::map new_values; + ASSERT_EQ(PERR_INCOMPLETE, + client_->multi_get("basic_test_multi_get", "5", "6", options, new_values, 1, -1)); + std::map expect_kvs({{"5", "5"}}); + ASSERT_EQ(expect_kvs, new_values); + } // set a expired value - ret = client->set("basic_test_multi_get", "", "expire_value", 5000, 1); - ASSERT_EQ(PERR_OK, ret); - std::this_thread::sleep_for(std::chrono::seconds(1)); - new_values.clear(); - ret = client->multi_get("basic_test_multi_get", "", "", options, new_values, 2); - ASSERT_EQ(PERR_INCOMPLETE, ret); - ASSERT_EQ(2, (int)new_values.size()); - ASSERT_EQ("1", new_values["1"]); + { + pegasus::pegasus_client::multi_get_options options; + ASSERT_EQ(PERR_OK, client_->set("basic_test_multi_get", "", "expire_value", 5000, 1)); + std::this_thread::sleep_for(std::chrono::seconds(1)); + std::map new_values; + ASSERT_EQ(PERR_INCOMPLETE, + client_->multi_get("basic_test_multi_get", "", "", options, new_values, 2)); + std::map expect_kvs({{"1", "1"}, {"1-abcdefg", "1-abcdefg"}}); + ASSERT_EQ(expect_kvs, new_values); + } // multi_del - std::set sortkeys; - sortkeys.insert(""); - sortkeys.insert("1"); - sortkeys.insert("1-abcdefg"); - sortkeys.insert("2"); - sortkeys.insert("2-abcdefg"); - sortkeys.insert("3"); - sortkeys.insert("3-efghijk"); - sortkeys.insert("4"); - sortkeys.insert("4-hijklmn"); - sortkeys.insert("5"); - sortkeys.insert("5-hijklmn"); - sortkeys.insert("6"); - sortkeys.insert("7"); - int64_t deleted_count; - ret = client->multi_del("basic_test_multi_get", sortkeys, deleted_count); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(13, deleted_count); + { + std::set sortkeys({"", + "1", + "1-abcdefg", + "2", + "2-abcdefg", + "3", + "3-efghijk", + "4", + "4-hijklmn", + "5", + "5-hijklmn", + "6", + "7"}); + int64_t deleted_count; + ASSERT_EQ(PERR_OK, client_->multi_del("basic_test_multi_get", sortkeys, deleted_count)); + ASSERT_EQ(13, deleted_count); + } // sortkey_count - ret = client->sortkey_count("basic_test_multi_get", count); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->sortkey_count("basic_test_multi_get", count)); ASSERT_EQ(0, count); } TEST_F(basic, multi_get_reverse) { // multi_set - std::map kvs; - kvs[""] = "0"; - kvs["1"] = "1"; - kvs["1-abcdefg"] = "1-abcdefg"; - kvs["2"] = "2"; - kvs["2-abcdefg"] = "2-abcdefg"; - kvs["3"] = "3"; - kvs["3-efghijk"] = "3-efghijk"; - kvs["4"] = "4"; - kvs["4-hijklmn"] = "4-hijklmn"; - kvs["5"] = "5"; - kvs["5-hijklmn"] = "5-hijklmn"; - kvs["6"] = "6"; - kvs["7"] = "7"; - int ret = client->multi_set("basic_test_multi_get_reverse", kvs); - ASSERT_EQ(PERR_OK, ret); + const std::map kvs({{"", "0"}, + {"1", "1"}, + {"1-abcdefg", "1-abcdefg"}, + {"2", "2"}, + {"2-abcdefg", "2-abcdefg"}, + {"3", "3"}, + {"3-efghijk", "3-efghijk"}, + {"4", "4"}, + {"4-hijklmn", "4-hijklmn"}, + {"5", "5"}, + {"5-hijklmn", "5-hijklmn"}, + {"6", "6"}, + {"7", "7"}}); + ASSERT_EQ(PERR_OK, client_->multi_set("basic_test_multi_get_reverse", kvs)); // sortkey_count int64_t count; - ret = client->sortkey_count("basic_test_multi_get_reverse", count); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->sortkey_count("basic_test_multi_get_reverse", count)); ASSERT_EQ(13, count); // [null, null) - pegasus::pegasus_client::multi_get_options options; - ASSERT_TRUE(options.start_inclusive); - ASSERT_FALSE(options.stop_inclusive); - options.reverse = true; - std::map new_values; - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(13, (int)new_values.size()); - ASSERT_EQ("0", new_values[""]); - ASSERT_EQ("1", new_values["1"]); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); - ASSERT_EQ("2", new_values["2"]); - ASSERT_EQ("2-abcdefg", new_values["2-abcdefg"]); - ASSERT_EQ("3", new_values["3"]); - ASSERT_EQ("3-efghijk", new_values["3-efghijk"]); - ASSERT_EQ("4", new_values["4"]); - ASSERT_EQ("4-hijklmn", new_values["4-hijklmn"]); - ASSERT_EQ("5", new_values["5"]); - ASSERT_EQ("5-hijklmn", new_values["5-hijklmn"]); - ASSERT_EQ("6", new_values["6"]); - ASSERT_EQ("7", new_values["7"]); + { + pegasus::pegasus_client::multi_get_options options; + ASSERT_TRUE(options.start_inclusive); + ASSERT_FALSE(options.stop_inclusive); + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + auto expect_kvs(kvs); + ASSERT_EQ(expect_kvs, new_values); + } // [null, null] - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = true; - options.stop_inclusive = true; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(13, (int)new_values.size()); - ASSERT_EQ("0", new_values[""]); - ASSERT_EQ("1", new_values["1"]); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); - ASSERT_EQ("2", new_values["2"]); - ASSERT_EQ("2-abcdefg", new_values["2-abcdefg"]); - ASSERT_EQ("3", new_values["3"]); - ASSERT_EQ("3-efghijk", new_values["3-efghijk"]); - ASSERT_EQ("4", new_values["4"]); - ASSERT_EQ("4-hijklmn", new_values["4-hijklmn"]); - ASSERT_EQ("5", new_values["5"]); - ASSERT_EQ("5-hijklmn", new_values["5-hijklmn"]); - ASSERT_EQ("6", new_values["6"]); - ASSERT_EQ("7", new_values["7"]); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = true; + options.stop_inclusive = true; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + auto expect_kvs(kvs); + ASSERT_EQ(expect_kvs, new_values); + } // (null, null) - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = false; - options.stop_inclusive = false; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(12, (int)new_values.size()); - ASSERT_EQ("1", new_values["1"]); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); - ASSERT_EQ("2", new_values["2"]); - ASSERT_EQ("2-abcdefg", new_values["2-abcdefg"]); - ASSERT_EQ("3", new_values["3"]); - ASSERT_EQ("3-efghijk", new_values["3-efghijk"]); - ASSERT_EQ("4", new_values["4"]); - ASSERT_EQ("4-hijklmn", new_values["4-hijklmn"]); - ASSERT_EQ("5", new_values["5"]); - ASSERT_EQ("5-hijklmn", new_values["5-hijklmn"]); - ASSERT_EQ("6", new_values["6"]); - ASSERT_EQ("7", new_values["7"]); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = false; + options.stop_inclusive = false; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + auto expect_kvs(kvs); + expect_kvs.erase(""); + ASSERT_EQ(expect_kvs, new_values); + } // (null, null] - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = false; - options.stop_inclusive = true; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(12, (int)new_values.size()); - ASSERT_EQ("1", new_values["1"]); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); - ASSERT_EQ("2", new_values["2"]); - ASSERT_EQ("2-abcdefg", new_values["2-abcdefg"]); - ASSERT_EQ("3", new_values["3"]); - ASSERT_EQ("3-efghijk", new_values["3-efghijk"]); - ASSERT_EQ("4", new_values["4"]); - ASSERT_EQ("4-hijklmn", new_values["4-hijklmn"]); - ASSERT_EQ("5", new_values["5"]); - ASSERT_EQ("5-hijklmn", new_values["5-hijklmn"]); - ASSERT_EQ("6", new_values["6"]); - ASSERT_EQ("7", new_values["7"]); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = false; + options.stop_inclusive = true; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + auto expect_kvs(kvs); + expect_kvs.erase(""); + ASSERT_EQ(expect_kvs, new_values); + } // [null, 1] - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = true; - options.stop_inclusive = true; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(2, (int)new_values.size()); - ASSERT_EQ("0", new_values[""]); - ASSERT_EQ("1", new_values["1"]); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = true; + options.stop_inclusive = true; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "1", options, new_values)); + std::map expect_kvs({{"", "0"}, {"1", "1"}}); + ASSERT_EQ(expect_kvs, new_values); + } // [null, 1) - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = true; - options.stop_inclusive = false; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("0", new_values[""]); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = true; + options.stop_inclusive = false; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "1", options, new_values)); + std::map expect_kvs({{"", "0"}}); + ASSERT_EQ(expect_kvs, new_values); + } // (null, 1] - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = false; - options.stop_inclusive = true; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("1", new_values["1"]); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = false; + options.stop_inclusive = true; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "1", options, new_values)); + std::map expect_kvs({{"1", "1"}}); + ASSERT_EQ(expect_kvs, new_values); + } // (null, 1) - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = false; - options.stop_inclusive = false; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = false; + options.stop_inclusive = false; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "1", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // [1, 1] - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = true; - options.stop_inclusive = true; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "1", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("1", new_values["1"]); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = true; + options.stop_inclusive = true; + options.reverse = true; + std::map new_values; + ASSERT_EQ( + PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "1", "1", options, new_values)); + std::map expect_kvs({{"1", "1"}}); + ASSERT_EQ(expect_kvs, new_values); + } // [1, 1) - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = true; - options.stop_inclusive = false; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "1", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = true; + options.stop_inclusive = false; + options.reverse = true; + std::map new_values; + ASSERT_EQ( + PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "1", "1", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // (1, 1] - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = false; - options.stop_inclusive = true; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "1", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = false; + options.stop_inclusive = true; + options.reverse = true; + std::map new_values; + ASSERT_EQ( + PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "1", "1", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // (1, 1) - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = false; - options.stop_inclusive = false; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "1", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = false; + options.stop_inclusive = false; + options.reverse = true; + std::map new_values; + ASSERT_EQ( + PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "1", "1", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // [2, 1] - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = true; - options.stop_inclusive = true; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "2", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = true; + options.stop_inclusive = true; + options.reverse = true; + std::map new_values; + ASSERT_EQ( + PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "2", "1", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-anywhere("-") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_ANYWHERE; - options.sort_key_filter_pattern = "-"; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(5, (int)new_values.size()); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); - ASSERT_EQ("2-abcdefg", new_values["2-abcdefg"]); - ASSERT_EQ("3-efghijk", new_values["3-efghijk"]); - ASSERT_EQ("4-hijklmn", new_values["4-hijklmn"]); - ASSERT_EQ("5-hijklmn", new_values["5-hijklmn"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_ANYWHERE; + options.sort_key_filter_pattern = "-"; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + const std::map expect_kvs({{"1-abcdefg", "1-abcdefg"}, + {"2-abcdefg", "2-abcdefg"}, + {"3-efghijk", "3-efghijk"}, + {"4-hijklmn", "4-hijklmn"}, + {"5-hijklmn", "5-hijklmn"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-anywhere("1") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_ANYWHERE; - options.sort_key_filter_pattern = "1"; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(2, (int)new_values.size()); - ASSERT_EQ("1", new_values["1"]); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_ANYWHERE; + options.sort_key_filter_pattern = "1"; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + std::map expect_kvs({{"1", "1"}, {"1-abcdefg", "1-abcdefg"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-anywhere("1-") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_ANYWHERE; - options.sort_key_filter_pattern = "1-"; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_ANYWHERE; + options.sort_key_filter_pattern = "1-"; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + std::map expect_kvs({{"1-abcdefg", "1-abcdefg"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-anywhere("abc") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_ANYWHERE; - options.sort_key_filter_pattern = "abc"; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(2, (int)new_values.size()); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); - ASSERT_EQ("2-abcdefg", new_values["2-abcdefg"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_ANYWHERE; + options.sort_key_filter_pattern = "abc"; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + const std::map expect_kvs( + {{"1-abcdefg", "1-abcdefg"}, {"2-abcdefg", "2-abcdefg"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-prefix("1") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "1"; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(2, (int)new_values.size()); - ASSERT_EQ("1", new_values["1"]); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "1"; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + std::map expect_kvs({{"1", "1"}, {"1-abcdefg", "1-abcdefg"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-prefix("1") in [0, 1) - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "1"; - options.start_inclusive = true; - options.stop_inclusive = false; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "0", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "1"; + options.start_inclusive = true; + options.stop_inclusive = false; + options.reverse = true; + std::map new_values; + ASSERT_EQ( + PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "0", "1", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-prefix("1") in [0, 1] - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "1"; - options.start_inclusive = true; - options.stop_inclusive = true; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "0", "1", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("1", new_values["1"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "1"; + options.start_inclusive = true; + options.stop_inclusive = true; + options.reverse = true; + std::map new_values; + ASSERT_EQ( + PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "0", "1", options, new_values)); + std::map expect_kvs({{"1", "1"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-prefix("1") in [1, 2] - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "1"; - options.start_inclusive = true; - options.stop_inclusive = true; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "1", "2", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(2, (int)new_values.size()); - ASSERT_EQ("1", new_values["1"]); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "1"; + options.start_inclusive = true; + options.stop_inclusive = true; + options.reverse = true; + std::map new_values; + ASSERT_EQ( + PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "1", "2", options, new_values)); + std::map expect_kvs({{"1", "1"}, {"1-abcdefg", "1-abcdefg"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-prefix("1") in (1, 2] - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "1"; - options.start_inclusive = false; - options.stop_inclusive = true; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "1", "2", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "1"; + options.start_inclusive = false; + options.stop_inclusive = true; + options.reverse = true; + std::map new_values; + ASSERT_EQ( + PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "1", "2", options, new_values)); + std::map expect_kvs({{"1-abcdefg", "1-abcdefg"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-prefix("1") in (1-abcdefg, 2] - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "1"; - options.start_inclusive = false; - options.stop_inclusive = true; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "1-abcdefg", "2", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "1"; + options.start_inclusive = false; + options.stop_inclusive = true; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get( + "basic_test_multi_get_reverse", "1-abcdefg", "2", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-prefix("1-") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "1-"; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "1-"; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + std::map expect_kvs({{"1-abcdefg", "1-abcdefg"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-prefix("1-x") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "1-x"; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "1-x"; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-prefix("abc") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "abc"; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "abc"; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-prefix("efg") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "efg"; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "efg"; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-prefix("ijk") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "ijk"; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "ijk"; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-prefix("lmn") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "lmn"; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "lmn"; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-prefix("5-hijklmn") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; - options.sort_key_filter_pattern = "5-hijklmn"; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("5-hijklmn", new_values["5-hijklmn"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_PREFIX; + options.sort_key_filter_pattern = "5-hijklmn"; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + std::map expect_kvs({{"5-hijklmn", "5-hijklmn"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-postfix("1") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; - options.sort_key_filter_pattern = "1"; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("1", new_values["1"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; + options.sort_key_filter_pattern = "1"; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + std::map expect_kvs({{"1", "1"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-postfix("1-") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; - options.sort_key_filter_pattern = "1-"; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; + options.sort_key_filter_pattern = "1-"; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-postfix("1-x") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; - options.sort_key_filter_pattern = "1-x"; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; + options.sort_key_filter_pattern = "1-x"; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-postfix("abc") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; - options.sort_key_filter_pattern = "abc"; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(0, (int)new_values.size()); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; + options.sort_key_filter_pattern = "abc"; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + ASSERT_TRUE(new_values.empty()); + } // match-postfix("efg") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; - options.sort_key_filter_pattern = "efg"; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(2, (int)new_values.size()); - ASSERT_EQ("1-abcdefg", new_values["1-abcdefg"]); - ASSERT_EQ("2-abcdefg", new_values["2-abcdefg"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; + options.sort_key_filter_pattern = "efg"; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + std::map expect_kvs( + {{"1-abcdefg", "1-abcdefg"}, {"2-abcdefg", "2-abcdefg"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-postfix("ijk") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; - options.sort_key_filter_pattern = "ijk"; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("3-efghijk", new_values["3-efghijk"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; + options.sort_key_filter_pattern = "ijk"; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + std::map expect_kvs({{"3-efghijk", "3-efghijk"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-postfix("lmn") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; - options.sort_key_filter_pattern = "lmn"; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(2, (int)new_values.size()); - ASSERT_EQ("4-hijklmn", new_values["4-hijklmn"]); - ASSERT_EQ("5-hijklmn", new_values["5-hijklmn"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; + options.sort_key_filter_pattern = "lmn"; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + std::map expect_kvs( + {{"4-hijklmn", "4-hijklmn"}, {"5-hijklmn", "5-hijklmn"}}); + ASSERT_EQ(expect_kvs, new_values); + } // match-postfix("5-hijklmn") - options = pegasus::pegasus_client::multi_get_options(); - options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; - options.sort_key_filter_pattern = "5-hijklmn"; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("5-hijklmn", new_values["5-hijklmn"]); + { + pegasus::pegasus_client::multi_get_options options; + options.sort_key_filter_type = pegasus::pegasus_client::FT_MATCH_POSTFIX; + options.sort_key_filter_pattern = "5-hijklmn"; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_OK, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values)); + std::map expect_kvs({{"5-hijklmn", "5-hijklmn"}}); + ASSERT_EQ(expect_kvs, new_values); + } // maxCount = 4 - options = pegasus::pegasus_client::multi_get_options(); - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "", "", options, new_values, 4, -1); - ASSERT_EQ(PERR_INCOMPLETE, ret); - ASSERT_EQ(4, (int)new_values.size()); - ASSERT_EQ("5", new_values["5"]); - ASSERT_EQ("5-hijklmn", new_values["5-hijklmn"]); - ASSERT_EQ("6", new_values["6"]); - ASSERT_EQ("7", new_values["7"]); + { + pegasus::pegasus_client::multi_get_options options; + options.reverse = true; + std::map new_values; + ASSERT_EQ( + PERR_INCOMPLETE, + client_->multi_get("basic_test_multi_get_reverse", "", "", options, new_values, 4, -1)); + std::map expect_kvs( + {{"5", "5"}, {"5-hijklmn", "5-hijklmn"}, {"6", "6"}, {"7", "7"}}); + ASSERT_EQ(expect_kvs, new_values); + } // maxCount = 1 - options = pegasus::pegasus_client::multi_get_options(); - options.start_inclusive = true; - options.stop_inclusive = true; - options.reverse = true; - new_values.clear(); - ret = client->multi_get("basic_test_multi_get_reverse", "5", "6", options, new_values, 1, -1); - ASSERT_EQ(PERR_INCOMPLETE, ret); - ASSERT_EQ(1, (int)new_values.size()); - ASSERT_EQ("6", new_values["6"]); + { + pegasus::pegasus_client::multi_get_options options; + options.start_inclusive = true; + options.stop_inclusive = true; + options.reverse = true; + std::map new_values; + ASSERT_EQ(PERR_INCOMPLETE, + client_->multi_get( + "basic_test_multi_get_reverse", "5", "6", options, new_values, 1, -1)); + std::map expect_kvs({{"6", "6"}}); + ASSERT_EQ(expect_kvs, new_values); + } // multi_del - std::set sortkeys; - sortkeys.insert(""); - sortkeys.insert("1"); - sortkeys.insert("1-abcdefg"); - sortkeys.insert("2"); - sortkeys.insert("2-abcdefg"); - sortkeys.insert("3"); - sortkeys.insert("3-efghijk"); - sortkeys.insert("4"); - sortkeys.insert("4-hijklmn"); - sortkeys.insert("5"); - sortkeys.insert("5-hijklmn"); - sortkeys.insert("6"); - sortkeys.insert("7"); - int64_t deleted_count; - ret = client->multi_del("basic_test_multi_get_reverse", sortkeys, deleted_count); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(13, deleted_count); + { + const std::set sortkeys_to_delete({"", + "1", + "1-abcdefg", + "2", + "2-abcdefg", + "3", + "3-efghijk", + "4", + "4-hijklmn", + "5", + "5-hijklmn", + "6", + "7"}); + int64_t deleted_count; + ASSERT_EQ( + PERR_OK, + client_->multi_del("basic_test_multi_get_reverse", sortkeys_to_delete, deleted_count)); + ASSERT_EQ(13, deleted_count); + } // sortkey_count - ret = client->sortkey_count("basic_test_multi_get_reverse", count); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->sortkey_count("basic_test_multi_get_reverse", count)); ASSERT_EQ(0, count); } TEST_F(basic, multi_set_get_del) { // multi_set - std::map kvs; - kvs["basic_test_sort_key_1"] = "basic_test_value_1"; - kvs["basic_test_sort_key_2"] = "basic_test_value_2"; - kvs["basic_test_sort_key_3"] = "basic_test_value_3"; - kvs["basic_test_sort_key_4"] = "basic_test_value_4"; - int ret = client->multi_set("basic_test_hash_key_1", kvs); - ASSERT_EQ(PERR_OK, ret); + const std::map kvs({{"basic_test_sort_key_1", "basic_test_value_1"}, + {"basic_test_sort_key_2", "basic_test_value_2"}, + {"basic_test_sort_key_3", "basic_test_value_3"}, + {"basic_test_sort_key_4", "basic_test_value_4"}}); + ASSERT_EQ(PERR_OK, client_->multi_set("basic_test_hash_key_1", kvs)); // sortkey_count int64_t count; - ret = client->sortkey_count("basic_test_hash_key_1", count); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->sortkey_count("basic_test_hash_key_1", count)); ASSERT_EQ(4, count); + const std::set expect_sortkeys({"basic_test_sort_key_1", + "basic_test_sort_key_2", + "basic_test_sort_key_3", + "basic_test_sort_key_4"}); + // multi_get - std::set sortkeys; - sortkeys.insert("basic_test_sort_key_0"); - sortkeys.insert("basic_test_sort_key_1"); - sortkeys.insert("basic_test_sort_key_2"); - sortkeys.insert("basic_test_sort_key_3"); - sortkeys.insert("basic_test_sort_key_4"); - std::map new_kvs; - ret = client->multi_get("basic_test_hash_key_1", sortkeys, new_kvs); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(4, new_kvs.size()); - auto it = new_kvs.begin(); - ASSERT_EQ("basic_test_sort_key_1", it->first); - ASSERT_EQ("basic_test_value_1", it->second); - it++; - ASSERT_EQ("basic_test_sort_key_2", it->first); - ASSERT_EQ("basic_test_value_2", it->second); - it++; - ASSERT_EQ("basic_test_sort_key_3", it->first); - ASSERT_EQ("basic_test_value_3", it->second); - it++; - ASSERT_EQ("basic_test_sort_key_4", it->first); - ASSERT_EQ("basic_test_value_4", it->second); + const std::set sortkeys({"basic_test_sort_key_0", + "basic_test_sort_key_1", + "basic_test_sort_key_2", + "basic_test_sort_key_3", + "basic_test_sort_key_4"}); + { + std::map actual_kvs; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_hash_key_1", sortkeys, actual_kvs)); + ASSERT_EQ(kvs, actual_kvs); + } // multi_get with limit count 4 - new_kvs.clear(); - ret = client->multi_get("basic_test_hash_key_1", sortkeys, new_kvs, 4); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(4, new_kvs.size()); - it = new_kvs.begin(); - ASSERT_EQ("basic_test_sort_key_1", it->first); - ASSERT_EQ("basic_test_value_1", it->second); - it++; - ASSERT_EQ("basic_test_sort_key_2", it->first); - ASSERT_EQ("basic_test_value_2", it->second); - it++; - ASSERT_EQ("basic_test_sort_key_3", it->first); - ASSERT_EQ("basic_test_value_3", it->second); - it++; - ASSERT_EQ("basic_test_sort_key_4", it->first); - ASSERT_EQ("basic_test_value_4", it->second); + { + std::map actual_kvs; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_hash_key_1", sortkeys, actual_kvs, 4)); + ASSERT_EQ(kvs, actual_kvs); + } // multi_get with limit count 3 - new_kvs.clear(); - ret = client->multi_get("basic_test_hash_key_1", sortkeys, new_kvs, 3); - ASSERT_EQ(PERR_INCOMPLETE, ret); - ASSERT_EQ(3, new_kvs.size()); - it = new_kvs.begin(); - ASSERT_EQ("basic_test_sort_key_1", it->first); - ASSERT_EQ("basic_test_value_1", it->second); - it++; - ASSERT_EQ("basic_test_sort_key_2", it->first); - ASSERT_EQ("basic_test_value_2", it->second); - it++; - ASSERT_EQ("basic_test_sort_key_3", it->first); - ASSERT_EQ("basic_test_value_3", it->second); + { + std::map actual_kvs; + ASSERT_EQ(PERR_INCOMPLETE, + client_->multi_get("basic_test_hash_key_1", sortkeys, actual_kvs, 3)); + auto expect_kvs(kvs); + expect_kvs.erase("basic_test_sort_key_4"); + ASSERT_EQ(expect_kvs, actual_kvs); + } // multi_get with limit count 1 - new_kvs.clear(); - ret = client->multi_get("basic_test_hash_key_1", sortkeys, new_kvs, 1); - ASSERT_EQ(PERR_INCOMPLETE, ret); - ASSERT_EQ(1, new_kvs.size()); - it = new_kvs.begin(); - ASSERT_EQ("basic_test_sort_key_1", it->first); - ASSERT_EQ("basic_test_value_1", it->second); + { + std::map actual_kvs; + ASSERT_EQ(PERR_INCOMPLETE, + client_->multi_get("basic_test_hash_key_1", sortkeys, actual_kvs, 1)); + std::map expect_kvs( + {{"basic_test_sort_key_1", "basic_test_value_1"}}); + ASSERT_EQ(expect_kvs, actual_kvs); + } // multi_get with empty sortkeys - sortkeys.clear(); - new_kvs.clear(); - ret = client->multi_get("basic_test_hash_key_1", sortkeys, new_kvs); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(4, new_kvs.size()); - it = new_kvs.begin(); - ASSERT_EQ("basic_test_sort_key_1", it->first); - ASSERT_EQ("basic_test_value_1", it->second); - it++; - ASSERT_EQ("basic_test_sort_key_2", it->first); - ASSERT_EQ("basic_test_value_2", it->second); - it++; - ASSERT_EQ("basic_test_sort_key_3", it->first); - ASSERT_EQ("basic_test_value_3", it->second); - it++; - ASSERT_EQ("basic_test_sort_key_4", it->first); - ASSERT_EQ("basic_test_value_4", it->second); + { + std::map actual_kvs; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_hash_key_1", {}, actual_kvs)); + ASSERT_EQ(kvs, actual_kvs); + } // multi_get_sortkeys with no limit count - sortkeys.clear(); - ret = client->multi_get_sortkeys("basic_test_hash_key_1", sortkeys, -1); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(4, sortkeys.size()); - auto it2 = sortkeys.begin(); - ASSERT_EQ("basic_test_sort_key_1", *it2); - it2++; - ASSERT_EQ("basic_test_sort_key_2", *it2); - it2++; - ASSERT_EQ("basic_test_sort_key_3", *it2); - it2++; - ASSERT_EQ("basic_test_sort_key_4", *it2); + { + std::set actual_sortkeys; + ASSERT_EQ(PERR_OK, + client_->multi_get_sortkeys("basic_test_hash_key_1", actual_sortkeys, -1)); + ASSERT_EQ(expect_sortkeys, actual_sortkeys); + } // multi_get_sortkeys with limit count - sortkeys.clear(); - ret = client->multi_get_sortkeys("basic_test_hash_key_1", sortkeys, 1); - ASSERT_EQ(PERR_INCOMPLETE, ret); - ASSERT_EQ(1, sortkeys.size()); - it2 = sortkeys.begin(); - ASSERT_EQ("basic_test_sort_key_1", *it2); + { + std::set actual_sortkeys; + ASSERT_EQ(PERR_INCOMPLETE, + client_->multi_get_sortkeys("basic_test_hash_key_1", actual_sortkeys, 1)); + std::set expect_sortkeys({"basic_test_sort_key_1"}); + ASSERT_EQ(expect_sortkeys, actual_sortkeys); + } // multi_del with empty sortkeys - sortkeys.clear(); int64_t deleted_count; - ret = client->multi_del("basic_test_hash_key_1", sortkeys, deleted_count); - ASSERT_EQ(PERR_INVALID_VALUE, ret); + { + ASSERT_EQ(PERR_INVALID_VALUE, + client_->multi_del("basic_test_hash_key_1", {}, deleted_count)); + ASSERT_EQ(0, deleted_count); + } // multi_del - sortkeys.clear(); - sortkeys.insert("basic_test_sort_key_0"); - sortkeys.insert("basic_test_sort_key_1"); - sortkeys.insert("basic_test_sort_key_2"); - ret = client->multi_del("basic_test_hash_key_1", sortkeys, deleted_count); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(3, deleted_count); + { + std::set sortkeys_to_delete( + {"basic_test_sort_key_0", "basic_test_sort_key_1", "basic_test_sort_key_2"}); + ASSERT_EQ(PERR_OK, + client_->multi_del("basic_test_hash_key_1", sortkeys_to_delete, deleted_count)); + ASSERT_EQ(3, deleted_count); + } // sortkey_count - ret = client->sortkey_count("basic_test_hash_key_1", count); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->sortkey_count("basic_test_hash_key_1", count)); ASSERT_EQ(2, count); // check deleted - sortkeys.clear(); - new_kvs.clear(); - ret = client->multi_get("basic_test_hash_key_1", sortkeys, new_kvs); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(2, new_kvs.size()); - it = new_kvs.begin(); - ASSERT_EQ("basic_test_sort_key_3", it->first); - ASSERT_EQ("basic_test_value_3", it->second); - it++; - ASSERT_EQ("basic_test_sort_key_4", it->first); - ASSERT_EQ("basic_test_value_4", it->second); + { + std::map actual_kvs; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_hash_key_1", {}, actual_kvs)); + std::map expect_kvs( + {{"basic_test_sort_key_3", "basic_test_value_3"}, + {"basic_test_sort_key_4", "basic_test_value_4"}}); + ASSERT_EQ(expect_kvs, actual_kvs); + } // multi_del - sortkeys.clear(); - sortkeys.insert("basic_test_sort_key_3"); - sortkeys.insert("basic_test_sort_key_4"); - ret = client->multi_del("basic_test_hash_key_1", sortkeys, deleted_count); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(2, deleted_count); + { + std::set sortkeys_to_delete( + {"basic_test_sort_key_3", "basic_test_sort_key_4"}); + ASSERT_EQ(PERR_OK, + client_->multi_del("basic_test_hash_key_1", sortkeys_to_delete, deleted_count)); + ASSERT_EQ(2, deleted_count); + } // sortkey_count - ret = client->sortkey_count("basic_test_hash_key_1", count); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->sortkey_count("basic_test_hash_key_1", count)); ASSERT_EQ(0, count); } TEST_F(basic, set_get_del_async) { - std::atomic callbacked(false); - int ret = 0; - std::string new_value_str; + std::string new_value; + // set_async - callbacked.store(false, std::memory_order_seq_cst); - client->async_set("basic_test_hash_key_1", - "basic_test_sort_key_1", - "basic_test_value_1", - [&](int err, internal_info &&info) { - ASSERT_EQ(PERR_OK, err); - ASSERT_GT(info.app_id, 0); - ASSERT_GT(info.partition_index, 0); - ASSERT_GT(info.decree, 0); - ASSERT_FALSE(info.server.empty()); - callbacked.store(true, std::memory_order_seq_cst); - }); - while (!callbacked.load(std::memory_order_seq_cst)) - usleep(100); + { + std::atomic callbacked(false); + client_->async_set("basic_test_hash_key_1", + "basic_test_sort_key_1", + "basic_test_value_1", + [&](int err, internal_info &&info) { + ASSERT_EQ(PERR_OK, err); + ASSERT_GT(info.app_id, 0); + ASSERT_GT(info.partition_index, 0); + ASSERT_GT(info.decree, 0); + ASSERT_FALSE(info.server.empty()); + callbacked.store(true, std::memory_order_seq_cst); + }); + while (!callbacked.load(std::memory_order_seq_cst)) + usleep(100); + } // exist - ret = client->exist("basic_test_hash_key_1", "basic_test_sort_key_1"); - ASSERT_EQ(PERR_OK, ret); - - ret = client->exist("basic_test_hash_key_1", "basic_test_sort_key_2"); - ASSERT_EQ(PERR_NOT_FOUND, ret); + ASSERT_EQ(PERR_OK, client_->exist("basic_test_hash_key_1", "basic_test_sort_key_1")); + ASSERT_EQ(PERR_NOT_FOUND, client_->exist("basic_test_hash_key_1", "basic_test_sort_key_2")); // sortkey_count int64_t count; - ret = client->sortkey_count("basic_test_hash_key_1", count); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->sortkey_count("basic_test_hash_key_1", count)); ASSERT_EQ(1, count); // get_async - callbacked.store(false, std::memory_order_seq_cst); - client->async_get("basic_test_hash_key_1", - "basic_test_sort_key_1", - [&](int err, std::string &&value, internal_info &&info) { - ASSERT_EQ(PERR_OK, err); - ASSERT_GT(info.app_id, 0); - ASSERT_GT(info.partition_index, 0); - ASSERT_EQ(info.decree, -1); - ASSERT_FALSE(info.server.empty()); - ASSERT_EQ("basic_test_value_1", value); - callbacked.store(true, std::memory_order_seq_cst); - }); - while (!callbacked.load(std::memory_order_seq_cst)) - usleep(100); - - callbacked.store(false, std::memory_order_seq_cst); - client->async_get("basic_test_hash_key_1", - "basic_test_sort_key_2", - [&](int err, std::string &&value, internal_info &&info) { - ASSERT_EQ(PERR_NOT_FOUND, err); - ASSERT_GT(info.app_id, 0); - ASSERT_GT(info.partition_index, 0); - ASSERT_EQ(info.decree, -1); - ASSERT_FALSE(info.server.empty()); - callbacked.store(true, std::memory_order_seq_cst); - }); - while (!callbacked.load(std::memory_order_seq_cst)) - usleep(100); + { + std::atomic callbacked(false); + client_->async_get("basic_test_hash_key_1", + "basic_test_sort_key_1", + [&](int err, std::string &&value, internal_info &&info) { + ASSERT_EQ(PERR_OK, err); + ASSERT_GT(info.app_id, 0); + ASSERT_GT(info.partition_index, 0); + ASSERT_EQ(info.decree, -1); + ASSERT_FALSE(info.server.empty()); + ASSERT_EQ("basic_test_value_1", value); + callbacked.store(true, std::memory_order_seq_cst); + }); + while (!callbacked.load(std::memory_order_seq_cst)) + usleep(100); + } + + { + std::atomic callbacked(false); + client_->async_get("basic_test_hash_key_1", + "basic_test_sort_key_2", + [&](int err, std::string &&value, internal_info &&info) { + ASSERT_EQ(PERR_NOT_FOUND, err); + ASSERT_GT(info.app_id, 0); + ASSERT_GT(info.partition_index, 0); + ASSERT_EQ(info.decree, -1); + ASSERT_FALSE(info.server.empty()); + callbacked.store(true, std::memory_order_seq_cst); + }); + while (!callbacked.load(std::memory_order_seq_cst)) + usleep(100); + } // del_async - callbacked.store(false, std::memory_order_seq_cst); - client->async_del( - "basic_test_hash_key_1", "basic_test_sort_key_1", [&](int err, internal_info &&info) { - ASSERT_EQ(PERR_OK, err); - ASSERT_GT(info.app_id, 0); - ASSERT_GT(info.partition_index, 0); - ASSERT_GT(info.decree, 0); - ASSERT_FALSE(info.server.empty()); - callbacked.store(true, std::memory_order_seq_cst); - }); - while (!callbacked.load(std::memory_order_seq_cst)) - usleep(100); + { + std::atomic callbacked(false); + client_->async_del( + "basic_test_hash_key_1", "basic_test_sort_key_1", [&](int err, internal_info &&info) { + ASSERT_EQ(PERR_OK, err); + ASSERT_GT(info.app_id, 0); + ASSERT_GT(info.partition_index, 0); + ASSERT_GT(info.decree, 0); + ASSERT_FALSE(info.server.empty()); + callbacked.store(true, std::memory_order_seq_cst); + }); + while (!callbacked.load(std::memory_order_seq_cst)) + usleep(100); + } // exist - ret = client->exist("basic_test_hash_key_1", "basic_test_sort_key_1"); - ASSERT_EQ(PERR_NOT_FOUND, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->exist("basic_test_hash_key_1", "basic_test_sort_key_1")); // sortkey_count - ret = client->sortkey_count("basic_test_hash_key_1", count); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->sortkey_count("basic_test_hash_key_1", count)); ASSERT_EQ(0, count); // get -- finally, using get_sync to get the key-value. - ret = client->get("basic_test_hash_key_1", "basic_test_sort_key_1", new_value_str); - ASSERT_EQ(PERR_NOT_FOUND, ret); + ASSERT_EQ(PERR_NOT_FOUND, + client_->get("basic_test_hash_key_1", "basic_test_sort_key_1", new_value)); } TEST_F(basic, multi_set_get_del_async) { - std::atomic callbacked(false); - int ret = 0; - std::map new_kvs; - // multi_set_async - std::map kvs; - kvs["basic_test_sort_key_1"] = "basic_test_value_1"; - kvs["basic_test_sort_key_2"] = "basic_test_value_2"; - kvs["basic_test_sort_key_3"] = "basic_test_value_3"; - kvs["basic_test_sort_key_4"] = "basic_test_value_4"; - callbacked.store(false, std::memory_order_seq_cst); - client->async_multi_set("basic_test_hash_key_1", kvs, [&](int err, internal_info &&info) { - ASSERT_EQ(PERR_OK, err); - ASSERT_GT(info.app_id, 0); - ASSERT_GT(info.partition_index, 0); - ASSERT_GT(info.decree, 0); - ASSERT_FALSE(info.server.empty()); - callbacked.store(true, std::memory_order_seq_cst); - }); - while (!callbacked.load(std::memory_order_seq_cst)) - usleep(100); - - // sortkey_count + std::map actual_kvs; int64_t count; - ret = client->sortkey_count("basic_test_hash_key_1", count); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(4, count); - // multi_get_async - std::set sortkeys; - sortkeys.insert("basic_test_sort_key_0"); - sortkeys.insert("basic_test_sort_key_1"); - sortkeys.insert("basic_test_sort_key_2"); - sortkeys.insert("basic_test_sort_key_3"); - sortkeys.insert("basic_test_sort_key_4"); - - callbacked.store(false, std::memory_order_seq_cst); - client->async_multi_get( - "basic_test_hash_key_1", - sortkeys, - [&](int err, std::map &&values, internal_info &&info) { + const std::map kvs({{"basic_test_sort_key_1", "basic_test_value_1"}, + {"basic_test_sort_key_2", "basic_test_value_2"}, + {"basic_test_sort_key_3", "basic_test_value_3"}, + {"basic_test_sort_key_4", "basic_test_value_4"}}); + const std::set expect_sortkeys({"basic_test_sort_key_1", + "basic_test_sort_key_2", + "basic_test_sort_key_3", + "basic_test_sort_key_4"}); + const std::set sortkeys_to_get({"basic_test_sort_key_0", + "basic_test_sort_key_1", + "basic_test_sort_key_2", + "basic_test_sort_key_3", + "basic_test_sort_key_4"}); + + // multi_set_async + { + std::atomic callbacked(false); + client_->async_multi_set("basic_test_hash_key_1", kvs, [&](int err, internal_info &&info) { ASSERT_EQ(PERR_OK, err); ASSERT_GT(info.app_id, 0); ASSERT_GT(info.partition_index, 0); - ASSERT_EQ(info.decree, -1); + ASSERT_GT(info.decree, 0); ASSERT_FALSE(info.server.empty()); - ASSERT_EQ(4, values.size()); - auto it = values.begin(); - ASSERT_EQ("basic_test_sort_key_1", it->first); - ASSERT_EQ("basic_test_value_1", it->second); - it++; - ASSERT_EQ("basic_test_sort_key_2", it->first); - ASSERT_EQ("basic_test_value_2", it->second); - it++; - ASSERT_EQ("basic_test_sort_key_3", it->first); - ASSERT_EQ("basic_test_value_3", it->second); - it++; - ASSERT_EQ("basic_test_sort_key_4", it->first); - ASSERT_EQ("basic_test_value_4", it->second); callbacked.store(true, std::memory_order_seq_cst); }); - while (!callbacked.load(std::memory_order_seq_cst)) - usleep(100); + while (!callbacked.load(std::memory_order_seq_cst)) + usleep(100); + + // sortkey_count + ASSERT_EQ(PERR_OK, client_->sortkey_count("basic_test_hash_key_1", count)); + ASSERT_EQ(4, count); + } + + // multi_get_async + { + std::atomic callbacked(false); + client_->async_multi_get( + "basic_test_hash_key_1", + sortkeys_to_get, + [&](int err, std::map &&values, internal_info &&info) { + ASSERT_EQ(PERR_OK, err); + ASSERT_GT(info.app_id, 0); + ASSERT_GT(info.partition_index, 0); + ASSERT_EQ(info.decree, -1); + ASSERT_FALSE(info.server.empty()); + ASSERT_EQ(kvs, values); + callbacked.store(true, std::memory_order_seq_cst); + }); + while (!callbacked.load(std::memory_order_seq_cst)) + usleep(100); + } // multi_get_async with limit count - callbacked.store(false, std::memory_order_seq_cst); - client->async_multi_get( - "basic_test_hash_key_1", - sortkeys, - [&](int err, std::map &&values, internal_info &&info) { - ASSERT_EQ(PERR_INCOMPLETE, err); - ASSERT_GT(info.app_id, 0); - ASSERT_GT(info.partition_index, 0); - ASSERT_EQ(info.decree, -1); - ASSERT_FALSE(info.server.empty()); - ASSERT_EQ(1, values.size()); - auto it = values.begin(); - ASSERT_EQ("basic_test_sort_key_1", it->first); - ASSERT_EQ("basic_test_value_1", it->second); - callbacked.store(true, std::memory_order_seq_cst); - }, - 1); - while (!callbacked.load(std::memory_order_seq_cst)) - usleep(100); + { + std::atomic callbacked(false); + client_->async_multi_get( + "basic_test_hash_key_1", + sortkeys_to_get, + [&](int err, std::map &&values, internal_info &&info) { + ASSERT_EQ(PERR_INCOMPLETE, err); + ASSERT_GT(info.app_id, 0); + ASSERT_GT(info.partition_index, 0); + ASSERT_EQ(info.decree, -1); + ASSERT_FALSE(info.server.empty()); + std::map expect_kvs( + {{"basic_test_sort_key_1", "basic_test_value_1"}}); + ASSERT_EQ(expect_kvs, values); + callbacked.store(true, std::memory_order_seq_cst); + }, + 1); + while (!callbacked.load(std::memory_order_seq_cst)) + usleep(100); + } // multi_get with empty sortkeys - sortkeys.clear(); - callbacked.store(false, std::memory_order_seq_cst); - client->async_multi_get( - "basic_test_hash_key_1", - sortkeys, - [&](int err, std::map &&values, internal_info &&info) { - ASSERT_EQ(PERR_OK, err); - ASSERT_GT(info.app_id, 0); - ASSERT_GT(info.partition_index, 0); - ASSERT_EQ(info.decree, -1); - ASSERT_FALSE(info.server.empty()); - ASSERT_EQ(4, values.size()); - auto it = values.begin(); - ASSERT_EQ("basic_test_sort_key_1", it->first); - ASSERT_EQ("basic_test_value_1", it->second); - it++; - ASSERT_EQ("basic_test_sort_key_2", it->first); - ASSERT_EQ("basic_test_value_2", it->second); - it++; - ASSERT_EQ("basic_test_sort_key_3", it->first); - ASSERT_EQ("basic_test_value_3", it->second); - it++; - ASSERT_EQ("basic_test_sort_key_4", it->first); - ASSERT_EQ("basic_test_value_4", it->second); - callbacked.store(true, std::memory_order_seq_cst); - }); - while (!callbacked.load(std::memory_order_seq_cst)) - usleep(100); + { + std::atomic callbacked(false); + client_->async_multi_get( + "basic_test_hash_key_1", + {}, + [&](int err, std::map &&values, internal_info &&info) { + ASSERT_EQ(PERR_OK, err); + ASSERT_GT(info.app_id, 0); + ASSERT_GT(info.partition_index, 0); + ASSERT_EQ(info.decree, -1); + ASSERT_FALSE(info.server.empty()); + ASSERT_EQ(kvs, values); + callbacked.store(true, std::memory_order_seq_cst); + }); + while (!callbacked.load(std::memory_order_seq_cst)) + usleep(100); + } // multi_get_sortkeys_async with limit count - callbacked.store(false, std::memory_order_seq_cst); - client->async_multi_get_sortkeys( - "basic_test_hash_key_1", - [&](int err, std::set &&sortkeys, internal_info &&info) { - ASSERT_EQ(PERR_INCOMPLETE, err); - ASSERT_GT(info.app_id, 0); - ASSERT_GT(info.partition_index, 0); - ASSERT_EQ(info.decree, -1); - ASSERT_FALSE(info.server.empty()); - ASSERT_EQ(1, sortkeys.size()); - auto it = sortkeys.begin(); - ASSERT_EQ("basic_test_sort_key_1", *it); - callbacked.store(true, std::memory_order_seq_cst); - }, - 1); - while (!callbacked.load(std::memory_order_seq_cst)) - usleep(100); + { + std::atomic callbacked(false); + const std::set expect_sortkeys({"basic_test_sort_key_1"}); + std::set actual_sortkeys; + client_->async_multi_get_sortkeys( + "basic_test_hash_key_1", + [&](int err, std::set &&actual_sortkeys, internal_info &&info) { + ASSERT_EQ(PERR_INCOMPLETE, err); + ASSERT_GT(info.app_id, 0); + ASSERT_GT(info.partition_index, 0); + ASSERT_EQ(info.decree, -1); + ASSERT_FALSE(info.server.empty()); + ASSERT_EQ(expect_sortkeys, actual_sortkeys); + callbacked.store(true, std::memory_order_seq_cst); + }, + 1); + while (!callbacked.load(std::memory_order_seq_cst)) + usleep(100); + } // multi_get_sortkeys_async with no limit count - callbacked.store(false, std::memory_order_seq_cst); - client->async_multi_get_sortkeys( - "basic_test_hash_key_1", - [&](int err, std::set &&sortkeys, internal_info &&info) { - ASSERT_EQ(PERR_OK, err); - ASSERT_GT(info.app_id, 0); - ASSERT_GT(info.partition_index, 0); - ASSERT_EQ(info.decree, -1); - ASSERT_FALSE(info.server.empty()); - ASSERT_EQ(4, sortkeys.size()); - auto it = sortkeys.begin(); - ASSERT_EQ("basic_test_sort_key_1", *it); - it++; - ASSERT_EQ("basic_test_sort_key_2", *it); - it++; - ASSERT_EQ("basic_test_sort_key_3", *it); - it++; - ASSERT_EQ("basic_test_sort_key_4", *it); - callbacked.store(true, std::memory_order_seq_cst); - }, - -1); - while (!callbacked.load(std::memory_order_seq_cst)) - usleep(100); + { + std::atomic callbacked(false); + std::set actual_sortkeys; + client_->async_multi_get_sortkeys( + "basic_test_hash_key_1", + [&](int err, std::set &&actual_sortkeys, internal_info &&info) { + ASSERT_EQ(PERR_OK, err); + ASSERT_GT(info.app_id, 0); + ASSERT_GT(info.partition_index, 0); + ASSERT_EQ(info.decree, -1); + ASSERT_FALSE(info.server.empty()); + ASSERT_EQ(expect_sortkeys, actual_sortkeys); + callbacked.store(true, std::memory_order_seq_cst); + }, + -1); + while (!callbacked.load(std::memory_order_seq_cst)) + usleep(100); + } // multi_del_async with empty sortkeys - sortkeys.clear(); - callbacked.store(false, std::memory_order_seq_cst); - client->async_multi_del("basic_test_hash_key_1", - sortkeys, - [&](int err, int64_t deleted_count, internal_info &&info) { - ASSERT_EQ(PERR_INVALID_VALUE, err); - callbacked.store(true, std::memory_order_seq_cst); - }); - while (!callbacked.load(std::memory_order_seq_cst)) - usleep(100); + { + std::atomic callbacked(false); + client_->async_multi_del( + "basic_test_hash_key_1", {}, [&](int err, int64_t deleted_count, internal_info &&info) { + ASSERT_EQ(PERR_INVALID_VALUE, err); + callbacked.store(true, std::memory_order_seq_cst); + }); + while (!callbacked.load(std::memory_order_seq_cst)) + usleep(100); + } // multi_del_async - sortkeys.clear(); - sortkeys.insert("basic_test_sort_key_0"); - sortkeys.insert("basic_test_sort_key_1"); - sortkeys.insert("basic_test_sort_key_2"); - callbacked.store(false, std::memory_order_seq_cst); - client->async_multi_del("basic_test_hash_key_1", - sortkeys, - [&](int err, int64_t deleted_count, internal_info &&info) { - ASSERT_EQ(PERR_OK, err); - ASSERT_GT(info.app_id, 0); - ASSERT_GT(info.partition_index, 0); - ASSERT_GT(info.decree, 0); - ASSERT_FALSE(info.server.empty()); - ASSERT_EQ(3, deleted_count); - callbacked.store(true, std::memory_order_seq_cst); - }); - while (!callbacked.load(std::memory_order_seq_cst)) - usleep(100); - - // sortkey_count - ret = client->sortkey_count("basic_test_hash_key_1", count); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(2, count); - - // check deleted --- using multi_get to check. - sortkeys.clear(); - new_kvs.clear(); - ret = client->multi_get("basic_test_hash_key_1", sortkeys, new_kvs); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(2, new_kvs.size()); - auto it = new_kvs.begin(); - ASSERT_EQ("basic_test_sort_key_3", it->first); - ASSERT_EQ("basic_test_value_3", it->second); - it++; - ASSERT_EQ("basic_test_sort_key_4", it->first); - ASSERT_EQ("basic_test_value_4", it->second); + { + std::atomic callbacked(false); + std::set sortkeys_to_delete( + {"basic_test_sort_key_0", "basic_test_sort_key_1", "basic_test_sort_key_2"}); + client_->async_multi_del("basic_test_hash_key_1", + sortkeys_to_delete, + [&](int err, int64_t deleted_count, internal_info &&info) { + ASSERT_EQ(PERR_OK, err); + ASSERT_GT(info.app_id, 0); + ASSERT_GT(info.partition_index, 0); + ASSERT_GT(info.decree, 0); + ASSERT_FALSE(info.server.empty()); + ASSERT_EQ(3, deleted_count); + callbacked.store(true, std::memory_order_seq_cst); + }); + while (!callbacked.load(std::memory_order_seq_cst)) + usleep(100); + + // sortkey_count + ASSERT_EQ(PERR_OK, client_->sortkey_count("basic_test_hash_key_1", count)); + ASSERT_EQ(2, count); + + // check deleted --- using multi_get to check. + std::map actual_kvs; + ASSERT_EQ(PERR_OK, client_->multi_get("basic_test_hash_key_1", {}, actual_kvs)); + std::map expect_kvs( + {{"basic_test_sort_key_3", "basic_test_value_3"}, + {"basic_test_sort_key_4", "basic_test_value_4"}}); + ASSERT_EQ(expect_kvs, actual_kvs); + } // multi_del_async - sortkeys.clear(); - sortkeys.insert("basic_test_sort_key_3"); - sortkeys.insert("basic_test_sort_key_4"); - callbacked.store(false, std::memory_order_seq_cst); - client->async_multi_del("basic_test_hash_key_1", - sortkeys, - [&](int err, int64_t deleted_count, internal_info &&info) { - ASSERT_EQ(PERR_OK, err); - ASSERT_GT(info.app_id, 0); - ASSERT_GT(info.partition_index, 0); - ASSERT_GT(info.decree, 0); - ASSERT_FALSE(info.server.empty()); - ASSERT_EQ(2, deleted_count); - callbacked.store(true, std::memory_order_seq_cst); - }); - while (!callbacked.load(std::memory_order_seq_cst)) - usleep(100); + { + std::atomic callbacked(false); + std::set sortkeys_to_delete( + {"basic_test_sort_key_3", "basic_test_sort_key_4"}); + client_->async_multi_del("basic_test_hash_key_1", + sortkeys_to_delete, + [&](int err, int64_t deleted_count, internal_info &&info) { + ASSERT_EQ(PERR_OK, err); + ASSERT_GT(info.app_id, 0); + ASSERT_GT(info.partition_index, 0); + ASSERT_GT(info.decree, 0); + ASSERT_FALSE(info.server.empty()); + ASSERT_EQ(2, deleted_count); + callbacked.store(true, std::memory_order_seq_cst); + }); + while (!callbacked.load(std::memory_order_seq_cst)) + usleep(100); + } // sortkey_count - ret = client->sortkey_count("basic_test_hash_key_1", count); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->sortkey_count("basic_test_hash_key_1", count)); ASSERT_EQ(0, count); } TEST_F(basic, scan_with_filter) { + int ret = 0; + const std::map kvs({{"m_1", "a"}, + {"m_2", "a"}, + {"m_3", "a"}, + {"m_4", "a"}, + {"m_5", "a"}, + {"n_1", "b"}, + {"n_2", "b"}, + {"n_3", "b"}}); + const std::map expect_kvs_prefixed_by_m( + {{"m_1", "a"}, {"m_2", "a"}, {"m_3", "a"}, {"m_4", "a"}, {"m_5", "a"}}); + // multi_set - std::map kvs; - kvs["m_1"] = "a"; - kvs["m_2"] = "a"; - kvs["m_3"] = "a"; - kvs["m_4"] = "a"; - kvs["m_5"] = "a"; - kvs["n_1"] = "b"; - kvs["n_2"] = "b"; - kvs["n_3"] = "b"; - int ret = client->multi_set("xyz", kvs); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->multi_set("xyz", kvs)); // scan with batch_size = 10 { @@ -1667,9 +1637,7 @@ TEST_F(basic, scan_with_filter) options.sort_key_filter_pattern = "m"; options.batch_size = 10; pegasus_client::pegasus_scanner *scanner = nullptr; - ret = client->get_scanner("xyz", "", "", options, scanner); - ASSERT_EQ(0, ret) << "Error occurred when getting scanner. error=" - << client->get_error_string(ret); + ASSERT_EQ(PERR_OK, client_->get_scanner("xyz", "", "", options, scanner)); ASSERT_NE(nullptr, scanner); std::map data; std::string hash_key; @@ -1681,12 +1649,7 @@ TEST_F(basic, scan_with_filter) data[sort_key] = value; } delete scanner; - ASSERT_EQ(5, data.size()); - ASSERT_NE(data.end(), data.find("m_1")); - ASSERT_NE(data.end(), data.find("m_2")); - ASSERT_NE(data.end(), data.find("m_3")); - ASSERT_NE(data.end(), data.find("m_4")); - ASSERT_NE(data.end(), data.find("m_5")); + ASSERT_EQ(expect_kvs_prefixed_by_m, data); } // scan with batch_size = 3 @@ -1696,8 +1659,7 @@ TEST_F(basic, scan_with_filter) options.sort_key_filter_pattern = "m"; options.batch_size = 3; pegasus_client::pegasus_scanner *scanner = nullptr; - ret = client->get_scanner("xyz", "", "", options, scanner); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get_scanner("xyz", "", "", options, scanner)); ASSERT_NE(nullptr, scanner); std::map data; std::string hash_key; @@ -1709,12 +1671,7 @@ TEST_F(basic, scan_with_filter) data[sort_key] = value; } delete scanner; - ASSERT_EQ(5, data.size()); - ASSERT_NE(data.end(), data.find("m_1")); - ASSERT_NE(data.end(), data.find("m_2")); - ASSERT_NE(data.end(), data.find("m_3")); - ASSERT_NE(data.end(), data.find("m_4")); - ASSERT_NE(data.end(), data.find("m_5")); + ASSERT_EQ(expect_kvs_prefixed_by_m, data); } // scan with batch_size = 10 @@ -1724,9 +1681,7 @@ TEST_F(basic, scan_with_filter) options.hash_key_filter_pattern = "xy"; options.batch_size = 10; pegasus_client::pegasus_scanner *scanner = nullptr; - ret = client->get_scanner("xyz", "", "", options, scanner); - ASSERT_EQ(0, ret) << "Error occurred when getting scanner. error=" - << client->get_error_string(ret); + ASSERT_EQ(PERR_OK, client_->get_scanner("xyz", "", "", options, scanner)); ASSERT_NE(nullptr, scanner); std::map data; std::string hash_key; @@ -1746,25 +1701,26 @@ TEST_F(basic, scan_with_filter) sortkeys.insert(kv.first); } int64_t deleted_count; - ret = client->multi_del("x", sortkeys, deleted_count); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->multi_del("x", sortkeys, deleted_count)); ASSERT_EQ(8, deleted_count); } TEST_F(basic, full_scan_with_filter) { + int ret = 0; // multi_set - std::map kvs; - kvs["m_1"] = "a"; - kvs["m_2"] = "a"; - kvs["m_3"] = "a"; - kvs["m_4"] = "a"; - kvs["m_5"] = "a"; - kvs["n_1"] = "b"; - kvs["n_2"] = "b"; - kvs["n_3"] = "b"; - int ret = client->multi_set("xyz", kvs); - ASSERT_EQ(PERR_OK, ret); + const std::map kvs({{"m_1", "a"}, + {"m_2", "a"}, + {"m_3", "a"}, + {"m_4", "a"}, + {"m_5", "a"}, + {"n_1", "b"}, + {"n_2", "b"}, + {"n_3", "b"}}); + ASSERT_EQ(PERR_OK, client_->multi_set("xyz", kvs)); + + const std::map expect_kvs_prefixed_by_m( + {{"m_1", "a"}, {"m_2", "a"}, {"m_3", "a"}, {"m_4", "a"}, {"m_5", "a"}}); // scan with sort key filter and batch_size = 10 { @@ -1773,8 +1729,7 @@ TEST_F(basic, full_scan_with_filter) options.sort_key_filter_pattern = "m"; options.batch_size = 10; std::vector scanners; - ret = client->get_unordered_scanners(1, options, scanners); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get_unordered_scanners(1, options, scanners)); ASSERT_EQ(1, scanners.size()); pegasus_client::pegasus_scanner *scanner = scanners[0]; std::map data; @@ -1787,12 +1742,7 @@ TEST_F(basic, full_scan_with_filter) data[sort_key] = value; } delete scanner; - ASSERT_EQ(5, data.size()); - ASSERT_NE(data.end(), data.find("m_1")); - ASSERT_NE(data.end(), data.find("m_2")); - ASSERT_NE(data.end(), data.find("m_3")); - ASSERT_NE(data.end(), data.find("m_4")); - ASSERT_NE(data.end(), data.find("m_5")); + ASSERT_EQ(expect_kvs_prefixed_by_m, data); } // scan with sort key filter and batch_size = 3 @@ -1802,8 +1752,7 @@ TEST_F(basic, full_scan_with_filter) options.sort_key_filter_pattern = "m"; options.batch_size = 3; std::vector scanners; - ret = client->get_unordered_scanners(1, options, scanners); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get_unordered_scanners(1, options, scanners)); ASSERT_EQ(1, scanners.size()); pegasus_client::pegasus_scanner *scanner = scanners[0]; std::map data; @@ -1816,12 +1765,7 @@ TEST_F(basic, full_scan_with_filter) data[sort_key] = value; } delete scanner; - ASSERT_EQ(5, data.size()); - ASSERT_NE(data.end(), data.find("m_1")); - ASSERT_NE(data.end(), data.find("m_2")); - ASSERT_NE(data.end(), data.find("m_3")); - ASSERT_NE(data.end(), data.find("m_4")); - ASSERT_NE(data.end(), data.find("m_5")); + ASSERT_EQ(expect_kvs_prefixed_by_m, data); } // scan with hash key filter and batch_size = 10 @@ -1831,8 +1775,7 @@ TEST_F(basic, full_scan_with_filter) options.hash_key_filter_pattern = "xy"; options.batch_size = 10; std::vector scanners; - ret = client->get_unordered_scanners(1, options, scanners); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get_unordered_scanners(1, options, scanners)); ASSERT_EQ(1, scanners.size()); pegasus_client::pegasus_scanner *scanner = scanners[0]; std::map data; @@ -1853,7 +1796,6 @@ TEST_F(basic, full_scan_with_filter) sortkeys.insert(kv.first); } int64_t deleted_count; - ret = client->multi_del("x", sortkeys, deleted_count); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->multi_del("x", sortkeys, deleted_count)); ASSERT_EQ(8, deleted_count); } diff --git a/src/test/function_test/base_api_test/test_batch_get.cpp b/src/test/function_test/base_api_test/test_batch_get.cpp index edb4ab69d6..f31adf9801 100644 --- a/src/test/function_test/base_api_test/test_batch_get.cpp +++ b/src/test/function_test/base_api_test/test_batch_get.cpp @@ -42,17 +42,14 @@ class batch_get : public test_util TEST_F(batch_get, set_and_then_batch_get) { - std::vector meta_list; - ASSERT_TRUE(replica_helper::load_meta_servers( - meta_list, PEGASUS_CLUSTER_SECTION_NAME.c_str(), "mycluster")); - auto rrdb_client = new ::dsn::apps::rrdb_client("mycluster", meta_list, client->get_app_name()); + auto rrdb_client = + new ::dsn::apps::rrdb_client(cluster_name_.c_str(), meta_list_, app_name_.c_str()); int test_data_count = 100; int test_timeout_milliseconds = 3000; uint64_t test_partition_hash = 0; apps::batch_get_request batch_request; - std::vector test_data_hash_keys(test_data_count); std::vector test_data_sort_keys(test_data_count); std::vector test_data_values(test_data_count); diff --git a/src/test/function_test/base_api_test/test_check_and_mutate.cpp b/src/test/function_test/base_api_test/test_check_and_mutate.cpp index 6464568ea4..4f5d25938f 100644 --- a/src/test/function_test/base_api_test/test_check_and_mutate.cpp +++ b/src/test/function_test/base_api_test/test_check_and_mutate.cpp @@ -41,8 +41,7 @@ TEST_F(check_and_mutate, value_not_exist) std::string hash_key("check_and_mutate_test_value_not_exist"); { - int ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); std::string value; pegasus_client::mutations mutations; @@ -51,62 +50,57 @@ TEST_F(check_and_mutate, value_not_exist) options.return_check_value = true; mutations.set("k1", "v1"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, + "", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v1", value); options.return_check_value = true; mutations.set("k1", "v2"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, + "", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v1", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v1", value); options.return_check_value = false; mutations.set("k1", "v1"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, + "", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_FALSE(results.check_value_returned); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v1", value); - ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); } { - int ret = client->del(hash_key, "k2"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k2")); std::string value; pegasus_client::mutations mutations; @@ -115,48 +109,43 @@ TEST_F(check_and_mutate, value_not_exist) options.return_check_value = true; mutations.set("k2", ""); - ret = client->check_and_mutate(hash_key, - "k2", - pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k2", + pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, + "", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k2", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k2", value)); ASSERT_EQ("", value); options.return_check_value = true; mutations.set("k2", "v2"); - ret = client->check_and_mutate(hash_key, - "k2", - pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k2", + pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, + "", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k2", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k2", value)); ASSERT_EQ("", value); - ret = client->del(hash_key, "k2"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k2")); } { - int ret = client->del(hash_key, "k3"); - ASSERT_EQ(0, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); std::string value; pegasus_client::mutations mutations; @@ -165,25 +154,22 @@ TEST_F(check_and_mutate, value_not_exist) options.return_check_value = true; mutations.set("k4", "v4"); - ret = client->check_and_mutate(hash_key, - "k3", - pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k3", + pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, + "", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k4", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k4", value)); ASSERT_EQ("v4", value); - ret = client->del(hash_key, "k3"); - ASSERT_EQ(0, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); } } @@ -192,8 +178,7 @@ TEST_F(check_and_mutate, value_exist) std::string hash_key("check_and_mutate_test_value_exist"); { - int ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); std::string value; pegasus_client::mutations mutations; @@ -202,68 +187,60 @@ TEST_F(check_and_mutate, value_exist) options.return_check_value = true; mutations.set("k1", "v1"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_EXIST, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_EXIST, + "", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_NOT_FOUND, ret); - - ret = client->set(hash_key, "k1", ""); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->get(hash_key, "k1", value)); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k1", "")); options.return_check_value = true; mutations.set("k1", "v1"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_EXIST, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_EXIST, + "", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v1", value); options.return_check_value = true; mutations.set("k1", "v2"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_EXIST, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_EXIST, + "", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v1", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); - ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); } { - int ret = client->set(hash_key, "k3", "v3"); - ASSERT_EQ(PERR_OK, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k3", "v3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); std::string value; pegasus_client::mutations mutations; @@ -272,26 +249,23 @@ TEST_F(check_and_mutate, value_exist) options.return_check_value = true; mutations.set("k4", "v4"); - ret = client->check_and_mutate(hash_key, - "k3", - pegasus_client::cas_check_type::CT_VALUE_EXIST, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k3", + pegasus_client::cas_check_type::CT_VALUE_EXIST, + "", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v3", results.check_value); - ret = client->get(hash_key, "k4", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k4", value)); ASSERT_EQ("v4", value); - ret = client->del(hash_key, "k3"); - ASSERT_EQ(0, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); } } @@ -300,8 +274,7 @@ TEST_F(check_and_mutate, value_not_empty) std::string hash_key("check_and_mutate_test_value_not_empty"); { - int ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); std::string value; pegasus_client::mutations mutations; @@ -310,71 +283,62 @@ TEST_F(check_and_mutate, value_not_empty) options.return_check_value = true; mutations.set("k1", "v1"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_NOT_EMPTY, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_NOT_EMPTY, + "", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_NOT_FOUND, ret); - - ret = client->set(hash_key, "k1", ""); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->get(hash_key, "k1", value)); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k1", "")); options.return_check_value = true; mutations.set("k1", "v1"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_NOT_EMPTY, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_NOT_EMPTY, + "", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("", value); - ret = client->set(hash_key, "k1", "v1"); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k1", "v1")); options.return_check_value = true; mutations.set("k1", "v2"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_NOT_EMPTY, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_NOT_EMPTY, + "", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v1", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); - ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); } { - int ret = client->set(hash_key, "k3", "v3"); - ASSERT_EQ(PERR_OK, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k3", "v3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); std::string value; pegasus_client::mutations mutations; @@ -383,26 +347,23 @@ TEST_F(check_and_mutate, value_not_empty) options.return_check_value = true; mutations.set("k4", "v4"); - ret = client->check_and_mutate(hash_key, - "k3", - pegasus_client::cas_check_type::CT_VALUE_NOT_EMPTY, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k3", + pegasus_client::cas_check_type::CT_VALUE_NOT_EMPTY, + "", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v3", results.check_value); - ret = client->get(hash_key, "k4", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k4", value)); ASSERT_EQ("v4", value); - ret = client->del(hash_key, "k3"); - ASSERT_EQ(0, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); } } TEST_F(check_and_mutate, value_match_anywhere) @@ -410,8 +371,7 @@ TEST_F(check_and_mutate, value_match_anywhere) std::string hash_key("check_and_mutate_test_value_match_anywhere"); { - int ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); std::string value; pegasus_client::mutations mutations; @@ -420,176 +380,162 @@ TEST_F(check_and_mutate, value_match_anywhere) options.return_check_value = true; mutations.set("k1", "v1"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, - "v", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, + "v", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_NOT_FOUND, ret); - - ret = client->set(hash_key, "k1", ""); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->get(hash_key, "k1", value)); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k1", "")); options.return_check_value = true; mutations.set("k1", "v1"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, - "v", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, + "v", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("", value); options.return_check_value = true; mutations.set("k1", "v1"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, + "", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v1", value); options.return_check_value = true; mutations.set("k1", "v2"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, + "", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v1", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; mutations.set("k1", "v111v"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, - "2", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, + "2", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v111v", value); options.return_check_value = true; mutations.set("k1", "v2"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, - "111", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, + "111", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v111v", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; mutations.set("k1", "v3"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, - "y", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, + "y", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; mutations.set("k1", "v3"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, - "v2v", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, + "v2v", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; mutations.set("k1", "v3"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, - "v2", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, + "v2", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v3", value); - ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); } { - int ret = client->set(hash_key, "k3", "v333v"); - ASSERT_EQ(PERR_OK, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k3", "v333v")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); std::string value; pegasus_client::mutations mutations; @@ -598,26 +544,23 @@ TEST_F(check_and_mutate, value_match_anywhere) options.return_check_value = true; mutations.set("k4", "v4"); - ret = client->check_and_mutate(hash_key, - "k3", - pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, - "333", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k3", + pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, + "333", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v333v", results.check_value); - ret = client->get(hash_key, "k4", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k4", value)); ASSERT_EQ("v4", value); - ret = client->del(hash_key, "k3"); - ASSERT_EQ(0, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); } } @@ -626,8 +569,7 @@ TEST_F(check_and_mutate, value_match_prefix) std::string hash_key("check_and_mutate_test_value_match_prefix"); { - int ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); std::string value; pegasus_client::mutations mutations; @@ -636,212 +578,197 @@ TEST_F(check_and_mutate, value_match_prefix) options.return_check_value = true; mutations.set("k1", "v1"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "v", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "v", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_NOT_FOUND, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->get(hash_key, "k1", value)); - ret = client->set(hash_key, "k1", ""); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k1", "")); options.return_check_value = true; mutations.set("k1", "v1"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "v", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "v", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("", value); options.return_check_value = true; mutations.set("k1", "v1"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v1", value); options.return_check_value = true; mutations.set("k1", "v2"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v1", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; mutations.set("k1", "v111v"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "v", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "v", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v111v", value); options.return_check_value = true; mutations.set("k1", "v2"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "111", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "111", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v111v", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v111v", value); options.return_check_value = true; mutations.set("k1", "v2"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "v111", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "v111", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v111v", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; mutations.set("k1", "v3"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "y", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "y", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; mutations.set("k1", "v3"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "v2v", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "v2v", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; mutations.set("k1", "v3"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "2", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "2", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; mutations.set("k1", "v3"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "v2", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "v2", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v3", value); - ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); } { - int ret = client->set(hash_key, "k3", "v333v"); - ASSERT_EQ(PERR_OK, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k3", "v333v")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); std::string value; pegasus_client::mutations mutations; @@ -850,26 +777,23 @@ TEST_F(check_and_mutate, value_match_prefix) options.return_check_value = true; mutations.set("k4", "v4"); - ret = client->check_and_mutate(hash_key, - "k3", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "v333", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k3", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "v333", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v333v", results.check_value); - ret = client->get(hash_key, "k4", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k4", value)); ASSERT_EQ("v4", value); - ret = client->del(hash_key, "k3"); - ASSERT_EQ(0, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); } } @@ -878,8 +802,7 @@ TEST_F(check_and_mutate, value_match_postfix) std::string hash_key("check_and_mutate_test_value_match_postfix"); { - int ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); std::string value; pegasus_client::mutations mutations; @@ -888,212 +811,197 @@ TEST_F(check_and_mutate, value_match_postfix) options.return_check_value = true; mutations.set("k1", "v1"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "v", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "v", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_NOT_FOUND, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->get(hash_key, "k1", value)); - ret = client->set(hash_key, "k1", ""); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k1", "")); options.return_check_value = true; mutations.set("k1", "v1"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "v", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "v", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("", value); options.return_check_value = true; mutations.set("k1", "v1"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v1", value); options.return_check_value = true; mutations.set("k1", "v2"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v1", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; mutations.set("k1", "v111v"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "2", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "2", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v111v", value); options.return_check_value = true; mutations.set("k1", "v2"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "111", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "111", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v111v", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v111v", value); options.return_check_value = true; mutations.set("k1", "v2"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "111v", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "111v", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v111v", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; mutations.set("k1", "v3"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "y", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "y", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; mutations.set("k1", "v3"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "2v2", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "2v2", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; mutations.set("k1", "v3"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "v", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "v", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; mutations.set("k1", "v3"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "v2", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "v2", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v3", value); - ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); } { - int ret = client->set(hash_key, "k3", "v333v"); - ASSERT_EQ(PERR_OK, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k3", "v333v")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); std::string value; pegasus_client::mutations mutations; @@ -1102,26 +1010,23 @@ TEST_F(check_and_mutate, value_match_postfix) options.return_check_value = true; mutations.set("k4", "v4"); - ret = client->check_and_mutate(hash_key, - "k3", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "333v", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k3", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "333v", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v333v", results.check_value); - ret = client->get(hash_key, "k4", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k4", value)); ASSERT_EQ("v4", value); - ret = client->del(hash_key, "k3"); - ASSERT_EQ(0, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); } } @@ -1130,8 +1035,7 @@ TEST_F(check_and_mutate, value_bytes_compare) std::string hash_key("check_and_mutate_test_value_bytes_compare"); { - int ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); std::string value; pegasus_client::mutations mutations; @@ -1140,86 +1044,78 @@ TEST_F(check_and_mutate, value_bytes_compare) options.return_check_value = true; mutations.set("k1", "v1"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_BYTES_EQUAL, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_BYTES_EQUAL, + "", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_NOT_FOUND, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->get(hash_key, "k1", value)); - ret = client->set(hash_key, "k1", ""); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k1", "")); options.return_check_value = true; mutations.set("k1", "v1"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_BYTES_EQUAL, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_BYTES_EQUAL, + "", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v1", value); options.return_check_value = true; mutations.set("k1", "v2"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_BYTES_EQUAL, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_BYTES_EQUAL, + "", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v1", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v1", value); options.return_check_value = true; mutations.set("k1", "v2"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_BYTES_EQUAL, - "v1", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_BYTES_EQUAL, + "v1", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v1", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); - ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); } { - int ret = client->set(hash_key, "k3", "v3"); - ASSERT_EQ(PERR_OK, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k3", "v3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); std::string value; pegasus_client::mutations mutations; @@ -1228,31 +1124,27 @@ TEST_F(check_and_mutate, value_bytes_compare) options.return_check_value = true; mutations.set("k4", "v4"); - ret = client->check_and_mutate(hash_key, - "k3", - pegasus_client::cas_check_type::CT_VALUE_BYTES_EQUAL, - "v3", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k3", + pegasus_client::cas_check_type::CT_VALUE_BYTES_EQUAL, + "v3", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v3", results.check_value); - ret = client->get(hash_key, "k4", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k4", value)); ASSERT_EQ("v4", value); - ret = client->del(hash_key, "k3"); - ASSERT_EQ(0, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); } { - int ret = client->set(hash_key, "k5", "v1"); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k5", "v1")); std::string value; pegasus_client::mutations mutations; @@ -1262,121 +1154,116 @@ TEST_F(check_and_mutate, value_bytes_compare) // v1 < v2 options.return_check_value = true; mutations.set("k5", "v2"); - ret = client->check_and_mutate(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_BYTES_LESS, - "v2", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_BYTES_LESS, + "v2", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v1", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("v2", value); // v2 <= v2 options.return_check_value = true; mutations.set("k5", "v3"); - ret = client->check_and_mutate(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_BYTES_LESS_OR_EQUAL, - "v2", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ( + PERR_OK, + client_->check_and_mutate(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_BYTES_LESS_OR_EQUAL, + "v2", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("v3", value); // v3 <= v4 options.return_check_value = true; mutations.set("k5", "v4"); - ret = client->check_and_mutate(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_BYTES_LESS_OR_EQUAL, - "v4", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ( + PERR_OK, + client_->check_and_mutate(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_BYTES_LESS_OR_EQUAL, + "v4", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v3", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("v4", value); // v4 >= v4 options.return_check_value = true; mutations.set("k5", "v5"); - ret = client->check_and_mutate( - hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_BYTES_GREATER_OR_EQUAL, - "v4", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate( + hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_BYTES_GREATER_OR_EQUAL, + "v4", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v4", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("v5", value); // v5 >= v4 options.return_check_value = true; mutations.set("k5", "v6"); - ret = client->check_and_mutate( - hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_BYTES_GREATER_OR_EQUAL, - "v4", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate( + hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_BYTES_GREATER_OR_EQUAL, + "v4", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v5", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("v6", value); // v6 > v5 options.return_check_value = true; mutations.set("k5", "v7"); - ret = client->check_and_mutate(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_BYTES_GREATER, - "v5", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_BYTES_GREATER, + "v5", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v6", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("v7", value); - ret = client->del(hash_key, "k5"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k5")); } } @@ -1385,8 +1272,7 @@ TEST_F(check_and_mutate, value_int_compare) std::string hash_key("check_and_mutate_test_value_int_compare"); { - int ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); std::string value; pegasus_client::mutations mutations; @@ -1395,164 +1281,150 @@ TEST_F(check_and_mutate, value_int_compare) options.return_check_value = true; mutations.set("k1", "2"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, - "1", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, + "1", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_NOT_FOUND, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->get(hash_key, "k1", value)); - ret = client->set(hash_key, "k1", ""); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k1", "")); options.return_check_value = true; mutations.set("k1", "2"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, - "1", - mutations, - options, - results); - ASSERT_EQ(PERR_INVALID_ARGUMENT, ret); + ASSERT_EQ(PERR_INVALID_ARGUMENT, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, + "1", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("", value); - ret = client->set(hash_key, "k1", "1"); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k1", "1")); options.return_check_value = true; mutations.set("k1", "2"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, - "1", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, + "1", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("1", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("2", value); options.return_check_value = true; mutations.set("k1", "3"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_INVALID_ARGUMENT, ret); + ASSERT_EQ(PERR_INVALID_ARGUMENT, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, + "", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("2", value); options.return_check_value = true; mutations.set("k1", "3"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, - "v1", - mutations, - options, - results); - ASSERT_EQ(PERR_INVALID_ARGUMENT, ret); + ASSERT_EQ(PERR_INVALID_ARGUMENT, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, + "v1", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("2", value); options.return_check_value = true; mutations.set("k1", "3"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, - "88888888888888888888888888888888888888888888888", - mutations, - options, - results); - ASSERT_EQ(PERR_INVALID_ARGUMENT, ret); + ASSERT_EQ(PERR_INVALID_ARGUMENT, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, + "88888888888888888888888888888888888888888888888", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("2", value); - ret = client->set(hash_key, "k1", "0"); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k1", "0")); options.return_check_value = true; mutations.set("k1", "-1"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, - "0", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, + "0", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("0", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("-1", value); options.return_check_value = true; mutations.set("k1", "-2"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, - "-1", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, + "-1", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("-1", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("-2", value); - ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); } { - int ret = client->set(hash_key, "k3", "3"); - ASSERT_EQ(PERR_OK, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k3", "3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); std::string value; pegasus_client::mutations mutations; @@ -1561,31 +1433,27 @@ TEST_F(check_and_mutate, value_int_compare) options.return_check_value = true; mutations.set("k4", "4"); - ret = client->check_and_mutate(hash_key, - "k3", - pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, - "3", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k3", + pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, + "3", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("3", results.check_value); - ret = client->get(hash_key, "k4", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k4", value)); ASSERT_EQ("4", value); - ret = client->del(hash_key, "k3"); - ASSERT_EQ(0, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); } { - int ret = client->set(hash_key, "k5", "1"); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k5", "1")); std::string value; pegasus_client::mutations mutations; @@ -1595,121 +1463,116 @@ TEST_F(check_and_mutate, value_int_compare) // 1 < 2 options.return_check_value = true; mutations.set("k5", "2"); - ret = client->check_and_mutate(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_INT_LESS, - "2", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_INT_LESS, + "2", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("1", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("2", value); // 2 <= 2 options.return_check_value = true; mutations.set("k5", "3"); - ret = client->check_and_mutate(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_INT_LESS_OR_EQUAL, - "2", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ( + PERR_OK, + client_->check_and_mutate(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_INT_LESS_OR_EQUAL, + "2", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("2", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("3", value); // 3 <= 4 options.return_check_value = true; mutations.set("k5", "4"); - ret = client->check_and_mutate(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_INT_LESS_OR_EQUAL, - "4", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ( + PERR_OK, + client_->check_and_mutate(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_INT_LESS_OR_EQUAL, + "4", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("3", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("4", value); // 4 >= 4 options.return_check_value = true; mutations.set("k5", "5"); - ret = - client->check_and_mutate(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_INT_GREATER_OR_EQUAL, - "4", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ( + PERR_OK, + client_->check_and_mutate(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_INT_GREATER_OR_EQUAL, + "4", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("4", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("5", value); // 5 >= 4 options.return_check_value = true; mutations.set("k5", "6"); - ret = - client->check_and_mutate(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_INT_GREATER_OR_EQUAL, - "4", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ( + PERR_OK, + client_->check_and_mutate(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_INT_GREATER_OR_EQUAL, + "4", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("5", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("6", value); // 6 > 5 options.return_check_value = true; mutations.set("k5", "7"); - ret = client->check_and_mutate(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_INT_GREATER, - "5", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_INT_GREATER, + "5", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("6", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("7", value); - ret = client->del(hash_key, "k5"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k5")); } } @@ -1718,16 +1581,20 @@ TEST_F(check_and_mutate, invalid_type) std::string hash_key("check_and_mutate_test_value_invalid_type"); { - int ret = 0; pegasus_client::mutations mutations; pegasus_client::check_and_mutate_options options; pegasus_client::check_and_mutate_results results; options.return_check_value = true; mutations.set("k1", "v1"); - ret = client->check_and_mutate( - hash_key, "k1", (pegasus_client::cas_check_type)100, "v", mutations, options, results); - ASSERT_EQ(PERR_INVALID_ARGUMENT, ret); + ASSERT_EQ(PERR_INVALID_ARGUMENT, + client_->check_and_mutate(hash_key, + "k1", + (pegasus_client::cas_check_type)100, + "v", + mutations, + options, + results)); ASSERT_FALSE(results.mutate_succeed); ASSERT_FALSE(results.check_value_returned); } @@ -1738,9 +1605,7 @@ TEST_F(check_and_mutate, set_del) std::string hash_key("check_and_mutate_test_set_del"); { - int ret = 0; - ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); std::string value; pegasus_client::mutations mutations; @@ -1750,20 +1615,19 @@ TEST_F(check_and_mutate, set_del) options.return_check_value = true; mutations.set("k1", "v1"); mutations.del("k1"); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, + "", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_NOT_FOUND, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->get(hash_key, "k1", value)); } } @@ -1772,9 +1636,7 @@ TEST_F(check_and_mutate, multi_get_mutations) std::string hash_key("check_and_mutate_test_multi_get_mutations"); { - int ret = 0; - ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); std::string value; pegasus_client::mutations mutations; @@ -1783,36 +1645,34 @@ TEST_F(check_and_mutate, multi_get_mutations) options.return_check_value = true; mutations.set("k1", "v1", 10); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, + "", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); ::sleep(12); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_NOT_FOUND, ret); - - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->get(hash_key, "k1", value)); + + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, + "", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v1", value); } } @@ -1822,9 +1682,7 @@ TEST_F(check_and_mutate, expire_seconds) std::string hash_key("check_and_mutate_test_expire_seconds"); { - int ret = 0; - ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); std::string value; pegasus_client::mutations mutations; @@ -1835,19 +1693,18 @@ TEST_F(check_and_mutate, expire_seconds) mutations.set("k1", "v1", 10); ::sleep(12); mutations.set("k2", "v2", 10); - ret = client->check_and_mutate(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, - "", - mutations, - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_mutate(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, + "", + mutations, + options, + results)); ASSERT_TRUE(results.mutate_succeed); ASSERT_TRUE(results.check_value_returned); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v1", value); } } diff --git a/src/test/function_test/base_api_test/test_check_and_set.cpp b/src/test/function_test/base_api_test/test_check_and_set.cpp index 55e516bd68..18995dab0a 100644 --- a/src/test/function_test/base_api_test/test_check_and_set.cpp +++ b/src/test/function_test/base_api_test/test_check_and_set.cpp @@ -41,146 +41,132 @@ TEST_F(check_and_set, value_not_exist) std::string hash_key("check_and_set_test_value_not_exist"); { - int ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); std::string value; pegasus_client::check_and_set_options options; pegasus_client::check_and_set_results results; options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, - "", - "k1", - "v1", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, + "", + "k1", + "v1", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v1", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, - "", - "k1", - "v2", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, + "", + "k1", + "v2", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v1", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v1", value); options.return_check_value = false; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, - "", - "k1", - "v1", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, + "", + "k1", + "v1", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_FALSE(results.check_value_returned); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v1", value); - ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); } { - int ret = client->del(hash_key, "k2"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k2")); std::string value; pegasus_client::check_and_set_options options; pegasus_client::check_and_set_results results; options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k2", - pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, - "", - "k2", - "", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k2", + pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, + "", + "k2", + "", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k2", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k2", value)); ASSERT_EQ("", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k2", - pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, - "", - "k2", - "v2", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k2", + pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, + "", + "k2", + "v2", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k2", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k2", value)); ASSERT_EQ("", value); - ret = client->del(hash_key, "k2"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k2")); } { - int ret = client->del(hash_key, "k3"); - ASSERT_EQ(0, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); std::string value; pegasus_client::check_and_set_options options; pegasus_client::check_and_set_results results; options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k3", - pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, - "", - "k4", - "v4", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k3", + pegasus_client::cas_check_type::CT_VALUE_NOT_EXIST, + "", + "k4", + "v4", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k4", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k4", value)); ASSERT_EQ("v4", value); - ret = client->del(hash_key, "k3"); - ASSERT_EQ(0, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); } } @@ -189,104 +175,93 @@ TEST_F(check_and_set, value_exist) std::string hash_key("check_and_set_test_value_exist"); { - int ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); std::string value; pegasus_client::check_and_set_options options; pegasus_client::check_and_set_results results; options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_EXIST, - "", - "k1", - "v1", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_EXIST, + "", + "k1", + "v1", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_NOT_FOUND, ret); - - ret = client->set(hash_key, "k1", ""); - ASSERT_EQ(PERR_OK, ret); - - options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_EXIST, - "", - "k1", - "v1", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->get(hash_key, "k1", value)); + + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k1", "")); + + options.return_check_value = true; + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_EXIST, + "", + "k1", + "v1", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v1", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_EXIST, - "", - "k1", - "v2", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_EXIST, + "", + "k1", + "v2", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v1", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); - ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); } { - int ret = client->set(hash_key, "k3", "v3"); - ASSERT_EQ(PERR_OK, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k3", "v3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); std::string value; pegasus_client::check_and_set_options options; pegasus_client::check_and_set_results results; options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k3", - pegasus_client::cas_check_type::CT_VALUE_EXIST, - "", - "k4", - "v4", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k3", + pegasus_client::cas_check_type::CT_VALUE_EXIST, + "", + "k4", + "v4", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v3", results.check_value); - ret = client->get(hash_key, "k4", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k4", value)); ASSERT_EQ("v4", value); - ret = client->del(hash_key, "k3"); - ASSERT_EQ(0, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); } } @@ -295,107 +270,95 @@ TEST_F(check_and_set, value_not_empty) std::string hash_key("check_and_set_test_value_not_empty"); { - int ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); std::string value; pegasus_client::check_and_set_options options; pegasus_client::check_and_set_results results; options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_NOT_EMPTY, - "", - "k1", - "v1", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_NOT_EMPTY, + "", + "k1", + "v1", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_NOT_FOUND, ret); - - ret = client->set(hash_key, "k1", ""); - ASSERT_EQ(PERR_OK, ret); - - options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_NOT_EMPTY, - "", - "k1", - "v1", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->get(hash_key, "k1", value)); + + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k1", "")); + + options.return_check_value = true; + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_NOT_EMPTY, + "", + "k1", + "v1", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("", value); - ret = client->set(hash_key, "k1", "v1"); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k1", "v1")); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_NOT_EMPTY, - "", - "k1", - "v2", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_NOT_EMPTY, + "", + "k1", + "v2", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v1", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); - ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); } { - int ret = client->set(hash_key, "k3", "v3"); - ASSERT_EQ(PERR_OK, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k3", "v3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); std::string value; pegasus_client::check_and_set_options options; pegasus_client::check_and_set_results results; options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k3", - pegasus_client::cas_check_type::CT_VALUE_NOT_EMPTY, - "", - "k4", - "v4", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k3", + pegasus_client::cas_check_type::CT_VALUE_NOT_EMPTY, + "", + "k4", + "v4", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v3", results.check_value); - ret = client->get(hash_key, "k4", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k4", value)); ASSERT_EQ("v4", value); - ret = client->del(hash_key, "k3"); - ASSERT_EQ(0, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); } } TEST_F(check_and_set, value_match_anywhere) @@ -403,212 +366,195 @@ TEST_F(check_and_set, value_match_anywhere) std::string hash_key("check_and_set_test_value_match_anywhere"); { - int ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); std::string value; pegasus_client::check_and_set_options options; pegasus_client::check_and_set_results results; options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, - "v", - "k1", - "v1", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, + "v", + "k1", + "v1", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_NOT_FOUND, ret); - - ret = client->set(hash_key, "k1", ""); - ASSERT_EQ(PERR_OK, ret); - - options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, - "v", - "k1", - "v1", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->get(hash_key, "k1", value)); + + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k1", "")); + + options.return_check_value = true; + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, + "v", + "k1", + "v1", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, - "", - "k1", - "v1", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, + "", + "k1", + "v1", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v1", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, - "", - "k1", - "v2", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, + "", + "k1", + "v2", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v1", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, - "2", - "k1", - "v111v", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, + "2", + "k1", + "v111v", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v111v", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, - "111", - "k1", - "v2", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, + "111", + "k1", + "v2", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v111v", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, - "y", - "k1", - "v3", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, + "y", + "k1", + "v3", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, - "v2v", - "k1", - "v3", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, + "v2v", + "k1", + "v3", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, - "v2", - "k1", - "v3", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, + "v2", + "k1", + "v3", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v3", value); - ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); } { - int ret = client->set(hash_key, "k3", "v333v"); - ASSERT_EQ(PERR_OK, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k3", "v333v")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); std::string value; pegasus_client::check_and_set_options options; pegasus_client::check_and_set_results results; options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k3", - pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, - "333", - "k4", - "v4", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k3", + pegasus_client::cas_check_type::CT_VALUE_MATCH_ANYWHERE, + "333", + "k4", + "v4", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v333v", results.check_value); - ret = client->get(hash_key, "k4", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k4", value)); ASSERT_EQ("v4", value); - ret = client->del(hash_key, "k3"); - ASSERT_EQ(0, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); } } @@ -617,248 +563,229 @@ TEST_F(check_and_set, value_match_prefix) std::string hash_key("check_and_set_test_value_match_prefix"); { - int ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); std::string value; pegasus_client::check_and_set_options options; pegasus_client::check_and_set_results results; options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "v", - "k1", - "v1", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "v", + "k1", + "v1", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_NOT_FOUND, ret); - - ret = client->set(hash_key, "k1", ""); - ASSERT_EQ(PERR_OK, ret); - - options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "v", - "k1", - "v1", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->get(hash_key, "k1", value)); + + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k1", "")); + + options.return_check_value = true; + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "v", + "k1", + "v1", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "", - "k1", - "v1", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "", + "k1", + "v1", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v1", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "", - "k1", - "v2", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "", + "k1", + "v2", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v1", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "v", - "k1", - "v111v", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "v", + "k1", + "v111v", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v111v", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "111", - "k1", - "v2", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "111", + "k1", + "v2", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v111v", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v111v", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "v111", - "k1", - "v2", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "v111", + "k1", + "v2", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v111v", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "y", - "k1", - "v3", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "y", + "k1", + "v3", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "v2v", - "k1", - "v3", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "v2v", + "k1", + "v3", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "2", - "k1", - "v3", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "2", + "k1", + "v3", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "v2", - "k1", - "v3", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "v2", + "k1", + "v3", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v3", value); - ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); } { - int ret = client->set(hash_key, "k3", "v333v"); - ASSERT_EQ(PERR_OK, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k3", "v333v")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); std::string value; pegasus_client::check_and_set_options options; pegasus_client::check_and_set_results results; options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k3", - pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, - "v333", - "k4", - "v4", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k3", + pegasus_client::cas_check_type::CT_VALUE_MATCH_PREFIX, + "v333", + "k4", + "v4", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v333v", results.check_value); - ret = client->get(hash_key, "k4", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k4", value)); ASSERT_EQ("v4", value); - ret = client->del(hash_key, "k3"); - ASSERT_EQ(0, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); } } @@ -867,248 +794,229 @@ TEST_F(check_and_set, value_match_postfix) std::string hash_key("check_and_set_test_value_match_postfix"); { - int ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); std::string value; pegasus_client::check_and_set_options options; pegasus_client::check_and_set_results results; options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "v", - "k1", - "v1", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "v", + "k1", + "v1", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_NOT_FOUND, ret); - - ret = client->set(hash_key, "k1", ""); - ASSERT_EQ(PERR_OK, ret); - - options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "v", - "k1", - "v1", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->get(hash_key, "k1", value)); + + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k1", "")); + + options.return_check_value = true; + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "v", + "k1", + "v1", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "", - "k1", - "v1", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "", + "k1", + "v1", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v1", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "", - "k1", - "v2", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "", + "k1", + "v2", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v1", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "2", - "k1", - "v111v", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "2", + "k1", + "v111v", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v111v", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "111", - "k1", - "v2", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "111", + "k1", + "v2", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v111v", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v111v", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "111v", - "k1", - "v2", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "111v", + "k1", + "v2", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v111v", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "y", - "k1", - "v3", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "y", + "k1", + "v3", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "2v2", - "k1", - "v3", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "2v2", + "k1", + "v3", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "v", - "k1", - "v3", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "v", + "k1", + "v3", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "v2", - "k1", - "v3", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "v2", + "k1", + "v3", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v3", value); - ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); } { - int ret = client->set(hash_key, "k3", "v333v"); - ASSERT_EQ(PERR_OK, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k3", "v333v")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); std::string value; pegasus_client::check_and_set_options options; pegasus_client::check_and_set_results results; options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k3", - pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, - "333v", - "k4", - "v4", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k3", + pegasus_client::cas_check_type::CT_VALUE_MATCH_POSTFIX, + "333v", + "k4", + "v4", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v333v", results.check_value); - ret = client->get(hash_key, "k4", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k4", value)); ASSERT_EQ("v4", value); - ret = client->del(hash_key, "k3"); - ASSERT_EQ(0, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); } } @@ -1117,127 +1025,114 @@ TEST_F(check_and_set, value_bytes_compare) std::string hash_key("check_and_set_test_value_bytes_compare"); { - int ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); std::string value; pegasus_client::check_and_set_options options; pegasus_client::check_and_set_results results; options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_BYTES_EQUAL, - "", - "k1", - "v1", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_BYTES_EQUAL, + "", + "k1", + "v1", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_NOT_FOUND, ret); - - ret = client->set(hash_key, "k1", ""); - ASSERT_EQ(PERR_OK, ret); - - options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_BYTES_EQUAL, - "", - "k1", - "v1", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->get(hash_key, "k1", value)); + + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k1", "")); + + options.return_check_value = true; + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_BYTES_EQUAL, + "", + "k1", + "v1", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v1", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_BYTES_EQUAL, - "", - "k1", - "v2", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_BYTES_EQUAL, + "", + "k1", + "v2", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v1", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v1", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_BYTES_EQUAL, - "v1", - "k1", - "v2", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_BYTES_EQUAL, + "v1", + "k1", + "v2", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v1", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("v2", value); - ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); } { - int ret = client->set(hash_key, "k3", "v3"); - ASSERT_EQ(PERR_OK, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k3", "v3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); std::string value; pegasus_client::check_and_set_options options; pegasus_client::check_and_set_results results; options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k3", - pegasus_client::cas_check_type::CT_VALUE_BYTES_EQUAL, - "v3", - "k4", - "v4", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k3", + pegasus_client::cas_check_type::CT_VALUE_BYTES_EQUAL, + "v3", + "k4", + "v4", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v3", results.check_value); - ret = client->get(hash_key, "k4", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k4", value)); ASSERT_EQ("v4", value); - ret = client->del(hash_key, "k3"); - ASSERT_EQ(0, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); } { - int ret = client->set(hash_key, "k5", "v1"); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k5", "v1")); std::string value; pegasus_client::check_and_set_options options; @@ -1245,120 +1140,117 @@ TEST_F(check_and_set, value_bytes_compare) // v1 < v2 options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_BYTES_LESS, - "v2", - "k5", - "v2", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_BYTES_LESS, + "v2", + "k5", + "v2", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v1", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("v2", value); // v2 <= v2 options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_BYTES_LESS_OR_EQUAL, - "v2", - "k5", - "v3", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ( + PERR_OK, + client_->check_and_set(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_BYTES_LESS_OR_EQUAL, + "v2", + "k5", + "v3", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v2", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("v3", value); // v3 <= v4 options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_BYTES_LESS_OR_EQUAL, - "v4", - "k5", - "v4", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ( + PERR_OK, + client_->check_and_set(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_BYTES_LESS_OR_EQUAL, + "v4", + "k5", + "v4", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v3", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("v4", value); // v4 >= v4 options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_BYTES_GREATER_OR_EQUAL, - "v4", - "k5", - "v5", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ( + PERR_OK, + client_->check_and_set(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_BYTES_GREATER_OR_EQUAL, + "v4", + "k5", + "v5", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v4", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("v5", value); // v5 >= v4 options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_BYTES_GREATER_OR_EQUAL, - "v4", - "k5", - "v6", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ( + PERR_OK, + client_->check_and_set(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_BYTES_GREATER_OR_EQUAL, + "v4", + "k5", + "v6", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v5", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("v6", value); // v6 > v5 options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_BYTES_GREATER, - "v5", - "k5", - "v7", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_BYTES_GREATER, + "v5", + "k5", + "v7", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("v6", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("v7", value); - ret = client->del(hash_key, "k5"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k5")); } } @@ -1367,205 +1259,186 @@ TEST_F(check_and_set, value_int_compare) std::string hash_key("check_and_set_test_value_int_compare"); { - int ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); std::string value; pegasus_client::check_and_set_options options; pegasus_client::check_and_set_results results; options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, - "1", - "k1", - "2", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, + "1", + "k1", + "2", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_FALSE(results.check_value_exist); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_NOT_FOUND, ret); - - ret = client->set(hash_key, "k1", ""); - ASSERT_EQ(PERR_OK, ret); - - options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, - "1", - "k1", - "2", - options, - results); - ASSERT_EQ(PERR_INVALID_ARGUMENT, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->get(hash_key, "k1", value)); + + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k1", "")); + + options.return_check_value = true; + ASSERT_EQ(PERR_INVALID_ARGUMENT, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, + "1", + "k1", + "2", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("", value); - ret = client->set(hash_key, "k1", "1"); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k1", "1")); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, - "1", - "k1", - "2", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, + "1", + "k1", + "2", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("1", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("2", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, - "", - "k1", - "3", - options, - results); - ASSERT_EQ(PERR_INVALID_ARGUMENT, ret); + ASSERT_EQ(PERR_INVALID_ARGUMENT, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, + "", + "k1", + "3", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("2", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, - "v1", - "k1", - "3", - options, - results); - ASSERT_EQ(PERR_INVALID_ARGUMENT, ret); + ASSERT_EQ(PERR_INVALID_ARGUMENT, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, + "v1", + "k1", + "3", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("2", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, - "88888888888888888888888888888888888888888888888", - "k1", - "3", - options, - results); - ASSERT_EQ(PERR_INVALID_ARGUMENT, ret); + ASSERT_EQ(PERR_INVALID_ARGUMENT, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, + "88888888888888888888888888888888888888888888888", + "k1", + "3", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("2", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("2", value); - ret = client->set(hash_key, "k1", "0"); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k1", "0")); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, - "0", - "k1", - "-1", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, + "0", + "k1", + "-1", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("0", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("-1", value); options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k1", - pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, - "-1", - "k1", - "-2", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k1", + pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, + "-1", + "k1", + "-2", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("-1", results.check_value); - ret = client->get(hash_key, "k1", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k1", value)); ASSERT_EQ("-2", value); - ret = client->del(hash_key, "k1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k1")); } { - int ret = client->set(hash_key, "k3", "3"); - ASSERT_EQ(PERR_OK, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k3", "3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); std::string value; pegasus_client::check_and_set_options options; pegasus_client::check_and_set_results results; options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k3", - pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, - "3", - "k4", - "4", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k3", + pegasus_client::cas_check_type::CT_VALUE_INT_EQUAL, + "3", + "k4", + "4", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("3", results.check_value); - ret = client->get(hash_key, "k4", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k4", value)); ASSERT_EQ("4", value); - ret = client->del(hash_key, "k3"); - ASSERT_EQ(0, ret); - ret = client->del(hash_key, "k4"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k3")); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k4")); } { - int ret = client->set(hash_key, "k5", "1"); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, "k5", "1")); std::string value; pegasus_client::check_and_set_options options; @@ -1573,120 +1446,115 @@ TEST_F(check_and_set, value_int_compare) // 1 < 2 options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_INT_LESS, - "2", - "k5", - "2", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_INT_LESS, + "2", + "k5", + "2", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("1", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("2", value); // 2 <= 2 options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_INT_LESS_OR_EQUAL, - "2", - "k5", - "3", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_INT_LESS_OR_EQUAL, + "2", + "k5", + "3", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("2", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("3", value); // 3 <= 4 options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_INT_LESS_OR_EQUAL, - "4", - "k5", - "4", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_INT_LESS_OR_EQUAL, + "4", + "k5", + "4", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("3", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("4", value); // 4 >= 4 options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_INT_GREATER_OR_EQUAL, - "4", - "k5", - "5", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ( + PERR_OK, + client_->check_and_set(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_INT_GREATER_OR_EQUAL, + "4", + "k5", + "5", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("4", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("5", value); // 5 >= 4 options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_INT_GREATER_OR_EQUAL, - "4", - "k5", - "6", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ( + PERR_OK, + client_->check_and_set(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_INT_GREATER_OR_EQUAL, + "4", + "k5", + "6", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("5", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("6", value); // 6 > 5 options.return_check_value = true; - ret = client->check_and_set(hash_key, - "k5", - pegasus_client::cas_check_type::CT_VALUE_INT_GREATER, - "5", - "k5", - "7", - options, - results); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, + client_->check_and_set(hash_key, + "k5", + pegasus_client::cas_check_type::CT_VALUE_INT_GREATER, + "5", + "k5", + "7", + options, + results)); ASSERT_TRUE(results.set_succeed); ASSERT_TRUE(results.check_value_returned); ASSERT_TRUE(results.check_value_exist); ASSERT_EQ("6", results.check_value); - ret = client->get(hash_key, "k5", value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(hash_key, "k5", value)); ASSERT_EQ("7", value); - ret = client->del(hash_key, "k5"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del(hash_key, "k5")); } } @@ -1695,14 +1563,19 @@ TEST_F(check_and_set, invalid_type) std::string hash_key("check_and_set_test_value_invalid_type"); { - int ret = 0; pegasus_client::check_and_set_options options; pegasus_client::check_and_set_results results; options.return_check_value = true; - ret = client->check_and_set( - hash_key, "k1", (pegasus_client::cas_check_type)100, "v", "k1", "v1", options, results); - ASSERT_EQ(PERR_INVALID_ARGUMENT, ret); + ASSERT_EQ(PERR_INVALID_ARGUMENT, + client_->check_and_set(hash_key, + "k1", + (pegasus_client::cas_check_type)100, + "v", + "k1", + "v1", + options, + results)); ASSERT_FALSE(results.set_succeed); ASSERT_FALSE(results.check_value_returned); } diff --git a/src/test/function_test/base_api_test/test_copy.cpp b/src/test/function_test/base_api_test/test_copy.cpp index cab897def2..f6494eaec4 100644 --- a/src/test/function_test/base_api_test/test_copy.cpp +++ b/src/test/function_test/base_api_test/test_copy.cpp @@ -41,130 +41,124 @@ using std::map; using std::string; using std::vector; -static const char CCH[] = "_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; -static const int max_batch_count = 500; -static const int timeout_ms = 5000; -static const int max_multi_set_concurrency = 20; -static const int default_partitions = 4; -static const string empty_hash_key = ""; -static const string source_app_name = "copy_data_source_table"; -static const string destination_app_name = "copy_data_destination_table"; -static char buffer[256]; -static map> base_data; -static pegasus_client *srouce_client; -static pegasus_client *destination_client; - class copy_data_test : public test_util { public: void SetUp() override { test_util::SetUp(); - create_table_and_get_client(); - fill_data(); + ASSERT_NO_FATAL_FAILURE(create_table_and_get_client()); + ASSERT_NO_FATAL_FAILURE(fill_data()); } void TearDown() override { test_util::TearDown(); - ASSERT_EQ(dsn::ERR_OK, ddl_client->drop_app(source_app_name, 0)); - ASSERT_EQ(dsn::ERR_OK, ddl_client->drop_app(destination_app_name, 0)); + ASSERT_EQ(dsn::ERR_OK, ddl_client_->drop_app(source_app_name, 0)); + ASSERT_EQ(dsn::ERR_OK, ddl_client_->drop_app(destination_app_name, 0)); } void verify_data() { pegasus_client::scan_options options; vector scanners; - int ret = destination_client->get_unordered_scanners(INT_MAX, options, scanners); - ASSERT_EQ(0, ret) << "Error occurred when getting scanner. error=" - << destination_client->get_error_string(ret); + ASSERT_EQ(PERR_OK, destination_client_->get_unordered_scanners(INT_MAX, options, scanners)); string hash_key; string sort_key; string value; - map> data; + map> actual_data; for (auto scanner : scanners) { ASSERT_NE(nullptr, scanner); + int ret = PERR_OK; while (PERR_OK == (ret = (scanner->next(hash_key, sort_key, value)))) { - check_and_put(data, hash_key, sort_key, value); + check_and_put(actual_data, hash_key, sort_key, value); } - ASSERT_EQ(PERR_SCAN_COMPLETE, ret) << "Error occurred when scan. error=" - << destination_client->get_error_string(ret); + ASSERT_EQ(PERR_SCAN_COMPLETE, ret); delete scanner; } - compare(data, base_data); - - ddebug_f("Data and base_data are the same."); + ASSERT_NO_FATAL_FAILURE(compare(expect_data_, actual_data)); } void create_table_and_get_client() { - dsn::error_code err; - err = ddl_client->create_app(source_app_name, "pegasus", default_partitions, 3, {}, false); - ASSERT_EQ(dsn::ERR_OK, err); - - err = ddl_client->create_app( - destination_app_name, "pegasus", default_partitions, 3, {}, false); - ASSERT_EQ(dsn::ERR_OK, err); - - srouce_client = pegasus_client_factory::get_client("mycluster", source_app_name.c_str()); - destination_client = - pegasus_client_factory::get_client("mycluster", destination_app_name.c_str()); + ASSERT_EQ( + dsn::ERR_OK, + ddl_client_->create_app(source_app_name, "pegasus", default_partitions, 3, {}, false)); + ASSERT_EQ(dsn::ERR_OK, + ddl_client_->create_app( + destination_app_name, "pegasus", default_partitions, 3, {}, false)); + srouce_client_ = + pegasus_client_factory::get_client(cluster_name_.c_str(), source_app_name.c_str()); + ASSERT_NE(nullptr, srouce_client_); + destination_client_ = + pegasus_client_factory::get_client(cluster_name_.c_str(), destination_app_name.c_str()); + ASSERT_NE(nullptr, destination_client_); } - // REQUIRED: 'buffer' has been filled with random chars. - const string random_string() + // REQUIRED: 'buffer_' has been filled with random chars. + const string random_string() const { - int pos = random() % sizeof(buffer); - buffer[pos] = CCH[random() % strlen(CCH)]; - unsigned int length = random() % sizeof(buffer) + 1; - if (pos + length < sizeof(buffer)) { - return string(buffer + pos, length); + int pos = random() % sizeof(buffer_); + unsigned int length = random() % sizeof(buffer_) + 1; + if (pos + length < sizeof(buffer_)) { + return string(buffer_ + pos, length); } else { - return string(buffer + pos, sizeof(buffer) - pos) + - string(buffer, length + pos - sizeof(buffer)); + return string(buffer_ + pos, sizeof(buffer_) - pos) + + string(buffer_, length + pos - sizeof(buffer_)); } } void fill_data() { - ddebug_f("FILLING_DATA..."); - srandom((unsigned int)time(nullptr)); - for (auto &c : buffer) { + for (auto &c : buffer_) { c = CCH[random() % strlen(CCH)]; } string hash_key; string sort_key; string value; - while (base_data[empty_hash_key].size() < 1000) { + while (expect_data_[empty_hash_key].size() < 1000) { sort_key = random_string(); value = random_string(); - int ret = srouce_client->set(empty_hash_key, sort_key, value); - ASSERT_EQ(PERR_OK, ret) << "Error occurred when set, hash_key=" << hash_key - << ", sort_key=" << sort_key - << ", error=" << srouce_client->get_error_string(ret); - base_data[empty_hash_key][sort_key] = value; + ASSERT_EQ(PERR_OK, srouce_client_->set(empty_hash_key, sort_key, value)) + << "hash_key=" << hash_key << ", sort_key=" << sort_key; + expect_data_[empty_hash_key][sort_key] = value; } - while (base_data.size() < 500) { + while (expect_data_.size() < 500) { hash_key = random_string(); - while (base_data[hash_key].size() < 10) { + while (expect_data_[hash_key].size() < 10) { sort_key = random_string(); value = random_string(); - int ret = srouce_client->set(hash_key, sort_key, value); - ASSERT_EQ(PERR_OK, ret) << "Error occurred when set, hash_key=" << hash_key - << ", sort_key=" << sort_key - << ", error=" << srouce_client->get_error_string(ret); - base_data[hash_key][sort_key] = value; + ASSERT_EQ(PERR_OK, srouce_client_->set(hash_key, sort_key, value)) + << "hash_key=" << hash_key << ", sort_key=" << sort_key; + expect_data_[hash_key][sort_key] = value; } } - - ddebug_f("Data filled."); } + +protected: + static const char CCH[]; + const string empty_hash_key = ""; + const string source_app_name = "copy_data_source_table"; + const string destination_app_name = "copy_data_destination_table"; + + const int max_batch_count = 500; + const int timeout_ms = 5000; + const int max_multi_set_concurrency = 20; + const int default_partitions = 4; + + char buffer_[256]; + map> expect_data_; + + pegasus_client *srouce_client_; + pegasus_client *destination_client_; }; +const char copy_data_test::CCH[] = + "_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; TEST_F(copy_data_test, EMPTY_HASH_KEY_COPY) { @@ -173,9 +167,7 @@ TEST_F(copy_data_test, EMPTY_HASH_KEY_COPY) pegasus_client::scan_options options; options.return_expire_ts = true; vector raw_scanners; - int ret = srouce_client->get_unordered_scanners(INT_MAX, options, raw_scanners); - ASSERT_EQ(pegasus::PERR_OK, ret) << "Error occurred when getting scanner. error=" - << srouce_client->get_error_string(ret); + ASSERT_EQ(PERR_OK, srouce_client_->get_unordered_scanners(INT_MAX, options, raw_scanners)); ddebug_f("open source app scanner succeed, partition_count = {}", raw_scanners.size()); @@ -198,7 +190,7 @@ TEST_F(copy_data_test, EMPTY_HASH_KEY_COPY) max_batch_count, timeout_ms, scanners[i], - destination_client, + destination_client_, nullptr, &error_occurred, max_multi_set_concurrency); @@ -223,8 +215,5 @@ TEST_F(copy_data_test, EMPTY_HASH_KEY_COPY) } ASSERT_FALSE(error_occurred.load()) << "error occurred, processing terminated or timeout!"; - - verify_data(); - - ddebug_f("finished copy data test.."); + ASSERT_NO_FATAL_FAILURE(verify_data()); } diff --git a/src/test/function_test/base_api_test/test_incr.cpp b/src/test/function_test/base_api_test/test_incr.cpp index 8e686d1886..0aeba6422f 100644 --- a/src/test/function_test/base_api_test/test_incr.cpp +++ b/src/test/function_test/base_api_test/test_incr.cpp @@ -38,267 +38,215 @@ class incr : public test_util TEST_F(incr, unexist_key) { - int ret = client->del("incr_test_unexist_key", ""); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del("incr_test_unexist_key", "")); int64_t new_value_int; - ret = client->incr("incr_test_unexist_key", "", 100, new_value_int); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->incr("incr_test_unexist_key", "", 100, new_value_int)); ASSERT_EQ(100, new_value_int); std::string new_value_str; - ret = client->get("incr_test_unexist_key", "", new_value_str); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->get("incr_test_unexist_key", "", new_value_str)); ASSERT_EQ("100", new_value_str); - ret = client->del("incr_test_unexist_key", ""); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del("incr_test_unexist_key", "")); } TEST_F(incr, empty_key) { - int ret = client->set("incr_test_empty_key", "", ""); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set("incr_test_empty_key", "", "")); int64_t new_value_int; - ret = client->incr("incr_test_empty_key", "", 100, new_value_int); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->incr("incr_test_empty_key", "", 100, new_value_int)); ASSERT_EQ(100, new_value_int); std::string new_value_str; - ret = client->get("incr_test_empty_key", "", new_value_str); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->get("incr_test_empty_key", "", new_value_str)); ASSERT_EQ("100", new_value_str); - ret = client->del("incr_test_empty_key", ""); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del("incr_test_empty_key", "")); } TEST_F(incr, negative_value) { - int ret = client->set("incr_test_negative_value", "", "-100"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set("incr_test_negative_value", "", "-100")); int64_t new_value_int; - ret = client->incr("incr_test_negative_value", "", -1, new_value_int); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->incr("incr_test_negative_value", "", -1, new_value_int)); ASSERT_EQ(-101, new_value_int); std::string new_value_str; - ret = client->get("incr_test_negative_value", "", new_value_str); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->get("incr_test_negative_value", "", new_value_str)); ASSERT_EQ("-101", new_value_str); - ret = client->del("incr_test_negative_value", ""); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del("incr_test_negative_value", "")); } TEST_F(incr, increase_zero) { - int ret = client->set("incr_test_increase_zero", "", "100"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set("incr_test_increase_zero", "", "100")); int64_t new_value_int; - ret = client->incr("incr_test_increase_zero", "", 0, new_value_int); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->incr("incr_test_increase_zero", "", 0, new_value_int)); ASSERT_EQ(100, new_value_int); std::string new_value_str; - ret = client->get("incr_test_increase_zero", "", new_value_str); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->get("incr_test_increase_zero", "", new_value_str)); ASSERT_EQ("100", new_value_str); - ret = client->del("incr_test_increase_zero", ""); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del("incr_test_increase_zero", "")); } TEST_F(incr, multiple_increment) { - int ret = client->set("incr_test_multiple_increment", "", "100"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set("incr_test_multiple_increment", "", "100")); int64_t new_value_int; - ret = client->incr("incr_test_multiple_increment", "", 1, new_value_int); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->incr("incr_test_multiple_increment", "", 1, new_value_int)); ASSERT_EQ(101, new_value_int); std::string new_value_str; - ret = client->get("incr_test_multiple_increment", "", new_value_str); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->get("incr_test_multiple_increment", "", new_value_str)); ASSERT_EQ("101", new_value_str); - ret = client->incr("incr_test_multiple_increment", "", 2, new_value_int); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->incr("incr_test_multiple_increment", "", 2, new_value_int)); ASSERT_EQ(103, new_value_int); - ret = client->get("incr_test_multiple_increment", "", new_value_str); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->get("incr_test_multiple_increment", "", new_value_str)); ASSERT_EQ("103", new_value_str); - ret = client->del("incr_test_multiple_increment", ""); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del("incr_test_multiple_increment", "")); } TEST_F(incr, invalid_old_data) { - int ret = client->set("incr_test_invalid_old_data", "", "aaa"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set("incr_test_invalid_old_data", "", "aaa")); int64_t new_value_int; - ret = client->incr("incr_test_invalid_old_data", "", 1, new_value_int); - ASSERT_EQ(PERR_INVALID_ARGUMENT, ret); + ASSERT_EQ(PERR_INVALID_ARGUMENT, + client_->incr("incr_test_invalid_old_data", "", 1, new_value_int)); ASSERT_EQ(0, new_value_int); std::string new_value_str; - ret = client->get("incr_test_invalid_old_data", "", new_value_str); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->get("incr_test_invalid_old_data", "", new_value_str)); ASSERT_EQ("aaa", new_value_str); - ret = client->del("incr_test_invalid_old_data", ""); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del("incr_test_invalid_old_data", "")); } TEST_F(incr, out_of_range_old_data) { - int ret = client->set( - "incr_test_out_of_range_old_data", "", "10000000000000000000000000000000000000"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, + client_->set( + "incr_test_out_of_range_old_data", "", "10000000000000000000000000000000000000")); int64_t new_value_int; - ret = client->incr("incr_test_out_of_range_old_data", "", 1, new_value_int); - ASSERT_EQ(PERR_INVALID_ARGUMENT, ret); + ASSERT_EQ(PERR_INVALID_ARGUMENT, + client_->incr("incr_test_out_of_range_old_data", "", 1, new_value_int)); ASSERT_EQ(0, new_value_int); std::string new_value_str; - ret = client->get("incr_test_out_of_range_old_data", "", new_value_str); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->get("incr_test_out_of_range_old_data", "", new_value_str)); ASSERT_EQ("10000000000000000000000000000000000000", new_value_str); - ret = client->del("incr_test_out_of_range_old_data", ""); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del("incr_test_out_of_range_old_data", "")); } TEST_F(incr, up_overflow) { - int ret = client->set("incr_test_up_overflow", "", "1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set("incr_test_up_overflow", "", "1")); int64_t new_value_int; - ret = client->incr("incr_test_up_overflow", "", LLONG_MAX, new_value_int); - ASSERT_EQ(PERR_INVALID_ARGUMENT, ret); + ASSERT_EQ(PERR_INVALID_ARGUMENT, + client_->incr("incr_test_up_overflow", "", LLONG_MAX, new_value_int)); ASSERT_EQ(1, new_value_int); std::string new_value_str; - ret = client->get("incr_test_up_overflow", "", new_value_str); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->get("incr_test_up_overflow", "", new_value_str)); ASSERT_EQ("1", new_value_str); - ret = client->del("incr_test_up_overflow", ""); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del("incr_test_up_overflow", "")); } TEST_F(incr, down_overflow) { - int ret = client->set("incr_test_down_overflow", "", "-1"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set("incr_test_down_overflow", "", "-1")); int64_t new_value_int; - ret = client->incr("incr_test_down_overflow", "", LLONG_MIN, new_value_int); - ASSERT_EQ(PERR_INVALID_ARGUMENT, ret); + ASSERT_EQ(PERR_INVALID_ARGUMENT, + client_->incr("incr_test_down_overflow", "", LLONG_MIN, new_value_int)); ASSERT_EQ(-1, new_value_int); std::string new_value_str; - ret = client->get("incr_test_down_overflow", "", new_value_str); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->get("incr_test_down_overflow", "", new_value_str)); ASSERT_EQ("-1", new_value_str); - ret = client->del("incr_test_down_overflow", ""); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del("incr_test_down_overflow", "")); } TEST_F(incr, preserve_ttl) { - int ret = client->set("incr_test_preserve_ttl", "", "100", 5000, 3); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set("incr_test_preserve_ttl", "", "100", 5000, 3)); int64_t new_value_int; - ret = client->incr("incr_test_preserve_ttl", "", 1, new_value_int); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->incr("incr_test_preserve_ttl", "", 1, new_value_int)); ASSERT_EQ(101, new_value_int); int ttl_seconds; - ret = client->ttl("incr_test_preserve_ttl", "", ttl_seconds); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->ttl("incr_test_preserve_ttl", "", ttl_seconds)); ASSERT_GE(3, ttl_seconds); sleep(4); std::string new_value_str; - ret = client->get("incr_test_preserve_ttl", "", new_value_str); - ASSERT_EQ(PERR_NOT_FOUND, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->get("incr_test_preserve_ttl", "", new_value_str)); - ret = client->del("incr_test_preserve_ttl", ""); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del("incr_test_preserve_ttl", "")); } TEST_F(incr, reset_ttl) { /// reset after old value ttl timeout - int ret = client->set("incr_test_reset_ttl", "", "100", 5000, 3); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set("incr_test_reset_ttl", "", "100", 5000, 3)); sleep(4); int64_t new_value_int; - ret = client->incr("incr_test_reset_ttl", "", 1, new_value_int); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->incr("incr_test_reset_ttl", "", 1, new_value_int)); ASSERT_EQ(1, new_value_int); int ttl_seconds; - ret = client->ttl("incr_test_reset_ttl", "", ttl_seconds); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->ttl("incr_test_reset_ttl", "", ttl_seconds)); ASSERT_GE(-1, ttl_seconds); - ret = client->del("incr_test_reset_ttl", ""); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del("incr_test_reset_ttl", "")); /// reset with new ttl - ret = client->set("incr_test_reset_ttl", "", "100"); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set("incr_test_reset_ttl", "", "100")); - ret = client->ttl("incr_test_reset_ttl", "", ttl_seconds); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->ttl("incr_test_reset_ttl", "", ttl_seconds)); ASSERT_GE(-1, ttl_seconds); - ret = client->incr("incr_test_reset_ttl", "", 1, new_value_int, 5000, 10); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->incr("incr_test_reset_ttl", "", 1, new_value_int, 5000, 10)); ASSERT_EQ(101, new_value_int); - ret = client->ttl("incr_test_reset_ttl", "", ttl_seconds); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->ttl("incr_test_reset_ttl", "", ttl_seconds)); ASSERT_LT(0, ttl_seconds); ASSERT_GE(10, ttl_seconds); - ret = client->del("incr_test_reset_ttl", ""); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del("incr_test_reset_ttl", "")); /// reset with no ttl - ret = client->set("incr_test_reset_ttl", "", "200", 5000, 10); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->set("incr_test_reset_ttl", "", "200", 5000, 10)); - ret = client->ttl("incr_test_reset_ttl", "", ttl_seconds); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->ttl("incr_test_reset_ttl", "", ttl_seconds)); ASSERT_LT(0, ttl_seconds); ASSERT_GE(10, ttl_seconds); - ret = client->incr("incr_test_reset_ttl", "", 1, new_value_int, 5000, -1); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->incr("incr_test_reset_ttl", "", 1, new_value_int, 5000, -1)); ASSERT_EQ(201, new_value_int); - ret = client->ttl("incr_test_reset_ttl", "", ttl_seconds); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->ttl("incr_test_reset_ttl", "", ttl_seconds)); ASSERT_GE(-1, ttl_seconds); - ret = client->del("incr_test_reset_ttl", ""); - ASSERT_EQ(0, ret); + ASSERT_EQ(PERR_OK, client_->del("incr_test_reset_ttl", "")); } diff --git a/src/test/function_test/base_api_test/test_range_read.cpp b/src/test/function_test/base_api_test/test_range_read.cpp index 8186947857..b4c6febd9a 100644 --- a/src/test/function_test/base_api_test/test_range_read.cpp +++ b/src/test/function_test/base_api_test/test_range_read.cpp @@ -21,48 +21,49 @@ #include #include "include/pegasus/client.h" #include "include/pegasus/error.h" +#include "test/function_test/utils/test_util.h" using namespace ::dsn; using namespace pegasus; -class range_read_test : public testing::Test +class range_read_test : public test_util { public: void prepare(const int32_t total_count, const int32_t expire_count) { + ASSERT_GE(total_count, expire_count); + if (expire_count > 0) { // set expire values for (auto i = 0; i < expire_count; i++) { std::string sort_key = "1-" + std::to_string(i); - sortkeys.insert(sort_key); - kvs[sort_key] = value; + expect_sortkeys_.insert(sort_key); + expect_kvs_[sort_key] = value; } - auto ret = pg_client->multi_set(hashkey, kvs, timeoutms, 1); - ASSERT_EQ(PERR_OK, ret); - std::this_thread::sleep_for(std::chrono::seconds(1)); - kvs.clear(); + ASSERT_EQ(PERR_OK, client_->multi_set(expect_hashkey, expect_kvs_, 5000, 1)); + std::this_thread::sleep_for(std::chrono::seconds(2)); + // all data is expired, so clear 'expect_kvs_'. + expect_kvs_.clear(); } if (total_count > expire_count) { // set normal values for (auto i = expire_count; i < total_count; i++) { std::string sort_key = "2-" + std::to_string(i); - sortkeys.insert(sort_key); - kvs[sort_key] = value; + expect_sortkeys_.insert(sort_key); + expect_kvs_[sort_key] = value; } - auto ret = pg_client->multi_set(hashkey, kvs); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->multi_set(expect_hashkey, expect_kvs_)); } } void cleanup(const int32_t expected_deleted_count) { int64_t deleted_count; - auto ret = pg_client->multi_del(hashkey, sortkeys, deleted_count); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(deleted_count, expected_deleted_count); - sortkeys.clear(); - kvs.clear(); + ASSERT_EQ(PERR_OK, client_->multi_del(expect_hashkey, expect_sortkeys_, deleted_count)); + ASSERT_EQ(expected_deleted_count, deleted_count); + expect_sortkeys_.clear(); + expect_kvs_.clear(); } void test_scan(const int32_t expire_count, @@ -73,52 +74,38 @@ class range_read_test : public testing::Test pegasus::pegasus_client::scan_options options; options.batch_size = batch_count; pegasus::pegasus_client::pegasus_scanner *scanner; - auto ret = pg_client->get_scanner(hashkey, "", "", options, scanner); - ASSERT_EQ(ret, PERR_OK); + ASSERT_EQ(PERR_OK, client_->get_scanner(expect_hashkey, "", "", options, scanner)); - std::map scan_kvs; + std::map actual_kvs; std::string hash_key; std::string sort_key; - std::string act_value; + std::string actual_value; auto i = expire_count; while (i < total_count) { - ret = scanner->next(hash_key, sort_key, act_value); - ASSERT_EQ(ret, PERR_OK); - ASSERT_EQ(hash_key, hashkey); - scan_kvs[sort_key] = act_value; + ASSERT_EQ(PERR_OK, scanner->next(hash_key, sort_key, actual_value)); + ASSERT_EQ(expect_hashkey, hash_key); + actual_kvs[sort_key] = actual_value; i++; } - ret = scanner->next(hash_key, sort_key, act_value); - ASSERT_EQ(ret, PERR_SCAN_COMPLETE); - ASSERT_EQ(expected_scan_count, scan_kvs.size()); + ASSERT_EQ(PERR_SCAN_COMPLETE, scanner->next(hash_key, sort_key, actual_value)); + ASSERT_EQ(expected_scan_count, actual_kvs.size()); delete scanner; - // compare scan result - for (auto it1 = kvs.begin(), it2 = scan_kvs.begin();; ++it1, ++it2) { - if (it1 == kvs.end()) { - ASSERT_EQ(it2, scan_kvs.end()); - break; - } - ASSERT_NE(it2, scan_kvs.end()); - ASSERT_EQ(*it1, *it2); - } + ASSERT_EQ(expect_kvs_, actual_kvs); } public: - const std::string table = "temp"; - const std::string hashkey = "range_read_hashkey"; - const std::string sortkey_prefix = "1-"; + const std::string expect_hashkey = "range_read_hashkey"; const std::string value = "value"; - const int32_t timeoutms = 5000; - pegasus_client *pg_client = pegasus_client_factory::get_client("mycluster", table.c_str()); - std::set sortkeys; - std::map kvs; + + std::set expect_sortkeys_; + std::map expect_kvs_; }; +// TODO(yingchun): use TEST_P to refact TEST_F(range_read_test, multiget_test) { pegasus::pegasus_client::multi_get_options options; - std::map new_values; struct test_struct { int32_t expire_count; @@ -142,13 +129,13 @@ TEST_F(range_read_test, multiget_test) {0, 4000, 100, PERR_INCOMPLETE, 100}}; for (auto test : tests) { - new_values.clear(); - prepare(test.total_count, test.expire_count); - auto ret = - pg_client->multi_get(hashkey, "", "", options, new_values, test.get_max_kv_count); - ASSERT_EQ(ret, test.expected_error); - ASSERT_EQ(new_values.size(), test.expected_value_count); - cleanup(test.total_count); + std::map new_values; + ASSERT_NO_FATAL_FAILURE(prepare(test.total_count, test.expire_count)); + ASSERT_EQ( + test.expected_error, + client_->multi_get(expect_hashkey, "", "", options, new_values, test.get_max_kv_count)); + ASSERT_EQ(test.expected_value_count, new_values.size()); + ASSERT_NO_FATAL_FAILURE(cleanup(test.total_count)); } } @@ -164,11 +151,10 @@ TEST_F(range_read_test, sortkeycount_test) } tests[]{{0, 500, PERR_OK, 500}, {500, 4000, PERR_OK, 3500}}; for (auto test : tests) { - prepare(test.total_count, test.expire_count); - auto ret = pg_client->sortkey_count(hashkey, count); - ASSERT_EQ(ret, test.expected_error); - ASSERT_EQ(count, test.expected_count); - cleanup(test.total_count); + ASSERT_NO_FATAL_FAILURE(prepare(test.total_count, test.expire_count)); + ASSERT_EQ(test.expected_error, client_->sortkey_count(expect_hashkey, count)); + ASSERT_EQ(test.expected_count, count); + ASSERT_NO_FATAL_FAILURE(cleanup(test.total_count)); } } @@ -196,8 +182,9 @@ TEST_F(range_read_test, scan_test) {0, 4000, 100, 4000}}; for (auto test : tests) { - prepare(test.total_count, test.expire_count); - test_scan(test.expire_count, test.total_count, test.batch_size, test.expected_scan_count); - cleanup(test.total_count); + ASSERT_NO_FATAL_FAILURE(prepare(test.total_count, test.expire_count)); + ASSERT_NO_FATAL_FAILURE(test_scan( + test.expire_count, test.total_count, test.batch_size, test.expected_scan_count)); + ASSERT_NO_FATAL_FAILURE(cleanup(test.total_count)); } } diff --git a/src/test/function_test/base_api_test/test_recall.cpp b/src/test/function_test/base_api_test/test_recall.cpp index 4cc72dc785..37f4ed31fc 100644 --- a/src/test/function_test/base_api_test/test_recall.cpp +++ b/src/test/function_test/base_api_test/test_recall.cpp @@ -40,97 +40,69 @@ using namespace pegasus; class drop_and_recall : public test_util { -}; - -TEST_F(drop_and_recall, simple) -{ - const std::string simple_table = "simple_table"; +protected: const std::string key_prefix = "hello"; const std::string value_prefix = "world"; - const int number = 10000; - const int partition_count = 4; - - // first create table - std::cerr << "create app " << simple_table << std::endl; - dsn::error_code error = - ddl_client->create_app(simple_table, "pegasus", partition_count, 3, {}, false); - ASSERT_EQ(dsn::ERR_OK, error); - - // list table - std::vector<::dsn::app_info> apps; - error = ddl_client->list_apps(dsn::app_status::AS_AVAILABLE, apps); - ASSERT_EQ(dsn::ERR_OK, error); - int app_id = 0; - for (auto &app : apps) { - if (app.app_name == simple_table) { - app_id = app.app_id; - break; - } - } - ASSERT_NE(0, app_id); - std::cerr << "app_id = " << app_id << std::endl; - pegasus::pegasus_client *pg_client = - pegasus::pegasus_client_factory::get_client("mycluster", simple_table.c_str()); + const int kv_count = 10000; +}; - std::vector hash_for_gpid(partition_count, ""); +TEST_F(drop_and_recall, simple) +{ + std::vector hashkeys_for_gpid(partition_count_, ""); // then write keys - std::cerr << "write " << number << " keys" << std::endl; - for (int i = 0; i < number; ++i) { + for (int i = 0; i < kv_count; ++i) { std::string hash_key = key_prefix + boost::lexical_cast(i); std::string sort_key = hash_key; std::string value = value_prefix + boost::lexical_cast(i); pegasus::pegasus_client::internal_info info; int ans; - RETRY_OPERATION(pg_client->set(hash_key, sort_key, value, 5000, 0, &info), ans); - ASSERT_EQ(0, ans); - ASSERT_TRUE(info.partition_index < partition_count); - if (hash_for_gpid[info.partition_index] == "") { - hash_for_gpid[info.partition_index] = hash_key; + RETRY_OPERATION(client_->set(hash_key, sort_key, value, 5000, 0, &info), ans); + ASSERT_EQ(PERR_OK, ans); + ASSERT_TRUE(info.partition_index < partition_count_); + if (hashkeys_for_gpid[info.partition_index].empty()) { + hashkeys_for_gpid[info.partition_index] = hash_key; } } - for (const auto &key : hash_for_gpid) { - ASSERT_TRUE(key != ""); + for (const auto &hashkey : hashkeys_for_gpid) { + ASSERT_FALSE(hashkey.empty()); } - // then drop the table - std::cerr << "drop table " << simple_table << std::endl; - ASSERT_EQ(dsn::ERR_OK, ddl_client->drop_app(simple_table, 0)); + // drop the table + ASSERT_EQ(dsn::ERR_OK, ddl_client_->drop_app(app_name_, 0)); // wait for all elements to be dropped - for (int i = 0; i < partition_count; ++i) { + for (int i = 0; i < partition_count_; ++i) { int j; for (j = 0; j < 60; ++j) { pegasus::pegasus_client::internal_info info; - pg_client->set(hash_for_gpid[i], "", "", 1000, 0, &info); + client_->set(hashkeys_for_gpid[i], "", "", 1000, 0, &info); if (info.app_id == -1) { - std::cerr << "partition " << i << " is removed from server" << std::endl; + std::cout << "partition " << i << " is removed from server" << std::endl; break; } else { std::this_thread::sleep_for(std::chrono::seconds(1)); } } - ASSERT_TRUE(j < 60); + ASSERT_LT(j, 60); } // then recall table - std::cerr << "start to recall table " << std::endl; - error = ddl_client->recall_app(app_id, ""); - ASSERT_EQ(dsn::ERR_OK, error); + ASSERT_EQ(dsn::ERR_OK, ddl_client_->recall_app(app_id_, "")); // then read all keys - for (int i = 0; i < number; ++i) { - std::string hash_key = key_prefix + boost::lexical_cast(i); + for (int i = 0; i < kv_count; ++i) { + std::string hash_key = key_prefix + std::to_string(i); std::string sort_key = hash_key; - std::string exp_value = value_prefix + boost::lexical_cast(i); + std::string exp_value = value_prefix + std::to_string(i); std::string act_value; int ans; - RETRY_OPERATION(pg_client->get(hash_key, sort_key, act_value), ans); - ASSERT_EQ(0, ans); + RETRY_OPERATION(client_->get(hash_key, sort_key, act_value), ans); + ASSERT_EQ(PERR_OK, ans); ASSERT_EQ(exp_value, act_value); } } diff --git a/src/test/function_test/base_api_test/test_scan.cpp b/src/test/function_test/base_api_test/test_scan.cpp index 323bc6a835..111bcd1d6b 100644 --- a/src/test/function_test/base_api_test/test_scan.cpp +++ b/src/test/function_test/base_api_test/test_scan.cpp @@ -35,117 +35,100 @@ using namespace ::pegasus; -static const char CCH[] = "_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; -static char buffer[256]; -static constexpr int ttl_seconds = 24 * 60 * 60; - -class scan : public test_util +class scan_test : public test_util { public: void SetUp() override { test_util::SetUp(); - // TODO(yingchun): can be removed? - ASSERT_EQ(dsn::ERR_OK, ddl_client->drop_app(app_name_, 0)); - ASSERT_EQ(dsn::ERR_OK, ddl_client->create_app(app_name_, "pegasus", 8, 3, {}, false)); - client = pegasus_client_factory::get_client(cluster_name_.c_str(), app_name_.c_str()); - ASSERT_TRUE(client != nullptr); + ASSERT_EQ(dsn::ERR_OK, ddl_client_->drop_app(app_name_, 0)); + ASSERT_EQ(dsn::ERR_OK, ddl_client_->create_app(app_name_, "pegasus", 8, 3, {}, false)); + client_ = pegasus_client_factory::get_client(cluster_name_.c_str(), app_name_.c_str()); + ASSERT_TRUE(client_ != nullptr); ASSERT_NO_FATAL_FAILURE(fill_database()); } - void TearDown() override - { - // TODO(yingchun): can be removed too? - ASSERT_EQ(dsn::ERR_OK, ddl_client->drop_app(app_name_, 0)); - } + void TearDown() override { ASSERT_EQ(dsn::ERR_OK, ddl_client_->drop_app(app_name_, 0)); } - // REQUIRED: 'buffer' has been filled with random chars. - static const std::string random_string() + // REQUIRED: 'buffer_' has been filled with random chars. + const std::string random_string() const { - int pos = random() % sizeof(buffer); - unsigned int length = random() % sizeof(buffer) + 1; - if (pos + length < sizeof(buffer)) { - return std::string(buffer + pos, length); + int pos = random() % sizeof(buffer_); + unsigned int length = random() % sizeof(buffer_) + 1; + if (pos + length < sizeof(buffer_)) { + return std::string(buffer_ + pos, length); } else { - return std::string(buffer + pos, sizeof(buffer) - pos) + - std::string(buffer, length + pos - sizeof(buffer)); + return std::string(buffer_ + pos, sizeof(buffer_) - pos) + + std::string(buffer_, length + pos - sizeof(buffer_)); } } - // REQUIRED: 'base' is empty + // REQUIRED: 'expect_kvs_' is empty void fill_database() { - ddebug("FILLING_DATABASE..."); - srandom((unsigned int)time(nullptr)); - for (auto &c : buffer) { + for (auto &c : buffer_) { c = CCH[random() % strlen(CCH)]; } int i = 0; - // Fill data with : -> , there are 1000 sort keys in - // the unique . - expected_hash_key = random_string(); + // Fill data with : -> , there are 1000 sort keys in + // the unique . + expected_hash_key_ = random_string(); std::string sort_key; std::string value; - while (base[expected_hash_key].size() < 1000) { + while (expect_kvs_[expected_hash_key_].size() < 1000) { sort_key = random_string(); value = random_string(); - int ret = client->set(expected_hash_key, sort_key, value); - ASSERT_EQ(PERR_OK, ret) << "Error occurred when set, hash_key=" << expected_hash_key - << ", sort_key=" << sort_key - << ", error=" << client->get_error_string(ret); + ASSERT_EQ(PERR_OK, client_->set(expected_hash_key_, sort_key, value)) + << "hash_key=" << expected_hash_key_ << ", sort_key=" << sort_key; i++; - base[expected_hash_key][sort_key] = value; + expect_kvs_[expected_hash_key_][sort_key] = value; } // 1000 kvs std::string hash_key; - // Fill data with : -> , except , there are + // Fill data with : -> , except , there are // total 499 hash keys and 10 sortkeys in each . - while (base.size() < 501) { + while (expect_kvs_.size() < 501) { hash_key = random_string(); - if (base.count(hash_key) != 0) { + if (expect_kvs_.count(hash_key) != 0) { continue; } - while (base[hash_key].size() < 10) { + while (expect_kvs_[hash_key].size() < 10) { sort_key = random_string(); - if (base[hash_key].count(sort_key) != 0) { + if (expect_kvs_[hash_key].count(sort_key) != 0) { continue; } value = random_string(); - int ret = client->set(hash_key, sort_key, value); - ASSERT_EQ(PERR_OK, ret) << "Error occurred when set, hash_key=" << hash_key - << ", sort_key=" << sort_key - << ", error=" << client->get_error_string(ret); + ASSERT_EQ(PERR_OK, client_->set(hash_key, sort_key, value)) + << "hash_key=" << hash_key << ", sort_key=" << sort_key; i++; - base[hash_key][sort_key] = value; + expect_kvs_[hash_key][sort_key] = value; } } // 1000 + 5000 kvs - // Fill data with : -> with TTL, except + // Fill data with : -> with TTL, except // and normal kvs, there are total 500 hash keys and 10 sortkeys in each . - while (base.size() < 1001) { + while (expect_kvs_.size() < 1001) { hash_key = random_string(); - if (base.count(hash_key) != 0) { + if (expect_kvs_.count(hash_key) != 0) { continue; } - while (base[hash_key].size() < 10) { + while (expect_kvs_[hash_key].size() < 10) { sort_key = random_string(); - if (base[hash_key].count(sort_key) != 0) { + if (expect_kvs_[hash_key].count(sort_key) != 0) { continue; } value = random_string(); auto expire_ts_seconds = static_cast(ttl_seconds) + utils::epoch_now(); - int ret = client->set(hash_key, sort_key, value, 5000, ttl_seconds, nullptr); - i++; - ASSERT_EQ(PERR_OK, ret) << "Error occurred when set, hash_key=" << hash_key - << ", sort_key=" << sort_key - << ", error=" << client->get_error_string(ret); - i++; - base[hash_key][sort_key] = value; - ttl_base[hash_key][sort_key] = + ASSERT_EQ(PERR_OK, + client_->set(hash_key, sort_key, value, 5000, ttl_seconds, nullptr)) + << "hash_key=" << hash_key << ", sort_key=" << sort_key; + i += 2; + expect_kvs_[hash_key][sort_key] = value; + expect_kvs_with_ttl_[hash_key][sort_key] = std::pair(value, expire_ts_seconds); } } @@ -154,21 +137,25 @@ class scan : public test_util ddebug_f("Database filled with kv count {}.", i); } -public: - std::string expected_hash_key; - std::map> base; - std::map>> ttl_base; +protected: + static const char CCH[]; + static constexpr int ttl_seconds = 24 * 60 * 60; + + char buffer_[256]; + + std::string expected_hash_key_; + std::map> expect_kvs_; + std::map>> + expect_kvs_with_ttl_; }; +const char scan_test::CCH[] = "_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; -TEST_F(scan, OVERALL_COUNT_ONLY) +TEST_F(scan_test, OVERALL_COUNT_ONLY) { - ddebug("TEST OVERALL_SCAN_COUNT_ONLY..."); pegasus_client::scan_options options; options.only_return_count = true; std::vector scanners; - int ret = client->get_unordered_scanners(3, options, scanners); - ASSERT_EQ(0, ret) << "Error occurred when getting scanner. error=" - << client->get_error_string(ret); + ASSERT_EQ(PERR_OK, client_->get_unordered_scanners(3, options, scanners)); ASSERT_LE(scanners.size(), 3); int i = 0; @@ -176,50 +163,48 @@ TEST_F(scan, OVERALL_COUNT_ONLY) for (auto scanner : scanners) { ASSERT_NE(nullptr, scanner); int32_t kv_count; + int ret; while (PERR_OK == (ret = (scanner->next(kv_count)))) { data_count += kv_count; i++; } ASSERT_EQ(PERR_SCAN_COMPLETE, ret) << "Error occurred when scan. error=" - << client->get_error_string(ret); + << client_->get_error_string(ret); delete scanner; } ddebug_f("scan count {}", i); int base_data_count = 0; - for (auto &m : base) { + for (auto &m : expect_kvs_) { base_data_count += m.second.size(); } ASSERT_EQ(base_data_count, data_count); } -TEST_F(scan, ALL_SORT_KEY) +TEST_F(scan_test, ALL_SORT_KEY) { - ddebug("TESTING_HASH_SCAN, ALL SORT_KEYS ...."); pegasus_client::scan_options options; std::map data; pegasus_client::pegasus_scanner *scanner = nullptr; - int ret = client->get_scanner(expected_hash_key, "", "", options, scanner); - ASSERT_EQ(PERR_OK, ret) << "Error occurred when getting scanner. error=" - << client->get_error_string(ret); + ASSERT_EQ(PERR_OK, client_->get_scanner(expected_hash_key_, "", "", options, scanner)); ASSERT_NE(nullptr, scanner); std::string hash_key; std::string sort_key; std::string value; + int ret; while (PERR_OK == (ret = (scanner->next(hash_key, sort_key, value)))) { - ASSERT_EQ(expected_hash_key, hash_key); - check_and_put(data, expected_hash_key, sort_key, value); + ASSERT_EQ(expected_hash_key_, hash_key); + check_and_put(data, expected_hash_key_, sort_key, value); } delete scanner; ASSERT_EQ(PERR_SCAN_COMPLETE, ret) << "Error occurred when scan. error=" - << client->get_error_string(ret); - ASSERT_NO_FATAL_FAILURE(compare(base[expected_hash_key], data, expected_hash_key)); + << client_->get_error_string(ret); + ASSERT_NO_FATAL_FAILURE(compare(expect_kvs_[expected_hash_key_], data, expected_hash_key_)); } -TEST_F(scan, BOUND_INCLUSIVE) +TEST_F(scan_test, BOUND_INCLUSIVE) { - ddebug("TESTING_HASH_SCAN, [start, stop]..."); - auto it1 = base[expected_hash_key].begin(); + auto it1 = expect_kvs_[expected_hash_key_].begin(); std::advance(it1, random() % 500); // [0,499] std::string start = it1->first; @@ -232,30 +217,27 @@ TEST_F(scan, BOUND_INCLUSIVE) options.stop_inclusive = true; std::map data; pegasus_client::pegasus_scanner *scanner = nullptr; - int ret = client->get_scanner(expected_hash_key, start, stop, options, scanner); - ASSERT_EQ(PERR_OK, ret) << "Error occurred when getting scanner. error=" - << client->get_error_string(ret); + ASSERT_EQ(PERR_OK, client_->get_scanner(expected_hash_key_, start, stop, options, scanner)); ASSERT_NE(nullptr, scanner); std::string hash_key; std::string sort_key; std::string value; + int ret; while (PERR_OK == (ret = (scanner->next(hash_key, sort_key, value)))) { - ASSERT_EQ(expected_hash_key, hash_key); - check_and_put(data, expected_hash_key, sort_key, value); + ASSERT_EQ(expected_hash_key_, hash_key); + check_and_put(data, expected_hash_key_, sort_key, value); } delete scanner; - ASSERT_EQ(PERR_SCAN_COMPLETE, ret) << "Error occurred when scan. error=" - << client->get_error_string(ret); + ASSERT_EQ(PERR_SCAN_COMPLETE, ret); ++it2; // to be the 'end' iterator ASSERT_NO_FATAL_FAILURE( - compare(data, std::map(it1, it2), expected_hash_key)); + compare(data, std::map(it1, it2), expected_hash_key_)); } -TEST_F(scan, BOUND_EXCLUSIVE) +TEST_F(scan_test, BOUND_EXCLUSIVE) { - ddebug("TESTING_HASH_SCAN, (start, stop)..."); - auto it1 = base[expected_hash_key].begin(); + auto it1 = expect_kvs_[expected_hash_key_].begin(); std::advance(it1, random() % 500); // [0,499] std::string start = it1->first; @@ -268,30 +250,28 @@ TEST_F(scan, BOUND_EXCLUSIVE) options.stop_inclusive = false; std::map data; pegasus_client::pegasus_scanner *scanner = nullptr; - int ret = client->get_scanner(expected_hash_key, start, stop, options, scanner); - ASSERT_EQ(PERR_OK, ret) << "Error occurred when getting scanner. error=" - << client->get_error_string(ret); + ASSERT_EQ(PERR_OK, client_->get_scanner(expected_hash_key_, start, stop, options, scanner)); ASSERT_NE(nullptr, scanner); std::string hash_key; std::string sort_key; std::string value; + int ret; while (PERR_OK == (ret = (scanner->next(hash_key, sort_key, value)))) { - ASSERT_EQ(expected_hash_key, hash_key); - check_and_put(data, expected_hash_key, sort_key, value); + ASSERT_EQ(expected_hash_key_, hash_key); + check_and_put(data, expected_hash_key_, sort_key, value); } delete scanner; ASSERT_EQ(PERR_SCAN_COMPLETE, ret) << "Error occurred when scan. error=" - << client->get_error_string(ret); + << client_->get_error_string(ret); ++it1; ASSERT_NO_FATAL_FAILURE( - compare(data, std::map(it1, it2), expected_hash_key)); + compare(data, std::map(it1, it2), expected_hash_key_)); } -TEST_F(scan, ONE_POINT) +TEST_F(scan_test, ONE_POINT) { - ddebug("TESTING_HASH_SCAN, [start, start]..."); - auto it1 = base[expected_hash_key].begin(); + auto it1 = expect_kvs_[expected_hash_key_].begin(); std::advance(it1, random() % 800); // [0,799] std::string start = it1->first; @@ -299,29 +279,23 @@ TEST_F(scan, ONE_POINT) options.start_inclusive = true; options.stop_inclusive = true; pegasus_client::pegasus_scanner *scanner = nullptr; - int ret = client->get_scanner(expected_hash_key, start, start, options, scanner); - ASSERT_EQ(PERR_OK, ret) << "Error occurred when getting scanner. error=" - << client->get_error_string(ret); + ASSERT_EQ(PERR_OK, client_->get_scanner(expected_hash_key_, start, start, options, scanner)); ASSERT_NE(nullptr, scanner); std::string hash_key; std::string sort_key; std::string value; - ret = scanner->next(hash_key, sort_key, value); - ASSERT_EQ(PERR_OK, ret) << "Error occurred when scan. error=" << client->get_error_string(ret); - ASSERT_EQ(expected_hash_key, hash_key); + ASSERT_EQ(PERR_OK, scanner->next(hash_key, sort_key, value)); + ASSERT_EQ(expected_hash_key_, hash_key); ASSERT_EQ(start, sort_key); ASSERT_EQ(it1->second, value); - ret = scanner->next(hash_key, sort_key, value); - ASSERT_EQ(PERR_SCAN_COMPLETE, ret) << "Error occurred when scan. error=" - << client->get_error_string(ret); + ASSERT_EQ(PERR_SCAN_COMPLETE, scanner->next(hash_key, sort_key, value)); delete scanner; } -TEST_F(scan, HALF_INCLUSIVE) +TEST_F(scan_test, HALF_INCLUSIVE) { - ddebug("TESTING_HASH_SCAN, [start, start)..."); - auto it1 = base[expected_hash_key].begin(); + auto it1 = expect_kvs_[expected_hash_key_].begin(); std::advance(it1, random() % 800); // [0,799] std::string start = it1->first; @@ -329,24 +303,19 @@ TEST_F(scan, HALF_INCLUSIVE) options.start_inclusive = true; options.stop_inclusive = false; pegasus_client::pegasus_scanner *scanner = nullptr; - int ret = client->get_scanner(expected_hash_key, start, start, options, scanner); - ASSERT_EQ(PERR_OK, ret) << "Error occurred when getting scanner. error=" - << client->get_error_string(ret); + ASSERT_EQ(PERR_OK, client_->get_scanner(expected_hash_key_, start, start, options, scanner)); ASSERT_NE(nullptr, scanner); std::string hash_key; std::string sort_key; std::string value; - ret = scanner->next(hash_key, sort_key, value); - ASSERT_EQ(PERR_SCAN_COMPLETE, ret) << "Error occurred when scan. error=" - << client->get_error_string(ret); + ASSERT_EQ(PERR_SCAN_COMPLETE, scanner->next(hash_key, sort_key, value)); delete scanner; } -TEST_F(scan, VOID_SPAN) +TEST_F(scan_test, VOID_SPAN) { - ddebug("TESTING_HASH_SCAN, [stop, start]..."); - auto it1 = base[expected_hash_key].begin(); + auto it1 = expect_kvs_[expected_hash_key_].begin(); std::advance(it1, random() % 500); // [0,499] std::string start = it1->first; @@ -358,28 +327,21 @@ TEST_F(scan, VOID_SPAN) options.start_inclusive = true; options.stop_inclusive = true; pegasus_client::pegasus_scanner *scanner = nullptr; - int ret = client->get_scanner(expected_hash_key, stop, start, options, scanner); - ASSERT_EQ(PERR_OK, ret) << "Error occurred when getting scanner. error=" - << client->get_error_string(ret); + ASSERT_EQ(PERR_OK, client_->get_scanner(expected_hash_key_, stop, start, options, scanner)); ASSERT_NE(nullptr, scanner); std::string hash_key; std::string sort_key; std::string value; - ret = scanner->next(hash_key, sort_key, value); - ASSERT_EQ(PERR_SCAN_COMPLETE, ret) << "Error occurred when scan. error=" - << client->get_error_string(ret); + ASSERT_EQ(PERR_SCAN_COMPLETE, scanner->next(hash_key, sort_key, value)); delete scanner; } -TEST_F(scan, OVERALL) +TEST_F(scan_test, OVERALL) { - ddebug("TEST OVERALL_SCAN..."); pegasus_client::scan_options options; std::vector scanners; - int ret = client->get_unordered_scanners(3, options, scanners); - ASSERT_EQ(0, ret) << "Error occurred when getting scanner. error=" - << client->get_error_string(ret); + ASSERT_EQ(PERR_OK, client_->get_unordered_scanners(3, options, scanners)); ASSERT_LE(scanners.size(), 3); std::string hash_key; @@ -388,24 +350,23 @@ TEST_F(scan, OVERALL) std::map> data; for (auto scanner : scanners) { ASSERT_NE(nullptr, scanner); + int ret; while (PERR_OK == (ret = (scanner->next(hash_key, sort_key, value)))) { check_and_put(data, hash_key, sort_key, value); } ASSERT_EQ(PERR_SCAN_COMPLETE, ret) << "Error occurred when scan. error=" - << client->get_error_string(ret); + << client_->get_error_string(ret); delete scanner; } - ASSERT_NO_FATAL_FAILURE(compare(base, data)); + ASSERT_NO_FATAL_FAILURE(compare(expect_kvs_, data)); } -TEST_F(scan, REQUEST_EXPIRE_TS) +TEST_F(scan_test, REQUEST_EXPIRE_TS) { pegasus_client::scan_options options; options.return_expire_ts = true; std::vector raw_scanners; - int ret = client->get_unordered_scanners(3, options, raw_scanners); - ASSERT_EQ(pegasus::PERR_OK, ret) << "Error occurred when getting scanner. error=" - << client->get_error_string(ret); + ASSERT_EQ(PERR_OK, client_->get_unordered_scanners(3, options, raw_scanners)); std::vector scanners; for (auto raw_scanner : raw_scanners) { @@ -437,7 +398,7 @@ TEST_F(scan, REQUEST_EXPIRE_TS) split_completed.store(true); } else { ASSERT_TRUE(false) << "Error occurred when scan. error=" - << client->get_error_string(err); + << client_->get_error_string(err); } op_completed.notify(); }); @@ -445,15 +406,15 @@ TEST_F(scan, REQUEST_EXPIRE_TS) } } - ASSERT_NO_FATAL_FAILURE(compare(base, data)); - ASSERT_NO_FATAL_FAILURE(compare(ttl_base, ttl_data)); + ASSERT_NO_FATAL_FAILURE(compare(expect_kvs_, data)); + ASSERT_NO_FATAL_FAILURE(compare(expect_kvs_with_ttl_, ttl_data)); } -TEST_F(scan, ITERATION_TIME_LIMIT) +TEST_F(scan_test, ITERATION_TIME_LIMIT) { // update iteration threshold to 1ms - auto response = ddl_client->set_app_envs( - client->get_app_name(), {ROCKSDB_ITERATION_THRESHOLD_TIME_MS}, {std::to_string(1)}); + auto response = ddl_client_->set_app_envs( + client_->get_app_name(), {ROCKSDB_ITERATION_THRESHOLD_TIME_MS}, {std::to_string(1)}); ASSERT_EQ(true, response.is_ok()); ASSERT_EQ(dsn::ERR_OK, response.get_value().err); // wait envs to be synced. @@ -466,24 +427,19 @@ TEST_F(scan, ITERATION_TIME_LIMIT) while (i < 9000) { sort_key = random_string(); value = random_string(); - int ret = client->set(expected_hash_key, sort_key, value); - ASSERT_EQ(PERR_OK, ret) << "Error occurred when set, hash_key=" << expected_hash_key - << ", sort_key=" << sort_key - << ", error=" << client->get_error_string(ret); + ASSERT_EQ(PERR_OK, client_->set(expected_hash_key_, sort_key, value)) + << "hash_key=" << expected_hash_key_ << ", sort_key=" << sort_key; i++; } // get sortkey count timeout int64_t count = 0; - int ret = client->sortkey_count(expected_hash_key, count); - ASSERT_EQ(0, ret); - ASSERT_EQ(count, -1); + ASSERT_EQ(PERR_OK, client_->sortkey_count(expected_hash_key_, count)); + ASSERT_EQ(-1, count); // set iteration threshold to 100ms - response = ddl_client->set_app_envs( - client->get_app_name(), {ROCKSDB_ITERATION_THRESHOLD_TIME_MS}, {std::to_string(100)}); - ASSERT_EQ(true, response.is_ok()); + response = ddl_client_->set_app_envs( + client_->get_app_name(), {ROCKSDB_ITERATION_THRESHOLD_TIME_MS}, {std::to_string(100)}); + ASSERT_TRUE(response.is_ok()); ASSERT_EQ(dsn::ERR_OK, response.get_value().err); - // wait envs to be synced. - std::this_thread::sleep_for(std::chrono::seconds(30)); } diff --git a/src/test/function_test/base_api_test/test_ttl.cpp b/src/test/function_test/base_api_test/test_ttl.cpp index 9c688dd7a0..afb148410e 100644 --- a/src/test/function_test/base_api_test/test_ttl.cpp +++ b/src/test/function_test/base_api_test/test_ttl.cpp @@ -29,217 +29,187 @@ using namespace ::dsn; using namespace ::pegasus; -std::string ttl_hash_key = "ttl_test_hash_key"; -std::string ttl_test_sort_key_0 = "ttl_test_sort_key_0"; -std::string ttl_test_sort_key_1 = "ttl_test_sort_key_1"; -std::string ttl_test_sort_key_2 = "ttl_test_sort_key_2"; -std::string ttl_test_value_0 = "ttl_test_value_0"; -std::string ttl_test_value_1 = "ttl_test_value_1"; -std::string ttl_test_value_2 = "ttl_test_value_2"; -int default_ttl = 3600; -int specify_ttl = 5; -int sleep_for_expiring = 10; -int sleep_for_envs_effect = 31; -int error_allow = 2; -int timeout = 5000; - -class ttl : public test_util +class ttl_test : public test_util { public: void SetUp() override { test_util::SetUp(); - set_default_ttl(0); + ASSERT_NO_FATAL_FAILURE(set_default_ttl_secs(0)); } - void TearDown() override { ASSERT_EQ(dsn::ERR_OK, ddl_client->drop_app(app_name_, 0)); } + void TearDown() override { ASSERT_EQ(dsn::ERR_OK, ddl_client_->drop_app(app_name_, 0)); } - void set_default_ttl(int ttl) + void set_default_ttl_secs(int32_t ttl) { std::map envs; - ddl_client->get_app_envs(client->get_app_name(), envs); + ASSERT_EQ(ERR_OK, ddl_client_->get_app_envs(client_->get_app_name(), envs)); std::string env = envs[TABLE_LEVEL_DEFAULT_TTL]; if ((env.empty() && ttl != 0) || env != std::to_string(ttl)) { - auto response = ddl_client->set_app_envs( - client->get_app_name(), {TABLE_LEVEL_DEFAULT_TTL}, {std::to_string(ttl)}); + auto response = ddl_client_->set_app_envs( + client_->get_app_name(), {TABLE_LEVEL_DEFAULT_TTL}, {std::to_string(ttl)}); ASSERT_EQ(true, response.is_ok()); ASSERT_EQ(ERR_OK, response.get_value().err); // wait envs to be synced. - std::this_thread::sleep_for(std::chrono::seconds(sleep_for_envs_effect)); + std::this_thread::sleep_for(std::chrono::seconds(sleep_secs_for_envs_effect)); } } + +protected: + const std::string ttl_hash_key = "ttl_test_hash_key"; + const std::string ttl_test_sort_key_0 = "ttl_test_sort_key_0"; + const std::string ttl_test_sort_key_1 = "ttl_test_sort_key_1"; + const std::string ttl_test_sort_key_2 = "ttl_test_sort_key_2"; + const std::string ttl_test_value_0 = "ttl_test_value_0"; + const std::string ttl_test_value_1 = "ttl_test_value_1"; + const std::string ttl_test_value_2 = "ttl_test_value_2"; + + const int32_t default_ttl_secs = 3600; + const int32_t specify_ttl_secs = 5; + const int32_t sleep_for_expiring = 10; + const int32_t sleep_secs_for_envs_effect = 31; + const int32_t error_allow = 2; + const int32_t timeout_ms = 5000; }; -TEST_F(ttl, set_without_default_ttl) +TEST_F(ttl_test, set_without_default_ttl) { // set with ttl - int ret = - client->set(ttl_hash_key, ttl_test_sort_key_1, ttl_test_value_1, timeout, specify_ttl); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ( + PERR_OK, + client_->set( + ttl_hash_key, ttl_test_sort_key_1, ttl_test_value_1, timeout_ms, specify_ttl_secs)); std::string value; - ret = client->get(ttl_hash_key, ttl_test_sort_key_1, value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(ttl_hash_key, ttl_test_sort_key_1, value)); ASSERT_EQ(ttl_test_value_1, value); - int ttl_seconds; - ret = client->ttl(ttl_hash_key, ttl_test_sort_key_1, ttl_seconds); - ASSERT_EQ(PERR_OK, ret); - ASSERT_TRUE(ttl_seconds > specify_ttl - error_allow && ttl_seconds <= specify_ttl) - << "ttl is " << ttl_seconds; + int32_t ttl_seconds; + ASSERT_EQ(PERR_OK, client_->ttl(ttl_hash_key, ttl_test_sort_key_1, ttl_seconds)); + ASSERT_GT(ttl_seconds, specify_ttl_secs - error_allow); + ASSERT_LE(ttl_seconds, specify_ttl_secs); // set without ttl - ret = client->set(ttl_hash_key, ttl_test_sort_key_2, ttl_test_value_2); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->set(ttl_hash_key, ttl_test_sort_key_2, ttl_test_value_2)); - ret = client->get(ttl_hash_key, ttl_test_sort_key_2, value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(ttl_hash_key, ttl_test_sort_key_2, value)); ASSERT_EQ(ttl_test_value_2, value); - ret = client->ttl(ttl_hash_key, ttl_test_sort_key_2, ttl_seconds); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(ttl_seconds, -1) << "ttl is " << ttl_seconds; + ASSERT_EQ(PERR_OK, client_->ttl(ttl_hash_key, ttl_test_sort_key_2, ttl_seconds)); + ASSERT_EQ(ttl_seconds, -1); // sleep a while std::this_thread::sleep_for(std::chrono::seconds(sleep_for_expiring)); // check expired one - ret = client->ttl(ttl_hash_key, ttl_test_sort_key_1, ttl_seconds); - ASSERT_EQ(PERR_NOT_FOUND, ret); - - ret = client->get(ttl_hash_key, ttl_test_sort_key_1, value); - ASSERT_EQ(PERR_NOT_FOUND, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->ttl(ttl_hash_key, ttl_test_sort_key_1, ttl_seconds)); + ASSERT_EQ(PERR_NOT_FOUND, client_->get(ttl_hash_key, ttl_test_sort_key_1, value)); // check exist one - ret = client->ttl(ttl_hash_key, ttl_test_sort_key_2, ttl_seconds); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(ttl_seconds, -1) << "ttl is " << ttl_seconds; + ASSERT_EQ(PERR_OK, client_->ttl(ttl_hash_key, ttl_test_sort_key_2, ttl_seconds)); + ASSERT_EQ(ttl_seconds, -1); - ret = client->get(ttl_hash_key, ttl_test_sort_key_2, value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(ttl_hash_key, ttl_test_sort_key_2, value)); ASSERT_EQ(ttl_test_value_2, value); // trigger a manual compaction - auto response = ddl_client->set_app_envs(client->get_app_name(), - {MANUAL_COMPACT_ONCE_TRIGGER_TIME_KEY}, - {std::to_string(time(nullptr))}); + auto response = ddl_client_->set_app_envs(client_->get_app_name(), + {MANUAL_COMPACT_ONCE_TRIGGER_TIME_KEY}, + {std::to_string(time(nullptr))}); ASSERT_EQ(true, response.is_ok()); ASSERT_EQ(ERR_OK, response.get_value().err); // wait envs to be synced, and manual lcompaction has been finished. - std::this_thread::sleep_for(std::chrono::seconds(sleep_for_envs_effect)); + std::this_thread::sleep_for(std::chrono::seconds(sleep_secs_for_envs_effect)); // check expired one - ret = client->ttl(ttl_hash_key, ttl_test_sort_key_1, ttl_seconds); - ASSERT_EQ(PERR_NOT_FOUND, ret); - - ret = client->get(ttl_hash_key, ttl_test_sort_key_1, value); - ASSERT_EQ(PERR_NOT_FOUND, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->ttl(ttl_hash_key, ttl_test_sort_key_1, ttl_seconds)); + ASSERT_EQ(PERR_NOT_FOUND, client_->get(ttl_hash_key, ttl_test_sort_key_1, value)); // check exist one - ret = client->ttl(ttl_hash_key, ttl_test_sort_key_2, ttl_seconds); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(ttl_seconds, -1) << "ttl is " << ttl_seconds; + ASSERT_EQ(PERR_OK, client_->ttl(ttl_hash_key, ttl_test_sort_key_2, ttl_seconds)); + ASSERT_EQ(ttl_seconds, -1); - ret = client->get(ttl_hash_key, ttl_test_sort_key_2, value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(ttl_hash_key, ttl_test_sort_key_2, value)); ASSERT_EQ(ttl_test_value_2, value); } -TEST_F(ttl, set_with_default_ttl) +TEST_F(ttl_test, set_with_default_ttl) { // set without ttl - int ret = client->set(ttl_hash_key, ttl_test_sort_key_0, ttl_test_value_0); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->set(ttl_hash_key, ttl_test_sort_key_0, ttl_test_value_0)); - // set default_ttl - set_default_ttl(default_ttl); + // set default_ttl_secs + ASSERT_NO_FATAL_FAILURE(set_default_ttl_secs(default_ttl_secs)); // set with ttl - ret = client->set(ttl_hash_key, ttl_test_sort_key_1, ttl_test_value_1, timeout, specify_ttl); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ( + PERR_OK, + client_->set( + ttl_hash_key, ttl_test_sort_key_1, ttl_test_value_1, timeout_ms, specify_ttl_secs)); std::string value; - ret = client->get(ttl_hash_key, ttl_test_sort_key_1, value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(ttl_hash_key, ttl_test_sort_key_1, value)); ASSERT_EQ(ttl_test_value_1, value); - int ttl_seconds; - ret = client->ttl(ttl_hash_key, ttl_test_sort_key_1, ttl_seconds); - ASSERT_EQ(PERR_OK, ret); - ASSERT_TRUE(ttl_seconds >= specify_ttl - error_allow && ttl_seconds <= specify_ttl) - << "ttl is " << ttl_seconds; + int32_t ttl_seconds; + ASSERT_EQ(PERR_OK, client_->ttl(ttl_hash_key, ttl_test_sort_key_1, ttl_seconds)); + + ASSERT_GE(ttl_seconds, specify_ttl_secs - error_allow); + ASSERT_LE(ttl_seconds, specify_ttl_secs); // set without ttl - ret = client->set(ttl_hash_key, ttl_test_sort_key_2, ttl_test_value_2); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->set(ttl_hash_key, ttl_test_sort_key_2, ttl_test_value_2)); - ret = client->get(ttl_hash_key, ttl_test_sort_key_2, value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->get(ttl_hash_key, ttl_test_sort_key_2, value)); ASSERT_EQ(ttl_test_value_2, value); - ret = client->ttl(ttl_hash_key, ttl_test_sort_key_2, ttl_seconds); - ASSERT_EQ(PERR_OK, ret); - ASSERT_TRUE(ttl_seconds >= default_ttl - error_allow && ttl_seconds <= default_ttl) - << "ttl is " << ttl_seconds; + ASSERT_EQ(PERR_OK, client_->ttl(ttl_hash_key, ttl_test_sort_key_2, ttl_seconds)); + ASSERT_GE(ttl_seconds, default_ttl_secs - error_allow); + ASSERT_LE(ttl_seconds, default_ttl_secs); // sleep a while std::this_thread::sleep_for(std::chrono::seconds(sleep_for_expiring)); // check forever one - ret = client->ttl(ttl_hash_key, ttl_test_sort_key_0, ttl_seconds); - ASSERT_EQ(PERR_OK, ret); - ASSERT_EQ(ttl_seconds, -1) << "ttl is " << ttl_seconds; + ASSERT_EQ(PERR_OK, client_->ttl(ttl_hash_key, ttl_test_sort_key_0, ttl_seconds)); + ASSERT_EQ(ttl_seconds, -1); // check expired one - ret = client->ttl(ttl_hash_key, ttl_test_sort_key_1, ttl_seconds); - ASSERT_EQ(PERR_NOT_FOUND, ret); - - ret = client->get(ttl_hash_key, ttl_test_sort_key_1, value); - ASSERT_EQ(PERR_NOT_FOUND, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->ttl(ttl_hash_key, ttl_test_sort_key_1, ttl_seconds)); + ASSERT_EQ(PERR_NOT_FOUND, client_->get(ttl_hash_key, ttl_test_sort_key_1, value)); // check exist one - ret = client->ttl(ttl_hash_key, ttl_test_sort_key_2, ttl_seconds); - ASSERT_EQ(PERR_OK, ret); - ASSERT_TRUE(ttl_seconds >= default_ttl - sleep_for_expiring - error_allow && - ttl_seconds <= default_ttl - sleep_for_expiring + error_allow) - << "ttl is " << ttl_seconds; - - ret = client->get(ttl_hash_key, ttl_test_sort_key_2, value); - ASSERT_EQ(PERR_OK, ret); + ASSERT_EQ(PERR_OK, client_->ttl(ttl_hash_key, ttl_test_sort_key_2, ttl_seconds)); + ASSERT_NEAR(ttl_seconds, default_ttl_secs - sleep_for_expiring, error_allow); + + ASSERT_EQ(PERR_OK, client_->get(ttl_hash_key, ttl_test_sort_key_2, value)); ASSERT_EQ(ttl_test_value_2, value); // trigger a manual compaction - auto response = ddl_client->set_app_envs(client->get_app_name(), - {MANUAL_COMPACT_ONCE_TRIGGER_TIME_KEY}, - {std::to_string(time(nullptr))}); + auto response = ddl_client_->set_app_envs(client_->get_app_name(), + {MANUAL_COMPACT_ONCE_TRIGGER_TIME_KEY}, + {std::to_string(time(nullptr))}); ASSERT_EQ(true, response.is_ok()); ASSERT_EQ(ERR_OK, response.get_value().err); // wait envs to be synced, and manual compaction has been finished. - std::this_thread::sleep_for(std::chrono::seconds(sleep_for_envs_effect)); + std::this_thread::sleep_for(std::chrono::seconds(sleep_secs_for_envs_effect)); // check forever one - ret = client->ttl(ttl_hash_key, ttl_test_sort_key_0, ttl_seconds); - ASSERT_EQ(PERR_OK, ret); - ASSERT_TRUE(ttl_seconds >= default_ttl - sleep_for_envs_effect - error_allow && - ttl_seconds <= default_ttl + error_allow) - << "ttl is " << ttl_seconds; + ASSERT_EQ(PERR_OK, client_->ttl(ttl_hash_key, ttl_test_sort_key_0, ttl_seconds)); + ASSERT_GE(ttl_seconds, default_ttl_secs - sleep_secs_for_envs_effect - error_allow); + ASSERT_LE(ttl_seconds, default_ttl_secs + error_allow); // check expired one - ret = client->ttl(ttl_hash_key, ttl_test_sort_key_1, ttl_seconds); - ASSERT_EQ(PERR_NOT_FOUND, ret); - - ret = client->get(ttl_hash_key, ttl_test_sort_key_1, value); - ASSERT_EQ(PERR_NOT_FOUND, ret); + ASSERT_EQ(PERR_NOT_FOUND, client_->ttl(ttl_hash_key, ttl_test_sort_key_1, ttl_seconds)); + ASSERT_EQ(PERR_NOT_FOUND, client_->get(ttl_hash_key, ttl_test_sort_key_1, value)); // check exist one - ret = client->ttl(ttl_hash_key, ttl_test_sort_key_2, ttl_seconds); - ASSERT_EQ(PERR_OK, ret); - ASSERT_TRUE( - ttl_seconds >= default_ttl - sleep_for_expiring - sleep_for_envs_effect - error_allow && - ttl_seconds <= default_ttl - sleep_for_expiring - sleep_for_envs_effect + error_allow) - << "ttl is " << ttl_seconds; + ASSERT_EQ(PERR_OK, client_->ttl(ttl_hash_key, ttl_test_sort_key_2, ttl_seconds)); + ASSERT_NEAR(ttl_seconds, + default_ttl_secs - sleep_for_expiring - sleep_secs_for_envs_effect, + error_allow); } diff --git a/src/test/function_test/bulk_load_test/test_bulk_load.cpp b/src/test/function_test/bulk_load_test/test_bulk_load.cpp index f31629e8df..f09f12fdb0 100644 --- a/src/test/function_test/bulk_load_test/test_bulk_load.cpp +++ b/src/test/function_test/bulk_load_test/test_bulk_load.cpp @@ -15,20 +15,22 @@ // specific language governing permissions and limitations // under the License. +#include + #include #include #include #include "include/pegasus/client.h" #include "include/pegasus/error.h" -#include #include "base/pegasus_const.h" -#include "test/function_test/utils/global_env.h" +#include "test/function_test/utils/test_util.h" using namespace ::dsn; using namespace ::dsn::replication; using namespace pegasus; +using std::map; using std::string; /// @@ -46,127 +48,74 @@ using std::string; /// hashkey: hashi sortkey: sorti value: newValue i=[0, 1000] /// hashkey: hashkeyj sortkey: sortkeyj value: newValue j=[0, 1000] /// -class bulk_load_test : public testing::Test +class bulk_load_test : public test_util { protected: - static void SetUpTestCase() { ASSERT_TRUE(pegasus_client_factory::initialize("config.ini")); } - - void SetUp() override + bulk_load_test() : test_util(map({{"rocksdb.allow_ingest_behind", "true"}})) { - pegasus_root_dir = global_env::instance()._pegasus_root; - working_root_dir = global_env::instance()._working_dir; - bulk_load_local_root = + TRICKY_CODE_TO_AVOID_LINK_ERROR; + bulk_load_local_root_ = utils::filesystem::path_combine("onebox/block_service/local_service/", LOCAL_ROOT); - - // initialize the clients - std::vector meta_list; - ASSERT_TRUE(replica_helper::load_meta_servers( - meta_list, PEGASUS_CLUSTER_SECTION_NAME.c_str(), "mycluster")); - ASSERT_FALSE(meta_list.empty()); - - ddl_client = std::make_shared(meta_list); - ASSERT_TRUE(ddl_client != nullptr); - - auto ret = ddl_client->drop_app(APP_NAME, 0); - ASSERT_EQ(ERR_OK, ret); - - ret = ddl_client->create_app( - APP_NAME, "pegasus", 8, 3, {{"rocksdb.allow_ingest_behind", "true"}}, false); - ASSERT_EQ(ERR_OK, ret); - int32_t new_app_id; - int32_t partition_count; - std::vector partitions; - ret = ddl_client->list_app(APP_NAME, _app_id, partition_count, partitions); - ASSERT_EQ(ERR_OK, ret); - pg_client = pegasus::pegasus_client_factory::get_client("mycluster", APP_NAME.c_str()); - ASSERT_TRUE(pg_client != nullptr); - - // copy bulk_load files - copy_bulk_load_files(); } - void TearDown() override + void SetUp() override { - chdir(pegasus_root_dir.c_str()); - string cmd = "rm -rf onebox/block_service"; - std::stringstream ss; - int iret = dsn::utils::pipe_execute(cmd.c_str(), ss); - std::cout << cmd << " output: " << ss.str() << std::endl; - ASSERT_EQ(iret, 0); + test_util::SetUp(); + ASSERT_NO_FATAL_FAILURE(copy_bulk_load_files()); } -public: - std::shared_ptr ddl_client; - pegasus::pegasus_client *pg_client; - std::string pegasus_root_dir; - std::string working_root_dir; - std::string bulk_load_local_root; - enum operation + void TearDown() override { - GET, - SET, - DEL, - NO_VALUE - }; + ASSERT_EQ(ERR_OK, ddl_client_->drop_app(app_name_, 0)); + ASSERT_NO_FATAL_FAILURE(run_cmd_from_project_root("rm -rf onebox/block_service")); + } -public: void copy_bulk_load_files() { - chdir(pegasus_root_dir.c_str()); - system("mkdir onebox/block_service"); - system("mkdir onebox/block_service/local_service"); - std::string copy_file_cmd = + ASSERT_NO_FATAL_FAILURE(run_cmd_from_project_root("mkdir -p onebox/block_service")); + ASSERT_NO_FATAL_FAILURE( + run_cmd_from_project_root("mkdir -p onebox/block_service/local_service")); + ASSERT_NO_FATAL_FAILURE(run_cmd_from_project_root( "cp -r src/test/function_test/bulk_load_test/pegasus-bulk-load-function-test-files/" + - LOCAL_ROOT + " onebox/block_service/local_service"; - system(copy_file_cmd.c_str()); - - std::stringstream cmd; - cmd << "echo '{\"app_id\":"; - cmd << _app_id; - cmd << ",\"app_name\":\"temp\",\"partition_count\":8}' > " - "onebox/block_service/local_service/bulk_load_root/cluster/temp/bulk_load_info"; - std::stringstream ss; - int ret = dsn::utils::pipe_execute(cmd.str().c_str(), ss); - std::cout << cmd.str() << " output: " << ss.str() << std::endl; - ASSERT_EQ(ret, 0); + LOCAL_ROOT + " onebox/block_service/local_service")); + string cmd = "echo '{\"app_id\":" + std::to_string(app_id_) + + ",\"app_name\":\"temp\",\"partition_count\":8}' > " + "onebox/block_service/local_service/bulk_load_root/cluster/temp/" + "bulk_load_info"; + ASSERT_NO_FATAL_FAILURE(run_cmd_from_project_root(cmd)); } error_code start_bulk_load(bool ingest_behind = false) { auto err_resp = - ddl_client->start_bulk_load(APP_NAME, CLUSTER, PROVIDER, LOCAL_ROOT, ingest_behind); + ddl_client_->start_bulk_load(app_name_, CLUSTER, PROVIDER, LOCAL_ROOT, ingest_behind); return err_resp.get_value().err; } - void remove_file(const std::string &file_path) + void remove_file(const string &file_path) { - std::string cmd = "rm " + file_path; - system(cmd.c_str()); + ASSERT_NO_FATAL_FAILURE(run_cmd_from_project_root("rm " + file_path)); } void replace_bulk_load_info() { - chdir(pegasus_root_dir.c_str()); - std::string cmd = - "cp -R " - "src/test/function_test/bulk_load_test/pegasus-bulk-load-function-test-files/" - "mock_bulk_load_info/. " + - bulk_load_local_root + "/" + CLUSTER + "/" + APP_NAME + "/"; - system(cmd.c_str()); + string cmd = "cp -R " + "src/test/function_test/bulk_load_test/pegasus-bulk-load-function-test-files/" + "mock_bulk_load_info/. " + + bulk_load_local_root_ + "/" + CLUSTER + "/" + app_name_ + "/"; + ASSERT_NO_FATAL_FAILURE(run_cmd_from_project_root(cmd)); } - void update_allow_ingest_behind(const std::string &allow_ingest_behind) + void update_allow_ingest_behind(const string &allow_ingest_behind) { // update app envs - std::vector keys; + std::vector keys; keys.emplace_back(ROCKSDB_ALLOW_INGEST_BEHIND); - std::vector values; + std::vector values; values.emplace_back(allow_ingest_behind); - auto err_resp = ddl_client->set_app_envs(APP_NAME, keys, values); - ASSERT_EQ(err_resp.get_value().err, ERR_OK); + ASSERT_EQ(ERR_OK, ddl_client_->set_app_envs(app_name_, keys, values).get_value().err); std::cout << "sleep 31s to wait app_envs update" << std::endl; std::this_thread::sleep_for(std::chrono::seconds(31)); - chdir(working_root_dir.c_str()); } bulk_load_status::type wait_bulk_load_finish(int64_t seconds) @@ -182,7 +131,7 @@ class bulk_load_test : public testing::Test std::cout << "sleep " << sleep_time << "s to query bulk status" << std::endl; std::this_thread::sleep_for(std::chrono::seconds(sleep_time)); - auto resp = ddl_client->query_bulk_load(APP_NAME).get_value(); + auto resp = ddl_client_->query_bulk_load(app_name_).get_value(); err = resp.err; if (err == ERR_OK) { last_status = resp.app_status; @@ -197,45 +146,48 @@ class bulk_load_test : public testing::Test ASSERT_NO_FATAL_FAILURE(verify_data(HASHKEY_PREFIX, SORTKEY_PREFIX)); } - void verify_data(const std::string &hashkey_prefix, const std::string &sortkey_prefix) + void verify_data(const string &hashkey_prefix, const string &sortkey_prefix) { - const std::string &expected_value = VALUE; + const string &expected_value = VALUE; for (int i = 0; i < COUNT; ++i) { - std::string hash_key = hashkey_prefix + std::to_string(i); + string hash_key = hashkey_prefix + std::to_string(i); for (int j = 0; j < COUNT; ++j) { - std::string sort_key = sortkey_prefix + std::to_string(j); - std::string act_value; - int ret = pg_client->get(hash_key, sort_key, act_value); - ASSERT_EQ(PERR_OK, ret) << "Failed to get [" << hash_key << "," << sort_key - << "], error is " << ret << std::endl; - ASSERT_EQ(expected_value, act_value) - << "get [" << hash_key << "," << sort_key << "], value = " << act_value - << ", but expected_value = " << expected_value << std::endl; + string sort_key = sortkey_prefix + std::to_string(j); + string act_value; + ASSERT_EQ(PERR_OK, client_->get(hash_key, sort_key, act_value)) << hash_key << "," + << sort_key; + ASSERT_EQ(expected_value, act_value) << hash_key << "," << sort_key; } } } - void operate_data(bulk_load_test::operation op, const std::string &value, int count) + enum operation + { + GET, + SET, + DEL, + NO_VALUE + }; + void operate_data(bulk_load_test::operation op, const string &value, int count) { for (int i = 0; i < count; ++i) { - std::string hash_key = HASHKEY_PREFIX + std::to_string(i); - std::string sort_key = SORTKEY_PREFIX + std::to_string(i); + string hash_key = HASHKEY_PREFIX + std::to_string(i); + string sort_key = SORTKEY_PREFIX + std::to_string(i); switch (op) { case bulk_load_test::operation::GET: { - std::string act_value; - int ret = pg_client->get(hash_key, sort_key, act_value); - ASSERT_EQ(ret, PERR_OK); - ASSERT_EQ(act_value, value); + string act_value; + ASSERT_EQ(PERR_OK, client_->get(hash_key, sort_key, act_value)); + ASSERT_EQ(value, act_value); } break; case bulk_load_test::operation::DEL: { - ASSERT_EQ(pg_client->del(hash_key, sort_key), PERR_OK); + ASSERT_EQ(PERR_OK, client_->del(hash_key, sort_key)); } break; case bulk_load_test::operation::SET: { - ASSERT_EQ(pg_client->set(hash_key, sort_key, value), PERR_OK); + ASSERT_EQ(PERR_OK, client_->set(hash_key, sort_key, value)); } break; case bulk_load_test::operation::NO_VALUE: { - std::string act_value; - ASSERT_EQ(pg_client->get(hash_key, sort_key, act_value), PERR_NOT_FOUND); + string act_value; + ASSERT_EQ(PERR_NOT_FOUND, client_->get(hash_key, sort_key, act_value)); } break; default: ASSERT_TRUE(false); @@ -244,17 +196,17 @@ class bulk_load_test : public testing::Test } } - const std::string LOCAL_ROOT = "bulk_load_root"; - const std::string CLUSTER = "cluster"; - const std::string APP_NAME = "temp"; - const std::string PROVIDER = "local_service"; +protected: + string bulk_load_local_root_; - const std::string HASHKEY_PREFIX = "hash"; - const std::string SORTKEY_PREFIX = "sort"; - const std::string VALUE = "newValue"; - const int32_t COUNT = 1000; + const string LOCAL_ROOT = "bulk_load_root"; + const string CLUSTER = "cluster"; + const string PROVIDER = "local_service"; - int32_t _app_id = 0; + const string HASHKEY_PREFIX = "hash"; + const string SORTKEY_PREFIX = "sort"; + const string VALUE = "newValue"; + const int32_t COUNT = 1000; }; /// @@ -264,12 +216,13 @@ class bulk_load_test : public testing::Test TEST_F(bulk_load_test, bulk_load_test_failed) { // bulk load failed because `bulk_load_info` file is missing - remove_file(bulk_load_local_root + "/" + CLUSTER + "/" + APP_NAME + "/bulk_load_info"); - ASSERT_EQ(start_bulk_load(), ERR_OBJECT_NOT_FOUND); + ASSERT_NO_FATAL_FAILURE( + remove_file(bulk_load_local_root_ + "/" + CLUSTER + "/" + app_name_ + "/bulk_load_info")); + ASSERT_EQ(ERR_OBJECT_NOT_FOUND, start_bulk_load()); // bulk load failed because `bulk_load_info` file inconsistent with current app_info - replace_bulk_load_info(); - ASSERT_EQ(start_bulk_load(), ERR_INCONSISTENT_STATE); + ASSERT_NO_FATAL_FAILURE(replace_bulk_load_info()); + ASSERT_EQ(ERR_INCONSISTENT_STATE, start_bulk_load()); } /// @@ -282,33 +235,34 @@ TEST_F(bulk_load_test, bulk_load_test_failed) TEST_F(bulk_load_test, bulk_load_tests) { // bulk load failed because partition[0] `bulk_load_metadata` file is missing - remove_file(bulk_load_local_root + "/" + CLUSTER + "/" + APP_NAME + "/0/bulk_load_metadata"); - ASSERT_EQ(start_bulk_load(), ERR_OK); + ASSERT_NO_FATAL_FAILURE(remove_file(bulk_load_local_root_ + "/" + CLUSTER + "/" + app_name_ + + "/0/bulk_load_metadata")); + ASSERT_EQ(ERR_OK, start_bulk_load()); // bulk load will get FAILED - ASSERT_EQ(wait_bulk_load_finish(300), bulk_load_status::BLS_FAILED); + ASSERT_EQ(bulk_load_status::BLS_FAILED, wait_bulk_load_finish(300)); // recover complete files - copy_bulk_load_files(); + ASSERT_NO_FATAL_FAILURE(copy_bulk_load_files()); // write old data - operate_data(operation::SET, "oldValue", 10); - operate_data(operation::GET, "oldValue", 10); + ASSERT_NO_FATAL_FAILURE(operate_data(operation::SET, "oldValue", 10)); + ASSERT_NO_FATAL_FAILURE(operate_data(operation::GET, "oldValue", 10)); - ASSERT_EQ(start_bulk_load(), ERR_OK); - ASSERT_EQ(wait_bulk_load_finish(300), bulk_load_status::BLS_SUCCEED); + ASSERT_EQ(ERR_OK, start_bulk_load()); + ASSERT_EQ(bulk_load_status::BLS_SUCCEED, wait_bulk_load_finish(300)); std::cout << "Start to verify data..." << std::endl; - verify_bulk_load_data(); + ASSERT_NO_FATAL_FAILURE(verify_bulk_load_data()); // value overide by bulk_loaded_data - operate_data(operation::GET, VALUE, 10); + ASSERT_NO_FATAL_FAILURE(operate_data(operation::GET, VALUE, 10)); // write data after bulk load succeed - operate_data(operation::SET, "valueAfterBulkLoad", 20); - operate_data(operation::GET, "valueAfterBulkLoad", 20); + ASSERT_NO_FATAL_FAILURE(operate_data(operation::SET, "valueAfterBulkLoad", 20)); + ASSERT_NO_FATAL_FAILURE(operate_data(operation::GET, "valueAfterBulkLoad", 20)); // del data after bulk load succeed - operate_data(operation::DEL, "", 15); - operate_data(operation::NO_VALUE, "", 15); + ASSERT_NO_FATAL_FAILURE(operate_data(operation::DEL, "", 15)); + ASSERT_NO_FATAL_FAILURE(operate_data(operation::NO_VALUE, "", 15)); } /// @@ -320,30 +274,30 @@ TEST_F(bulk_load_test, bulk_load_tests) /// TEST_F(bulk_load_test, bulk_load_ingest_behind_tests) { - update_allow_ingest_behind("false"); + ASSERT_NO_FATAL_FAILURE(update_allow_ingest_behind("false")); // app envs allow_ingest_behind = false, request ingest_behind = true - ASSERT_EQ(start_bulk_load(true), ERR_INCONSISTENT_STATE); + ASSERT_EQ(ERR_INCONSISTENT_STATE, start_bulk_load(true)); - update_allow_ingest_behind("true"); + ASSERT_NO_FATAL_FAILURE(update_allow_ingest_behind("true")); // write old data - operate_data(operation::SET, "oldValue", 10); - operate_data(operation::GET, "oldValue", 10); + ASSERT_NO_FATAL_FAILURE(operate_data(operation::SET, "oldValue", 10)); + ASSERT_NO_FATAL_FAILURE(operate_data(operation::GET, "oldValue", 10)); - ASSERT_EQ(start_bulk_load(true), ERR_OK); - ASSERT_EQ(wait_bulk_load_finish(300), bulk_load_status::BLS_SUCCEED); + ASSERT_EQ(ERR_OK, start_bulk_load(true)); + ASSERT_EQ(bulk_load_status::BLS_SUCCEED, wait_bulk_load_finish(300)); std::cout << "Start to verify data..." << std::endl; // value overide by bulk_loaded_data - operate_data(operation::GET, "oldValue", 10); + ASSERT_NO_FATAL_FAILURE(operate_data(operation::GET, "oldValue", 10)); ASSERT_NO_FATAL_FAILURE(verify_data("hashkey", "sortkey")); // write data after bulk load succeed - operate_data(operation::SET, "valueAfterBulkLoad", 20); - operate_data(operation::GET, "valueAfterBulkLoad", 20); + ASSERT_NO_FATAL_FAILURE(operate_data(operation::SET, "valueAfterBulkLoad", 20)); + ASSERT_NO_FATAL_FAILURE(operate_data(operation::GET, "valueAfterBulkLoad", 20)); // del data after bulk load succeed - operate_data(operation::DEL, "", 15); - operate_data(operation::NO_VALUE, "", 15); + ASSERT_NO_FATAL_FAILURE(operate_data(operation::DEL, "", 15)); + ASSERT_NO_FATAL_FAILURE(operate_data(operation::NO_VALUE, "", 15)); } diff --git a/src/test/function_test/detect_hotspot_test/test_detect_hotspot.cpp b/src/test/function_test/detect_hotspot_test/test_detect_hotspot.cpp index 1b79524d97..b1c56e8a65 100644 --- a/src/test/function_test/detect_hotspot_test/test_detect_hotspot.cpp +++ b/src/test/function_test/detect_hotspot_test/test_detect_hotspot.cpp @@ -17,62 +17,47 @@ * under the License. */ -#include +#include -#include +#include #include +#include + #include "include/pegasus/client.h" -#include +#include "include/pegasus/error.h" #include "base/pegasus_const.h" #include "test/function_test/utils/utils.h" +#include "test/function_test/utils/test_util.h" using namespace ::dsn; -using namespace ::dsn::replication; using namespace pegasus; -using std::string; -enum detection_type +class detect_hotspot_test : public test_util { - read_data, - write_data -}; -enum key_type -{ - random_dataset, - hotspot_dataset -}; +protected: + const int64_t max_detection_second = 100; + const int64_t warmup_second = 30; -class detect_hotspot_test : public testing::Test -{ -public: - static void SetUpTestCase() { ASSERT_TRUE(pegasus_client_factory::initialize("config.ini")); } +protected: + enum detection_type + { + read_data, + write_data + }; + enum key_type + { + random_dataset, + hotspot_dataset + }; void SetUp() override { - string cmd = "curl 'localhost:34101/updateConfig?enable_detect_hotkey=true'"; - std::stringstream ss; - ASSERT_EQ(0, dsn::utils::pipe_execute(cmd.c_str(), ss)) << cmd << " output: " << ss.str() - << std::endl; - - std::vector meta_list; - ASSERT_TRUE(replica_helper::load_meta_servers( - meta_list, PEGASUS_CLUSTER_SECTION_NAME.c_str(), "single_master_cluster")); - ASSERT_FALSE(meta_list.empty()); - - ddl_client_ = std::make_shared(meta_list); - ASSERT_TRUE(ddl_client_ != nullptr); - - ASSERT_EQ(dsn::ERR_OK, - ddl_client_->create_app(app_name.c_str(), "pegasus", 8, 3, {}, false)); + TRICKY_CODE_TO_AVOID_LINK_ERROR; + test_util::SetUp(); - pg_client = - pegasus::pegasus_client_factory::get_client("single_master_cluster", app_name.c_str()); - ASSERT_TRUE(pg_client != nullptr); - - int32_t partition_count = 0; - ASSERT_EQ(dsn::ERR_OK, - ddl_client_->list_app(app_name, app_id, partition_count, partitions)); + ASSERT_NO_FATAL_FAILURE(run_cmd_from_project_root( + "curl 'localhost:34101/updateConfig?enable_detect_hotkey=true'")); } void generate_dataset(int64_t time_duration, detection_type dt, key_type kt) @@ -84,10 +69,10 @@ class detect_hotspot_test : public testing::Test std::string s_key = "sortkey_" + index; std::string value = "value_" + index; if (dt == detection_type::write_data) { - ASSERT_EQ(PERR_OK, pg_client->set(h_key, s_key, value)); + ASSERT_EQ(PERR_OK, client_->set(h_key, s_key, value)); } else { - int err = pg_client->get(h_key, s_key, value); - ASSERT_TRUE(err == PERR_OK || err == PERR_NOT_FOUND); + int err = client_->get(h_key, s_key, value); + ASSERT_TRUE(err == PERR_OK || err == PERR_NOT_FOUND) << err; } } } @@ -103,12 +88,11 @@ class detect_hotspot_test : public testing::Test req.action = dsn::replication::detect_action::QUERY; bool find_hotkey = false; - int partition_index; dsn::replication::detect_hotkey_response resp; - for (partition_index = 0; partition_index < partitions.size(); partition_index++) { - req.pid = dsn::gpid(app_id, partition_index); + for (int partition_index = 0; partition_index < partitions_.size(); partition_index++) { + req.pid = dsn::gpid(app_id_, partition_index); ASSERT_EQ(dsn::ERR_OK, - ddl_client_->detect_hotkey(partitions[partition_index].primary, req, resp)); + ddl_client_->detect_hotkey(partitions_[partition_index].primary, req, resp)); if (!resp.hotkey_result.empty()) { find_hotkey = true; break; @@ -126,17 +110,17 @@ class detect_hotspot_test : public testing::Test sleep(15); req.action = dsn::replication::detect_action::STOP; - for (partition_index = 0; partition_index < partitions.size(); partition_index++) { + for (int partition_index = 0; partition_index < partitions_.size(); partition_index++) { ASSERT_EQ(dsn::ERR_OK, - ddl_client_->detect_hotkey(partitions[partition_index].primary, req, resp)); + ddl_client_->detect_hotkey(partitions_[partition_index].primary, req, resp)); ASSERT_EQ(dsn::ERR_OK, resp.err); } req.action = dsn::replication::detect_action::QUERY; - for (partition_index = 0; partition_index < partitions.size(); partition_index++) { - req.pid = dsn::gpid(app_id, partition_index); + for (int partition_index = 0; partition_index < partitions_.size(); partition_index++) { + req.pid = dsn::gpid(app_id_, partition_index); ASSERT_EQ(dsn::ERR_OK, - ddl_client_->detect_hotkey(partitions[partition_index].primary, req, resp)); + ddl_client_->detect_hotkey(partitions_[partition_index].primary, req, resp)); ASSERT_EQ("Can't get hotkey now, now state: hotkey_collector_state::STOPPED", resp.err_hint); } @@ -164,16 +148,16 @@ class detect_hotspot_test : public testing::Test dsn::replication::detect_hotkey_request req; req.type = dsn::replication::hotkey_type::type::WRITE; req.action = dsn::replication::detect_action::START; - req.pid = dsn::gpid(app_id, target_partition); + req.pid = dsn::gpid(app_id_, target_partition); dsn::replication::detect_hotkey_response resp; ASSERT_EQ(dsn::ERR_OK, - ddl_client_->detect_hotkey(partitions[target_partition].primary, req, resp)); + ddl_client_->detect_hotkey(partitions_[target_partition].primary, req, resp)); ASSERT_EQ(dsn::ERR_OK, resp.err); req.action = dsn::replication::detect_action::QUERY; ASSERT_EQ(dsn::ERR_OK, - ddl_client_->detect_hotkey(partitions[target_partition].primary, req, resp)); + ddl_client_->detect_hotkey(partitions_[target_partition].primary, req, resp)); ASSERT_EQ("Can't get hotkey now, now state: hotkey_collector_state::COARSE_DETECTING", resp.err_hint); @@ -184,7 +168,7 @@ class detect_hotspot_test : public testing::Test req.action = dsn::replication::detect_action::QUERY; ASSERT_EQ(dsn::ERR_OK, - ddl_client_->detect_hotkey(partitions[target_partition].primary, req, resp)); + ddl_client_->detect_hotkey(partitions_[target_partition].primary, req, resp)); ASSERT_EQ("Can't get hotkey now, now state: hotkey_collector_state::STOPPED", resp.err_hint); } @@ -204,17 +188,9 @@ class detect_hotspot_test : public testing::Test max_detection_second, detection_type::read_data, key_type::random_dataset)); ASSERT_NO_FATAL_FAILURE(get_result(detection_type::read_data, key_type::random_dataset)); } - - const std::string app_name = "hotspot_test"; - const int64_t max_detection_second = 100; - const int64_t warmup_second = 30; - int32_t app_id; - std::vector partitions; - std::shared_ptr ddl_client_; - pegasus::pegasus_client *pg_client; }; -TEST_F(detect_hotspot_test, write_hotspot_data) +TEST_F(detect_hotspot_test, write_hotspot_data_test) { std::cout << "start testing write hotspot data..." << std::endl; ASSERT_NO_FATAL_FAILURE(write_hotspot_data()); diff --git a/src/test/function_test/partition_split_test/test_split.cpp b/src/test/function_test/partition_split_test/test_split.cpp index 48fa464e7e..7456b81300 100644 --- a/src/test/function_test/partition_split_test/test_split.cpp +++ b/src/test/function_test/partition_split_test/test_split.cpp @@ -22,56 +22,43 @@ #include #include "base/pegasus_const.h" +#include "test/function_test/utils/test_util.h" using namespace dsn; using namespace dsn::replication; using namespace pegasus; -class partition_split_test : public testing::Test +class partition_split_test : public test_util { public: - static void SetUpTestCase() { ASSERT_TRUE(pegasus_client_factory::initialize("config.ini")); } + partition_split_test() : test_util() + { + TRICKY_CODE_TO_AVOID_LINK_ERROR; + static int32_t test_case = 0; + app_name_ = table_name_prefix + std::to_string(test_case++); + } void SetUp() override { - test_case++; - table_name = table_name_prefix + std::to_string(test_case); - std::vector meta_list; - ASSERT_TRUE(replica_helper::load_meta_servers( - meta_list, PEGASUS_CLUSTER_SECTION_NAME.c_str(), "mycluster")); - ASSERT_FALSE(meta_list.empty()); - - ddl_client = std::make_shared(meta_list); - ASSERT_TRUE(ddl_client != nullptr); - error_code error = - ddl_client->create_app(table_name, "pegasus", partition_count, 3, {}, false); - ASSERT_EQ(ERR_OK, error); - - pg_client = pegasus_client_factory::get_client("mycluster", table_name.c_str()); - ASSERT_TRUE(pg_client != nullptr); + test_util::SetUp(); ASSERT_NO_FATAL_FAILURE(write_data_before_split()); - - auto err_resp = ddl_client->start_partition_split(table_name, partition_count * 2); - ASSERT_EQ(ERR_OK, err_resp.get_value().err); - std::cout << "Table(" << table_name << ") start partition split succeed" << std::endl; + ASSERT_EQ( + ERR_OK, + ddl_client_->start_partition_split(app_name_, partition_count_ * 2).get_value().err); } - void TearDown() override - { - count_during_split = 0; - expected.clear(); - ASSERT_EQ(ERR_OK, ddl_client->drop_app(table_name, 0)); - } + void TearDown() override { ASSERT_EQ(ERR_OK, ddl_client_->drop_app(app_name_, 0)); } bool is_split_finished() { - auto err_resp = ddl_client->query_partition_split(table_name); + auto err_resp = ddl_client_->query_partition_split(app_name_); + auto status_map = err_resp.get_value().status; return err_resp.get_value().err == ERR_INVALID_STATE; } bool check_partition_split_status(int32_t target_pidx, split_status::type target_status) { - auto err_resp = ddl_client->query_partition_split(table_name); + auto err_resp = ddl_client_->query_partition_split(app_name_); auto status_map = err_resp.get_value().status; // is_single_partition if (target_pidx > 0) { @@ -81,12 +68,12 @@ class partition_split_test : public testing::Test // all partitions int32_t finish_count = 0; - for (auto i = 0; i < partition_count; ++i) { + for (auto i = 0; i < partition_count_; ++i) { if (status_map.find(i) != status_map.end() && status_map[i] == target_status) { finish_count++; } } - return finish_count == partition_count; + return finish_count == partition_count_; } error_code control_partition_split(split_control_type::type type, @@ -94,19 +81,17 @@ class partition_split_test : public testing::Test int32_t old_partition_count = 0) { auto err_resp = - ddl_client->control_partition_split(table_name, type, parent_pidx, old_partition_count); + ddl_client_->control_partition_split(app_name_, type, parent_pidx, old_partition_count); return err_resp.get_value().err; } void write_data_before_split() { - std::cout << "Write data before partition split......" << std::endl; for (int32_t i = 0; i < dataset_count; ++i) { std::string hash_key = dataset_hashkey_prefix + std::to_string(i); std::string sort_key = dataset_sortkey_prefix + std::to_string(i); - auto ret = pg_client->set(hash_key, sort_key, data_value); - ASSERT_EQ(ret, PERR_OK) << ret; - expected[hash_key][sort_key] = data_value; + ASSERT_EQ(PERR_OK, client_->set(hash_key, sort_key, data_value)); + expected_kvs_[hash_key][sort_key] = data_value; } } @@ -117,13 +102,13 @@ class partition_split_test : public testing::Test void write_data_during_split() { - std::string hash = splitting_hashkey_prefix + std::to_string(count_during_split); - std::string sort = splitting_sortkey_prefix + std::to_string(count_during_split); - auto ret = pg_client->set(hash, sort, data_value); + std::string hash = splitting_hashkey_prefix + std::to_string(count_during_split_); + std::string sort = splitting_sortkey_prefix + std::to_string(count_during_split_); + auto ret = client_->set(hash, sort, data_value); ASSERT_TRUE(is_valid(ret)) << ret << ", " << hash << " : " << sort; if (ret == PERR_OK) { - expected[hash][sort] = data_value; - count_during_split++; + expected_kvs_[hash][sort] = data_value; + count_during_split_++; } } @@ -132,22 +117,22 @@ class partition_split_test : public testing::Test auto index = rand() % dataset_count; std::string hash = dataset_hashkey_prefix + std::to_string(index); std::string sort = dataset_sortkey_prefix + std::to_string(index); - std::string expected_value; - auto ret = pg_client->get(hash, sort, expected_value); - dassert(is_valid(ret), "ret"); + std::string actual_value; + auto ret = client_->get(hash, sort, actual_value); + ASSERT_TRUE(is_valid(ret)) << ret << ", " << hash << " : " << sort; if (ret == PERR_OK) { - ASSERT_EQ(expected_value, data_value); + ASSERT_EQ(data_value, actual_value); } } void verify_data_after_split() { - std::cout << "Verify data(count=" << dataset_count + count_during_split + std::cout << "Verify data(count=" << dataset_count + count_during_split_ << ") after partition split......" << std::endl; ASSERT_NO_FATAL_FAILURE( verify_data(dataset_hashkey_prefix, dataset_sortkey_prefix, dataset_count)); ASSERT_NO_FATAL_FAILURE( - verify_data(splitting_hashkey_prefix, splitting_sortkey_prefix, count_during_split)); + verify_data(splitting_hashkey_prefix, splitting_sortkey_prefix, count_during_split_)); } void verify_data(const std::string &hashkey_prefix, @@ -158,8 +143,8 @@ class partition_split_test : public testing::Test std::string hash_key = hashkey_prefix + std::to_string(i); std::string sort_key = sortkey_prefix + std::to_string(i); std::string value; - ASSERT_EQ(PERR_OK, pg_client->get(hash_key, sort_key, value)); - ASSERT_EQ(expected[hash_key][sort_key], value); + ASSERT_EQ(PERR_OK, client_->get(hash_key, sort_key, value)); + ASSERT_EQ(expected_kvs_[hash_key][sort_key], value); } } @@ -171,15 +156,15 @@ class partition_split_test : public testing::Test pegasus_client::pegasus_scanner *scanner = nullptr; pegasus_client::scan_options options; - auto ret = pg_client->get_scanner( + auto ret = client_->get_scanner( dataset_hashkey_prefix + std::to_string(count), "", "", options, scanner); - ASSERT_TRUE(is_valid(ret)); + ASSERT_TRUE(is_valid(ret)) << ret; if (ret == PERR_OK) { std::string hash_key; std::string sort_key; - std::string expected_value; - while (scanner->next(hash_key, sort_key, expected_value) == 0) { - ASSERT_EQ(expected[hash_key][sort_key], expected_value); + std::string actual_value; + while (scanner->next(hash_key, sort_key, actual_value) == 0) { + ASSERT_EQ(expected_kvs_[hash_key][sort_key], actual_value); } } delete scanner; @@ -191,44 +176,38 @@ class partition_split_test : public testing::Test std::vector scanners; pegasus_client::scan_options options; options.timeout_ms = 30000; - auto ret = pg_client->get_unordered_scanners(10000, options, scanners); - ASSERT_EQ(ret, PERR_OK); + ASSERT_EQ(PERR_OK, client_->get_unordered_scanners(10000, options, scanners)); int32_t count = 0; for (auto i = 0; i < scanners.size(); i++) { std::string hash_key; std::string sort_key; - std::string expected_value; + std::string actual_value; pegasus_client::internal_info info; pegasus_client::pegasus_scanner *scanner = scanners[i]; - while (scanner->next(hash_key, sort_key, expected_value, &info) == 0) { - ASSERT_EQ(expected[hash_key][sort_key], expected_value); + while (scanner->next(hash_key, sort_key, actual_value, &info) == 0) { + ASSERT_EQ(expected_kvs_[hash_key][sort_key], actual_value); count++; } } - ASSERT_EQ(count, dataset_count); + ASSERT_EQ(dataset_count, count); for (auto scanner : scanners) { delete scanner; } } public: - std::shared_ptr ddl_client; - pegasus_client *pg_client; - std::unordered_map> expected; - const int32_t partition_count = 4; - const int32_t dataset_count = 1000; const std::string table_name_prefix = "split_table_test_"; - std::string table_name; const std::string dataset_hashkey_prefix = "hashkey"; const std::string dataset_sortkey_prefix = "sortkey"; const std::string splitting_hashkey_prefix = "keyh_"; const std::string splitting_sortkey_prefix = "keys_"; const std::string data_value = "vaule"; - int32_t count_during_split = 0; - static int32_t test_case; -}; -int32_t partition_split_test::test_case = 0; + const int32_t dataset_count = 1000; + + std::unordered_map> expected_kvs_; + int32_t count_during_split_ = 0; +}; TEST_F(partition_split_test, split_with_write) { @@ -272,22 +251,20 @@ TEST_F(partition_split_test, pause_split) bool already_pause = false, already_restart = false; int32_t target_partition = 2, count = 30; do { - write_data_during_split(); + ASSERT_NO_FATAL_FAILURE(write_data_during_split()); // pause target partition split if (!already_pause && check_partition_split_status(-1, split_status::SPLITTING)) { - error_code error = control_partition_split(split_control_type::PAUSE, target_partition); - ASSERT_EQ(ERR_OK, error); - std::cout << "Table(" << table_name << ") pause partition[" << target_partition + ASSERT_EQ(ERR_OK, control_partition_split(split_control_type::PAUSE, target_partition)); + std::cout << "Table(" << app_name_ << ") pause partition[" << target_partition << "] split succeed" << std::endl; already_pause = true; } // restart target partition split - if (!already_restart && count_during_split >= count && + if (!already_restart && count_during_split_ >= count && check_partition_split_status(target_partition, split_status::PAUSED)) { - error_code error = - control_partition_split(split_control_type::RESTART, target_partition); - ASSERT_EQ(ERR_OK, error); - std::cout << "Table(" << table_name << ") restart split partition[" << target_partition + ASSERT_EQ(ERR_OK, + control_partition_split(split_control_type::RESTART, target_partition)); + std::cout << "Table(" << app_name_ << ") restart split partition[" << target_partition << "] succeed" << std::endl; already_restart = true; } @@ -302,14 +279,12 @@ TEST_F(partition_split_test, cancel_split) { // pause partition split bool already_pause = false; - error_code error = ERR_OK; do { - write_data_during_split(); + ASSERT_NO_FATAL_FAILURE(write_data_during_split()); // pause all partition split if (!already_pause && check_partition_split_status(-1, split_status::SPLITTING)) { - error = control_partition_split(split_control_type::PAUSE, -1); - ASSERT_EQ(ERR_OK, error); - std::cout << "Table(" << table_name << ") pause all partitions split succeed" + ASSERT_EQ(ERR_OK, control_partition_split(split_control_type::PAUSE, -1)); + std::cout << "Table(" << app_name_ << ") pause all partitions split succeed" << std::endl; already_pause = true; } @@ -317,14 +292,14 @@ TEST_F(partition_split_test, cancel_split) } while (!check_partition_split_status(-1, split_status::PAUSED)); // cancel partition split - error = control_partition_split(split_control_type::CANCEL, -1, partition_count); - ASSERT_EQ(ERR_OK, error); - std::cout << "Table(" << table_name << ") cancel partitions split succeed" << std::endl; + ASSERT_EQ(ERR_OK, control_partition_split(split_control_type::CANCEL, -1, partition_count_)); + std::cout << "Table(" << app_name_ << ") cancel partitions split succeed" << std::endl; // write data during cancel partition split do { - write_data_during_split(); + ASSERT_NO_FATAL_FAILURE(write_data_during_split()); std::this_thread::sleep_for(std::chrono::seconds(1)); } while (!is_split_finished()); + std::cout << "Partition split succeed" << std::endl; ASSERT_NO_FATAL_FAILURE(verify_data_after_split()); } diff --git a/src/test/function_test/recovery_test/test_recovery.cpp b/src/test/function_test/recovery_test/test_recovery.cpp index 7c67ee4f5d..5cad0510ad 100644 --- a/src/test/function_test/recovery_test/test_recovery.cpp +++ b/src/test/function_test/recovery_test/test_recovery.cpp @@ -23,70 +23,48 @@ #include #include #include -#include + +#include +#include #include #include #include #include "include/pegasus/client.h" -#include #include "base/pegasus_const.h" #include "test/function_test/utils/global_env.h" +#include "test/function_test/utils/test_util.h" using namespace dsn::replication; using namespace pegasus; -class recovery_test : public testing::Test +// TODO(yingchun): add a check for it, get config by curl +// NOTE: THREAD_POOL_META_SERVER worker count should be greater than 1 +// This function test update 'distributed_lock_service_type' to +// 'distributed_lock_service_simple', which executes in threadpool THREAD_POOL_META_SERVER +// As a result, failure detection lock executes in this pool +// if worker count = 1, it will lead to ERR_TIMEOUT when execute 'ddl_client_->do_recovery' +class recovery_test : public test_util { protected: - static void SetUpTestCase() { ASSERT_TRUE(pegasus_client_factory::initialize("config.ini")); } - void SetUp() override { - // NOTE: THREAD_POOL_META_SERVER worker count should be greater than 1 - // This function test update 'distributed_lock_service_type' to - // 'distributed_lock_service_simple', which executes in threadpool THREAD_POOL_META_SERVER - // As a result, failure detection lock executes in this pool - // if worker count = 1, it will lead to ERR_TIMEOUT when execute 'ddl_client->do_recovery' - - // 2. initialize the clients - std::vector meta_list; - ASSERT_TRUE(replica_helper::load_meta_servers( - meta_list, PEGASUS_CLUSTER_SECTION_NAME.c_str(), "single_master_cluster")); - ASSERT_FALSE(meta_list.empty()); - - ddl_client = std::make_shared(meta_list); - ASSERT_TRUE(ddl_client != nullptr); - pg_client = pegasus::pegasus_client_factory::get_client("single_master_cluster", - table_name.c_str()); - ASSERT_TRUE(pg_client != nullptr); - - // 3. write some data to the app - dsn::error_code err; - // first create the app - err = ddl_client->create_app(table_name, "pegasus", default_partitions, 3, {}, false); - ASSERT_EQ(dsn::ERR_OK, err); - - // then write keys - std::cerr << "write " << set_count << " keys" << std::endl; - for (int i = 0; i < set_count; ++i) { - std::string hash_key = key_prefix + boost::lexical_cast(i); + TRICKY_CODE_TO_AVOID_LINK_ERROR; + test_util::SetUp(); + for (int i = 0; i < dataset_count; ++i) { + std::string hash_key = key_prefix + std::to_string(i); std::string sort_key = hash_key; - std::string value = value_prefix + boost::lexical_cast(i); + std::string value = value_prefix + std::to_string(i); pegasus::pegasus_client::internal_info info; - int ans = pg_client->set(hash_key, sort_key, value, 5000, 0, &info); + int ans = client_->set(hash_key, sort_key, value, 5000, 0, &info); ASSERT_EQ(0, ans); - ASSERT_TRUE(info.partition_index < default_partitions); + ASSERT_TRUE(info.partition_index < partition_count_); } } -public: - std::shared_ptr ddl_client; - pegasus::pegasus_client *pg_client; - public: std::vector get_rpc_address_list(const std::vector ports) { @@ -101,95 +79,55 @@ class recovery_test : public testing::Test void stop_replica(int id) { - char command[512]; - snprintf(command, - 512, - "cd %s && ./run.sh stop_onebox_instance -r %d", - global_env::instance()._pegasus_root.c_str(), - id); - system(command); + ASSERT_NO_FATAL_FAILURE( + run_cmd_from_project_root("./run.sh stop_onebox_instance -r " + std::to_string(id))); } void stop_meta(int id) { - char command[512]; - snprintf(command, - 512, - "cd %s && ./run.sh stop_onebox_instance -m %d", - global_env::instance()._pegasus_root.c_str(), - id); - system(command); + ASSERT_NO_FATAL_FAILURE( + run_cmd_from_project_root("./run.sh stop_onebox_instance -m " + std::to_string(id))); } void start_meta(int id) { - char command[512]; - snprintf(command, - 512, - "cd %s && ./run.sh start_onebox_instance -m %d", - global_env::instance()._pegasus_root.c_str(), - id); - system(command); + ASSERT_NO_FATAL_FAILURE( + run_cmd_from_project_root("./run.sh start_onebox_instance -m " + std::to_string(id))); } void start_replica(int id) { - char command[512]; - snprintf(command, - 512, - "cd %s && ./run.sh start_onebox_instance -r %d", - global_env::instance()._pegasus_root.c_str(), - id); - system(command); + ASSERT_NO_FATAL_FAILURE( + run_cmd_from_project_root("./run.sh start_onebox_instance -r " + std::to_string(id))); } void clear_remote_storage() { - char command[512]; - snprintf(command, - 512, - "cd %s && rm -rf onebox/meta1/data/meta/meta_state_service.log", - global_env::instance()._pegasus_root.c_str()); - system(command); + ASSERT_NO_FATAL_FAILURE( + run_cmd_from_project_root("rm -rf onebox/meta1/data/meta/meta_state_service.log")); } void config_meta_to_do_cold_recovery() { - char command[512]; - snprintf( - command, - 512, - "cd %s && sed -i \"/^\\s*recover_from_replica_server/c recover_from_replica_server = " - "true\" onebox/meta1/config.ini", - global_env::instance()._pegasus_root.c_str()); - system(command); + ASSERT_NO_FATAL_FAILURE(run_cmd_from_project_root( + "sed -i \"/^\\s*recover_from_replica_server/c recover_from_replica_server = true\" " + "onebox/meta1/config.ini")); } void delete_replica(int replica_id, int app_id, int partition_id) { - char command[512]; - snprintf(command, - 512, - "cd %s/onebox/replica%d/data/replica/reps && rm -rf %d.%d.pegasus", - global_env::instance()._pegasus_root.c_str(), - replica_id, - app_id, - partition_id); - std::cout << command << std::endl; - system(command); + std::string cmd = fmt::format("rm -rf onebox/replica{}/data/replica/reps/{}.{}.pegasus", + replica_id, + app_id, + partition_id); + ASSERT_NO_FATAL_FAILURE(run_cmd_from_project_root(cmd)); } void delete_replicas_for_app_id(int replica_id, int app_id) { - char command[512]; - snprintf(command, - 512, - "cd %s/onebox/replica%d/data/replica/reps && rm -rf %d.*.pegasus", - global_env::instance()._pegasus_root.c_str(), - replica_id, - app_id); - std::cout << command << std::endl; - system(command); + std::string cmd = fmt::format( + "rm -rf onebox/replica{}/data/replica/reps/{}.*.pegasus", replica_id, app_id); + ASSERT_NO_FATAL_FAILURE(run_cmd_from_project_root(cmd)); } // 1. stop replicas @@ -197,13 +135,13 @@ class recovery_test : public testing::Test void prepare_recovery() { // then stop all jobs - stop_meta(1); + ASSERT_NO_FATAL_FAILURE(stop_meta(1)); for (int i = 1; i <= 3; ++i) { - stop_replica(i); + ASSERT_NO_FATAL_FAILURE(stop_replica(i)); } - clear_remote_storage(); - config_meta_to_do_cold_recovery(); + ASSERT_NO_FATAL_FAILURE(clear_remote_storage()); + ASSERT_NO_FATAL_FAILURE(config_meta_to_do_cold_recovery()); // sleep some time, in case that the socket is time-wait std::cout << "sleep for a while to wait the socket to destroy" << std::endl; std::this_thread::sleep_for(std::chrono::seconds(10)); @@ -213,148 +151,135 @@ class recovery_test : public testing::Test { // then check to read all keys for (int i = 0; i < count; ++i) { - std::string hash_key = key_prefix + boost::lexical_cast(i); + std::string hash_key = key_prefix + std::to_string(i); std::string sort_key = hash_key; - std::string exp_value = value_prefix + boost::lexical_cast(i); + std::string exp_value = value_prefix + std::to_string(i); std::string act_value; - int ans = pg_client->get(hash_key, sort_key, act_value); - ASSERT_EQ(0, ans); + ASSERT_EQ(PERR_OK, client_->get(hash_key, sort_key, act_value)); ASSERT_EQ(exp_value, act_value); } } - static const std::string table_name; - static const std::string key_prefix; - static const std::string value_prefix; - static const int default_partitions = 4; - static const int set_count = 2048; + const std::string key_prefix = "hello_key"; + const std::string value_prefix = "world_key"; + static const int dataset_count = 2048; }; -const std::string recovery_test::table_name = "test_table"; -const std::string recovery_test::key_prefix = "hello_key"; -const std::string recovery_test::value_prefix = "world_key"; - TEST_F(recovery_test, recovery) { - dsn::error_code err; - // first test the basic recovery - std::cout << ">>>>> test basic recovery <<<<<" << std::endl; { - prepare_recovery(); + ASSERT_NO_FATAL_FAILURE(prepare_recovery()); // start all jobs again for (int i = 1; i <= 3; ++i) { - start_replica(i); + ASSERT_NO_FATAL_FAILURE(start_replica(i)); } std::cout << "sleep for a while to wait the replica to start" << std::endl; std::this_thread::sleep_for(std::chrono::seconds(20)); - start_meta(1); + ASSERT_NO_FATAL_FAILURE(start_meta(1)); std::cout << "sleep for a while to wait the meta to come to alive" << std::endl; std::this_thread::sleep_for(std::chrono::seconds(10)); // then do recovery auto nodes = get_rpc_address_list({34801, 34802, 34803}); - err = ddl_client->do_recovery(nodes, 30, false, false, std::string()); - ASSERT_EQ(dsn::ERR_OK, err); + ASSERT_EQ(dsn::ERR_OK, ddl_client_->do_recovery(nodes, 30, false, false, std::string())); // send another recovery command - err = ddl_client->do_recovery(nodes, 30, false, false, std::string()); - ASSERT_EQ(dsn::ERR_SERVICE_ALREADY_RUNNING, err); + ASSERT_EQ(dsn::ERR_SERVICE_ALREADY_RUNNING, + ddl_client_->do_recovery(nodes, 30, false, false, std::string())); // then wait the apps to ready - err = ddl_client->create_app(table_name, "pegasus", default_partitions, 3, {}, false); - ASSERT_EQ(dsn::ERR_OK, err); + ASSERT_EQ(dsn::ERR_OK, + ddl_client_->create_app(app_name_, "pegasus", partition_count_, 3, {}, false)); - verify_data(set_count); + ASSERT_NO_FATAL_FAILURE(verify_data(dataset_count)); } // recover from subset of all nodes std::cout << ">>>>> test recovery from subset of all nodes <<<<<" << std::endl; { - prepare_recovery(); - for (int i = 1; i <= 3; ++i) - start_replica(i); + ASSERT_NO_FATAL_FAILURE(prepare_recovery()); + for (int i = 1; i <= 3; ++i) { + ASSERT_NO_FATAL_FAILURE(start_replica(i)); + } std::cout << "sleep for a while to wait the replica to start" << std::endl; std::this_thread::sleep_for(std::chrono::seconds(20)); - start_meta(1); + ASSERT_NO_FATAL_FAILURE(start_meta(1)); std::cout << "sleep for a while to wait the meta to come to alive" << std::endl; std::this_thread::sleep_for(std::chrono::seconds(10)); // recovery only from 1 & 2 std::vector nodes = get_rpc_address_list({34801, 34802}); - ddl_client->do_recovery(nodes, 30, false, false, std::string()); - ASSERT_EQ(dsn::ERR_OK, err); + ASSERT_EQ(dsn::ERR_OK, ddl_client_->do_recovery(nodes, 30, false, false, std::string())); // then wait the app to ready - err = ddl_client->create_app(table_name, "pegasus", default_partitions, 3, {}, false); - ASSERT_EQ(dsn::ERR_OK, err); + ASSERT_EQ(dsn::ERR_OK, + ddl_client_->create_app(app_name_, "pegasus", partition_count_, 3, {}, false)); - verify_data(set_count); + ASSERT_NO_FATAL_FAILURE(verify_data(dataset_count)); } // recovery from whole, but some partitions has been removed std::cout << ">>>>> test recovery, some partitions have been lost <<<<<" << std::endl; { - prepare_recovery(); - for (int i = 0; i < default_partitions; ++i) { + ASSERT_NO_FATAL_FAILURE(prepare_recovery()); + for (int i = 0; i < partition_count_; ++i) { int replica_id = dsn::rand::next_u32(1, 3); delete_replica(replica_id, 2, i); } // start all jobs again for (int i = 1; i <= 3; ++i) { - start_replica(i); + ASSERT_NO_FATAL_FAILURE(start_replica(i)); } std::cout << "sleep for a while to wait the replica to start" << std::endl; std::this_thread::sleep_for(std::chrono::seconds(20)); - start_meta(1); + ASSERT_NO_FATAL_FAILURE(start_meta(1)); std::cout << "sleep for a while to wait the meta to come to alive" << std::endl; std::this_thread::sleep_for(std::chrono::seconds(10)); // then do recovery auto nodes = get_rpc_address_list({34801, 34802, 34803}); - err = ddl_client->do_recovery(nodes, 30, false, false, std::string()); - ASSERT_EQ(dsn::ERR_OK, err); + ASSERT_EQ(dsn::ERR_OK, ddl_client_->do_recovery(nodes, 30, false, false, std::string())); // then wait the apps to ready - err = ddl_client->create_app(table_name, "pegasus", default_partitions, 3, {}, false); - ASSERT_EQ(dsn::ERR_OK, err); + ASSERT_EQ(dsn::ERR_OK, + ddl_client_->create_app(app_name_, "pegasus", partition_count_, 3, {}, false)); - verify_data(set_count); + ASSERT_NO_FATAL_FAILURE(verify_data(dataset_count)); } // some apps has been totally removed std::cout << ">>>>> test recovery, app 1 is removed <<<<<" << std::endl; { - prepare_recovery(); + ASSERT_NO_FATAL_FAILURE(prepare_recovery()); for (int i = 1; i < 4; ++i) { delete_replicas_for_app_id(i, 1); } // start all jobs again for (int i = 1; i <= 3; ++i) { - start_replica(i); + ASSERT_NO_FATAL_FAILURE(start_replica(i)); } std::cout << "sleep for a while to wait the replica to start" << std::endl; std::this_thread::sleep_for(std::chrono::seconds(20)); - start_meta(1); + ASSERT_NO_FATAL_FAILURE(start_meta(1)); std::cout << "sleep for a while to wait the meta to come to alive" << std::endl; std::this_thread::sleep_for(std::chrono::seconds(10)); // then do recovery auto nodes = get_rpc_address_list({34801, 34802, 34803}); - err = ddl_client->do_recovery(nodes, 30, false, false, std::string()); - ASSERT_EQ(dsn::ERR_OK, err); + ASSERT_EQ(dsn::ERR_OK, ddl_client_->do_recovery(nodes, 30, false, false, std::string())); // then wait the apps to ready - err = ddl_client->create_app(table_name, "pegasus", default_partitions, 3, {}, false); - ASSERT_EQ(dsn::ERR_OK, err); + ASSERT_EQ(dsn::ERR_OK, + ddl_client_->create_app(app_name_, "pegasus", partition_count_, 3, {}, false)); - verify_data(set_count); + ASSERT_NO_FATAL_FAILURE(verify_data(dataset_count)); } } diff --git a/src/test/function_test/restore_test/test_restore.cpp b/src/test/function_test/restore_test/test_restore.cpp index a185206a77..19a1605790 100644 --- a/src/test/function_test/restore_test/test_restore.cpp +++ b/src/test/function_test/restore_test/test_restore.cpp @@ -33,6 +33,8 @@ using namespace ::dsn; using namespace ::dsn::replication; using namespace pegasus; +// TODO(yingchun): backup & restore festure is on refactoring, we can refactor the related function +// test later. class restore_test : public testing::Test { public: @@ -288,43 +290,29 @@ class restore_test : public testing::Test int32_t old_app_id; int64_t time_stamp; - static const std::string policy_name; - static const std::string backup_provider_name; - static const int backup_interval_seconds; - static const int backup_history_count_to_keep; - static const std::string start_time; - - static const std::string app_name; - - static const std::string hash_key_prefix; - static const std::string sort_key_prefix; - static const std::string value_prefix; - - static const int kv_pair_cnt; - static const int default_partition_cnt; + const std::string policy_name = "policy_1"; + const std::string backup_provider_name = "local_service"; + // NOTICE: we enqueue a time task to check whether policy should start backup periodically, the + // period is 5min, so the time between two backup is at least 5min, but if we set the + // backup_interval_seconds smaller enough such as smaller than the time of finishing once + // backup, we + // can start next backup immediately when current backup is finished + // The backup interval must be greater than checkpoint reserve time, see + // backup_service::add_backup_policy() for details. + const int backup_interval_seconds = 700; + const int backup_history_count_to_keep = 6; + const std::string start_time = "24:0"; + + const std::string app_name = "backup_test"; + + const std::string hash_key_prefix = "hash_key"; + const std::string sort_key_prefix = "sort_key"; + const std::string value_prefix = "value"; + + const int kv_pair_cnt = 10000; + const int default_partition_cnt = 8; }; -const std::string restore_test::policy_name = "policy_1"; -const std::string restore_test::backup_provider_name = "local_service"; -// NOTICE: we enqueue a time task to check whether policy should start backup periodically, the -// period is 5min, so the time between two backup is at least 5min, but if we set the -// backup_interval_seconds smaller enough such as smaller than the time of finishing once backup, we -// can start next backup immediately when current backup is finished -// The backup interval must be greater than checkpoint reserve time, see -// backup_service::add_backup_policy() for details. -const int restore_test::backup_interval_seconds = 700; -const int restore_test::backup_history_count_to_keep = 6; -const std::string restore_test::start_time = "24:0"; - -const std::string restore_test::app_name = "backup_test"; - -const std::string restore_test::hash_key_prefix = "hash_key"; -const std::string restore_test::sort_key_prefix = "sort_key"; -const std::string restore_test::value_prefix = "value"; - -const int restore_test::kv_pair_cnt = 10000; -const int restore_test::default_partition_cnt = 8; - TEST_F(restore_test, restore) { std::cout << "start testing restore..." << std::endl; diff --git a/src/test/function_test/throttle_test/test_throttle.cpp b/src/test/function_test/throttle_test/test_throttle.cpp index a8f9c1a186..1b1780716a 100644 --- a/src/test/function_test/throttle_test/test_throttle.cpp +++ b/src/test/function_test/throttle_test/test_throttle.cpp @@ -17,6 +17,8 @@ * under the License. */ +#include + #include #include #include "include/pegasus/client.h" @@ -29,10 +31,12 @@ #include "base/pegasus_const.h" #include "test/function_test/utils/global_env.h" #include "test/function_test/utils/utils.h" +#include "test/function_test/utils/test_util.h" using namespace dsn; using namespace dsn::replication; using namespace pegasus; +using std::string; enum class throttle_type { @@ -52,7 +56,7 @@ enum class operation_type struct throttle_test_plan { - std::string test_plan_case = ""; + string test_plan_case; operation_type ot = operation_type::get; int single_value_sz = 0; int multi_count = 0; @@ -61,132 +65,62 @@ struct throttle_test_plan bool is_hotkey = false; }; -#define ToString(x) #x - -#define TIMELY_RECORD(time_interval, is_reject, size) \ - do { \ - records[ToString(time_interval##_query_times)]++; \ - records[ToString(time_interval##_query_size)] += size; \ - if (is_reject) { \ - records[ToString(time_interval##_reject_times)]++; \ - records[ToString(time_interval##_reject_size)] += size; \ - } else { \ - records[ToString(time_interval##_successful_times)]++; \ - records[ToString(time_interval##_successful_size)] += size; \ - } \ - } while (0) - struct throttle_test_recorder { + static const uint64_t limit_duration_ms = 10 * 1000; + + string test_name; uint64_t start_time_ms; - uint64_t duration_ms; - std::map records; - std::string test_name; - std::vector parameter_seq = {"total_qps", - "total_size_per_sec", - "first_10_ms_successful_times", - "first_100_ms_successful_times", - "first_1000_ms_successful_times", - "first_5000_ms_successful_times", - "first_10_ms_successful_size", - "first_100_ms_successful_size", - "first_1000_ms_successful_size", - "first_5000_ms_successful_size"}; - - throttle_test_recorder() - { - for (const auto &key : parameter_seq) { - records[key] = 0; - } - } + std::atomic total_successful_times; + std::atomic total_successful_size; + uint64_t total_qps = 0; + uint64_t total_size_per_sec = 0; + + throttle_test_recorder() {} - void start_test(const std::string &test_case, uint64_t time_duration_s) + void reset(const string &test_case) { test_name = test_case; start_time_ms = dsn_now_ms(); - duration_ms = time_duration_s * 1000; - records.emplace(std::make_pair("duration_ms", duration_ms)); + total_successful_times = 0; + total_successful_size = 0; + total_qps = 0; + total_size_per_sec = 0; } - bool is_time_up() { return dsn_now_ms() - start_time_ms > duration_ms; } + bool is_time_up() { return dsn_now_ms() - start_time_ms > limit_duration_ms; } void record(uint64_t size, bool is_reject) { - if (is_time_up()) { - return; - } - auto now_ns = dsn_now_ms(); - if (now_ns - start_time_ms <= 10) { - TIMELY_RECORD(first_10_ms, is_reject, size); - } - if (now_ns - start_time_ms <= 100) { - TIMELY_RECORD(first_100_ms, is_reject, size); - } - if (now_ns - start_time_ms <= 1000) { - TIMELY_RECORD(first_1000_ms, is_reject, size); + if (!is_reject) { + total_successful_times++; + total_successful_size += size; } - if (now_ns - start_time_ms <= 5000) { - TIMELY_RECORD(first_5000_ms, is_reject, size); - } - TIMELY_RECORD(total, is_reject, size); - - records["total_qps"] = records["total_successful_times"] / (duration_ms / 1000); - records["total_size_per_sec"] = records["total_successful_size"] / (duration_ms / 1000); } - void print_results(const std::string &dir) + void finalize() { - std::streambuf *psbuf, *backup; - std::ofstream file; - file.open(dir, std::ios::out | std::ios::app); - backup = std::cout.rdbuf(); - psbuf = file.rdbuf(); - std::cout.rdbuf(psbuf); - - std::cout << "test case: " << test_name << std::endl; - for (const auto &iter : parameter_seq) { - std::cout << iter << ": " << records[iter] << std::endl; - } - std::cout << std::endl; - - std::cout.rdbuf(backup); - file.close(); - - return; + total_qps = total_successful_times / (limit_duration_ms / 1000); + total_size_per_sec = total_successful_size / (limit_duration_ms / 1000); } }; -const int test_hashkey_len = 50; -const int test_sortkey_len = 50; - // read/write throttle function test // the details of records are saved in // `./src/builder/test/function_test/throttle_test/throttle_test_result.txt` -class throttle_test : public testing::Test +class throttle_test : public test_util { public: - static void SetUpTestCase() { ASSERT_TRUE(pegasus_client_factory::initialize("config.ini")); } + const int test_hashkey_len = 50; + const int test_sortkey_len = 50; + throttle_test_recorder result; - void SetUp() override - { - std::vector meta_list; - ASSERT_TRUE(replica_helper::load_meta_servers( - meta_list, PEGASUS_CLUSTER_SECTION_NAME.c_str(), "single_master_cluster")); - ASSERT_FALSE(meta_list.empty()); - - ddl_client = std::make_shared(meta_list); - ASSERT_TRUE(ddl_client != nullptr); - pg_client = - pegasus::pegasus_client_factory::get_client("single_master_cluster", app_name.c_str()); - ASSERT_TRUE(pg_client != nullptr); - - auto err = ddl_client->create_app(app_name.c_str(), "pegasus", 4, 3, {}, false); - ASSERT_EQ(dsn::ERR_OK, err); - } +public: + throttle_test() { TRICKY_CODE_TO_AVOID_LINK_ERROR; } void set_throttle(throttle_type type, uint64_t value) { - std::vector keys, values; + std::vector keys, values; if (type == throttle_type::read_by_qps) { keys.emplace_back("replica.read_throttling"); values.emplace_back(fmt::format("{}*reject*200", value)); @@ -200,36 +134,30 @@ class throttle_test : public testing::Test keys.emplace_back("replica.write_throttling_by_size"); values.emplace_back(fmt::format("{}*reject*200", value)); } - auto resp = ddl_client->set_app_envs(app_name, keys, values); - dassert_f( - resp.get_error().code() == ERR_OK, "Set env failed: {}", resp.get_value().hint_message); + ASSERT_EQ(ERR_OK, ddl_client_->set_app_envs(app_name_, keys, values).get_error().code()); } void restore_throttle() { - std::map envs; - ddl_client->get_app_envs(app_name, envs); - std::vector keys; - for (const auto &iter : envs) { - keys.emplace_back(iter.first); + std::map envs; + ASSERT_EQ(ERR_OK, ddl_client_->get_app_envs(app_name_, envs)); + std::vector keys; + for (const auto &env : envs) { + keys.emplace_back(env.first); } - auto resp = ddl_client->del_app_envs(app_name, keys); - dassert_f(resp == ERR_OK, "Del env failed"); + ASSERT_EQ(ERR_OK, ddl_client_->del_app_envs(app_name_, keys)); } - throttle_test_recorder start_test(throttle_test_plan test_plan, uint64_t time_duration_s = 10) + void start_test(const throttle_test_plan &test_plan) { std::cout << fmt::format("start test, on {}", test_plan.test_plan_case) << std::endl; - dassert(pg_client, "pg_client is nullptr"); - - throttle_test_recorder r; - r.start_test(test_plan.test_plan_case, time_duration_s); + result.reset(test_plan.test_plan_case); bool is_running = true; std::atomic ref_count(0); - while (!r.is_time_up()) { + while (!result.is_time_up()) { auto h_key = generate_hotkey(test_plan.is_hotkey, 75, test_hashkey_len); auto s_key = generate_random_string(test_sortkey_len); auto value = generate_random_string(test_plan.random_value_size @@ -240,9 +168,10 @@ class throttle_test : public testing::Test generate_str_vector_by_random( test_plan.single_value_sz, test_plan.multi_count, test_plan.random_value_size)); - if (test_plan.ot == operation_type::set) { + switch (test_plan.ot) { + case operation_type::set: { ref_count++; - pg_client->async_set( + client_->async_set( h_key, s_key, value, @@ -251,15 +180,16 @@ class throttle_test : public testing::Test ref_count--; return; } - dassert_f(ec == PERR_OK || ec == PERR_APP_BUSY, - "get/set data failed, error code:{}", - ec); - r.record(value.size() + h_key.size() + s_key.size(), ec == PERR_APP_BUSY); + ASSERT_TRUE(ec == PERR_OK || ec == PERR_APP_BUSY) << ec; + result.record(value.size() + h_key.size() + s_key.size(), + ec == PERR_APP_BUSY); ref_count--; }); - } else if (test_plan.ot == operation_type::multi_set) { + break; + } + case operation_type::multi_set: { ref_count++; - pg_client->async_multi_set( + client_->async_multi_set( h_key, sortkey_value_pairs, [&, h_key, sortkey_value_pairs](int ec, pegasus_client::internal_info &&info) { @@ -267,19 +197,19 @@ class throttle_test : public testing::Test ref_count--; return; } - dassert_f(ec == PERR_OK || ec == PERR_APP_BUSY, - "get/set data failed, error code:{}", - ec); + ASSERT_TRUE(ec == PERR_OK || ec == PERR_APP_BUSY) << ec; int total_size = 0; for (const auto &iter : sortkey_value_pairs) { total_size += iter.second.size(); } - r.record(total_size + h_key.size(), ec == PERR_APP_BUSY); + result.record(total_size + h_key.size(), ec == PERR_APP_BUSY); ref_count--; }); - } else if (test_plan.ot == operation_type::get) { + break; + } + case operation_type::get: { ref_count++; - pg_client->async_set( + client_->async_set( h_key, s_key, value, @@ -288,30 +218,30 @@ class throttle_test : public testing::Test ref_count--; return; } - dassert_f(ec_write == PERR_OK, "set data failed, error code:{}", ec_write); + ASSERT_EQ(PERR_OK, ec_write); ref_count++; - pg_client->async_get( + client_->async_get( h_key, s_key, - [&, h_key, s_key, value](int ec_read, - std::string &&val, - pegasus_client::internal_info &&info) { + [&, h_key, s_key, value]( + int ec_read, string &&val, pegasus_client::internal_info &&info) { if (!is_running) { ref_count--; return; } - dassert_f(ec_read == PERR_OK || ec_read == PERR_APP_BUSY, - "get data failed, error code:{}", - ec_read); - r.record(value.size() + h_key.size() + s_key.size(), - ec_read == PERR_APP_BUSY); + ASSERT_TRUE(ec_read == PERR_OK || ec_read == PERR_APP_BUSY) + << ec_read; + result.record(value.size() + h_key.size() + s_key.size(), + ec_read == PERR_APP_BUSY); ref_count--; }); ref_count--; }); - } else if (test_plan.ot == operation_type::multi_get) { + break; + } + case operation_type::multi_get: { ref_count++; - pg_client->async_multi_set( + client_->async_multi_set( h_key, sortkey_value_pairs, [&, h_key](int ec_write, pegasus_client::internal_info &&info) { @@ -319,154 +249,142 @@ class throttle_test : public testing::Test ref_count--; return; } - dassert_f(ec_write == PERR_OK, "set data failed, error code:{}", ec_write); + ASSERT_EQ(PERR_OK, ec_write); ref_count++; - std::set empty_sortkeys; - pg_client->async_multi_get( + client_->async_multi_get( h_key, - empty_sortkeys, + {}, [&, h_key](int ec_read, - std::map &&values, + std::map &&values, pegasus_client::internal_info &&info) { if (!is_running) { ref_count--; return; } - dassert_f(ec_read == PERR_OK || ec_read == PERR_APP_BUSY, - "get data failed, error code:{}", - ec_read); + ASSERT_TRUE(ec_read == PERR_OK || ec_read == PERR_APP_BUSY) + << ec_read; int total_size = 0; for (const auto &iter : values) { total_size += iter.second.size(); } - r.record(total_size + h_key.size(), ec_read == PERR_APP_BUSY); + result.record(total_size + h_key.size(), ec_read == PERR_APP_BUSY); ref_count--; }); ref_count--; }); + break; + } } } is_running = false; while (ref_count.load() != 0) { sleep(1); } - - r.print_results("./src/builder/test/function_test/throttle_test/throttle_test_result.txt"); - return r; } - - const std::string app_name = "throttle_test"; - std::shared_ptr ddl_client; - pegasus::pegasus_client *pg_client; }; TEST_F(throttle_test, test) { throttle_test_plan plan; - throttle_test_recorder result; plan = {"set test / throttle by size / normal value size", operation_type::set, 1024, 1, 50}; - set_throttle(throttle_type::write_by_size, - plan.limit_qps * plan.single_value_sz * plan.multi_count); + ASSERT_NO_FATAL_FAILURE(set_throttle(throttle_type::write_by_size, + plan.limit_qps * plan.single_value_sz * plan.multi_count)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_qps"], plan.limit_qps + 15); - ASSERT_GT(result.records["total_qps"], plan.limit_qps - 15); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + result.finalize(); + ASSERT_NEAR(result.total_qps, plan.limit_qps, 15); plan = {"set test / throttle by qps / normal value size", operation_type::set, 1024, 1, 50}; - set_throttle(throttle_type::write_by_qps, plan.limit_qps); + ASSERT_NO_FATAL_FAILURE(set_throttle(throttle_type::write_by_qps, plan.limit_qps)); std::cout << "wait 30s for setting env " << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_qps"], plan.limit_qps + 15); - ASSERT_GT(result.records["total_qps"], plan.limit_qps - 15); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + result.finalize(); + ASSERT_NEAR(result.total_qps, plan.limit_qps, 15); plan = {"get test / throttle by size / normal value size", operation_type::get, 1024, 1, 50}; - set_throttle(throttle_type::read_by_size, - plan.limit_qps * plan.single_value_sz * plan.multi_count); + ASSERT_NO_FATAL_FAILURE(set_throttle(throttle_type::read_by_size, + plan.limit_qps * plan.single_value_sz * plan.multi_count)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 1.3); - ASSERT_GT(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 0.7); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + auto actual_value = (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps; + result.finalize(); + ASSERT_NEAR(result.total_size_per_sec, actual_value, actual_value * 0.3); plan = {"get test / throttle by qps", operation_type::get, 1024, 1, 50}; - set_throttle(throttle_type::read_by_qps, plan.limit_qps); + ASSERT_NO_FATAL_FAILURE(set_throttle(throttle_type::read_by_qps, plan.limit_qps)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_qps"], plan.limit_qps + 15); - ASSERT_GT(result.records["total_qps"], plan.limit_qps - 15); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + result.finalize(); + ASSERT_NEAR(result.total_qps, plan.limit_qps, 15); plan = {"multi_get test / throttle by size / normal value size", operation_type::multi_get, 1024, 50, 50}; - set_throttle(throttle_type::read_by_size, - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps); + ASSERT_NO_FATAL_FAILURE( + set_throttle(throttle_type::read_by_size, + (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 1.3); - ASSERT_GT(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 0.7); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + actual_value = (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps; + result.finalize(); + ASSERT_NEAR(result.total_size_per_sec, actual_value, actual_value * 0.3); plan = {"multi_set test / throttle by size / normal value size", operation_type::multi_set, 1024, 50, 50}; - set_throttle(throttle_type::write_by_size, - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps); + ASSERT_NO_FATAL_FAILURE( + set_throttle(throttle_type::write_by_size, + (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 1.3); - ASSERT_GT(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 0.7); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + actual_value = (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps; + result.finalize(); + ASSERT_NEAR(result.total_size_per_sec, actual_value, actual_value * 0.3); plan = { "set test / throttle by qps&size / normal value size", operation_type::set, 1024, 1, 50}; - set_throttle(throttle_type::write_by_size, - plan.limit_qps * plan.single_value_sz * plan.multi_count); - set_throttle(throttle_type::write_by_qps, plan.limit_qps); + ASSERT_NO_FATAL_FAILURE(set_throttle(throttle_type::write_by_size, + plan.limit_qps * plan.single_value_sz * plan.multi_count)); + ASSERT_NO_FATAL_FAILURE(set_throttle(throttle_type::write_by_qps, plan.limit_qps)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_qps"], plan.limit_qps + 15); - ASSERT_GT(result.records["total_qps"], plan.limit_qps - 15); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + result.finalize(); + ASSERT_NEAR(result.total_qps, plan.limit_qps, 15); plan = { "get test / throttle by qps&size / normal value size", operation_type::get, 1024, 1, 50}; - set_throttle(throttle_type::read_by_size, - plan.limit_qps * plan.single_value_sz * plan.multi_count); - set_throttle(throttle_type::read_by_qps, plan.limit_qps); + ASSERT_NO_FATAL_FAILURE(set_throttle(throttle_type::read_by_size, + plan.limit_qps * plan.single_value_sz * plan.multi_count)); + ASSERT_NO_FATAL_FAILURE(set_throttle(throttle_type::read_by_qps, plan.limit_qps)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_qps"], plan.limit_qps + 15); - ASSERT_GT(result.records["total_qps"], plan.limit_qps - 15); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + result.finalize(); + ASSERT_NEAR(result.total_qps, plan.limit_qps, 15); // mix throttle case plan = {"set test / throttle by qps&size,loose size throttle / normal value size", @@ -474,193 +392,181 @@ TEST_F(throttle_test, test) 1024, 1, 50}; - set_throttle(throttle_type::write_by_size, - plan.limit_qps * - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * 1000); - set_throttle(throttle_type::write_by_qps, plan.limit_qps); + ASSERT_NO_FATAL_FAILURE(set_throttle( + throttle_type::write_by_size, + plan.limit_qps * (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * 1000)); + ASSERT_NO_FATAL_FAILURE(set_throttle(throttle_type::write_by_qps, plan.limit_qps)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_qps"], plan.limit_qps + 15); - ASSERT_GT(result.records["total_qps"], plan.limit_qps - 15); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + result.finalize(); + ASSERT_NEAR(result.total_qps, plan.limit_qps, 15); plan = {"get test / throttle by qps&size,loose size throttle/normal value size", operation_type::get, 1024, 1, 50}; - set_throttle(throttle_type::read_by_size, - plan.limit_qps * - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * 1000); - set_throttle(throttle_type::read_by_qps, plan.limit_qps); + ASSERT_NO_FATAL_FAILURE(set_throttle( + throttle_type::read_by_size, + plan.limit_qps * (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * 1000)); + ASSERT_NO_FATAL_FAILURE(set_throttle(throttle_type::read_by_qps, plan.limit_qps)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_qps"], plan.limit_qps + 15); - ASSERT_GT(result.records["total_qps"], plan.limit_qps - 15); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + result.finalize(); + ASSERT_NEAR(result.total_qps, plan.limit_qps, 15); plan = {"set test / throttle by qps&size,loose qps throttle / normal value size", operation_type::set, 1024, 1, 50}; - set_throttle(throttle_type::write_by_size, - plan.limit_qps * plan.single_value_sz * plan.multi_count); - set_throttle(throttle_type::write_by_qps, plan.limit_qps * 1000); + ASSERT_NO_FATAL_FAILURE(set_throttle(throttle_type::write_by_size, + plan.limit_qps * plan.single_value_sz * plan.multi_count)); + ASSERT_NO_FATAL_FAILURE(set_throttle(throttle_type::write_by_qps, plan.limit_qps * 1000)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 1.3); - ASSERT_GT(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 0.7); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + actual_value = (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps; + result.finalize(); + ASSERT_NEAR(result.total_size_per_sec, actual_value, actual_value * 0.3); plan = {"get test / throttle by qps&size,loose qps throttle/normal value size", operation_type::get, 1024, 1, 50}; - set_throttle(throttle_type::read_by_size, - plan.limit_qps * plan.single_value_sz * plan.multi_count); - set_throttle(throttle_type::read_by_qps, plan.limit_qps * 1000); + ASSERT_NO_FATAL_FAILURE(set_throttle(throttle_type::read_by_size, + plan.limit_qps * plan.single_value_sz * plan.multi_count)); + ASSERT_NO_FATAL_FAILURE(set_throttle(throttle_type::read_by_qps, plan.limit_qps * 1000)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 1.3); - ASSERT_GT(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 0.7); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + actual_value = (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps; + result.finalize(); + ASSERT_NEAR(result.total_size_per_sec, actual_value, actual_value * 0.3); // big value test can't run normally in the function test plan = {"set test / throttle by size / 20kb value size", operation_type::set, 1024 * 20, 1, 50}; - set_throttle(throttle_type::write_by_size, - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps); + ASSERT_NO_FATAL_FAILURE( + set_throttle(throttle_type::write_by_size, + (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 1.3); - ASSERT_GT(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 0.7); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + actual_value = (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps; + result.finalize(); + ASSERT_NEAR(result.total_size_per_sec, actual_value, actual_value * 0.3); plan = {"get test / throttle by size / 20kb value size", operation_type::get, 1024 * 20, 1, 50}; - set_throttle(throttle_type::read_by_size, - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps); + ASSERT_NO_FATAL_FAILURE( + set_throttle(throttle_type::read_by_size, + (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 1.3); - ASSERT_GT(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 0.7); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + actual_value = (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps; + result.finalize(); + ASSERT_NEAR(result.total_size_per_sec, actual_value, actual_value * 0.3); plan = {"set test / throttle by size / 50kb value size", operation_type::set, 1024 * 50, 1, 50}; - set_throttle(throttle_type::write_by_size, - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps); + ASSERT_NO_FATAL_FAILURE( + set_throttle(throttle_type::write_by_size, + (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 1.3); - ASSERT_GT(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 0.7); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + actual_value = (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps; + result.finalize(); + ASSERT_NEAR(result.total_size_per_sec, actual_value, actual_value * 0.3); plan = {"get test / throttle by size / 50kb value size", operation_type::get, 1024 * 50, 1, 50}; - set_throttle(throttle_type::read_by_size, - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps); + ASSERT_NO_FATAL_FAILURE( + set_throttle(throttle_type::read_by_size, + (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 1.3); - ASSERT_GT(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 0.7); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + actual_value = (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps; + result.finalize(); + ASSERT_NEAR(result.total_size_per_sec, actual_value, actual_value * 0.3); plan = {"set test / throttle by size / 100b value size", operation_type::set, 100, 1, 50}; - set_throttle(throttle_type::write_by_size, - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps); + ASSERT_NO_FATAL_FAILURE( + set_throttle(throttle_type::write_by_size, + (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 1.3); - ASSERT_GT(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 0.7); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + actual_value = (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps; + result.finalize(); + ASSERT_NEAR(result.total_size_per_sec, actual_value, actual_value * 0.3); plan = {"get test / throttle by size / 100b value size", operation_type::get, 100, 1, 50}; - set_throttle(throttle_type::read_by_size, - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps); + ASSERT_NO_FATAL_FAILURE( + set_throttle(throttle_type::read_by_size, + (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 1.3); - ASSERT_GT(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 0.7); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + actual_value = (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps; + result.finalize(); + ASSERT_NEAR(result.total_size_per_sec, actual_value, actual_value * 0.3); plan = {"set test / throttle by size / 10b value size", operation_type::set, 10, 1, 50}; - set_throttle(throttle_type::write_by_size, - (plan.single_value_sz + test_hashkey_len + test_sortkey_len) * plan.multi_count * - plan.limit_qps); + ASSERT_NO_FATAL_FAILURE( + set_throttle(throttle_type::write_by_size, + (plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 1.3); - ASSERT_GT(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 0.7); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + actual_value = (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps; + result.finalize(); + ASSERT_NEAR(result.total_size_per_sec, actual_value, actual_value * 0.3); plan = {"get test / throttle by size / 10b value size", operation_type::get, 10, 1, 50}; - set_throttle(throttle_type::read_by_size, - (plan.single_value_sz + test_hashkey_len + test_sortkey_len) * plan.multi_count * - plan.limit_qps); + ASSERT_NO_FATAL_FAILURE( + set_throttle(throttle_type::read_by_size, + (plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 1.3); - ASSERT_GT(result.records["total_size_per_sec"], - (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * - plan.multi_count * plan.limit_qps * 0.7); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + actual_value = (uint64_t)(plan.single_value_sz + test_hashkey_len + test_sortkey_len) * + plan.multi_count * plan.limit_qps; + result.finalize(); + ASSERT_NEAR(result.total_size_per_sec, actual_value, actual_value * 0.3); // random value case plan = {"multi_get test / throttle by size / random value size", @@ -669,13 +575,13 @@ TEST_F(throttle_test, test) 50, 50, true}; - set_throttle(throttle_type::read_by_size, 5000000); + ASSERT_NO_FATAL_FAILURE(set_throttle(throttle_type::read_by_size, 5000000)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_size_per_sec"], (uint64_t)5000000 * 1.3); - ASSERT_GT(result.records["total_size_per_sec"], (uint64_t)5000000 * 0.7); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + result.finalize(); + ASSERT_NEAR(result.total_size_per_sec, (uint64_t)5000000, (uint64_t)5000000 * 0.3); plan = {"multi_set test / throttle by size / random value size", operation_type::multi_set, @@ -683,99 +589,111 @@ TEST_F(throttle_test, test) 50, 50, true}; - set_throttle(throttle_type::write_by_size, 5000000); + ASSERT_NO_FATAL_FAILURE(set_throttle(throttle_type::write_by_size, 5000000)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_size_per_sec"], (uint64_t)5000000 * 1.3); - ASSERT_GT(result.records["total_size_per_sec"], (uint64_t)5000000 * 0.7); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + result.finalize(); + ASSERT_NEAR(result.total_size_per_sec, (uint64_t)5000000, (uint64_t)5000000 * 0.3); // hotkey test plan = { "get test / throttle by qps / hotkey test", operation_type::get, 1024, 1, 50, false, true}; - set_throttle(throttle_type::read_by_qps, plan.limit_qps); + ASSERT_NO_FATAL_FAILURE(set_throttle(throttle_type::read_by_qps, plan.limit_qps)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_qps"], plan.limit_qps + 15); - ASSERT_GT(result.records["total_qps"], plan.limit_qps - 15); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + result.finalize(); + ASSERT_NEAR(result.total_qps, plan.limit_qps, 15); plan = { "set test / throttle by qps / hotkey test", operation_type::set, 1024, 1, 50, false, true}; - set_throttle(throttle_type::write_by_qps, plan.limit_qps); + ASSERT_NO_FATAL_FAILURE(set_throttle(throttle_type::write_by_qps, plan.limit_qps)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_qps"], plan.limit_qps + 15); - ASSERT_GT(result.records["total_qps"], plan.limit_qps - 15); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + result.finalize(); + ASSERT_NEAR(result.total_qps, plan.limit_qps, 15); plan = { "set test / throttle by size / hotkey test", operation_type::set, 1024, 1, 50, false, true}; - set_throttle(throttle_type::write_by_size, - plan.limit_qps * plan.single_value_sz * plan.multi_count); + ASSERT_NO_FATAL_FAILURE(set_throttle(throttle_type::write_by_size, + plan.limit_qps * plan.single_value_sz * plan.multi_count)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_size_per_sec"], - (uint64_t)plan.limit_qps * plan.single_value_sz * plan.multi_count * 1.3); - ASSERT_GT(result.records["total_size_per_sec"], - (uint64_t)plan.limit_qps * plan.single_value_sz * plan.multi_count * 0.7); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + actual_value = (uint64_t)plan.limit_qps * plan.single_value_sz * plan.multi_count; + result.finalize(); + ASSERT_NEAR(result.total_size_per_sec, actual_value, actual_value * 0.3); plan = { "get test / throttle by size / hotkey test", operation_type::get, 1024, 1, 50, false, true}; - set_throttle(throttle_type::read_by_size, - plan.limit_qps * plan.single_value_sz * plan.multi_count); + ASSERT_NO_FATAL_FAILURE(set_throttle(throttle_type::read_by_size, + plan.limit_qps * plan.single_value_sz * plan.multi_count)); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_size_per_sec"], - (uint64_t)plan.limit_qps * plan.single_value_sz * plan.multi_count * 1.3); - ASSERT_GT(result.records["total_size_per_sec"], - (uint64_t)plan.limit_qps * plan.single_value_sz * plan.multi_count * 0.7); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + actual_value = (uint64_t)plan.limit_qps * plan.single_value_sz * plan.multi_count; + result.finalize(); + ASSERT_NEAR(result.total_size_per_sec, actual_value, actual_value * 0.3); // mix delay&reject test plan = { "set test / throttle by qps 500 / no delay throttle", operation_type::set, 1024, 1, 500}; - ddl_client->set_app_envs(app_name, {"replica.write_throttling"}, {"500*reject*200"}); + ASSERT_EQ(ERR_OK, + ddl_client_->set_app_envs(app_name_, {"replica.write_throttling"}, {"500*reject*200"}) + .get_error() + .code()); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_qps"], plan.limit_qps + 100); - ASSERT_GT(result.records["total_qps"], plan.limit_qps - 100); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + result.finalize(); + ASSERT_NEAR(result.total_qps, plan.limit_qps, 100); plan = { "get test / throttle by qps 500 / no delay throttle", operation_type::get, 1024, 1, 500}; - ddl_client->set_app_envs(app_name, {"replica.read_throttling"}, {"500*reject*200"}); + ASSERT_EQ(ERR_OK, + ddl_client_->set_app_envs(app_name_, {"replica.read_throttling"}, {"500*reject*200"}) + .get_error() + .code()); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_qps"], plan.limit_qps + 100); - ASSERT_GT(result.records["total_qps"], plan.limit_qps - 100); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + result.finalize(); + ASSERT_NEAR(result.total_qps, plan.limit_qps, 100); plan = {"set test / throttle by qps 500 / delay throttle", operation_type::set, 1024, 1, 500}; - ddl_client->set_app_envs( - app_name, {"replica.write_throttling"}, {"300*delay*100,500*reject*200"}); + ASSERT_EQ(ERR_OK, + ddl_client_ + ->set_app_envs( + app_name_, {"replica.write_throttling"}, {"300*delay*100,500*reject*200"}) + .get_error() + .code()); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_qps"], plan.limit_qps + 100); - ASSERT_GT(result.records["total_qps"], plan.limit_qps - 100); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + result.finalize(); + ASSERT_NEAR(result.total_qps, plan.limit_qps, 100); plan = {"get test / throttle by qps 500 / delay throttle", operation_type::get, 1024, 1, 500}; - ddl_client->set_app_envs( - app_name, {"replica.read_throttling"}, {"300*delay*100,500*reject*200"}); + ASSERT_EQ( + ERR_OK, + ddl_client_ + ->set_app_envs(app_name_, {"replica.read_throttling"}, {"300*delay*100,500*reject*200"}) + .get_error() + .code()); std::cout << "wait 30s for setting env" << std::endl; sleep(30); - result = start_test(plan); - restore_throttle(); - ASSERT_LE(result.records["total_qps"], plan.limit_qps + 100); - ASSERT_GT(result.records["total_qps"], plan.limit_qps - 100); + ASSERT_NO_FATAL_FAILURE(start_test(plan)); + ASSERT_NO_FATAL_FAILURE(restore_throttle()); + result.finalize(); + ASSERT_NEAR(result.total_qps, plan.limit_qps, 100); } diff --git a/src/test/function_test/utils/CMakeLists.txt b/src/test/function_test/utils/CMakeLists.txt index 2d86b2e58b..d11e603b17 100644 --- a/src/test/function_test/utils/CMakeLists.txt +++ b/src/test/function_test/utils/CMakeLists.txt @@ -21,6 +21,7 @@ set(MY_PROJ_SRC "") set(MY_PROJ_LIBS dsn_client dsn_replication_common + pegasus_base pegasus_client_static gtest ) diff --git a/src/test/function_test/utils/global_env.cpp b/src/test/function_test/utils/global_env.cpp index 838a6dbba2..787ac7eaa9 100644 --- a/src/test/function_test/utils/global_env.cpp +++ b/src/test/function_test/utils/global_env.cpp @@ -26,42 +26,32 @@ #include #include +#include + #include "dsn/dist/fmt_logging.h" #include "dsn/utility/utils.h" #include "dsn/tool-api/rpc_address.h" #include "dsn/c/api_layer1.h" +#include "test/function_test/utils/utils.h" global_env::global_env() { - std::cout << "============" << std::endl << "start global_env()" << std::endl; get_dirs(); get_hostip(); } void global_env::get_dirs() { - const char *cmd1 = "ps aux | grep '/meta1/pegasus_server' | grep -v grep | awk '{print $2}'"; - std::stringstream ss1; - int ret = dsn::utils::pipe_execute(cmd1, ss1); - std::cout << cmd1 << " output: " << ss1.str() << std::endl; - dcheck_eq(ret, 0); - int meta1_pid; - ss1 >> meta1_pid; - std::cout << "meta1 pid: " << meta1_pid << std::endl; + std::string output1; + ASSERT_NO_FATAL_FAILURE(run_cmd( + "ps aux | grep '/meta1/pegasus_server' | grep -v grep | awk '{print $2}'", &output1)); // get the dir of a process in onebox, say: $PEGASUS/onebox/meta1 - char cmd2[512] = {0}; - sprintf(cmd2, "readlink /proc/%d/cwd", meta1_pid); - std::stringstream ss2; - ret = dsn::utils::pipe_execute(cmd2, ss2); - std::cout << cmd2 << " output: " << ss2.str() << std::endl; - dcheck_eq(ret, 0); - std::string meta1_dir; - ss2 >> meta1_dir; - std::cout << "meta1 dir: " << meta1_dir << std::endl; + std::string output2; + ASSERT_NO_FATAL_FAILURE(run_cmd("readlink /proc/" + output1 + "/cwd", &output2)); - _pegasus_root = dirname(dirname((char *)meta1_dir.c_str())); - std::cout << "project root: " << _pegasus_root << std::endl; + _pegasus_root = dirname(dirname((char *)output2.c_str())); + std::cout << "Pegasus project root: " << _pegasus_root << std::endl; char task_target[512] = {0}; dassert_f(getcwd(task_target, sizeof(task_target)), ""); @@ -77,5 +67,4 @@ void global_env::get_hostip() memset(buffer, 0, sizeof(buffer)); dassert_f(inet_ntop(AF_INET, &ipnet, buffer, sizeof(buffer)), ""); _host_ip = buffer; - std::cout << "get ip: " << _host_ip << std::endl; } diff --git a/src/test/function_test/utils/test_util.cpp b/src/test/function_test/utils/test_util.cpp index ae7b75de02..e4403a631b 100644 --- a/src/test/function_test/utils/test_util.cpp +++ b/src/test/function_test/utils/test_util.cpp @@ -26,7 +26,10 @@ #include "dsn/dist/replication/replication_other_types.h" #include "dsn/tool-api/rpc_address.h" #include "include/pegasus/client.h" +#include "test/function_test/utils/global_env.h" +#include "test/function_test/utils/utils.h" +using dsn::partition_configuration; using dsn::replication::replica_helper; using dsn::replication::replication_ddl_client; using dsn::rpc_address; @@ -34,7 +37,10 @@ using std::vector; namespace pegasus { -test_util::test_util() : cluster_name_("mycluster"), app_name_("temp") {} +test_util::test_util(std::map create_envs) + : cluster_name_("mycluster"), app_name_("temp"), create_envs_(std::move(create_envs)) +{ +} test_util::~test_util() {} @@ -42,16 +48,37 @@ void test_util::SetUpTestCase() { ASSERT_TRUE(pegasus_client_factory::initialize void test_util::SetUp() { - vector meta_list; ASSERT_TRUE(replica_helper::load_meta_servers( - meta_list, PEGASUS_CLUSTER_SECTION_NAME.c_str(), cluster_name_.c_str())); - ASSERT_FALSE(meta_list.empty()); - ddl_client = std::make_shared(meta_list); - ASSERT_TRUE(ddl_client != nullptr); - - ASSERT_EQ(dsn::ERR_OK, ddl_client->create_app(app_name_, "pegasus", 8, 3, {}, false)); - client = pegasus_client_factory::get_client(cluster_name_.c_str(), app_name_.c_str()); - ASSERT_TRUE(client != nullptr); + meta_list_, PEGASUS_CLUSTER_SECTION_NAME.c_str(), cluster_name_.c_str())); + ASSERT_FALSE(meta_list_.empty()); + + ddl_client_ = std::make_shared(meta_list_); + ASSERT_TRUE(ddl_client_ != nullptr); + + dsn::error_code ret = + ddl_client_->create_app(app_name_, "pegasus", partition_count_, 3, create_envs_, false); + if (ret == dsn::ERR_INVALID_PARAMETERS) { + ASSERT_EQ(dsn::ERR_OK, ddl_client_->drop_app(app_name_, 0)); + ASSERT_EQ(dsn::ERR_OK, + ddl_client_->create_app( + app_name_, "pegasus", partition_count_, 3, create_envs_, false)); + } else { + ASSERT_EQ(dsn::ERR_OK, ret); + } + client_ = pegasus_client_factory::get_client(cluster_name_.c_str(), app_name_.c_str()); + ASSERT_TRUE(client_ != nullptr); + + int32_t partition_count; + ASSERT_EQ(dsn::ERR_OK, ddl_client_->list_app(app_name_, app_id_, partition_count, partitions_)); + ASSERT_NE(0, app_id_); + ASSERT_EQ(partition_count_, partition_count); + ASSERT_EQ(partition_count_, partitions_.size()); +} + +void test_util::run_cmd_from_project_root(const std::string &cmd) +{ + ASSERT_EQ(0, chdir(global_env::instance()._pegasus_root.c_str())); + ASSERT_NO_FATAL_FAILURE(run_cmd(cmd)); } } // namespace pegasus diff --git a/src/test/function_test/utils/test_util.h b/src/test/function_test/utils/test_util.h index b1578e7f3d..facd289e70 100644 --- a/src/test/function_test/utils/test_util.h +++ b/src/test/function_test/utils/test_util.h @@ -19,11 +19,21 @@ #pragma once +#include #include - +#include #include +// TODO(yingchun): it's too tricky, but I don't know how does it happen, we can fix it later. +#define TRICKY_CODE_TO_AVOID_LINK_ERROR \ + do { \ + ddl_client_->create_app("", "pegasus", 0, 0, {}, false); \ + pegasus_client_factory::get_client("", ""); \ + } while (false) + namespace dsn { +class partition_configuration; +class rpc_address; namespace replication { class replication_ddl_client; } // namespace replication @@ -35,17 +45,24 @@ class pegasus_client; class test_util : public ::testing::Test { public: - test_util(); + test_util(std::map create_envs = {}); virtual ~test_util(); static void SetUpTestCase(); void SetUp() override; + void run_cmd_from_project_root(const std::string &cmd); + protected: - std::string cluster_name_; + const std::string cluster_name_; std::string app_name_; - pegasus_client *client = nullptr; - std::shared_ptr ddl_client; + const std::map create_envs_; + int32_t app_id_; + int32_t partition_count_ = 8; + std::vector partitions_; + pegasus_client *client_ = nullptr; + std::vector meta_list_; + std::shared_ptr ddl_client_; }; } // namespace pegasus diff --git a/src/test/function_test/utils/utils.h b/src/test/function_test/utils/utils.h index a40c02d20b..6712a67af5 100644 --- a/src/test/function_test/utils/utils.h +++ b/src/test/function_test/utils/utils.h @@ -19,15 +19,16 @@ #pragma once -#include #include #include +#include +#include #define RETRY_OPERATION(CLIENT_FUNCTION, RESULT) \ do { \ for (int i = 0; i < 60; ++i) { \ RESULT = CLIENT_FUNCTION; \ - if (RESULT == 0) { \ + if (RESULT == PERR_OK) { \ break; \ } else { \ std::this_thread::sleep_for(std::chrono::milliseconds(500)); \ @@ -201,3 +202,15 @@ inline void compare(const T &expect, const U &actual) ASSERT_NO_FATAL_FAILURE(compare(it1->second, it2->second, it1->first)); } } + +inline void run_cmd(const std::string &cmd, std::string *output = nullptr) +{ + std::stringstream ss; + int ret = dsn::utils::pipe_execute(cmd.c_str(), ss); + ASSERT_TRUE(ret == 0 || ret == 256) << "ret: " << ret << std::endl + << "cmd: " << cmd << std::endl + << "output: " << ss.str(); + if (output) { + *output = dsn::utils::trim_string((char *)ss.str().c_str()); + } +}