}
};
-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();
{
string section = "global";
- librados::ObjectWriteOperation *op = new_op();
+ librados::ObjectWriteOperation op;
int i;
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)
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)
{
/* 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 */
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)
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;
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());
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;
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);
}
}