]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test: Reorg multi_stress_watch to prepare for ec option
authorDavid Zafman <david.zafman@inktank.com>
Wed, 19 Mar 2014 02:35:55 +0000 (19:35 -0700)
committerDavid Zafman <david.zafman@inktank.com>
Fri, 21 Mar 2014 06:10:14 +0000 (23:10 -0700)
If old options are specified maintain backward compatibility

Signed-off-by: David Zafman <david.zafman@inktank.com>
src/test/multi_stress_watch.cc

index eb21bdaa450308a63075166cb789bcc88afda814..42e2f4cbc468a1c9a49b0cd8fe962ee951aa12b7 100644 (file)
@@ -29,17 +29,82 @@ public:
     }
 };
 
+void
+test_loop(Rados &cluster, std::string pool_name, std::string obj_name)
+{
+  int ret;
+  IoCtx ioctx;
+  ret = cluster.ioctx_create(pool_name.c_str(), ioctx);
+  if (ret < 0) {
+    std::cerr << "ioctx_create " << pool_name << " failed with " << ret << std::endl;
+    exit(1);
+  }
+
+  ret = ioctx.create(obj_name, false);
+  if (ret < 0) {
+    std::cerr << "create failed with " << ret << std::endl;
+    exit(1);
+  }
+
+  for (int i = 0; i < 10000; ++i) {
+    std::cerr << "Iteration " << i << std::endl;
+    uint64_t handle;
+    WatchNotifyTestCtx ctx;
+    ret = ioctx.watch(obj_name, 0, &handle, &ctx);
+    assert(!ret);
+    bufferlist bl2;
+    ret = ioctx.notify(obj_name, 0, bl2);
+    assert(!ret);
+    TestAlarm alarm;
+    sem_wait(&sem);
+    ioctx.unwatch(obj_name, handle);
+  }
+
+  ioctx.close();
+}
+
+void
+test_replicated(Rados &cluster, std::string pool_name, std::string obj_name)
+{
+  // May already exist
+  cluster.pool_create(pool_name.c_str());
+
+  test_loop(cluster, pool_name, obj_name);
+}
+
+void
+test_erasure(Rados &cluster, std::string pool_name, std::string obj_name)
+{
+  std::cout << "Skip erasure test" << std::endl;
+  return;
+}
+
 int main(int args, char **argv)
 {
-  if (args < 3) {
-    std::cerr << "Error: " << argv[0] << " pool_name obj_name" << std::endl;
+  if (args != 3 && args != 4) {
+    std::cerr << "Error: " << argv[0] << " [ec|rep] pool_name obj_name" << std::endl;
     return 1;
   }
 
-  std::string pool_name(argv[1]);
-  std::string obj_name(argv[2]);
+  std::string pool_name, obj_name, type;
+  // For backward compatibility with unmodified teuthology version
+  if (args == 3) {
+    type = "rep";
+    pool_name = argv[1];
+    obj_name = argv[2];
+  } else {
+    type = argv[1];
+    pool_name = argv[2];
+    obj_name = argv[3];
+  }
+  std::cerr << "Test type " << type << std::endl;
   std::cerr << "pool_name, obj_name are " << pool_name << ", " << obj_name << std::endl;
 
+  if (type != "ec" && type != "rep") {
+    std::cerr << "Error: " << argv[0] << " Invalid arg must be 'ec' or 'rep' saw " << type << std::endl;
+    return 1;
+  }
+
   char *id = getenv("CEPH_CLIENT_ID");
   if (id) std::cerr << "Client id is: " << id << std::endl;
   Rados cluster;
@@ -61,30 +126,11 @@ int main(int args, char **argv)
   }
   cluster.connect();
 
-  // May already exist
-  cluster.pool_create(pool_name.c_str());
-
-  IoCtx ioctx;
-  cluster.ioctx_create(pool_name.c_str(), ioctx);
-
-  ioctx.create(obj_name, false);
-
-  
-  for (int i = 0; i < 10000; ++i) {
-    std::cerr << "Iteration " << i << std::endl;
-    uint64_t handle;
-    WatchNotifyTestCtx ctx;
-    ret = ioctx.watch(obj_name, 0, &handle, &ctx);
-    assert(!ret);
-    bufferlist bl2;
-    ret = ioctx.notify(obj_name, 0, bl2);
-    assert(!ret);
-    TestAlarm alarm;
-    sem_wait(&sem);
-    ioctx.unwatch(obj_name, handle);
-  }
+  if (type == "rep")
+    test_replicated(cluster, pool_name, obj_name);
+  else if (type == "ec")
+    test_erasure(cluster, pool_name, obj_name);
 
-  ioctx.close();
   sem_destroy(&sem);
   return 0;
 }