#include "crush/CrushWrapper.h"
TEST(CrushWrapper, get_immediate_parent) {
- CrushWrapper *c = new CrushWrapper;
-
+ std::unique_ptr<CrushWrapper> c(new CrushWrapper);
+
const int ROOT_TYPE = 1;
c->set_type_name(ROOT_TYPE, "root");
const int OSD_TYPE = 0;
EXPECT_EQ(0, ret);
EXPECT_EQ("root", loc.first);
EXPECT_EQ("default", loc.second);
-
- delete c;
}
TEST(CrushWrapper, move_bucket) {
- CrushWrapper *c = new CrushWrapper;
+ std::unique_ptr<CrushWrapper> c(new CrushWrapper);
const int ROOT_TYPE = 2;
c->set_type_name(ROOT_TYPE, "root");
EXPECT_EQ("root", loc.first);
EXPECT_EQ("root1", loc.second);
}
-
- delete c;
}
TEST(CrushWrapper, swap_bucket) {
- CrushWrapper *c = new CrushWrapper;
+ std::unique_ptr<CrushWrapper> c(new CrushWrapper);
const int ROOT_TYPE = 2;
c->set_type_name(ROOT_TYPE, "root");
}
TEST(CrushWrapper, rename_bucket_or_item) {
- CrushWrapper *c = new CrushWrapper;
+ std::unique_ptr<CrushWrapper> c(new CrushWrapper);
const int ROOT_TYPE = 2;
c->set_type_name(ROOT_TYPE, "root");
int osd0id = c->get_item_id("osd0");
EXPECT_EQ(0, c->rename_item("osd.0", "osd0renamed", &ss));
EXPECT_EQ(osd0id, c->get_item_id("osd0renamed"));
-
- delete c;
}
TEST(CrushWrapper, check_item_loc) {
- CrushWrapper *c = new CrushWrapper;
+ std::unique_ptr<CrushWrapper> c(new CrushWrapper);
int item = 0;
float expected_weight = 1.0;
EXPECT_TRUE(c->check_item_loc(g_ceph_context, item, loc, &weight));
EXPECT_EQ(expected_weight, weight);
}
-
- delete c;
}
TEST(CrushWrapper, update_item) {
- CrushWrapper *c = new CrushWrapper;
+ std::unique_ptr<CrushWrapper> c(new CrushWrapper);
const int ROOT_TYPE = 2;
c->set_type_name(ROOT_TYPE, "root");
EXPECT_EQ(modified_weight, c->get_item_weightf(item));
EXPECT_FALSE(c->check_item_loc(g_ceph_context, item, loc, &weight));
EXPECT_TRUE(c->check_item_loc(g_ceph_context, item, other_loc, &weight));
-
- delete c;
}
TEST(CrushWrapper, adjust_item_weight) {
- CrushWrapper *c = new CrushWrapper;
+ std::unique_ptr<CrushWrapper> c(new CrushWrapper);
const int ROOT_TYPE = 2;
c->set_type_name(ROOT_TYPE, "root");
EXPECT_EQ(1, c->adjust_item_weightf_in_loc(g_ceph_context, item, modified_weight, loc_two));
EXPECT_EQ(original_weight, c->get_item_weightf_in_loc(item, loc_one));
EXPECT_EQ(modified_weight, c->get_item_weightf_in_loc(item, loc_two));
-
- delete c;
}
TEST(CrushWrapper, adjust_subtree_weight) {
- CrushWrapper *c = new CrushWrapper;
+ std::unique_ptr<CrushWrapper> c(new CrushWrapper);
const int ROOT_TYPE = 2;
c->set_type_name(ROOT_TYPE, "root");
ASSERT_EQ(c->get_bucket_weight(host0), 262144);
ASSERT_EQ(c->get_item_weight(host0), 262144);
ASSERT_EQ(c->get_bucket_weight(rootno), 262144 + 131072);
-
- delete c;
}
TEST(CrushWrapper, insert_item) {
- CrushWrapper *c = new CrushWrapper;
+ std::unique_ptr<CrushWrapper> c(new CrushWrapper);
const int ROOT_TYPE = 2;
c->set_type_name(ROOT_TYPE, "root");
EXPECT_EQ(-EINVAL, c->insert_item(g_ceph_context, item, 1.0,
"osd." + stringify(item), loc));
}
-
- delete c;
}
TEST(CrushWrapper, remove_item) {
- auto *c = new CrushWrapper;
+ std::unique_ptr<CrushWrapper> c(new CrushWrapper);
const int ROOT_TYPE = 2;
c->set_type_name(ROOT_TYPE, "root");
ASSERT_EQ(0, c->remove_item(g_ceph_context, item_to_remove, true));
float weight;
EXPECT_FALSE(c->check_item_loc(g_ceph_context, item_to_remove, loc, &weight));
-
- delete c;
}
TEST(CrushWrapper, item_bucket_names) {
- CrushWrapper *c = new CrushWrapper;
+ std::unique_ptr<CrushWrapper> c(new CrushWrapper);
int index = 123;
string name = "NAME";
EXPECT_EQ(-EINVAL, c->set_item_name(index, "\001"));
EXPECT_TRUE(c->item_exists(index));
EXPECT_EQ(index, c->get_item_id(name));
EXPECT_EQ(name, c->get_item_name(index));
- delete c;
}
TEST(CrushWrapper, bucket_types) {
- CrushWrapper *c = new CrushWrapper;
+ std::unique_ptr<CrushWrapper> c(new CrushWrapper);
int index = 123;
string name = "NAME";
c->set_type_name(index, name);
EXPECT_EQ(1, c->get_num_type_names());
EXPECT_EQ(index, c->get_type_id(name));
EXPECT_EQ(name, c->get_type_name(index));
- delete c;
}
TEST(CrushWrapper, is_valid_crush_name) {
}
TEST(CrushWrapper, dump_rules) {
- CrushWrapper *c = new CrushWrapper;
+ std::unique_ptr<CrushWrapper> c(new CrushWrapper);
const int ROOT_TYPE = 1;
c->set_type_name(ROOT_TYPE, "root");
c->get_rule_weight_osd_map(0, &wm);
ASSERT_TRUE(wm.size() == 1);
ASSERT_TRUE(wm[0] == 1.0);
-
- delete c;
}
TEST(CrushWrapper, distance) {
arg_map.args = choose_args;
uint64_t features = CEPH_FEATURE_CRUSH_TUNABLES5|CEPH_FEATURE_INCARNATION_2;
+ int64_t caid = CrushWrapper::DEFAULT_CHOOSE_ARGS;
// if the client is capable, encode choose_args
{
- c.choose_args[0] = arg_map;
+ c.choose_args[caid] = arg_map;
bufferlist bl;
c.encode(bl, features|CEPH_FEATURE_CRUSH_CHOOSE_ARGS);
bufferlist::iterator i(bl.begin());
CrushWrapper c_new;
c_new.decode(i);
ASSERT_EQ(1u, c_new.choose_args.size());
- ASSERT_EQ(1u, c_new.choose_args[0].args[-1-id].weight_set_size);
- ASSERT_EQ(weights, c_new.choose_args[0].args[-1-id].weight_set[0].weights[0]);
+ ASSERT_EQ(1u, c_new.choose_args[caid].args[-1-id].weight_set_size);
+ ASSERT_EQ(weights, c_new.choose_args[caid].args[-1-id].weight_set[0].weights[0]);
ASSERT_EQ(weight, c_new.get_bucket_item_weightf(id, 0));
}
// if the client is not compatible, copy choose_arg in the weights
{
- c.choose_args[0] = arg_map;
+ c.choose_args[caid] = arg_map;
bufferlist bl;
c.encode(bl, features);
c.choose_args.clear();
ASSERT_FALSE(c.name_exists("default~ssd"));
}
-TEST(CrushWrapper, class_is_in_use) {
- CrushWrapper c;
- c.create();
- c.set_type_name(1, "root");
-
- int weight = 1;
- map<string,string> loc;
- loc["root"] = "default";
-
- ASSERT_FALSE(c.class_is_in_use(0));
-
- int item = 1;
- c.insert_item(g_ceph_context, item, weight, "osd.1", loc);
- int class_id = c.get_or_create_class_id("ssd");
- c.class_map[item] = class_id;
-
- ASSERT_TRUE(c.class_is_in_use(c.get_class_id("ssd")));
- ASSERT_EQ(0, c.remove_class_name("ssd"));
- ASSERT_FALSE(c.class_is_in_use(c.get_class_id("ssd")));
-}
-
TEST(CrushWrapper, remove_class_name) {
CrushWrapper c;
c.create();
// choose + choose
{
cout << "take + choose + choose + choose + emit" << std::endl;
- int rule = c.add_rule(5, 2, 0, 1, 10, 2);
+ int rule = c.add_rule(2, 5, 0, 1, 10);
ASSERT_EQ(2, rule);
c.set_rule_step_take(rule, 0, bno);
c.set_rule_step_choose_indep(rule, 1, 2, 2);