]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados_test_stub: add support for flushing watches
authorJason Dillaman <dillaman@redhat.com>
Thu, 30 Apr 2015 17:36:26 +0000 (13:36 -0400)
committerJason Dillaman <dillaman@redhat.com>
Thu, 4 Jun 2015 20:49:51 +0000 (16:49 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/test/librados_test_stub/TestMemRadosClient.cc
src/test/librados_test_stub/TestWatchNotify.cc
src/test/librados_test_stub/TestWatchNotify.h

index 73abfa9a08980ea8a2a7a154de569a3dc1910bd9..b89f4eb6fed2a6bd939db8e9937bed5fe36c851e 100644 (file)
@@ -116,6 +116,7 @@ int TestMemRadosClient::pool_reverse_lookup(int64_t id, std::string *name) {
 }
 
 int TestMemRadosClient::watch_flush() {
+  get_watch_notify().flush();
   return 0;
 }
 
index 6fd77483bf27f4884965c24409f7cb8968b3348a..d51b893cf8d94d6efced7072ba5e8880e4963f05 100644 (file)
@@ -11,7 +11,8 @@ namespace librados {
 
 TestWatchNotify::TestWatchNotify(CephContext *cct)
   : m_cct(cct), m_finisher(new Finisher(cct)), m_handle(), m_notify_id(),
-    m_file_watcher_lock("librados::TestWatchNotify::m_file_watcher_lock") {
+    m_file_watcher_lock("librados::TestWatchNotify::m_file_watcher_lock"),
+    m_pending_notifies(0) {
   m_cct->get();
   m_finisher->start();
 }
@@ -31,6 +32,13 @@ TestWatchNotify::Watcher::Watcher()
   : lock("TestWatchNotify::Watcher::lock") {
 }
 
+void TestWatchNotify::flush() {
+  Mutex::Locker file_watcher_locker(m_file_watcher_lock);
+  while (m_pending_notifies > 0) {
+    m_file_watcher_cond.Wait(m_file_watcher_lock);
+  }
+}
+
 int TestWatchNotify::list_watchers(const std::string& o,
                                    std::list<obj_watch_t> *out_watchers) {
   SharedWatcher watcher = get_watcher(o);
@@ -61,6 +69,7 @@ int TestWatchNotify::notify(const std::string& oid, bufferlist& bl,
     RWLock::WLocker l(watcher->lock);
     {
       Mutex::Locker l2(m_file_watcher_lock);
+      ++m_pending_notifies;
       uint64_t notify_id = ++m_notify_id;
 
       SharedNotifyHandle notify_handle(new NotifyHandle());
@@ -203,6 +212,13 @@ void TestWatchNotify::execute_notify(const std::string &oid,
   Mutex::Locker l3(*lock);
   *done = true;
   cond->Signal();
+
+  {
+    Mutex::Locker file_watcher_locker(m_file_watcher_lock);
+    if (--m_pending_notifies == 0) {
+      m_file_watcher_cond.Signal();
+    }
+  }
 }
 
 } // namespace librados
index f73ee3a793e8e1c4c25697edc942f3dc9385f835..4912ef27444a899efc333597b52482f9449e6f1e 100644 (file)
@@ -53,6 +53,7 @@ public:
   TestWatchNotify(CephContext *cct);
   ~TestWatchNotify();
 
+  void flush();
   int list_watchers(const std::string& o,
                     std::list<obj_watch_t> *out_watchers);
   int notify(const std::string& o, bufferlist& bl,
@@ -74,6 +75,9 @@ private:
   uint64_t m_notify_id;
 
   Mutex m_file_watcher_lock;
+  Cond m_file_watcher_cond;
+  uint64_t m_pending_notifies;
+
   FileWatchers m_file_watchers;
 
   SharedWatcher get_watcher(const std::string& oid);