]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/cls: test_cls_log doesn't allocate ObjectOperations
authorCasey Bodley <cbodley@redhat.com>
Sat, 20 May 2017 23:56:09 +0000 (19:56 -0400)
committerCasey Bodley <cbodley@redhat.com>
Tue, 6 Aug 2019 20:38:16 +0000 (16:38 -0400)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/test/cls_log/test_cls_log.cc

index 68a5e2fe2ada896e45a9b7c84b52406ee06ffcf0..300e658cf751333e204a9fe876fb60a5c6474210 100644 (file)
@@ -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<cls_log_entry>& 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<cls_log_entry>& 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<cls_log_entry> 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<cls_log_entry>::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<cls_log_entry> 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<cls_log_entry>::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<cls_log_entry> 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);
   }
 }