summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@inktank.com>2013-03-15 11:14:02 -0700
committerYehuda Sadeh <yehuda@inktank.com>2013-03-22 11:29:11 -0700
commite31d00da6336278ce51f917bfd40a5aa90c5ff13 (patch)
tree331e9d48ebce7fe2de6feeef8939df91a0d402b8
parent7cb7b2808db1310294e7ec73bfe205039d4c6325 (diff)
downloadceph-e31d00da6336278ce51f917bfd40a5aa90c5ff13.tar.gz
cls_log: extend unitest
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r--src/test/cls_log/test_cls_log.cc234
1 files changed, 212 insertions, 22 deletions
diff --git a/src/test/cls_log/test_cls_log.cc b/src/test/cls_log/test_cls_log.cc
index a6dd007806c..bf694c27f69 100644
--- a/src/test/cls_log/test_cls_log.cc
+++ b/src/test/cls_log/test_cls_log.cc
@@ -24,6 +24,16 @@ static librados::ObjectReadOperation *new_rop() {
return new librados::ObjectReadOperation();
}
+static void reset_op(librados::ObjectWriteOperation **pop) {
+ delete *pop;
+ *pop = new_op();
+}
+
+static void reset_rop(librados::ObjectReadOperation **pop) {
+ delete *pop;
+ *pop = new_rop();
+}
+
static int read_bl(bufferlist& bl, int *i)
{
bufferlist::iterator iter = bl.begin();
@@ -47,7 +57,60 @@ void add_log(librados::ObjectWriteOperation *op, utime_t& timestamp, string& sec
}
-TEST(cls_rgw, test_log_add)
+string get_name(int i)
+{
+ string name_prefix = "data-source";
+
+ char buf[16];
+ snprintf(buf, sizeof(buf), "%d", i);
+ return name_prefix + buf;
+}
+
+void generate_log(librados::IoCtx& ioctx, string& oid, int max, utime_t& start_time, bool modify_time)
+{
+ string section = "global";
+
+ librados::ObjectWriteOperation *op = new_op();
+
+ int i;
+
+ for (i = 0; i < max; i++) {
+ uint32_t secs = start_time.sec();
+ if (modify_time)
+ secs += i;
+
+ utime_t ts(secs, start_time.nsec());
+ string name = get_name(i);
+
+ add_log(op, ts, section, name, i);
+ }
+
+ ASSERT_EQ(0, ioctx.operate(oid, op));
+
+ delete op;
+}
+
+utime_t get_time(utime_t& start_time, int i, bool modify_time)
+{
+ uint32_t secs = start_time.sec();
+ if (modify_time)
+ secs += i;
+ return utime_t(secs, start_time.nsec());
+}
+
+void check_entry(cls_log_entry& entry, utime_t& start_time, int i, bool modified_time)
+{
+ string section = "global";
+ string name = get_name(i);
+ utime_t ts = get_time(start_time, i, modified_time);
+
+ ASSERT_EQ(section, entry.section);
+ ASSERT_EQ(name, entry.name);
+ ASSERT_EQ(ts, entry.timestamp);
+}
+
+
+TEST(cls_rgw, test_log_add_same_time)
{
librados::Rados rados;
librados::IoCtx ioctx;
@@ -66,29 +129,101 @@ TEST(cls_rgw, test_log_add)
ASSERT_EQ(0, ioctx.create(oid, true));
- librados::ObjectWriteOperation *op = new_op();
+ /* generate log */
- utime_t now = ceph_clock_now(g_ceph_context);
+ utime_t start_time = ceph_clock_now(g_ceph_context);
+ generate_log(ioctx, oid, 10, start_time, false);
- string section = "global";
- string name = "data-source";
+ librados::ObjectReadOperation *rop = new_rop();
+
+ list<cls_log_entry> entries;
+ bool truncated;
+
+ /* check list */
+
+ cls_log_list(*rop, start_time, 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;
+
+ /* 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; i < 10; i++) {
- add_log(op, now, section, name, 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);
}
- ASSERT_EQ(0, ioctx.operate(oid, op));
+ reset_rop(&rop);
- delete op;
+ /* check list again, now want to be truncated*/
+
+ cls_log_list(*rop, start_time, 1, entries, &truncated);
+
+ ASSERT_EQ(0, ioctx.operate(oid, rop, &obl));
+
+ ASSERT_EQ(1, (int)entries.size());
+ ASSERT_EQ(1, (int)truncated);
+
+ delete rop;
+}
+
+TEST(cls_rgw, test_log_add_different_time)
+{
+ 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));
+
+
+ /* generate log */
+
+ utime_t start_time = ceph_clock_now(g_ceph_context);
+ generate_log(ioctx, oid, 10, start_time, true);
librados::ObjectReadOperation *rop = new_rop();
list<cls_log_entry> entries;
bool truncated;
- cls_log_list(*rop, now, 1000, entries, &truncated);
+ /* check list */
+
+ cls_log_list(*rop, start_time, 1000, entries, &truncated);
bufferlist obl;
ASSERT_EQ(0, ioctx.operate(oid, rop, &obl));
@@ -98,30 +233,85 @@ TEST(cls_rgw, test_log_add)
list<cls_log_entry>::iterator iter;
- map<int, bool> check_ents;
+ /* returned entries should be sorted by time */
+ map<int, cls_log_entry> check_ents;
- for (iter = entries.begin(); iter != entries.end(); ++iter) {
- cls_log_entry& entry = *iter;
+ int i;
- ASSERT_EQ(section, entry.section);
- ASSERT_EQ(name, entry.name);
+ for (i = 0, iter = entries.begin(); iter != entries.end(); ++iter, ++i) {
+ cls_log_entry& entry = *iter;
int num;
+
ASSERT_EQ(0, read_bl(entry.data, &num));
- check_ents[num] = true;
+ ASSERT_EQ(i, num);
- ASSERT_EQ(now, entry.timestamp);
+ check_entry(entry, start_time, i, true);
}
- ASSERT_EQ(10, (int)check_ents.size());
+ reset_rop(&rop);
- map<int, bool>::iterator ei;
+ /* check list again with shifted time */
- for (i = 0, ei = check_ents.begin(); i < 10; i++, ++ei) {
- ASSERT_EQ(i, ei->first);
- }
+ utime_t next_time = get_time(start_time, 1, true);
+
+ cls_log_list(*rop, next_time, 10, entries, &truncated);
+
+ ASSERT_EQ(0, ioctx.operate(oid, rop, &obl));
+ ASSERT_EQ(9, (int)entries.size());
+ ASSERT_EQ(0, (int)truncated);
+
+ delete rop;
}
+TEST(cls_rgw, test_log_trim)
+{
+ 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));
+
+ /* generate log */
+
+ utime_t start_time = ceph_clock_now(g_ceph_context);
+ generate_log(ioctx, oid, 10, start_time, true);
+
+ librados::ObjectReadOperation *rop = new_rop();
+
+ list<cls_log_entry> entries;
+ bool truncated;
+
+ /* check list */
+
+ /* trim */
+
+ for (int i = 0; i < 10; i++) {
+ utime_t trim_time = get_time(start_time, i, true);
+
+ utime_t zero_time;
+
+ ASSERT_EQ(0, cls_log_trim(ioctx, oid, zero_time, trim_time));
+
+ cls_log_list(*rop, start_time, 1000, entries, &truncated);
+
+ bufferlist obl;
+ ASSERT_EQ(0, ioctx.operate(oid, rop, &obl));
+
+ ASSERT_EQ(9 - i, (int)entries.size());
+ ASSERT_EQ(0, (int)truncated);
+ }
+}