]>
Commit | Line | Data |
---|---|---|
1e59de90 | 1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
7c673cae FG |
2 | // vim: ts=8 sw=2 smarttab |
3 | ||
11fdf7f2 | 4 | #include "include/rados/librados.hpp" |
7c673cae | 5 | #include "include/types.h" |
11fdf7f2 | 6 | |
7c673cae FG |
7 | #include "cls/version/cls_version_types.h" |
8 | #include "cls/version/cls_version_client.h" | |
9 | ||
10 | #include "gtest/gtest.h" | |
11fdf7f2 | 11 | #include "test/librados/test_cxx.h" |
7c673cae FG |
12 | |
13 | #include <errno.h> | |
14 | #include <string> | |
15 | #include <vector> | |
16 | ||
20effc67 TL |
17 | using namespace std; |
18 | ||
7c673cae FG |
19 | static librados::ObjectWriteOperation *new_op() { |
20 | return new librados::ObjectWriteOperation(); | |
21 | } | |
22 | ||
23 | static librados::ObjectReadOperation *new_rop() { | |
24 | return new librados::ObjectReadOperation(); | |
25 | } | |
26 | ||
27 | TEST(cls_rgw, test_version_inc_read) | |
28 | { | |
29 | librados::Rados rados; | |
30 | librados::IoCtx ioctx; | |
31 | string pool_name = get_temp_pool_name(); | |
32 | ||
33 | /* create pool */ | |
34 | ASSERT_EQ("", create_one_pool_pp(pool_name, rados)); | |
35 | ASSERT_EQ(0, rados.ioctx_create(pool_name.c_str(), ioctx)); | |
36 | ||
37 | /* add chains */ | |
38 | string oid = "obj"; | |
39 | ||
40 | ||
41 | /* create object */ | |
42 | ||
43 | ASSERT_EQ(0, ioctx.create(oid, true)); | |
44 | ||
45 | obj_version ver; | |
46 | ||
47 | ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver)); | |
48 | ASSERT_EQ(0, (long long)ver.ver); | |
49 | ASSERT_EQ(0, (int)ver.tag.size()); | |
50 | ||
51 | ||
52 | /* inc version */ | |
53 | librados::ObjectWriteOperation *op = new_op(); | |
54 | cls_version_inc(*op); | |
55 | ASSERT_EQ(0, ioctx.operate(oid, op)); | |
56 | ||
57 | ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver)); | |
58 | ASSERT_GT((long long)ver.ver, 0); | |
59 | ASSERT_NE(0, (int)ver.tag.size()); | |
60 | ||
61 | /* inc version again! */ | |
62 | delete op; | |
63 | op = new_op(); | |
64 | cls_version_inc(*op); | |
65 | ASSERT_EQ(0, ioctx.operate(oid, op)); | |
66 | ||
67 | obj_version ver2; | |
68 | ||
69 | ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver2)); | |
70 | ASSERT_GT((long long)ver2.ver, (long long)ver.ver); | |
71 | ASSERT_EQ(0, (int)ver2.tag.compare(ver.tag)); | |
72 | ||
73 | delete op; | |
74 | ||
75 | obj_version ver3; | |
76 | ||
77 | librados::ObjectReadOperation *rop = new_rop(); | |
78 | cls_version_read(*rop, &ver3); | |
79 | bufferlist outbl; | |
80 | ASSERT_EQ(0, ioctx.operate(oid, rop, &outbl)); | |
81 | ASSERT_EQ(ver2.ver, ver3.ver); | |
82 | ASSERT_EQ(1, (long long)ver2.compare(&ver3)); | |
83 | ||
84 | delete rop; | |
85 | } | |
86 | ||
87 | ||
88 | TEST(cls_rgw, test_version_set) | |
89 | { | |
90 | librados::Rados rados; | |
91 | librados::IoCtx ioctx; | |
92 | string pool_name = get_temp_pool_name(); | |
93 | ||
94 | /* create pool */ | |
95 | ASSERT_EQ("", create_one_pool_pp(pool_name, rados)); | |
96 | ASSERT_EQ(0, rados.ioctx_create(pool_name.c_str(), ioctx)); | |
97 | ||
98 | /* add chains */ | |
99 | string oid = "obj"; | |
100 | ||
101 | ||
102 | /* create object */ | |
103 | ||
104 | ASSERT_EQ(0, ioctx.create(oid, true)); | |
105 | ||
106 | obj_version ver; | |
107 | ||
108 | ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver)); | |
109 | ASSERT_EQ(0, (long long)ver.ver); | |
110 | ASSERT_EQ(0, (int)ver.tag.size()); | |
111 | ||
112 | ||
113 | ver.ver = 123; | |
114 | ver.tag = "foo"; | |
115 | ||
116 | /* set version */ | |
117 | librados::ObjectWriteOperation *op = new_op(); | |
118 | cls_version_set(*op, ver); | |
119 | ASSERT_EQ(0, ioctx.operate(oid, op)); | |
120 | ||
121 | /* read version */ | |
122 | obj_version ver2; | |
123 | ||
124 | ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver2)); | |
125 | ASSERT_EQ((long long)ver2.ver, (long long)ver.ver); | |
126 | ASSERT_EQ(0, (int)ver2.tag.compare(ver.tag)); | |
127 | ||
128 | delete op; | |
129 | } | |
130 | ||
131 | TEST(cls_rgw, test_version_inc_cond) | |
132 | { | |
133 | librados::Rados rados; | |
134 | librados::IoCtx ioctx; | |
135 | string pool_name = get_temp_pool_name(); | |
136 | ||
137 | /* create pool */ | |
138 | ASSERT_EQ("", create_one_pool_pp(pool_name, rados)); | |
139 | ASSERT_EQ(0, rados.ioctx_create(pool_name.c_str(), ioctx)); | |
140 | ||
141 | /* add chains */ | |
142 | string oid = "obj"; | |
143 | ||
144 | /* create object */ | |
145 | ||
146 | ASSERT_EQ(0, ioctx.create(oid, true)); | |
147 | ||
148 | obj_version ver; | |
149 | ||
150 | ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver)); | |
151 | ASSERT_EQ(0, (long long)ver.ver); | |
152 | ASSERT_EQ(0, (int)ver.tag.size()); | |
153 | ||
154 | /* inc version */ | |
155 | librados::ObjectWriteOperation *op = new_op(); | |
156 | cls_version_inc(*op); | |
157 | ASSERT_EQ(0, ioctx.operate(oid, op)); | |
158 | ||
159 | ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver)); | |
160 | ASSERT_GT((long long)ver.ver, 0); | |
161 | ASSERT_NE(0, (int)ver.tag.size()); | |
162 | ||
163 | obj_version cond_ver = ver; | |
164 | ||
165 | ||
166 | /* inc version again! */ | |
167 | delete op; | |
168 | op = new_op(); | |
169 | cls_version_inc(*op); | |
170 | ASSERT_EQ(0, ioctx.operate(oid, op)); | |
171 | ||
172 | obj_version ver2; | |
173 | ||
174 | ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver2)); | |
175 | ASSERT_GT((long long)ver2.ver, (long long)ver.ver); | |
176 | ASSERT_EQ(0, (int)ver2.tag.compare(ver.tag)); | |
177 | ||
178 | ||
179 | /* now check various condition tests */ | |
180 | cls_version_inc(*op, cond_ver, VER_COND_NONE); | |
181 | ASSERT_EQ(0, ioctx.operate(oid, op)); | |
182 | ||
183 | ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver2)); | |
184 | ASSERT_GT((long long)ver2.ver, (long long)ver.ver); | |
185 | ASSERT_EQ(0, (int)ver2.tag.compare(ver.tag)); | |
186 | ||
187 | /* a bunch of conditions that should fail */ | |
188 | delete op; | |
189 | op = new_op(); | |
190 | cls_version_inc(*op, cond_ver, VER_COND_EQ); | |
191 | ASSERT_EQ(-ECANCELED, ioctx.operate(oid, op)); | |
192 | ||
193 | delete op; | |
194 | op = new_op(); | |
195 | cls_version_inc(*op, cond_ver, VER_COND_LT); | |
196 | ASSERT_EQ(-ECANCELED, ioctx.operate(oid, op)); | |
197 | ||
198 | delete op; | |
199 | op = new_op(); | |
200 | cls_version_inc(*op, cond_ver, VER_COND_LE); | |
201 | ASSERT_EQ(-ECANCELED, ioctx.operate(oid, op)); | |
202 | ||
203 | delete op; | |
204 | op = new_op(); | |
205 | cls_version_inc(*op, cond_ver, VER_COND_TAG_NE); | |
206 | ASSERT_EQ(-ECANCELED, ioctx.operate(oid, op)); | |
207 | ||
208 | ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver2)); | |
209 | ASSERT_GT((long long)ver2.ver, (long long)ver.ver); | |
210 | ASSERT_EQ(0, (int)ver2.tag.compare(ver.tag)); | |
211 | ||
212 | /* a bunch of conditions that should succeed */ | |
213 | delete op; | |
214 | op = new_op(); | |
215 | cls_version_inc(*op, ver2, VER_COND_EQ); | |
216 | ASSERT_EQ(0, ioctx.operate(oid, op)); | |
217 | ||
218 | delete op; | |
219 | op = new_op(); | |
220 | cls_version_inc(*op, cond_ver, VER_COND_GT); | |
221 | ASSERT_EQ(0, ioctx.operate(oid, op)); | |
222 | ||
223 | delete op; | |
224 | op = new_op(); | |
225 | cls_version_inc(*op, cond_ver, VER_COND_GE); | |
226 | ASSERT_EQ(0, ioctx.operate(oid, op)); | |
227 | ||
228 | delete op; | |
229 | op = new_op(); | |
230 | cls_version_inc(*op, cond_ver, VER_COND_TAG_EQ); | |
231 | ASSERT_EQ(0, ioctx.operate(oid, op)); | |
232 | ||
233 | delete op; | |
234 | } | |
235 | ||
236 | TEST(cls_rgw, test_version_inc_check) | |
237 | { | |
238 | librados::Rados rados; | |
239 | librados::IoCtx ioctx; | |
240 | string pool_name = get_temp_pool_name(); | |
241 | ||
242 | /* create pool */ | |
243 | ASSERT_EQ("", create_one_pool_pp(pool_name, rados)); | |
244 | ASSERT_EQ(0, rados.ioctx_create(pool_name.c_str(), ioctx)); | |
245 | ||
246 | /* add chains */ | |
247 | string oid = "obj"; | |
248 | ||
249 | ||
250 | /* create object */ | |
251 | ||
252 | ASSERT_EQ(0, ioctx.create(oid, true)); | |
253 | ||
254 | obj_version ver; | |
255 | ||
256 | ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver)); | |
257 | ASSERT_EQ(0, (long long)ver.ver); | |
258 | ASSERT_EQ(0, (int)ver.tag.size()); | |
259 | ||
260 | /* inc version */ | |
261 | librados::ObjectWriteOperation *op = new_op(); | |
262 | cls_version_inc(*op); | |
263 | ASSERT_EQ(0, ioctx.operate(oid, op)); | |
264 | ||
265 | ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver)); | |
266 | ASSERT_GT((long long)ver.ver, 0); | |
267 | ASSERT_NE(0, (int)ver.tag.size()); | |
268 | ||
269 | obj_version cond_ver = ver; | |
270 | ||
271 | /* a bunch of conditions that should succeed */ | |
272 | librados::ObjectReadOperation *rop = new_rop(); | |
273 | cls_version_check(*rop, cond_ver, VER_COND_EQ); | |
274 | bufferlist bl; | |
275 | ASSERT_EQ(0, ioctx.operate(oid, rop, &bl)); | |
276 | ||
277 | delete rop; | |
278 | rop = new_rop(); | |
279 | cls_version_check(*rop, cond_ver, VER_COND_GE); | |
280 | ASSERT_EQ(0, ioctx.operate(oid, rop, &bl)); | |
281 | ||
282 | delete rop; | |
283 | rop = new_rop(); | |
284 | cls_version_check(*rop, cond_ver, VER_COND_LE); | |
285 | ASSERT_EQ(0, ioctx.operate(oid, rop, &bl)); | |
286 | ||
287 | delete rop; | |
288 | rop = new_rop(); | |
289 | cls_version_check(*rop, cond_ver, VER_COND_TAG_EQ); | |
290 | ASSERT_EQ(0, ioctx.operate(oid, rop, &bl)); | |
291 | ||
292 | obj_version ver2; | |
293 | ||
294 | delete op; | |
295 | op = new_op(); | |
296 | cls_version_inc(*op); | |
297 | ASSERT_EQ(0, ioctx.operate(oid, op)); | |
298 | ||
299 | ASSERT_EQ(0, cls_version_read(ioctx, oid, &ver2)); | |
300 | ASSERT_GT((long long)ver2.ver, (long long)ver.ver); | |
301 | ASSERT_EQ(0, (int)ver2.tag.compare(ver.tag)); | |
302 | ||
303 | delete op; | |
304 | ||
305 | /* a bunch of conditions that should fail */ | |
306 | delete rop; | |
307 | rop = new_rop(); | |
308 | cls_version_check(*rop, ver, VER_COND_LT); | |
309 | ASSERT_EQ(-ECANCELED, ioctx.operate(oid, rop, &bl)); | |
310 | ||
311 | delete rop; | |
312 | rop = new_rop(); | |
313 | cls_version_check(*rop, cond_ver, VER_COND_LE); | |
314 | ASSERT_EQ(-ECANCELED, ioctx.operate(oid, rop, &bl)); | |
315 | ||
316 | delete rop; | |
317 | rop = new_rop(); | |
318 | cls_version_check(*rop, cond_ver, VER_COND_TAG_NE); | |
319 | ASSERT_EQ(-ECANCELED, ioctx.operate(oid, rop, &bl)); | |
320 | ||
321 | delete rop; | |
322 | } |