diff options
author | Yehuda Sadeh <yehuda@inktank.com> | 2013-03-14 13:42:44 -0700 |
---|---|---|
committer | Yehuda Sadeh <yehuda@inktank.com> | 2013-04-15 14:23:13 -0700 |
commit | f367c46858bfc6a24ccf93bae5dad9126f4d2f5a (patch) | |
tree | 72683c9410099e07d5963b4e9cc0ea892fab2f1c | |
parent | 646643d5613dfc20ff502490ce79fdc4957c1365 (diff) | |
download | ceph-f367c46858bfc6a24ccf93bae5dad9126f4d2f5a.tar.gz |
cls_log: unitest
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r-- | src/Makefile.am | 6 | ||||
-rw-r--r-- | src/test/cls_log/test_cls_log.cc | 127 |
2 files changed, 133 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 11756f698fd..870c88dac38 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -953,6 +953,12 @@ ceph_test_cls_version_LDADD = librados.la libcls_version_client.a ${UNITTEST_STA ceph_test_cls_version_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS} bin_DEBUGPROGRAMS += ceph_test_cls_version +ceph_test_cls_log_SOURCES = test/cls_log/test_cls_log.cc \ + test/librados/test.cc +ceph_test_cls_log_LDADD = libglobal.la librados.la libcls_log_client.a ${UNITTEST_STATIC_LDADD} +ceph_test_cls_log_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS} +bin_DEBUGPROGRAMS += ceph_test_cls_log + ceph_test_cls_lock_SOURCES = test/cls_lock/test_cls_lock.cc test/librados/test.cc ceph_test_cls_lock_LDFLAGS = ${AM_LDFLAGS} ceph_test_cls_lock_LDADD = libcls_lock_client.a librados.la ${UNITTEST_STATIC_LDADD} diff --git a/src/test/cls_log/test_cls_log.cc b/src/test/cls_log/test_cls_log.cc new file mode 100644 index 00000000000..a6dd007806c --- /dev/null +++ b/src/test/cls_log/test_cls_log.cc @@ -0,0 +1,127 @@ +// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "include/types.h" +#include "cls/log/cls_log_types.h" +#include "cls/log/cls_log_client.h" + +#include "include/utime.h" +#include "common/Clock.h" +#include "global/global_context.h" + +#include "gtest/gtest.h" +#include "test/librados/test.h" + +#include <errno.h> +#include <string> +#include <vector> + +static librados::ObjectWriteOperation *new_op() { + return new librados::ObjectWriteOperation(); +} + +static librados::ObjectReadOperation *new_rop() { + return new librados::ObjectReadOperation(); +} + +static int read_bl(bufferlist& bl, int *i) +{ + bufferlist::iterator iter = bl.begin(); + + try { + ::decode(*i, iter); + } catch (buffer::error& err) { + std::cout << "failed to decode buffer" << std::endl; + return -EIO; + } + + return 0; +} + +void add_log(librados::ObjectWriteOperation *op, utime_t& timestamp, string& section, string&name, int i) +{ + bufferlist bl; + ::encode(i, bl); + + cls_log_add(*op, timestamp, section, name, bl); +} + + +TEST(cls_rgw, test_log_add) +{ + librados::Rados rados; + librados::IoCtx ioctx; + string pool_name = get_temp_pool_name(); + + /* create pool */ + ASSERT_EQ("", create_one_pool_pp(pool_name, rados)); + ASSERT_EQ(0, rados.ioctx_create(pool_name.c_str(), ioctx)); + + /* add chains */ + string oid = "obj"; + + + /* create object */ + + ASSERT_EQ(0, ioctx.create(oid, true)); + + + librados::ObjectWriteOperation *op = new_op(); + + utime_t now = ceph_clock_now(g_ceph_context); + + string section = "global"; + string name = "data-source"; + + int i; + + for (i = 0; i < 10; i++) { + add_log(op, now, section, name, i); + } + + ASSERT_EQ(0, ioctx.operate(oid, op)); + + delete op; + + librados::ObjectReadOperation *rop = new_rop(); + + list<cls_log_entry> entries; + bool truncated; + + cls_log_list(*rop, now, 1000, entries, &truncated); + + bufferlist obl; + ASSERT_EQ(0, ioctx.operate(oid, rop, &obl)); + + ASSERT_EQ(10, (int)entries.size()); + ASSERT_EQ(0, (int)truncated); + + list<cls_log_entry>::iterator iter; + + map<int, bool> check_ents; + + for (iter = entries.begin(); iter != entries.end(); ++iter) { + cls_log_entry& entry = *iter; + + ASSERT_EQ(section, entry.section); + ASSERT_EQ(name, entry.name); + + int num; + ASSERT_EQ(0, read_bl(entry.data, &num)); + + check_ents[num] = true; + + ASSERT_EQ(now, entry.timestamp); + } + + ASSERT_EQ(10, (int)check_ents.size()); + + map<int, bool>::iterator ei; + + for (i = 0, ei = check_ents.begin(); i < 10; i++, ++ei) { + ASSERT_EQ(i, ei->first); + } + +} + + |