]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
add unit test for snap rename in imagewatcher
authorxinxin shu <xinxin.shu@intel.com>
Mon, 24 Aug 2015 01:51:21 +0000 (09:51 +0800)
committerxinxin shu <xinxin.shu@intel.com>
Wed, 2 Sep 2015 23:52:28 +0000 (07:52 +0800)
Signed-off-by: xinxin shu <xinxin.shu@intel.com>
src/test/librbd/test_ImageWatcher.cc

index 881315226ea437753677fb2bb10e6581e689a94c..2bc72bf918094fe642cba9b5e5f371db55e8506c 100644 (file)
@@ -906,6 +906,46 @@ TEST_F(TestImageWatcher, NotifySnapCreateError) {
   ASSERT_EQ(expected_notify_ops, m_notifies);
 }
 
+TEST_F(TestImageWatcher, NotifySnapRename) {
+  REQUIRE_FEATURE(RBD_FEATURE_EXCLUSIVE_LOCK);
+
+  librbd::ImageCtx *ictx;
+  ASSERT_EQ(0, open_image(m_image_name, &ictx));
+
+  ASSERT_EQ(0, register_image_watch(*ictx));
+  ASSERT_EQ(0, lock_image(*ictx, LOCK_EXCLUSIVE,
+        "auto " + stringify(m_watch_ctx->get_handle())));
+
+  m_notify_acks = {{NOTIFY_OP_SNAP_RENAME, create_response_message(0)}};
+
+  RWLock::RLocker l(ictx->owner_lock);
+  ASSERT_EQ(0, ictx->image_watcher->notify_snap_rename(1, "snap-rename"));
+
+  NotifyOps expected_notify_ops;
+  expected_notify_ops += NOTIFY_OP_SNAP_RENAME;
+  ASSERT_EQ(expected_notify_ops, m_notifies);
+}
+
+TEST_F(TestImageWatcher, NotifySnapRenameError) {
+  REQUIRE_FEATURE(RBD_FEATURE_EXCLUSIVE_LOCK);
+
+  librbd::ImageCtx *ictx;
+  ASSERT_EQ(0, open_image(m_image_name, &ictx));
+
+  ASSERT_EQ(0, register_image_watch(*ictx));
+  ASSERT_EQ(0, lock_image(*ictx, LOCK_EXCLUSIVE,
+        "auto " + stringify(m_watch_ctx->get_handle())));
+
+  m_notify_acks = {{NOTIFY_OP_SNAP_RENAME, create_response_message(-EEXIST)}};
+
+  RWLock::RLocker l(ictx->owner_lock);
+  ASSERT_EQ(-EEXIST, ictx->image_watcher->notify_snap_rename(1, "snap-rename"));
+
+  NotifyOps expected_notify_ops;
+  expected_notify_ops += NOTIFY_OP_SNAP_RENAME;
+  ASSERT_EQ(expected_notify_ops, m_notifies);
+}
+
 TEST_F(TestImageWatcher, NotifySnapRemove) {
   REQUIRE_FEATURE(RBD_FEATURE_EXCLUSIVE_LOCK);