diff --git a/src/test/function_test/restore/test_restore.cpp b/src/test/function_test/restore/test_restore.cpp index 1646aab036..2548ba6036 100644 --- a/src/test/function_test/restore/test_restore.cpp +++ b/src/test/function_test/restore/test_restore.cpp @@ -56,22 +56,20 @@ class restore_test : public test_util { test_util::SetUp(); - std::string provider_dir = "block_service/local_service"; - policy_dir = "onebox/" + provider_dir + '/' + - dsn::utils::filesystem::path_combine(kClusterName_, policy_name); - backup_dir = "onebox/" + provider_dir + '/' + kClusterName_; + backup_path_ = fmt::format("onebox/block_service/local_service/{}", kClusterName_); - NO_FATALS(write_data(kv_pair_cnt)); + NO_FATALS(write_data(kTestCount)); std::vector app_ids({table_id_}); - auto err = ddl_client_->add_backup_policy(policy_name, - backup_provider_name, - app_ids, - backup_interval_seconds, - backup_history_count_to_keep, - start_time); - std::cout << "add backup policy complete with err = " << err.to_string() << std::endl; - ASSERT_EQ(err, ERR_OK); + // 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. + ASSERT_EQ( + ERR_OK, + ddl_client_->add_backup_policy("policy_1", "local_service", app_ids, 700, 6, "24:0")); } void TearDown() override { ASSERT_EQ(ERR_OK, ddl_client_->drop_app(table_name_, 0)); } @@ -80,25 +78,26 @@ class restore_test : public test_util { std::this_thread::sleep_for(std::chrono::seconds(30)); ASSERT_EQ(ERR_OK, - ddl_client_->do_restore(backup_provider_name, + ddl_client_->do_restore("local_service", kClusterName_, /* policy_name */ "", - time_stamp, + first_backup_timestamp_, table_name_, table_id_, - new_app_name, + kNewTableName, false)); - NO_FATALS(wait_table_healthy(new_app_name)); + NO_FATALS(wait_table_healthy(kNewTableName)); } void wait_backup_complete() { ASSERT_IN_TIME( [&] { - time_stamp = get_first_backup_timestamp(); - fmt::print(stdout, "first backup_timestamp = {}", time_stamp); + first_backup_timestamp_ = get_first_backup_timestamp(); + fmt::print(stdout, "first backup_timestamp = {}", first_backup_timestamp_); - auto backup_info = fmt::format("{}/{}/backup_info", backup_dir, time_stamp); + auto backup_info = + fmt::format("{}/{}/backup_info", backup_path_, first_backup_timestamp_); ASSERT_TRUE(dsn::utils::filesystem::file_exists(backup_info)); }, 180); @@ -108,10 +107,10 @@ class restore_test : public test_util { std::string pegasus_root_dir = global_env::instance()._pegasus_root; CHECK_EQ(0, ::chdir(pegasus_root_dir.c_str())); - std::string cmd = "cd " + backup_dir + "; " - "ls -c > restore_app_from_backup_test_tmp; " - "tail -n 1 restore_app_from_backup_test_tmp; " - "rm restore_app_from_backup_test_tmp"; + std::string cmd = "cd " + backup_path_ + "; " + "ls -c > restore_app_from_backup_test_tmp; " + "tail -n 1 restore_app_from_backup_test_tmp; " + "rm restore_app_from_backup_test_tmp"; std::stringstream ss; int ret = dsn::utils::pipe_execute(cmd.c_str(), ss); std::cout << cmd << " output: " << ss.str() << std::endl; @@ -131,40 +130,21 @@ class restore_test : public test_util } public: - std::string policy_dir; - std::string backup_dir; + const int kTestCount = 10000; + const std::string kNewTableName = "backup_test_new"; - const std::string new_app_name = "backup_test_new"; - int64_t time_stamp; - - 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 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; + int64_t first_backup_timestamp_; + std::string backup_path_; }; TEST_F(restore_test, restore) { - std::cout << "start testing restore..." << std::endl; + fmt::print("start testing restore...\n"); // step1: wait backup complete NO_FATALS(wait_backup_complete()); // step2: test restore NO_FATALS(restore()); // step3: verify_data - NO_FATALS(verify_data(new_app_name, kv_pair_cnt)); - std::cout << "restore passed....." << std::endl; + NO_FATALS(verify_data(kNewTableName, kTestCount)); + fmt::print("restore passed...\n"); } diff --git a/src/test/function_test/utils/test_util.cpp b/src/test/function_test/utils/test_util.cpp index a395b4b3c2..5e5e4614b4 100644 --- a/src/test/function_test/utils/test_util.cpp +++ b/src/test/function_test/utils/test_util.cpp @@ -189,7 +189,7 @@ void test_util::operate_data(OperateDataType type, ASSERT_NE(client, nullptr); int64_t start = dsn_now_ms(); ASSERT_GT(count, 0); - ASSERT_LT(count, 10000); + ASSERT_LE(count, 10000); for (int i = 0; i < count; i++) { auto hashkey = fmt::format("{}{:04}", hashkey_prefix, i); std::string value;