From: Xiaoxi Chen Date: Fri, 10 Apr 2015 01:39:44 +0000 (+0800) Subject: test/store_test Add get_omap_iterator test cases X-Git-Tag: v9.1.0~242^2~69 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b595aac4e1245f4478332a3aa30300e7495e65d4;p=ceph.git test/store_test Add get_omap_iterator test cases omap iterator test cases include: iter aganist omap lower_bound upper_bound Signed-off-by: Xiaoxi Chen --- diff --git a/src/test/objectstore/store_test.cc b/src/test/objectstore/store_test.cc index 8ce487823446..aa20a87be387 100644 --- a/src/test/objectstore/store_test.cc +++ b/src/test/objectstore/store_test.cc @@ -2030,6 +2030,81 @@ TEST_P(StoreTest, OMapTest) { ASSERT_EQ(r, 0); } +TEST_P(StoreTest, OMapIterator) { + coll_t cid; + ghobject_t hoid(hobject_t("tesomap", "", CEPH_NOSNAP, 0, 0, "")); + int count = 0; + int r; + { + ObjectStore::Transaction t; + t.create_collection(cid, 0); + r = store->apply_transaction(t); + ASSERT_EQ(r, 0); + } + + map attrs; + { + ObjectStore::Transaction t; + t.touch(cid, hoid); + t.omap_clear(cid, hoid); + map start_set; + t.omap_setkeys(cid, hoid, start_set); + store->apply_transaction(t); + } + ObjectMap::ObjectMapIterator iter = store->get_omap_iterator(cid, hoid); + bool correct; + //basic iteration + for (int i = 0; i < 100; i++) { + if (!(i%5)) { + std::cout << "On iteration " << i << std::endl; + } + ObjectStore::Transaction t; + bufferlist bl; + iter = store->get_omap_iterator(cid, hoid); + + for (iter->seek_to_first(), count=0; iter->valid(); iter->next(), count++) { + string key = iter->key(); + bufferlist value = iter->value(); + correct = attrs.count(key) && (string(value.c_str()) == string(attrs[key].c_str())); + if (!correct) { + if (attrs.count(key) > 0) { + std::cout << "key " << key << "in omap , " << value.c_str() << " : " << attrs[key].c_str() << std::endl; + } + else + std::cout << "key " << key << "should not exists in omap" << std::endl; + } + ASSERT_EQ(correct, true); + } + ASSERT_EQ(attrs.size(), count); + + char buf[100]; + snprintf(buf, sizeof(buf), "%d", i); + bl.clear(); + bufferptr bp(buf, strlen(buf) + 1); + bl.append(bp); + map to_add; + to_add.insert(pair("key-" + string(buf), bl)); + attrs.insert(pair("key-" + string(buf), bl)); + t.omap_setkeys(cid, hoid, to_add); + store->apply_transaction(t); + } + //lower bound + string bound_key = "key-5"; + iter->lower_bound(bound_key); + correct = bound_key <= iter->key(); + if (!correct) { + std::cout << "lower bound, bound key is " << bound_key << " < iter key is " << iter->key() << std::endl; + } + ASSERT_EQ(correct, true); + //upper bound + iter->upper_bound(bound_key); + correct = iter->key() > bound_key; + if (!correct) { + std::cout << "upper bound, bound key is " << bound_key << " >= iter key is " << iter->key() << std::endl; + } + ASSERT_EQ(correct, true); +} + TEST_P(StoreTest, XattrTest) { coll_t cid; ghobject_t hoid(hobject_t("tesomap", "", CEPH_NOSNAP, 0, 0, ""));