Skip to content

Commit

Permalink
refactor: change the way to call replication_ddl_client::set_app_envs (
Browse files Browse the repository at this point in the history
  • Loading branch information
zhao liwei authored and Wu Tao committed Sep 24, 2019
1 parent e5fcffd commit 8fb0099
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion rdsn
Submodule rdsn updated 128 files
16 changes: 12 additions & 4 deletions src/shell/commands/table_management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,11 +744,19 @@ bool set_app_envs(command_executor *e, shell_context *sc, arguments args)
values.emplace_back(args.argv[idx++]);
}

::dsn::error_code ret = sc->ddl_client->set_app_envs(sc->current_app_name, keys, values);

if (ret != ::dsn::ERR_OK) {
fprintf(stderr, "set app env failed with err = %s\n", ret.to_string());
auto err_resp = sc->ddl_client->set_app_envs(sc->current_app_name, keys, values);
dsn::error_s err = err_resp.get_error();
std::string hint_msg;
if (err.is_ok()) {
err = dsn::error_s::make(err_resp.get_value().err);
hint_msg = err_resp.get_value().hint_message;
}
if (!err.is_ok()) {
fmt::print(stderr, "set app envs failed with error {} [hint:\"{}\"]!\n", err, hint_msg);
} else {
fmt::print(stdout, "set app envs succeed\n");
}

return true;
}

Expand Down
23 changes: 13 additions & 10 deletions src/test/function_test/test_ttl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ void set_default_ttl(int ttl)

std::string env = envs[TABLE_LEVEL_DEFAULT_TTL];
if ((env.empty() && ttl != 0) || env != std::to_string(ttl)) {
dsn::error_code ec = ddl_client->set_app_envs(
auto response = ddl_client->set_app_envs(
client->get_app_name(), {TABLE_LEVEL_DEFAULT_TTL}, {std::to_string(ttl)});
ASSERT_EQ(ERR_OK, ec);
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));
Expand Down Expand Up @@ -99,10 +100,11 @@ TEST(ttl, set_without_default_ttl)
ASSERT_EQ(ttl_test_value_2, value);

// trigger a manual compaction
dsn::error_code ec = ddl_client->set_app_envs(client->get_app_name(),
{MANUAL_COMPACT_ONCE_TRIGGER_TIME_KEY},
{std::to_string(time(nullptr))});
ASSERT_EQ(ERR_OK, ec);
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));
Expand Down Expand Up @@ -191,10 +193,11 @@ TEST(ttl, set_with_default_ttl)
ASSERT_EQ(ttl_test_value_2, value);

// trigger a manual compaction
dsn::error_code ec = ddl_client->set_app_envs(client->get_app_name(),
{MANUAL_COMPACT_ONCE_TRIGGER_TIME_KEY},
{std::to_string(time(nullptr))});
ASSERT_EQ(ERR_OK, ec);
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));
Expand Down

0 comments on commit 8fb0099

Please sign in to comment.