mirror of
https://github.com/ceph/ceph
synced 2025-01-03 01:22:53 +00:00
ceph_test_keyvaluedb: some simple KeyValueDB unit tests
Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
parent
f3ddb75e3e
commit
522f8509ad
@ -1450,6 +1450,23 @@ target_link_libraries(test_objectstore
|
||||
${CMAKE_DL_LIBS}
|
||||
)
|
||||
|
||||
add_executable(test_keyvaluedb
|
||||
objectstore/test_kv.cc
|
||||
$<TARGET_OBJECTS:heap_profiler_objs>
|
||||
)
|
||||
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
|
||||
|
@ -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)
|
||||
|
148
src/test/objectstore/test_kv.cc
Normal file
148
src/test/objectstore/test_kv.cc
Normal file
@ -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 <sage@newdream.net>
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#include <time.h>
|
||||
#include <sys/mount.h>
|
||||
#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 <gtest/gtest.h>
|
||||
|
||||
#if GTEST_HAS_PARAM_TEST
|
||||
|
||||
class KVTest : public ::testing::TestWithParam<const char*> {
|
||||
public:
|
||||
boost::scoped_ptr<KeyValueDB> 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<const char*> 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();
|
||||
}
|
Loading…
Reference in New Issue
Block a user