]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/rgw/test_rgw_gc_log.cc
import 15.2.0 Octopus source
[ceph.git] / ceph / src / test / rgw / test_rgw_gc_log.cc
1 // -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "rgw/rgw_gc_log.h"
5
6 #include "test/librados/test_cxx.h"
7 #include "gtest/gtest.h"
8
9 // creates a rados client and temporary pool
10 struct RadosEnv : public ::testing::Environment {
11 static std::optional<std::string> pool_name;
12 public:
13 static std::optional<librados::Rados> rados;
14
15 void SetUp() override {
16 rados.emplace();
17 // create pool
18 std::string name = get_temp_pool_name();
19 ASSERT_EQ("", create_one_pool_pp(name, *rados));
20 pool_name = name;
21 }
22 void TearDown() override {
23 if (pool_name) {
24 ASSERT_EQ(0, destroy_one_pool_pp(*pool_name, *rados));
25 }
26 rados.reset();
27 }
28
29 static int ioctx_create(librados::IoCtx& ioctx) {
30 return rados->ioctx_create(pool_name->c_str(), ioctx);
31 }
32 };
33 std::optional<std::string> RadosEnv::pool_name;
34 std::optional<librados::Rados> RadosEnv::rados;
35
36 auto *const rados_env = ::testing::AddGlobalTestEnvironment(new RadosEnv);
37
38 class rgw_gc_log : public ::testing::Test {
39 protected:
40 static librados::IoCtx ioctx;
41
42 static void SetUpTestSuite() {
43 ASSERT_EQ(0, RadosEnv::ioctx_create(ioctx));
44 }
45 static void TearDownTestSuite() {
46 ioctx.close();
47 }
48
49 // use the test's name as the oid so different tests don't conflict
50 std::string get_test_oid() const {
51 return ::testing::UnitTest::GetInstance()->current_test_info()->name();
52 }
53 };
54 librados::IoCtx rgw_gc_log::ioctx;
55
56
57 TEST_F(rgw_gc_log, init_existing_queue)
58 {
59 const std::string oid = get_test_oid();
60 {
61 // successfully inits new object
62 librados::ObjectWriteOperation op;
63 gc_log_init2(op, 1, 1);
64 ASSERT_EQ(0, ioctx.operate(oid, &op));
65 }
66 {
67 // version check fails on second init
68 librados::ObjectWriteOperation op;
69 gc_log_init2(op, 1, 1);
70 ASSERT_EQ(-ECANCELED, ioctx.operate(oid, &op));
71 }
72 }
73
74 TEST_F(rgw_gc_log, init_existing_omap)
75 {
76 const std::string oid = get_test_oid();
77 {
78 librados::ObjectWriteOperation op;
79 cls_rgw_gc_obj_info info;
80 gc_log_enqueue1(op, 5, info);
81 ASSERT_EQ(0, ioctx.operate(oid, &op));
82 }
83 {
84 // init succeeds with existing omap entries
85 librados::ObjectWriteOperation op;
86 gc_log_init2(op, 1, 1);
87 ASSERT_EQ(0, ioctx.operate(oid, &op));
88 }
89 }
90
91 TEST_F(rgw_gc_log, enqueue1_after_init)
92 {
93 const std::string oid = get_test_oid();
94 {
95 librados::ObjectWriteOperation op;
96 gc_log_init2(op, 1, 1);
97 ASSERT_EQ(0, ioctx.operate(oid, &op));
98 }
99 {
100 // version check fails on omap enqueue
101 librados::ObjectWriteOperation op;
102 cls_rgw_gc_obj_info info;
103 gc_log_enqueue1(op, 5, info);
104 ASSERT_EQ(-ECANCELED, ioctx.operate(oid, &op));
105 }
106 }
107
108 TEST_F(rgw_gc_log, enqueue2_before_init)
109 {
110 const std::string oid = get_test_oid();
111 {
112 // version check fails on cls_rgw_gc enqueue
113 librados::ObjectWriteOperation op;
114 gc_log_enqueue2(op, 5, {});
115 ASSERT_EQ(-ECANCELED, ioctx.operate(oid, &op));
116 }
117 }
118
119 TEST_F(rgw_gc_log, defer1_after_init)
120 {
121 const std::string oid = get_test_oid();
122 {
123 librados::ObjectWriteOperation op;
124 gc_log_init2(op, 1, 1);
125 ASSERT_EQ(0, ioctx.operate(oid, &op));
126 }
127 {
128 // version check fails on omap defer
129 librados::ObjectWriteOperation op;
130 gc_log_defer1(op, 5, {});
131 ASSERT_EQ(-ECANCELED, ioctx.operate(oid, &op));
132 }
133 }
134
135 TEST_F(rgw_gc_log, defer2_before_init)
136 {
137 const std::string oid = get_test_oid();
138 {
139 // version check fails on cls_rgw_gc defer
140 librados::ObjectWriteOperation op;
141 gc_log_defer2(op, 5, {});
142 ASSERT_EQ(-ECANCELED, ioctx.operate(oid, &op));
143 }
144 }