]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test/test_stress_watch.cc: added simple watch stress test
authorSamuel Just <samuel.just@dreamhost.com>
Mon, 19 Sep 2011 23:27:03 +0000 (16:27 -0700)
committerSamuel Just <samuel.just@dreamhost.com>
Thu, 22 Sep 2011 20:18:48 +0000 (13:18 -0700)
Signed-off-by: Samuel Just <samuel.just@dreamhost.com>
src/.gitignore
src/Makefile.am
src/test/test_stress_watch.cc [new file with mode: 0644]

index ab499b500c3cb07da58ab7e674699bb035636dcc..e60302a656fe4b242c9cf8cb6897687c29231b8d 100644 (file)
@@ -42,6 +42,7 @@
 /test_librados_build
 /test_librgw_build
 /testsnaps
+/test_stress_watch
 /test_store
 /test_libcommon_build
 /test_mutate
index 156cbafec2fc2aeeac1b06141d5dd0db7979d00d..63d849b9e0d36e9238998570f74ba970b8497bd0 100644 (file)
@@ -635,6 +635,12 @@ test_store_LDADD =  librados.la ${UNITTEST_STATIC_LDADD} libos.la $(LIBGLOBAL_LD
 test_store_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS}
 bin_DEBUGPROGRAMS += test_store
 
+test_stress_watch_SOURCES = test/test_stress_watch.cc test/rados-api/test.cc
+test_stress_watch_LDFLAGS = ${AM_LDFLAGS}
+test_stress_watch_LDADD =  librados.la ${UNITTEST_STATIC_LDADD}
+test_stress_watch_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS}
+bin_DEBUGPROGRAMS += test_stress_watch
+
 # shell scripts
 editpaths = sed \
        -e 's|@bindir[@]|$(bindir)|g' \
diff --git a/src/test/test_stress_watch.cc b/src/test/test_stress_watch.cc
new file mode 100644 (file)
index 0000000..8679c92
--- /dev/null
@@ -0,0 +1,56 @@
+#include "include/rados/librados.h"
+#include "include/rados/librados.hpp"
+#include "test/rados-api/test.h"
+
+#include "gtest/gtest.h"
+#include <semaphore.h>
+#include <errno.h>
+#include <map>
+#include <sstream>
+#include <iostream>
+#include <string>
+
+using namespace librados;
+using ceph::buffer;
+using std::map;
+using std::ostringstream;
+using std::string;
+
+static sem_t sem;
+
+class WatchNotifyTestCtx : public WatchCtx
+{
+public:
+    void notify(uint8_t opcode, uint64_t ver, bufferlist& bl)
+    {
+      sem_post(&sem);
+    }
+};
+
+TEST(WatchStress, Stress1) {
+  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);
+  WatchNotifyTestCtx ctx;
+  
+  ASSERT_EQ(0, ioctx.create("foo", false));
+
+  for (int i = 0; i < 10000; ++i) {
+    std::cerr << "Iteration " << i << std::endl;
+    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);
+}