]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
systest: add st_rados_watch building block for watch/notify tests
authorJosh Durgin <josh.durgin@dreamhost.com>
Tue, 26 Jul 2011 23:12:12 +0000 (16:12 -0700)
committerJosh Durgin <josh.durgin@dreamhost.com>
Tue, 2 Aug 2011 21:17:15 +0000 (14:17 -0700)
Signed-off-by: Josh Durgin <josh.durgin@dreamhost.com>
src/test/system/st_rados_watch.cc [new file with mode: 0644]
src/test/system/st_rados_watch.h [new file with mode: 0644]

diff --git a/src/test/system/st_rados_watch.cc b/src/test/system/st_rados_watch.cc
new file mode 100644 (file)
index 0000000..d6647de
--- /dev/null
@@ -0,0 +1,82 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+* Ceph - scalable distributed file system
+*
+* Copyright (C) 2011 New Dream Network
+*
+* This is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License version 2.1, as published by the Free Software
+* Foundation.  See file COPYING.
+*
+*/
+
+#include "cross_process_sem.h"
+#include "include/rados/librados.h"
+#include "st_rados_watch.h"
+#include "systest_runnable.h"
+
+void notify_cb(uint8_t opcode, uint64_t ver, void *arg)
+{
+  int *notifies = reinterpret_cast<int*>(arg);
+  ++(*notifies);
+}
+
+StRadosWatch::StRadosWatch(int argc, const char **argv,
+                          CrossProcessSem *setup_sem,
+                          CrossProcessSem *watch_sem,
+                          CrossProcessSem *notify_sem,
+                          int num_notifies,
+                          const std::string &pool_name,
+                          const std::string &obj_name)
+  : SysTestRunnable(argc, argv),
+    m_setup_sem(setup_sem),
+    m_watch_sem(watch_sem),
+    m_notify_sem(notify_sem),
+    m_num_notifies(num_notifies),
+    m_pool_name(pool_name),
+    m_obj_name(obj_name)
+{
+}
+
+StRadosWatch::
+~StRadosWatch()
+{
+}
+
+int StRadosWatch::
+run()
+{
+  rados_t cl;
+  RETURN1_IF_NONZERO(rados_create(&cl, NULL));
+  rados_conf_parse_argv(cl, m_argc, m_argv);
+  RETURN1_IF_NONZERO(rados_conf_read_file(cl, NULL));
+  if (m_setup_sem) {
+    m_setup_sem->wait();
+    m_setup_sem->post();
+  }
+
+  rados_ioctx_t io_ctx;
+  uint64_t handle;
+  int num_notifies = 0;
+  RETURN1_IF_NONZERO(rados_connect(cl));
+  RETURN1_IF_NONZERO(rados_ioctx_create(cl, m_pool_name.c_str(), &io_ctx));
+  printf("%s: watching object %s\n", get_id_str(), m_obj_name.c_str());
+  RETURN1_IF_NONZERO(rados_watch(io_ctx, m_obj_name.c_str(), 0, &handle,
+                                reinterpret_cast<rados_watchcb_t>(notify_cb),
+                                reinterpret_cast<void*>(&num_notifies)));
+  if (m_watch_sem) {
+    m_watch_sem->post();
+  }
+
+  m_notify_sem->wait();
+  m_notify_sem->post();
+
+  RETURN1_IF_NOT_VAL(m_num_notifies, num_notifies);
+  rados_unwatch(io_ctx, m_obj_name.c_str(), handle);
+  rados_ioctx_destroy(io_ctx);
+  rados_shutdown(cl);
+
+  return 0;
+}
diff --git a/src/test/system/st_rados_watch.h b/src/test/system/st_rados_watch.h
new file mode 100644 (file)
index 0000000..e5ae130
--- /dev/null
@@ -0,0 +1,54 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+* Ceph - scalable distributed file system
+*
+* Copyright (C) 2011 New Dream Network
+*
+* This is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License version 2.1, as published by the Free Software
+* Foundation.  See file COPYING.
+*
+*/
+
+#ifndef TEST_SYSTEM_ST_RADOS_WATCH_H
+#define TEST_SYSTEM_ST_RADOS_WATCH_H
+
+#include "systest_runnable.h"
+
+class CrossProcessSem;
+
+/*
+ * st_rados_watch
+ *
+ * 1. waits on setup_sem
+ * 2. posts to setup_sem
+ * 3. watches an object
+ * 4. posts to watch_sem
+ * 5. waits on notify_sem
+ * 6. posts to notify_sem
+ * 7. checks that the correct number of notifies were received
+ */
+class StRadosWatch : public SysTestRunnable
+{
+public:
+  StRadosWatch(int argc, const char **argv,
+              CrossProcessSem *setup_sem,
+              CrossProcessSem *watch_sem,
+              CrossProcessSem *notify_sem,
+              int num_notifies,
+              const std::string &pool_name,
+              const std::string &obj_name);
+  ~StRadosWatch();
+  virtual int run();
+private:
+  CrossProcessSem *m_setup_sem;
+  CrossProcessSem *m_watch_sem;
+  CrossProcessSem *m_notify_sem;
+  int m_num_notifies;
+  std::string m_pool_name;
+  std::string m_obj_name;
+};
+
+#endif