summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@inktank.com>2013-06-18 00:04:46 -0700
committerYehuda Sadeh <yehuda@inktank.com>2013-06-18 00:04:46 -0700
commite2af5fbe2555d734311bafe724afcae9936c89c0 (patch)
tree19b1fc74d1f2c0fe7acbf3481f051092a6aae8f8
parent1ecec3a1fc9f6b16b575eac4405c2bed7a6b488c (diff)
downloadceph-e2af5fbe2555d734311bafe724afcae9936c89c0.tar.gz
test: test for cls_statelog
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r--src/Makefile.am14
-rw-r--r--src/test/cls_statelog/test_cls_statelog.cc158
2 files changed, 170 insertions, 2 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 8f9b850a0ea..43a588b7841 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -609,6 +609,10 @@ libcls_log_client_a_SOURCES = \
cls/log/cls_log_client.cc
noinst_LIBRARIES += libcls_log_client.a
+libcls_statelog_client_a_SOURCES = \
+ cls/statelog/cls_statelog_client.cc
+noinst_LIBRARIES += libcls_statelog_client.a
+
libcls_rgw_client_a_SOURCES = \
cls/rgw/cls_rgw_client.cc \
cls/rgw/cls_rgw_types.cc \
@@ -1002,6 +1006,12 @@ ceph_test_cls_log_LDADD = libglobal.la librados.la libcls_log_client.a ${UNITTES
ceph_test_cls_log_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS}
bin_DEBUGPROGRAMS += ceph_test_cls_log
+ceph_test_cls_statelog_SOURCES = test/cls_statelog/test_cls_statelog.cc \
+ test/librados/test.cc
+ceph_test_cls_statelog_LDADD = libglobal.la librados.la libcls_statelog_client.a ${UNITTEST_STATIC_LDADD}
+ceph_test_cls_statelog_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS}
+bin_DEBUGPROGRAMS += ceph_test_cls_statelog
+
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}
@@ -1652,8 +1662,8 @@ noinst_HEADERS = \
cls/log/cls_log_types.h\
cls/log/cls_log_ops.h\
cls/log/cls_log_client.h\
- cls/log/cls_statelog_types.h\
- cls/log/cls_statelog_ops.h\
+ cls/statelog/cls_statelog_types.h\
+ cls/statelog/cls_statelog_ops.h\
cls/rgw/cls_rgw_client.h\
cls/rgw/cls_rgw_ops.h\
cls/rgw/cls_rgw_types.h\
diff --git a/src/test/cls_statelog/test_cls_statelog.cc b/src/test/cls_statelog/test_cls_statelog.cc
new file mode 100644
index 00000000000..d1ace1e31c9
--- /dev/null
+++ b/src/test/cls_statelog/test_cls_statelog.cc
@@ -0,0 +1,158 @@
+// -*- 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/statelog/cls_statelog_types.h"
+#include "cls/statelog/cls_statelog_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 void reset_rop(librados::ObjectReadOperation **pop) {
+ delete *pop;
+ *pop = new_rop();
+}
+
+void add_log(librados::ObjectWriteOperation *op, const string& client_id, const string& op_id, string& obj, uint32_t state)
+{
+ bufferlist bl;
+ ::encode(state, bl);
+
+ cls_statelog_add(*op, client_id, op_id, obj, state, bl);
+}
+
+void next_op_id(string& op_id, int *id)
+{
+ char buf[16];
+ snprintf(buf, sizeof(buf), "%d", *id);
+ op_id = buf;
+ (*id)++;
+}
+
+string get_name(int i)
+{
+ string name_prefix = "data-source";
+
+ char buf[16];
+ snprintf(buf, sizeof(buf), "%d", i);
+ return name_prefix + buf;
+}
+
+TEST(cls_rgw, test_statelog_basic)
+{
+ 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));
+
+ string oid = "obj";
+
+ /* create object */
+ ASSERT_EQ(0, ioctx.create(oid, true));
+
+ int id = 0;
+ string client_id[] = { "client-1", "client-2" };
+
+ int num_ops = 10;
+ string op_ids[num_ops];
+
+ librados::ObjectWriteOperation *op = new_op();
+
+ for (int i = 0; i < num_ops; i++) {
+ next_op_id(op_ids[i], &id);
+ char buf[16];
+ snprintf(buf, sizeof(buf), "obj-%d", i / 2);
+
+ string cid = client_id[i / (num_ops / 2)];
+
+ string obj = buf;
+ add_log(op, cid, op_ids[i], obj, i /* just for testing */);
+ }
+ ASSERT_EQ(0, ioctx.operate(oid, op));
+
+ librados::ObjectReadOperation *rop = new_rop();
+
+ list<cls_statelog_entry> entries;
+ bool truncated;
+
+ /* check list by client_id */
+
+ string marker;
+
+ string obj;
+ string cid = client_id[0];
+ string op_id;
+
+ cls_statelog_list(*rop, cid, op_id, obj, marker, 0, entries, &marker, &truncated);
+
+ bufferlist obl;
+ ASSERT_EQ(0, ioctx.operate(oid, rop, &obl));
+
+ ASSERT_EQ(5, (int)entries.size());
+ ASSERT_EQ(0, (int)truncated);
+#if 0
+ list<cls_log_entry>::iterator iter;
+
+ /* need to sort returned entries, all were using the same time as key */
+ map<int, cls_log_entry> check_ents;
+
+ for (iter = entries.begin(); iter != entries.end(); ++iter) {
+ cls_log_entry& entry = *iter;
+
+ int num;
+ ASSERT_EQ(0, read_bl(entry.data, &num));
+
+ check_ents[num] = entry;
+ }
+
+ ASSERT_EQ(10, (int)check_ents.size());
+
+ map<int, cls_log_entry>::iterator ei;
+
+ /* verify entries are as expected */
+
+ int i;
+
+ for (i = 0, ei = check_ents.begin(); i < 10; i++, ++ei) {
+ cls_log_entry& entry = ei->second;
+
+ ASSERT_EQ(i, ei->first);
+ check_entry(entry, start_time, i, false);
+ }
+
+ reset_rop(&rop);
+
+ /* check list again, now want to be truncated*/
+
+ marker.clear();
+
+ cls_log_list(*rop, start_time, to_time, marker, 1, entries, &marker, &truncated);
+
+ ASSERT_EQ(0, ioctx.operate(oid, rop, &obl));
+
+ ASSERT_EQ(1, (int)entries.size());
+ ASSERT_EQ(1, (int)truncated);
+
+ delete rop;
+#endif
+}
+