]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Add test case for librados assert_version()
authorKim Vandry <vandry@TZoNE.ORG>
Fri, 30 Jan 2015 12:56:19 +0000 (21:56 +0900)
committerKim Vandry <vandry@TZoNE.ORG>
Sat, 31 Jan 2015 05:39:53 +0000 (14:39 +0900)
Signed-off-by: Kim Vandry <vandry@TZoNE.ORG>
src/test/librados/misc.cc

index 59f5d9f42db73d7fe421f7d2bae631b0d727c971..233d7a7ac8c8292d6199f420fe286b07f6e6a18f 100644 (file)
@@ -510,6 +510,34 @@ TEST_F(LibRadosMiscPP, AssertExistsPP) {
   ASSERT_EQ(-EEXIST, ioctx.create("asdffoo", true));
 }
 
+TEST_F(LibRadosMiscPP, AssertVersionPP) {
+  char buf[64];
+  memset(buf, 0xcc, sizeof(buf));
+  bufferlist bl;
+  bl.append(buf, sizeof(buf));
+
+  // Create test object...
+  ASSERT_EQ(0, ioctx.create("asdfbar", true));
+  // ...then write it again to guarantee that the
+  // (unsigned) version must be at least 1 (not 0)
+  // since we want to decrement it by 1 later.
+  ASSERT_EQ(0, ioctx.write_full("asdfbar", bl));
+
+  uint64_t v = ioctx.get_last_version();
+  ObjectWriteOperation op1;
+  op1.assert_version(v+1);
+  op1.write(0, bl);
+  ASSERT_EQ(-EOVERFLOW, ioctx.operate("asdfbar", &op1));
+  ObjectWriteOperation op2;
+  op2.assert_version(v-1);
+  op2.write(0, bl);
+  ASSERT_EQ(-ERANGE, ioctx.operate("asdfbar", &op2));
+  ObjectWriteOperation op3;
+  op3.assert_version(v);
+  op3.write(0, bl);
+  ASSERT_EQ(0, ioctx.operate("asdfbar", &op3));
+}
+
 TEST_F(LibRadosMiscPP, BigAttrPP) {
   char buf[64];
   memset(buf, 0xcc, sizeof(buf));