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