summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Watkins <noahwatkins@gmail.com>2013-02-24 14:43:01 -0800
committerNoah Watkins <noahwatkins@gmail.com>2013-08-25 08:58:27 -0700
commit1a7fa285c5b95f749da0befe987599fa90e1fcde (patch)
tree27b0e6bd87bbebf94b82b5f77c4020a7ec8c3346
parent78297797e9f26aab118e2b81630079d6e31e59f7 (diff)
downloadceph-1a7fa285c5b95f749da0befe987599fa90e1fcde.tar.gz
lua: support cls_cxx_map_clear
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
-rw-r--r--src/cls/lua/cls_lua.cc11
-rw-r--r--src/test/cls_lua/test_cls_lua.cc27
-rw-r--r--src/test/cls_lua/test_script.lua9
3 files changed, 47 insertions, 0 deletions
diff --git a/src/cls/lua/cls_lua.cc b/src/cls/lua/cls_lua.cc
index 0d0028e3469..4d112b6cf75 100644
--- a/src/cls/lua/cls_lua.cc
+++ b/src/cls/lua/cls_lua.cc
@@ -362,6 +362,16 @@ static int clslua_map_set_val(lua_State *L)
}
/*
+ * cls_cxx_map_clear
+ */
+static int clslua_map_clear(lua_State *L)
+{
+ cls_method_context_t hctx = clslua_get_hctx(L);
+ int ret = cls_cxx_map_clear(hctx);
+ return clslua_opresult(L, (ret == 0), ret, 0);
+}
+
+/*
* Functions registered in the 'cls' module.
*/
static const luaL_Reg clslua_lib[] = {
@@ -372,6 +382,7 @@ static const luaL_Reg clslua_lib[] = {
{"stat", clslua_stat},
{"read", clslua_read},
{"write", clslua_write},
+ {"map_clear", clslua_map_clear},
{"map_get_val", clslua_map_get_val},
{"map_set_val", clslua_map_set_val},
{"getxattr", clslua_getxattr},
diff --git a/src/test/cls_lua/test_cls_lua.cc b/src/test/cls_lua/test_cls_lua.cc
index e470a82b867..7208ef5af84 100644
--- a/src/test/cls_lua/test_cls_lua.cc
+++ b/src/test/cls_lua/test_cls_lua.cc
@@ -247,6 +247,33 @@ TEST_F(ClsLua, Stat) {
ASSERT_EQ(-ENOENT, __clslua_exec("dne", test_script, NULL, "stat_sdne_pcall"));
}
+TEST_F(ClsLua, MapClear) {
+ /* write some data into a key */
+ string msg = "This is a test message";
+ bufferlist val;
+ val.append(msg.c_str(), msg.size());
+ map<string, bufferlist> map;
+ map["foo"] = val;
+ ASSERT_EQ(0, ioctx.omap_set(oid, map));
+
+ /* test we can get it back out */
+ set<string> keys;
+ keys.insert("foo");
+ map.clear();
+ ASSERT_EQ(0, (int)map.count("foo"));
+ ASSERT_EQ(0, ioctx.omap_get_vals_by_keys(oid, keys, &map));
+ ASSERT_EQ(1, (int)map.count("foo"));
+
+ /* now clear it */
+ ASSERT_EQ(0, clslua_exec(test_script, NULL, "map_clear"));
+
+ /* test that the map we get back is empty now */
+ map.clear();
+ ASSERT_EQ(0, (int)map.count("foo"));
+ ASSERT_EQ(0, ioctx.omap_get_vals_by_keys(oid, keys, &map));
+ ASSERT_EQ(0, (int)map.count("foo"));
+}
+
TEST_F(ClsLua, MapSetVal) {
/* build some input value */
bufferlist orig_val;
diff --git a/src/test/cls_lua/test_script.lua b/src/test/cls_lua/test_script.lua
index d04728b3723..ae9cc9f1452 100644
--- a/src/test/cls_lua/test_script.lua
+++ b/src/test/cls_lua/test_script.lua
@@ -166,6 +166,15 @@ end
cls.register(map_set_val)
--
+-- MapClear
+--
+function map_clear()
+ cls.map_clear()
+end
+
+cls.register(map_clear)
+
+--
-- BufferlistEquality
--
function bl_eq_empty_equal(input, output)