From 4c4f71c377d64da086fa47826508c721e0d51e15 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Sat, 20 May 2017 19:56:09 -0400 Subject: [PATCH] test/cls: test_cls_log doesn't allocate ObjectOperations Signed-off-by: Casey Bodley --- src/test/cls_log/test_cls_log.cc | 150 ++++++++++++------------------- 1 file changed, 59 insertions(+), 91 deletions(-) diff --git a/src/test/cls_log/test_cls_log.cc b/src/test/cls_log/test_cls_log.cc index 68a5e2fe2ad..300e658cf75 100644 --- a/src/test/cls_log/test_cls_log.cc +++ b/src/test/cls_log/test_cls_log.cc @@ -36,19 +36,6 @@ class cls_log : public ::testing::Test { } }; -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(); -} - static int read_bl(bufferlist& bl, int *i) { auto iter = bl.cbegin(); @@ -85,7 +72,7 @@ void generate_log(librados::IoCtx& ioctx, string& oid, int max, utime_t& start_t { string section = "global"; - librados::ObjectWriteOperation *op = new_op(); + librados::ObjectWriteOperation op; int i; @@ -97,12 +84,10 @@ void generate_log(librados::IoCtx& ioctx, string& oid, int max, utime_t& start_t utime_t ts(secs, start_time.nsec()); string name = get_name(i); - add_log(op, ts, section, name, i); + add_log(&op, ts, section, name, i); } - ASSERT_EQ(0, ioctx.operate(oid, op)); - - delete op; + ASSERT_EQ(0, ioctx.operate(oid, &op)); } utime_t get_time(utime_t& start_time, int i, bool modify_time) @@ -124,6 +109,27 @@ void check_entry(cls_log_entry& entry, utime_t& start_time, int i, bool modified ASSERT_EQ(ts, entry.timestamp); } +static int log_list(librados::IoCtx& ioctx, const std::string& oid, + utime_t& from, utime_t& to, + const string& in_marker, int max_entries, + list& entries, + string *out_marker, bool *truncated) +{ + librados::ObjectReadOperation rop; + cls_log_list(rop, from, to, in_marker, max_entries, + entries, out_marker, truncated); + bufferlist obl; + return ioctx.operate(oid, &rop, &obl); +} + +static int log_list(librados::IoCtx& ioctx, const std::string& oid, + utime_t& from, utime_t& to, int max_entries, + list& entries, bool *truncated) +{ + std::string marker; + return log_list(ioctx, oid, from, to, marker, max_entries, + entries, &marker, truncated); +} TEST_F(cls_log, test_log_add_same_time) { @@ -135,27 +141,19 @@ TEST_F(cls_log, test_log_add_same_time) /* generate log */ utime_t start_time = ceph_clock_now(); + utime_t to_time = get_time(start_time, 1, true); generate_log(ioctx, oid, 10, start_time, false); - librados::ObjectReadOperation *rop = new_rop(); - list entries; bool truncated; /* check list */ - - utime_t to_time = get_time(start_time, 1, true); - - string marker; - - cls_log_list(*rop, start_time, to_time, marker, 0, entries, &marker, &truncated); - - bufferlist obl; - ASSERT_EQ(0, ioctx.operate(oid, rop, &obl)); - - ASSERT_EQ(10, (int)entries.size()); - ASSERT_EQ(0, (int)truncated); - + { + ASSERT_EQ(0, log_list(ioctx, oid, start_time, to_time, 0, + entries, &truncated)); + ASSERT_EQ(10, (int)entries.size()); + ASSERT_EQ(0, (int)truncated); + } list::iterator iter; /* need to sort returned entries, all were using the same time as key */ @@ -185,21 +183,13 @@ TEST_F(cls_log, test_log_add_same_time) 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; - + { + ASSERT_EQ(0, log_list(ioctx, oid, start_time, to_time, 1, + entries, &truncated)); + ASSERT_EQ(1, (int)entries.size()); + ASSERT_EQ(1, (int)truncated); + } } TEST_F(cls_log, test_log_add_different_time) @@ -214,23 +204,18 @@ TEST_F(cls_log, test_log_add_different_time) utime_t start_time = ceph_clock_now(); generate_log(ioctx, oid, 10, start_time, true); - librados::ObjectReadOperation *rop = new_rop(); - list entries; bool truncated; utime_t to_time = utime_t(start_time.sec() + 10, start_time.nsec()); - string marker; - - /* check list */ - cls_log_list(*rop, start_time, to_time, marker, 0, entries, &marker, &truncated); - - bufferlist obl; - ASSERT_EQ(0, ioctx.operate(oid, rop, &obl)); - - ASSERT_EQ(10, (int)entries.size()); - ASSERT_EQ(0, (int)truncated); + { + /* check list */ + ASSERT_EQ(0, log_list(ioctx, oid, start_time, to_time, 0, + entries, &truncated)); + ASSERT_EQ(10, (int)entries.size()); + ASSERT_EQ(0, (int)truncated); + } list::iterator iter; @@ -251,31 +236,21 @@ TEST_F(cls_log, test_log_add_different_time) check_entry(entry, start_time, i, true); } - reset_rop(&rop); - /* check list again with shifted time */ - utime_t next_time = get_time(start_time, 1, true); - - marker.clear(); - - cls_log_list(*rop, next_time, to_time, marker, 0, entries, &marker, &truncated); - - ASSERT_EQ(0, ioctx.operate(oid, rop, &obl)); - - ASSERT_EQ(9, (int)entries.size()); - ASSERT_EQ(0, (int)truncated); - - reset_rop(&rop); - - marker.clear(); + { + utime_t next_time = get_time(start_time, 1, true); + ASSERT_EQ(0, log_list(ioctx, oid, next_time, to_time, 0, + entries, &truncated)); + ASSERT_EQ(9u, entries.size()); + ASSERT_FALSE(truncated); + } + string marker; i = 0; do { - bufferlist obl; - string old_marker = marker; - cls_log_list(*rop, start_time, to_time, old_marker, 1, entries, &marker, &truncated); - - ASSERT_EQ(0, ioctx.operate(oid, rop, &obl)); + string old_marker = std::move(marker); + ASSERT_EQ(0, log_list(ioctx, oid, start_time, to_time, old_marker, 1, + entries, &marker, &truncated)); ASSERT_NE(old_marker, marker); ASSERT_EQ(1, (int)entries.size()); @@ -298,8 +273,6 @@ TEST_F(cls_log, test_log_trim) utime_t start_time = ceph_clock_now(); generate_log(ioctx, oid, 10, start_time, true); - librados::ObjectReadOperation *rop = new_rop(); - list entries; bool truncated; @@ -316,14 +289,9 @@ TEST_F(cls_log, test_log_trim) ASSERT_EQ(0, cls_log_trim(ioctx, oid, zero_time, trim_time, start_marker, end_marker)); - string marker; - - cls_log_list(*rop, start_time, to_time, marker, 0, entries, &marker, &truncated); - - bufferlist obl; - ASSERT_EQ(0, ioctx.operate(oid, rop, &obl)); - - ASSERT_EQ(9 - i, (int)entries.size()); - ASSERT_EQ(0, (int)truncated); + ASSERT_EQ(0, log_list(ioctx, oid, start_time, to_time, 0, + entries, &truncated)); + ASSERT_EQ(9u - i, entries.size()); + ASSERT_FALSE(truncated); } } -- 2.39.5