From: Colin Patrick McCabe Date: Wed, 17 Aug 2011 00:37:38 +0000 (-0700) Subject: test/rados-api/watch_notify.cc: implement C++ ver X-Git-Tag: v0.34~81^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=65626edec7539ba4facfe9bc90e070e57f8b2ee5;p=ceph.git test/rados-api/watch_notify.cc: implement C++ ver Signed-off-by: Colin McCabe --- diff --git a/src/test/rados-api/watch_notify.cc b/src/test/rados-api/watch_notify.cc index 48afbe1b83d1..1fceee4e8075 100644 --- a/src/test/rados-api/watch_notify.cc +++ b/src/test/rados-api/watch_notify.cc @@ -1,10 +1,13 @@ #include "include/rados/librados.h" +#include "include/rados/librados.hpp" #include "test/rados-api/test.h" #include #include #include "gtest/gtest.h" +using namespace librados; + static sem_t sem; static void watch_notify_test_cb(uint8_t opcode, uint64_t ver, void *arg) @@ -12,6 +15,15 @@ static void watch_notify_test_cb(uint8_t opcode, uint64_t ver, void *arg) sem_post(&sem); } +class WatchNotifyTestCtx : public WatchCtx +{ +public: + void notify(uint8_t opcode, uint64_t ver, bufferlist& bl) + { + sem_post(&sem); + } +}; + TEST(LibRadosWatchNotify, WatchNotifyTest) { ASSERT_EQ(0, sem_init(&sem, 0, 0)); char buf[128]; @@ -34,3 +46,27 @@ TEST(LibRadosWatchNotify, WatchNotifyTest) { sem_destroy(&sem); } +TEST(LibRadosWatchNotify, WatchNotifyTestPP) { + ASSERT_EQ(0, sem_init(&sem, 0, 0)); + Rados cluster; + std::string pool_name = get_temp_pool_name(); + ASSERT_EQ("", create_one_pool_pp(pool_name, cluster)); + IoCtx ioctx; + cluster.ioctx_create(pool_name.c_str(), ioctx); + char buf[128]; + memset(buf, 0xcc, sizeof(buf)); + bufferlist bl1; + bl1.append(buf, sizeof(buf)); + ASSERT_EQ((int)sizeof(buf), ioctx.write("foo", bl1, sizeof(buf), 0)); + uint64_t handle; + WatchNotifyTestCtx ctx; + ASSERT_EQ(0, ioctx.watch("foo", 0, &handle, &ctx)); + bufferlist bl2; + ASSERT_EQ(0, ioctx.notify("foo", 0, bl2)); + TestAlarm alarm; + sem_wait(&sem); + ioctx.unwatch("foo", handle); + ioctx.close(); + ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster)); + sem_destroy(&sem); +}