Skip to content

Commit

Permalink
add meta_app_operation_test
Browse files Browse the repository at this point in the history
  • Loading branch information
empiredan committed Nov 12, 2024
1 parent 9893e64 commit 3cb2ec7
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/meta/duplication/meta_duplication_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <string_view>
#include <type_traits>

#include "common//duplication_common.h"
#include "common/duplication_common.h"
#include "common/common.h"
#include "common/gpid.h"
#include "common/replication.codes.h"
Expand Down
81 changes: 72 additions & 9 deletions src/meta/test/meta_app_operation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <utility>
#include <vector>

#include "common/duplication_common.h"
#include "common/gpid.h"
#include "common/json_helper.h"
#include "common/replica_envs.h"
Expand Down Expand Up @@ -62,7 +63,7 @@ namespace replication {
class meta_app_operation_test : public meta_test_base
{
public:
meta_app_operation_test() {}
meta_app_operation_test() = default;

error_code create_app_test(int32_t partition_count,
int32_t replica_count,
Expand Down Expand Up @@ -320,6 +321,34 @@ class meta_app_operation_test : public meta_test_base
tracker.wait_outstanding_tasks();
}

void verify_app_envs(const std::string &app_name,
const std::map<std::string, std::string> &expected_envs)
{
auto app = find_app(app_name);
CHECK(app, "app({}) does not exist", app_name);

auto app_path = _ss->get_app_path(*app);

dsn::task_tracker tracker;
_ms->get_remote_storage()->get_data(
app_path,
LPC_META_CALLBACK,
[app_name, expected_envs, app](error_code ec, const blob &value) {
ASSERT_EQ(ERR_OK, ec);

app_info ainfo;
dsn::json::json_forwarder<app_info>::decode(value, ainfo);

ASSERT_EQ(app_name, app->app_name);
ASSERT_EQ(app_name, ainfo.app_name);
ASSERT_EQ(app->app_id, ainfo.app_id);
ASSERT_EQ(expected_envs, app->envs);
ASSERT_EQ(expected_envs, ainfo.envs);
},
&tracker);
tracker.wait_outstanding_tasks();
}

const std::string APP_NAME = "app_operation_test";
const std::string OLD_APP_NAME = "old_app_operation";
};
Expand Down Expand Up @@ -502,6 +531,34 @@ TEST_F(meta_app_operation_test, create_app)
app_status::AS_INVALID,
ERR_OK,
{{"rocksdb.write_buffer_size", "33554432"}}},
{APP_NAME + "_13",
4,
3,
2,
3,
3,
false,
app_status::AS_INVALID,
ERR_OK,
{{duplication_constants::kDuplicationEnvMasterClusterKey, "source_cluster"},
{duplication_constants::kDuplicationEnvMasterMetasKey, "10.1.2.3:34601"},
{duplication_constants::kDuplicationEnvMasterAppNameKey, APP_NAME + "_13_remote"},
{duplication_constants::kDuplicationEnvMasterCreateFollowerAppStatusKey,
duplication_constants::kDuplicationEnvMasterCreateFollowerAppStatusCreating}}},
{APP_NAME + "_13",
4,
3,
2,
3,
3,
false,
app_status::AS_AVAILABLE,
ERR_OK,
{{duplication_constants::kDuplicationEnvMasterClusterKey, "source_cluster"},
{duplication_constants::kDuplicationEnvMasterMetasKey, "10.1.2.3:34601"},
{duplication_constants::kDuplicationEnvMasterAppNameKey, APP_NAME + "_13_remote"},
{duplication_constants::kDuplicationEnvMasterCreateFollowerAppStatusKey,
duplication_constants::kDuplicationEnvMasterCreateFollowerAppStatusCreating}}},
};

clear_nodes();
Expand Down Expand Up @@ -546,12 +603,17 @@ TEST_F(meta_app_operation_test, create_app)
} else if (test.before_status != app_status::AS_INVALID) {
update_app_status(test.before_status);
}

