From: Sage Weil Date: Wed, 26 Aug 2015 17:55:45 +0000 (-0400) Subject: ceph_test_keyvaluedb: some simple KeyValueDB unit tests X-Git-Tag: v9.1.0~242^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=522f8509ad17fcabd90e31cb1a9b670f2925ccb0;p=ceph.git ceph_test_keyvaluedb: some simple KeyValueDB unit tests Signed-off-by: Sage Weil --- diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 3ffbc29f211..6a5f10cc0b8 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -1450,6 +1450,23 @@ target_link_libraries(test_objectstore ${CMAKE_DL_LIBS} ) +add_executable(test_keyvaluedb + objectstore/test_kv.cc + $ + ) +set_target_properties(test_keyvaluedb PROPERTIES COMPILE_FLAGS + ${UNITTEST_CXX_FLAGS}) +target_link_libraries(test_keyvaluedb + os + common + ${UNITTEST_LIBS} + global + ${EXTRALIBS} + ${BLKID_LIBRARIES} + ${TCMALLOC_LIBS} + ${CMAKE_DL_LIBS} + ) + add_executable(test_objectstore_workloadgen objectstore/workload_generator.cc objectstore/TestObjectStoreState.cc diff --git a/src/test/Makefile-server.am b/src/test/Makefile-server.am index bb3ce82fe7e..8bf8cfcb19e 100644 --- a/src/test/Makefile-server.am +++ b/src/test/Makefile-server.am @@ -55,6 +55,11 @@ ceph_test_objectstore_LDADD = $(LIBOS) $(UNITTEST_LDADD) $(CEPH_GLOBAL) ceph_test_objectstore_CXXFLAGS = $(UNITTEST_CXXFLAGS) bin_DEBUGPROGRAMS += ceph_test_objectstore +ceph_test_keyvaluedb_SOURCES = test/objectstore/test_kv.cc +ceph_test_keyvaluedb_LDADD = $(LIBOS) $(UNITTEST_LDADD) $(CEPH_GLOBAL) +ceph_test_keyvaluedb_CXXFLAGS = $(UNITTEST_CXXFLAGS) +bin_DEBUGPROGRAMS += ceph_test_keyvaluedb + ceph_test_filestore_SOURCES = test/filestore/TestFileStore.cc ceph_test_filestore_LDADD = $(LIBOS) $(UNITTEST_LDADD) $(CEPH_GLOBAL) ceph_test_filestore_CXXFLAGS = $(UNITTEST_CXXFLAGS) diff --git a/src/test/objectstore/test_kv.cc b/src/test/objectstore/test_kv.cc new file mode 100644 index 00000000000..61007e3bf33 --- /dev/null +++ b/src/test/objectstore/test_kv.cc @@ -0,0 +1,148 @@ +// -*- 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) 2004-2006 Sage Weil + * + * 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 +#include +#include +#include +#include +#include "os/KeyValueDB.h" +#include "include/Context.h" +#include "common/ceph_argparse.h" +#include "global/global_init.h" +#include "common/Mutex.h" +#include "common/Cond.h" +#include "common/errno.h" +#include "include/stringify.h" +#include + +#if GTEST_HAS_PARAM_TEST + +class KVTest : public ::testing::TestWithParam { +public: + boost::scoped_ptr db; + + KVTest() : db(0) {} + + void init() { + db.reset(KeyValueDB::create(g_ceph_context, string(GetParam()), + string("kv_test_temp_dir"))); + } + void fini() { + db.reset(NULL); + } + + virtual void SetUp() { + int r = ::mkdir("kv_test_temp_dir", 0777); + if (r < 0 && errno != EEXIST) { + r = -errno; + cerr << __func__ << ": unable to create kv_test_temp_dir" + << ": " << cpp_strerror(r) << std::endl; + return; + } + init(); + } + virtual void TearDown() { + fini(); + } +}; + +TEST_P(KVTest, OpenClose) { + ASSERT_EQ(0, db->create_and_open(cout)); + fini(); +} + +TEST_P(KVTest, OpenCloseReopenClose) { + ASSERT_EQ(0, db->create_and_open(cout)); + fini(); + init(); + ASSERT_EQ(0, db->open(cout)); + fini(); +} + +TEST_P(KVTest, PutReopen) { + ASSERT_EQ(0, db->create_and_open(cout)); + { + KeyValueDB::Transaction t = db->get_transaction(); + bufferlist value; + value.append("value"); + t->set("prefix", "key", value); + t->set("prefix", "key2", value); + t->set("prefix", "key3", value); + db->submit_transaction_sync(t); + } + fini(); + + init(); + ASSERT_EQ(0, db->open(cout)); + { + bufferlist v; + ASSERT_EQ(0, db->get("prefix", "key", &v)); + ASSERT_EQ(v.length(), 5u); + ASSERT_EQ(0, db->get("prefix", "key2", &v)); + ASSERT_EQ(v.length(), 5u); + } + { + KeyValueDB::Transaction t = db->get_transaction(); + t->rmkey("prefix", "key"); + t->rmkey("prefix", "key3"); + db->submit_transaction_sync(t); + } + fini(); + + init(); + ASSERT_EQ(0, db->open(cout)); + { + bufferlist v; + ASSERT_EQ(-ENOENT, db->get("prefix", "key", &v)); + ASSERT_EQ(0, db->get("prefix", "key2", &v)); + ASSERT_EQ(v.length(), 5u); + ASSERT_EQ(-ENOENT, db->get("prefix", "key3", &v)); + } + fini(); +} + + +INSTANTIATE_TEST_CASE_P( + KeyValueDB, + KVTest, + ::testing::Values("leveldb", "rocksdb")); + +#else + +// Google Test may not support value-parameterized tests with some +// compilers. If we use conditional compilation to compile out all +// code referring to the gtest_main library, MSVC linker will not link +// that library at all and consequently complain about missing entry +// point defined in that library (fatal error LNK1561: entry point +// must be defined). This dummy test keeps gtest_main linked in. +TEST(DummyTest, ValueParameterizedTestsAreNotSupportedOnThisPlatform) {} + +#endif + +int main(int argc, char **argv) { + vector args; + argv_to_vec(argc, (const char **)argv, args); + env_to_vec(args); + + global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); + common_init_finish(g_ceph_context); + g_ceph_context->_conf->set_val( + "enable_experimental_unrecoverable_data_corrupting_features", + "rocksdb"); + g_ceph_context->_conf->apply_changes(NULL); + + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}