summaryrefslogtreecommitdiffstats
path: root/src/test/cls_version
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
commite6918187568dbd01842d8d1d2c808ce16a894239 (patch)
tree64f88b554b444a49f656b6c656111a145cbbaa28 /src/test/cls_version
parentInitial commit. (diff)
downloadceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz
ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/cls_version')
-rw-r--r--src/test/cls_version/CMakeLists.txt16
-rw-r--r--src/test/cls_version/test_cls_version.cc322
2 files changed, 338 insertions, 0 deletions
diff --git a/src/test/cls_version/CMakeLists.txt b/src/test/cls_version/CMakeLists.txt
new file mode 100644
index 000000000..05264017b
--- /dev/null
+++ b/src/test/cls_version/CMakeLists.txt
@@ -0,0 +1,16 @@
+# ceph_test_cls_version
+add_executable(ceph_test_cls_version
+ test_cls_version.cc
+ )
+target_link_libraries(ceph_test_cls_version
+ librados
+ cls_version_client
+ global
+ ${UNITTEST_LIBS}
+ ${BLKID_LIBRARIES}
+ ${CMAKE_DL_LIBS}
+ ${CRYPTO_LIBS}
+ ${EXTRALIBS}
+ radostest-cxx
+ )
+
diff --git a/src/test/cls_version/test_cls_version.cc b/src/test/cls_version/test_cls_version.cc
new file mode 100644
index 000000000..b86756a78
--- /dev/null
+++ b/src/test/cls_version/test_cls_version.cc
@@ -0,0 +1,322 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "include/rados/librados.hpp"
+#include "include/types.h"
+
+#include "cls/version/cls_version_types.h"
+#include "cls/version/cls_version_client.h"
+
+#include "gtest/gtest.h"
+#include "test/librados/test_cxx.h"
+
+#include <errno.h>
+#include <string>
+#include <vector>
+
+using namespace std;
+
+static librados::ObjectWriteOperation *new_op() {
+ return new librados::ObjectWriteOperation();
+}
+
+static librados::ObjectReadOperation *new_rop() {
+ return new librados::ObjectReadOperation();
+}
+
+TEST(cls_rgw, test_version_inc_read)
+{
+ librados::Rados rados;
+ librados::IoCtx ioctx;
+ string pool_name = get_temp_pool_name();
+
+ /* create pool */
+ ASSERT_EQ("", create_one_pool_pp(pool_name, rados));
+ ASSERT_EQ(0, rados.ioctx_create(pool_name.c_str(), ioctx));
+
+ /* add chains */
+ string oid = "obj";
+
+
+ /* create object */
+
+ ASSERT_EQ(0, ioctx.create(oid, true));
+
+ obj_version ver;
+
+ ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver));
+ ASSERT_EQ(0, (long long)ver.ver);
+ ASSERT_EQ(0, (int)ver.tag.size());
+
+
+ /* inc version */
+ librados::ObjectWriteOperation *op = new_op();
+ cls_version_inc(*op);
+ ASSERT_EQ(0, ioctx.operate(oid, op));
+
+ ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver));
+ ASSERT_GT((long long)ver.ver, 0);
+ ASSERT_NE(0, (int)ver.tag.size());
+
+ /* inc version again! */
+ delete op;
+ op = new_op();
+ cls_version_inc(*op);
+ ASSERT_EQ(0, ioctx.operate(oid, op));
+
+ obj_version ver2;
+
+ ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver2));
+ ASSERT_GT((long long)ver2.ver, (long long)ver.ver);
+ ASSERT_EQ(0, (int)ver2.tag.compare(ver.tag));
+
+ delete op;
+
+ obj_version ver3;
+
+ librados::ObjectReadOperation *rop = new_rop();
+ cls_version_read(*rop, &ver3);
+ bufferlist outbl;
+ ASSERT_EQ(0, ioctx.operate(oid, rop, &outbl));
+ ASSERT_EQ(ver2.ver, ver3.ver);
+ ASSERT_EQ(1, (long long)ver2.compare(&ver3));
+
+ delete rop;
+}
+
+
+TEST(cls_rgw, test_version_set)
+{
+ librados::Rados rados;
+ librados::IoCtx ioctx;
+ string pool_name = get_temp_pool_name();
+
+ /* create pool */
+ ASSERT_EQ("", create_one_pool_pp(pool_name, rados));
+ ASSERT_EQ(0, rados.ioctx_create(pool_name.c_str(), ioctx));
+
+ /* add chains */
+ string oid = "obj";
+
+
+ /* create object */
+
+ ASSERT_EQ(0, ioctx.create(oid, true));
+
+ obj_version ver;
+
+ ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver));
+ ASSERT_EQ(0, (long long)ver.ver);
+ ASSERT_EQ(0, (int)ver.tag.size());
+
+
+ ver.ver = 123;
+ ver.tag = "foo";
+
+ /* set version */
+ librados::ObjectWriteOperation *op = new_op();
+ cls_version_set(*op, ver);
+ ASSERT_EQ(0, ioctx.operate(oid, op));
+
+ /* read version */
+ obj_version ver2;
+
+ ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver2));
+ ASSERT_EQ((long long)ver2.ver, (long long)ver.ver);
+ ASSERT_EQ(0, (int)ver2.tag.compare(ver.tag));
+
+ delete op;
+}
+
+TEST(cls_rgw, test_version_inc_cond)
+{
+ librados::Rados rados;
+ librados::IoCtx ioctx;
+ string pool_name = get_temp_pool_name();
+
+ /* create pool */
+ ASSERT_EQ("", create_one_pool_pp(pool_name, rados));
+ ASSERT_EQ(0, rados.ioctx_create(pool_name.c_str(), ioctx));
+
+ /* add chains */
+ string oid = "obj";
+
+ /* create object */
+
+ ASSERT_EQ(0, ioctx.create(oid, true));
+
+ obj_version ver;
+
+ ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver));
+ ASSERT_EQ(0, (long long)ver.ver);
+ ASSERT_EQ(0, (int)ver.tag.size());
+
+ /* inc version */
+ librados::ObjectWriteOperation *op = new_op();
+ cls_version_inc(*op);
+ ASSERT_EQ(0, ioctx.operate(oid, op));
+
+ ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver));
+ ASSERT_GT((long long)ver.ver, 0);
+ ASSERT_NE(0, (int)ver.tag.size());
+
+ obj_version cond_ver = ver;
+
+
+ /* inc version again! */
+ delete op;
+ op = new_op();
+ cls_version_inc(*op);
+ ASSERT_EQ(0, ioctx.operate(oid, op));
+
+ obj_version ver2;
+
+ ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver2));
+ ASSERT_GT((long long)ver2.ver, (long long)ver.ver);
+ ASSERT_EQ(0, (int)ver2.tag.compare(ver.tag));
+
+
+ /* now check various condition tests */
+ cls_version_inc(*op, cond_ver, VER_COND_NONE);
+ ASSERT_EQ(0, ioctx.operate(oid, op));
+
+ ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver2));
+ ASSERT_GT((long long)ver2.ver, (long long)ver.ver);
+ ASSERT_EQ(0, (int)ver2.tag.compare(ver.tag));
+
+ /* a bunch of conditions that should fail */
+ delete op;
+ op = new_op();
+ cls_version_inc(*op, cond_ver, VER_COND_EQ);
+ ASSERT_EQ(-ECANCELED, ioctx.operate(oid, op));
+
+ delete op;
+ op = new_op();
+ cls_version_inc(*op, cond_ver, VER_COND_LT);
+ ASSERT_EQ(-ECANCELED, ioctx.operate(oid, op));
+
+ delete op;
+ op = new_op();
+ cls_version_inc(*op, cond_ver, VER_COND_LE);
+ ASSERT_EQ(-ECANCELED, ioctx.operate(oid, op));
+
+ delete op;
+ op = new_op();
+ cls_version_inc(*op, cond_ver, VER_COND_TAG_NE);
+ ASSERT_EQ(-ECANCELED, ioctx.operate(oid, op));
+
+ ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver2));
+ ASSERT_GT((long long)ver2.ver, (long long)ver.ver);
+ ASSERT_EQ(0, (int)ver2.tag.compare(ver.tag));
+
+ /* a bunch of conditions that should succeed */
+ delete op;
+ op = new_op();
+ cls_version_inc(*op, ver2, VER_COND_EQ);
+ ASSERT_EQ(0, ioctx.operate(oid, op));
+
+ delete op;
+ op = new_op();
+ cls_version_inc(*op, cond_ver, VER_COND_GT);
+ ASSERT_EQ(0, ioctx.operate(oid, op));
+
+ delete op;
+ op = new_op();
+ cls_version_inc(*op, cond_ver, VER_COND_GE);
+ ASSERT_EQ(0, ioctx.operate(oid, op));
+
+ delete op;
+ op = new_op();
+ cls_version_inc(*op, cond_ver, VER_COND_TAG_EQ);
+ ASSERT_EQ(0, ioctx.operate(oid, op));
+
+ delete op;
+}
+
+TEST(cls_rgw, test_version_inc_check)
+{
+ librados::Rados rados;
+ librados::IoCtx ioctx;
+ string pool_name = get_temp_pool_name();
+
+ /* create pool */
+ ASSERT_EQ("", create_one_pool_pp(pool_name, rados));
+ ASSERT_EQ(0, rados.ioctx_create(pool_name.c_str(), ioctx));
+
+ /* add chains */
+ string oid = "obj";
+
+
+ /* create object */
+
+ ASSERT_EQ(0, ioctx.create(oid, true));
+
+ obj_version ver;
+
+ ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver));
+ ASSERT_EQ(0, (long long)ver.ver);
+ ASSERT_EQ(0, (int)ver.tag.size());
+
+ /* inc version */
+ librados::ObjectWriteOperation *op = new_op();
+ cls_version_inc(*op);
+ ASSERT_EQ(0, ioctx.operate(oid, op));
+
+ ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver));
+ ASSERT_GT((long long)ver.ver, 0);
+ ASSERT_NE(0, (int)ver.tag.size());
+
+ obj_version cond_ver = ver;
+
+ /* a bunch of conditions that should succeed */
+ librados::ObjectReadOperation *rop = new_rop();
+ cls_version_check(*rop, cond_ver, VER_COND_EQ);
+ bufferlist bl;
+ ASSERT_EQ(0, ioctx.operate(oid, rop, &bl));
+
+ delete rop;
+ rop = new_rop();
+ cls_version_check(*rop, cond_ver, VER_COND_GE);
+ ASSERT_EQ(0, ioctx.operate(oid, rop, &bl));
+
+ delete rop;
+ rop = new_rop();
+ cls_version_check(*rop, cond_ver, VER_COND_LE);
+ ASSERT_EQ(0, ioctx.operate(oid, rop, &bl));
+
+ delete rop;
+ rop = new_rop();
+ cls_version_check(*rop, cond_ver, VER_COND_TAG_EQ);
+ ASSERT_EQ(0, ioctx.operate(oid, rop, &bl));
+
+ obj_version ver2;
+
+ delete op;
+ op = new_op();
+ cls_version_inc(*op);
+ ASSERT_EQ(0, ioctx.operate(oid, op));
+
+ ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver2));
+ ASSERT_GT((long long)ver2.ver, (long long)ver.ver);
+ ASSERT_EQ(0, (int)ver2.tag.compare(ver.tag));
+
+ delete op;
+
+ /* a bunch of conditions that should fail */
+ delete rop;
+ rop = new_rop();
+ cls_version_check(*rop, ver, VER_COND_LT);
+ ASSERT_EQ(-ECANCELED, ioctx.operate(oid, rop, &bl));
+
+ delete rop;
+ rop = new_rop();
+ cls_version_check(*rop, cond_ver, VER_COND_LE);
+ ASSERT_EQ(-ECANCELED, ioctx.operate(oid, rop, &bl));
+
+ delete rop;
+ rop = new_rop();
+ cls_version_check(*rop, cond_ver, VER_COND_TAG_NE);
+ ASSERT_EQ(-ECANCELED, ioctx.operate(oid, rop, &bl));
+
+ delete rop;
+}