auto err = create_app_test(test.partition_count,
test.replica_count,
test.success_if_exist,
test.app_name,
test.envs);
ASSERT_EQ(err, test.expected_err);
ASSERT_EQ(test.expected_err, err);

if (test.expected_err == ERR_OK) {
verify_app_envs(test.app_name, test.envs);
}

_ms->set_node_state(nodes, true);
}
Expand All @@ -570,38 +632,39 @@ TEST_F(meta_app_operation_test, create_app)
ASSERT_TRUE(all_test_envs.find(option) != all_test_envs.end());
}
}

// set FLAGS_min_allowed_replica_count successfully
res = update_flag("min_allowed_replica_count", "2");
ASSERT_TRUE(res.is_ok());
ASSERT_EQ(FLAGS_min_allowed_replica_count, 2);
ASSERT_EQ(2, FLAGS_min_allowed_replica_count);

// set FLAGS_max_allowed_replica_count successfully
res = update_flag("max_allowed_replica_count", "6");
ASSERT_TRUE(res.is_ok());
ASSERT_EQ(FLAGS_max_allowed_replica_count, 6);
ASSERT_EQ(6, FLAGS_max_allowed_replica_count);

// failed to set FLAGS_min_allowed_replica_count due to individual validation
res = update_flag("min_allowed_replica_count", "0");
ASSERT_EQ(res.code(), ERR_INVALID_PARAMETERS);
ASSERT_EQ(FLAGS_min_allowed_replica_count, 2);
ASSERT_EQ(2, FLAGS_min_allowed_replica_count);
std::cout << res.description() << std::endl;

// failed to set FLAGS_max_allowed_replica_count due to individual validation
res = update_flag("max_allowed_replica_count", "0");
ASSERT_EQ(res.code(), ERR_INVALID_PARAMETERS);
ASSERT_EQ(FLAGS_max_allowed_replica_count, 6);
ASSERT_EQ(6, FLAGS_max_allowed_replica_count);
std::cout << res.description() << std::endl;

// failed to set FLAGS_min_allowed_replica_count due to grouped validation
res = update_flag("min_allowed_replica_count", "7");
ASSERT_EQ(res.code(), ERR_INVALID_PARAMETERS);
ASSERT_EQ(FLAGS_min_allowed_replica_count, 2);
ASSERT_EQ(2, FLAGS_min_allowed_replica_count);
std::cout << res.description() << std::endl;

// failed to set FLAGS_max_allowed_replica_count due to grouped validation
res = update_flag("max_allowed_replica_count", "1");
ASSERT_EQ(res.code(), ERR_INVALID_PARAMETERS);
ASSERT_EQ(FLAGS_max_allowed_replica_count, 6);
ASSERT_EQ(6, FLAGS_max_allowed_replica_count);
std::cout << res.description() << std::endl;

// recover original FLAGS_min_allowed_replica_count
Expand All @@ -614,7 +677,7 @@ TEST_F(meta_app_operation_test, create_app)
res = update_flag("max_allowed_replica_count",
std::to_string(reserved_max_allowed_replica_count));
ASSERT_TRUE(res.is_ok());
ASSERT_EQ(FLAGS_max_allowed_replica_count, reserved_max_allowed_replica_count);
ASSERT_EQ(reserved_max_allowed_replica_count, FLAGS_max_allowed_replica_count);

// recover original FLAGS_min_live_node_count_for_unfreeze
set_min_live_node_count_for_unfreeze(reserved_min_live_node_count_for_unfreeze);
Expand Down
2 changes: 1 addition & 1 deletion src/meta/test/meta_duplication_service_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class meta_duplication_service_test : public meta_test_base
static const std::string kTestRemoteAppName;
static const int32_t kTestRemoteReplicaCount;

meta_duplication_service_test() {}
meta_duplication_service_test() = default;

duplication_add_response create_dup(const std::string &app_name,
const std::string &remote_cluster,
Expand Down

0 comments on commit 3cb2ec7

Please sign in to comment.