]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
tests: introduce BufferList.ContiguousAppender.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 19 Oct 2018 17:09:35 +0000 (19:09 +0200)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 1 Feb 2019 21:54:51 +0000 (22:54 +0100)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/test/bufferlist.cc

index 00bdb288775da005e83e142ddbd22e195d4df694..b33018dd044966b1090c96a221aa42591e76f291 100644 (file)
@@ -2681,6 +2681,38 @@ TEST(BufferList, InternalCarriage) {
   EXPECT_EQ(bl.get_num_buffers(), 3u);
 }
 
+TEST(BufferList, ContiguousAppender) {
+  ceph::bufferlist bl;
+  EXPECT_EQ(bl.get_num_buffers(), 0u);
+
+  // we expect a flush in ~contiguous_appender
+  {
+    auto ap = bl.get_contiguous_appender(100);
+
+    denc(42l, ap);
+    EXPECT_EQ(bl.get_num_buffers(), 1u);
+
+    // append bufferlist with single ptr inside. This should
+    // commit changes to bl::_len and the underlying bp::len.
+    {
+      ceph::bufferlist bl_with_foo;
+      bl_with_foo.append("foo", 3);
+      EXPECT_EQ(bl_with_foo.length(), 3u);
+      EXPECT_EQ(bl_with_foo.get_num_buffers(), 1u);
+
+      ap.append(bl_with_foo);
+      // 3 as the ap::append(const bl&) splits the bp with free
+      // space.
+      EXPECT_EQ(bl.get_num_buffers(), 3u);
+    }
+
+    denc(24l, ap);
+    EXPECT_EQ(bl.get_num_buffers(), 3u);
+    EXPECT_EQ(bl.length(), sizeof(long) + 3u);
+  }
+  EXPECT_EQ(bl.length(), 2u * sizeof(long) + 3u);
+}
+
 TEST(BufferList, TestPtrAppend) {
   bufferlist bl;
   char correct[MAX_TEST];