]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test/osd: Add TestReadWrite
authorSamuel Just <samuel.just@dreamhost.com>
Mon, 24 Oct 2011 18:42:30 +0000 (11:42 -0700)
committerSamuel Just <samuel.just@dreamhost.com>
Mon, 24 Oct 2011 18:46:04 +0000 (11:46 -0700)
Signed-off-by: Samuel Just <samuel.just@dreamhost.com>
src/.gitignore
src/Makefile.am
src/test/osd/TestReadWrite.cc [new file with mode: 0644]
src/test/osd/TestSnaps.cc

index f0c358f54c74a0510db89d1999fec4cd35bb683e..879d075f81d966bffc36f5e7e4bb36898cef51f7 100644 (file)
@@ -42,6 +42,7 @@
 /test_librados_build
 /test_librgw_build
 /testsnaps
+/testreadwrite
 /test_stress_watch
 /multi_stress_watch
 /test_store
index 102f31617de2255dcc367338091aa99a5b4a7fe3..b70cf1905563ea9bb8d52ddee7a04b1d00513d16 100644 (file)
@@ -185,6 +185,10 @@ testsnaps_SOURCES = test/osd/TestSnaps.cc test/osd/TestOpStat.cc test/osd/Object
 testsnaps_LDADD = librados.la $(LIBGLOBAL_LDA)
 bin_DEBUGPROGRAMS += testsnaps
 
+testreadwrite_SOURCES = test/osd/TestReadWrite.cc test/osd/TestOpStat.cc test/osd/Object.cc  test/osd/RadosModel.cc
+testreadwrite_LDADD = librados.la $(LIBGLOBAL_LDA)
+bin_DEBUGPROGRAMS += testreadwrite
+
 multi_stress_watch_SOURCES = test/multi_stress_watch.cc test/rados-api/test.cc
 multi_stress_watch_LDADD = librados.la $(LIBGLOBAL_LDA)
 bin_DEBUGPROGRAMS += multi_stress_watch 
diff --git a/src/test/osd/TestReadWrite.cc b/src/test/osd/TestReadWrite.cc
new file mode 100644 (file)
index 0000000..400155f
--- /dev/null
@@ -0,0 +1,114 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+#include "common/Mutex.h"
+#include "common/Cond.h"
+
+#include <iostream>
+#include <sstream>
+#include <map>
+#include <set>
+#include <list>
+#include <string>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "test/osd/RadosModel.h"
+
+using namespace std;
+
+TestOp::~TestOp()
+{
+}
+
+TestOpGenerator::~TestOpGenerator()
+{
+}
+
+struct ReadWriteGenerator : public TestOpGenerator
+{
+  TestOp *nextop;
+  int op;
+  int ops;
+  int objects;
+  int read_percent;
+  ReadWriteGenerator(int ops, int objects, int read_percent) :
+    nextop(0), op(0), ops(ops), objects(objects), read_percent(read_percent)
+  {}
+
+
+  TestOp *next(RadosTestContext &context)
+  {
+    op++;
+    if (op <= objects) {
+      stringstream oid;
+      oid << op;
+      cout << "Writing initial " << oid.str() << std::endl;
+      return new WriteOp(&context, oid.str());
+    } else if (op >= ops) {
+      return 0;
+    }
+
+    if (nextop) {
+      TestOp *retval = nextop;
+      nextop = 0;
+      return retval;
+    }
+    int switchval = rand() % 100;
+    if (switchval < read_percent) {
+      string oid = *(rand_choose(context.oid_not_in_use));
+      cout << "Reading " << oid << std::endl;
+      return new ReadOp(&context, oid, 0);
+    } else {
+      string oid = *(rand_choose(context.oid_not_in_use));
+      cout << "Writing " << oid << " current snap is "
+          << context.current_snap << std::endl;
+      return new WriteOp(&context, oid, 0);
+    }
+  }
+};
+
+int main(int argc, char **argv)
+{
+  int ops = 10000;
+  int objects = 500;
+  int read_percent = 50;
+  int max_in_flight = 16;
+  int size = 4000000; // 4 MB
+  if (argc > 1) {
+    ops = atoi(argv[1]);
+  }
+
+  if (argc > 2) {
+    objects = atoi(argv[2]);
+  }
+
+  if (argc > 3) {
+    read_percent = atoi(argv[3]);
+  }
+
+  if (argc > 4) {
+    max_in_flight = atoi(argv[4]);
+  }
+
+  if (argc > 5) {
+    size = atoi(argv[5]);
+  }
+
+  if (max_in_flight > objects) {
+    cerr << "Error: max_in_flight must be less than the number of objects"
+        << std::endl;
+    return 0;
+  }
+
+  char *id = getenv("CEPH_CLIENT_ID");
+  if (id) cerr << "Client id is: " << id << std::endl;
+  string pool_name = "data";
+  VarLenGenerator cont_gen(size);
+  RadosTestContext context(pool_name, max_in_flight, cont_gen, id);
+
+  ReadWriteGenerator gen = ReadWriteGenerator(ops, objects, read_percent);
+  context.loop(&gen);
+
+  context.shutdown();
+  cerr << context.errors << " errors." << std::endl;
+  return 0;
+}
index 8f921f22e9fd62d9e1a6e4cdec7827c72e5935f2..a73e3371807cb46c32e77371075010442e3aab7c 100644 (file)
@@ -103,7 +103,7 @@ int main(int argc, char **argv)
   }
 
   if (max_in_flight > objects) {
-    cerr << "Error: max_in_flight must be greater than the number of objects" 
+    cerr << "Error: max_in_flight must be less than the number of objects"
         << std::endl;
     return 0;
   }