]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_test_objectstore: extract StoreTestFixture into store_test_fixture.cc
authorKefu Chai <kchai@redhat.com>
Thu, 22 Sep 2016 05:08:46 +0000 (13:08 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 22 Sep 2016 07:45:35 +0000 (15:45 +0800)
so it can be reused by other tests like test_memstore_clone.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/test/objectstore/CMakeLists.txt
src/test/objectstore/store_test.cc
src/test/objectstore/store_test_fixture.cc [new file with mode: 0644]
src/test/objectstore/store_test_fixture.h [new file with mode: 0644]

index 25633d2575bdf915c1f80c0343960570cf4279f8..b839bd7bc53b82296528c3c8e216c9015a50782c 100644 (file)
@@ -11,6 +11,7 @@ install(TARGETS ceph_perf_objectstore
 #ceph_test_objectstore
 add_executable(ceph_test_objectstore
   store_test.cc
+  store_test_fixture.cc
   )
 set_target_properties(ceph_test_objectstore PROPERTIES COMPILE_FLAGS
   ${UNITTEST_CXX_FLAGS})
index 0248ae45c302d49389753875e358748f1ee47e67..59a1b3c334e93e828e7ae06a60ca39271d8cbaff 100644 (file)
@@ -34,6 +34,8 @@
 #include <gtest/gtest.h>
 
 #include "include/unordered_map.h"
+#include "store_test_fixture.h"
+
 typedef boost::mt11213b gen_type;
 
 #if GTEST_HAS_PARAM_TEST
@@ -83,51 +85,6 @@ int apply_transaction(
   }
 }
 
-class StoreTest : public ::testing::TestWithParam<const char*> {
-public:
-  boost::scoped_ptr<ObjectStore> store;
-
-  StoreTest() : store(0) {}
-
-  void rm_r(string path) {
-    string cmd = string("rm -r ") + path;
-    cout << "==> " << cmd << std::endl;
-    int r = ::system(cmd.c_str());
-    if (r) {
-      cerr << "failed with exit code " << r
-          << ", continuing anyway" << std::endl;
-    }
-  }
-
-  virtual void SetUp() {
-    int r = ::mkdir("store_test_temp_dir", 0777);
-    if (r < 0) {
-      r = -errno;
-      cerr << __func__ << ": unable to create store_test_temp_dir" << ": " << cpp_strerror(r) << std::endl;
-      return;
-    }
-
-    ObjectStore *store_ = ObjectStore::create(g_ceph_context,
-                                              string(GetParam()),
-                                              string("store_test_temp_dir"),
-                                              string("store_test_temp_journal"));
-    if (!store_) {
-      cerr << __func__ << ": objectstore type " << string(GetParam()) << " doesn't exist yet!" << std::endl;
-      return;
-    }
-    EXPECT_EQ(store_->mkfs(), 0);
-    EXPECT_EQ(store_->mount(), 0);
-    store.reset(store_);
-  }
-
-  virtual void TearDown() {
-    if (store) {
-      int r = store->umount();
-      EXPECT_EQ(r, 0);
-      rm_r("store_test_temp_dir");
-    }
-  }
-};
 
 bool sorted(const vector<ghobject_t> &in, bool bitwise) {
   ghobject_t start;
@@ -143,6 +100,14 @@ bool sorted(const vector<ghobject_t> &in, bool bitwise) {
   return true;
 }
 
+class StoreTest : public StoreTestFixture,
+                  public ::testing::WithParamInterface<const char*> {
+public:
+  StoreTest()
+    : StoreTestFixture(GetParam())
+  {}
+};
+
 TEST_P(StoreTest, collect_metadata) {
   map<string,string> pm;
   store->collect_metadata(&pm);
diff --git a/src/test/objectstore/store_test_fixture.cc b/src/test/objectstore/store_test_fixture.cc
new file mode 100644 (file)
index 0000000..7f2069a
--- /dev/null
@@ -0,0 +1,46 @@
+#include <stdlib.h>
+#include <string>
+#include <iostream>
+#include <gtest/gtest.h>
+
+#include "common/errno.h"
+#include "os/ObjectStore.h"
+#include "store_test_fixture.h"
+
+static void rm_r(const string& path) {
+  string cmd = string("rm -r ") + path;
+  cout << "==> " << cmd << std::endl;
+  int r = ::system(cmd.c_str());
+  if (r) {
+    cerr << "failed with exit code " << r
+         << ", continuing anyway" << std::endl;
+  }
+}
+
+void StoreTestFixture::SetUp() {
+  int r = ::mkdir(data_dir.c_str(), 0777);
+  if (r < 0) {
+    r = -errno;
+    cerr << __func__ << ": unable to create " << data_dir << ": " << cpp_strerror(r) << std::endl;
+    return;
+  }
+
+  store.reset(ObjectStore::create(g_ceph_context,
+                                  type,
+                                  data_dir,
+                                  string("store_test_temp_journal")));
+  if (!store) {
+    cerr << __func__ << ": objectstore type " << type << " doesn't exist yet!" << std::endl;
+    return;
+  }
+  EXPECT_EQ(0, store->mkfs());
+  EXPECT_EQ(0, store->mount());
+}
+
+void StoreTestFixture::TearDown() {
+  if (store) {
+    int r = store->umount();
+    EXPECT_EQ(0, r);
+    rm_r(data_dir);
+  }
+}
diff --git a/src/test/objectstore/store_test_fixture.h b/src/test/objectstore/store_test_fixture.h
new file mode 100644 (file)
index 0000000..8d65f2a
--- /dev/null
@@ -0,0 +1,19 @@
+#include <string>
+#include <boost/scoped_ptr.hpp>
+#include <gtest/gtest.h>
+
+class ObjectStore;
+
+class StoreTestFixture : public ::testing::Test {
+  const std::string type;
+  const std::string data_dir;
+
+public:
+  boost::scoped_ptr<ObjectStore> store;
+
+  StoreTestFixture(const std::string& type)
+    : type(type), data_dir(type + ".test_temp_dir")
+  {}
+  void SetUp() override;
+  void TearDown() override;
+};