1 #include "include/rados/librados.h"
2 #include "include/rados/librados.hpp"
3 #include "test/librados/test.h"
4 #include "test/librados/TestCase.h"
6 #include "common/ceph_time.h"
10 #include "gtest/gtest.h"
12 using namespace librados;
14 typedef RadosTest LibRadosStat;
15 typedef RadosTestPP LibRadosStatPP;
16 typedef RadosTestEC LibRadosStatEC;
17 typedef RadosTestECPP LibRadosStatECPP;
19 TEST_F(LibRadosStat, Stat) {
21 memset(buf, 0xcc, sizeof(buf));
22 ASSERT_EQ(0, rados_write(ioctx, "foo", buf, sizeof(buf), 0));
25 ASSERT_EQ(0, rados_stat(ioctx, "foo", &size, &mtime));
26 ASSERT_EQ(sizeof(buf), size);
27 ASSERT_EQ(-ENOENT, rados_stat(ioctx, "nonexistent", &size, &mtime));
30 TEST_F(LibRadosStatPP, StatPP) {
32 memset(buf, 0xcc, sizeof(buf));
34 bl.append(buf, sizeof(buf));
35 ASSERT_EQ(0, ioctx.write("foo", bl, sizeof(buf), 0));
38 ASSERT_EQ(0, ioctx.stat("foo", &size, &mtime));
39 ASSERT_EQ(sizeof(buf), size);
40 ASSERT_EQ(-ENOENT, ioctx.stat("nonexistent", &size, &mtime));
43 TEST_F(LibRadosStatPP, Stat2Mtime2PP) {
45 memset(buf, 0xcc, sizeof(buf));
47 bl.append(buf, sizeof(buf));
48 librados::ObjectWriteOperation op;
50 ts.tv_sec = 1457129052;
51 ts.tv_nsec = 123456789;
54 ASSERT_EQ(0, ioctx.operate("foo", &op));
56 /* XXX time comparison asserts could spuriously fail */
60 ASSERT_EQ(0, ioctx.stat("foo", &size, &mtime));
61 ASSERT_EQ(sizeof(buf), size);
62 ASSERT_EQ(mtime, ts.tv_sec);
65 ASSERT_EQ(0, ioctx.stat2("foo", &size, &ts2));
66 ASSERT_EQ(sizeof(buf), size);
67 ASSERT_EQ(ts2.tv_sec, ts.tv_sec);
68 ASSERT_EQ(ts2.tv_nsec, ts.tv_nsec);
70 ASSERT_EQ(-ENOENT, ioctx.stat2("nonexistent", &size, &ts2));
73 TEST_F(LibRadosStat, StatNS) {
75 memset(buf, 0xcc, sizeof(buf));
76 rados_ioctx_set_namespace(ioctx, "");
77 ASSERT_EQ(0, rados_write(ioctx, "foo", buf, sizeof(buf), 0));
78 ASSERT_EQ(0, rados_write(ioctx, "foo2", buf, sizeof(buf), 0));
81 memset(buf2, 0xcc, sizeof(buf2));
82 rados_ioctx_set_namespace(ioctx, "nspace");
83 ASSERT_EQ(0, rados_write(ioctx, "foo", buf2, sizeof(buf2), 0));
87 rados_ioctx_set_namespace(ioctx, "");
88 ASSERT_EQ(0, rados_stat(ioctx, "foo", &size, &mtime));
89 ASSERT_EQ(sizeof(buf), size);
90 ASSERT_EQ(-ENOENT, rados_stat(ioctx, "nonexistent", &size, &mtime));
92 rados_ioctx_set_namespace(ioctx, "nspace");
93 ASSERT_EQ(0, rados_stat(ioctx, "foo", &size, &mtime));
94 ASSERT_EQ(sizeof(buf2), size);
95 ASSERT_EQ(-ENOENT, rados_stat(ioctx, "nonexistent", &size, &mtime));
96 ASSERT_EQ(-ENOENT, rados_stat(ioctx, "foo2", &size, &mtime));
99 TEST_F(LibRadosStatPP, StatPPNS) {
101 memset(buf, 0xcc, sizeof(buf));
103 bl.append(buf, sizeof(buf));
104 ioctx.set_namespace("");
105 ASSERT_EQ(0, ioctx.write("foo", bl, sizeof(buf), 0));
106 ASSERT_EQ(0, ioctx.write("foo2", bl, sizeof(buf), 0));
109 memset(buf2, 0xbb, sizeof(buf2));
111 bl2.append(buf2, sizeof(buf2));
112 ioctx.set_namespace("nspace");
113 ASSERT_EQ(0, ioctx.write("foo", bl2, sizeof(buf2), 0));
117 ioctx.set_namespace("");
118 ASSERT_EQ(0, ioctx.stat("foo", &size, &mtime));
119 ASSERT_EQ(sizeof(buf), size);
120 ASSERT_EQ(-ENOENT, ioctx.stat("nonexistent", &size, &mtime));
122 ioctx.set_namespace("nspace");
123 ASSERT_EQ(0, ioctx.stat("foo", &size, &mtime));
124 ASSERT_EQ(sizeof(buf2), size);
125 ASSERT_EQ(-ENOENT, ioctx.stat("nonexistent", &size, &mtime));
126 ASSERT_EQ(-ENOENT, ioctx.stat("foo2", &size, &mtime));
129 TEST_F(LibRadosStat, ClusterStat) {
130 struct rados_cluster_stat_t result;
131 ASSERT_EQ(0, rados_cluster_stat(cluster, &result));
134 TEST_F(LibRadosStatPP, ClusterStatPP) {
135 cluster_stat_t cstat;
136 ASSERT_EQ(0, cluster.cluster_stat(cstat));
139 TEST_F(LibRadosStat, PoolStat) {
141 char actual_pool_name[80];
142 unsigned l = rados_ioctx_get_pool_name(ioctx, actual_pool_name, sizeof(actual_pool_name));
143 ASSERT_EQ(strlen(actual_pool_name), l);
144 ASSERT_EQ(0, strcmp(actual_pool_name, pool_name.c_str()));
145 memset(buf, 0xff, sizeof(buf));
146 ASSERT_EQ(0, rados_write(ioctx, "foo", buf, sizeof(buf), 0));
147 struct rados_pool_stat_t stats;
148 memset(&stats, 0, sizeof(stats));
149 ASSERT_EQ(0, rados_ioctx_pool_stat(ioctx, &stats));
152 TEST_F(LibRadosStatPP, PoolStatPP) {
153 std::string n = ioctx.get_pool_name();
154 ASSERT_EQ(n, pool_name);
156 memset(buf, 0xff, sizeof(buf));
158 bl1.append(buf, sizeof(buf));
159 ASSERT_EQ(0, ioctx.write("foo", bl1, sizeof(buf), 0));
160 std::list<std::string> v;
161 std::map<std::string,stats_map> stats;
162 ASSERT_EQ(0, cluster.get_pool_stats(v, stats));
165 TEST_F(LibRadosStatEC, Stat) {
167 memset(buf, 0xcc, sizeof(buf));
168 ASSERT_EQ(0, rados_write(ioctx, "foo", buf, sizeof(buf), 0));
171 ASSERT_EQ(0, rados_stat(ioctx, "foo", &size, &mtime));
172 ASSERT_EQ(sizeof(buf), size);
173 ASSERT_EQ(-ENOENT, rados_stat(ioctx, "nonexistent", &size, &mtime));
176 TEST_F(LibRadosStatECPP, StatPP) {
178 memset(buf, 0xcc, sizeof(buf));
180 bl.append(buf, sizeof(buf));
181 ASSERT_EQ(0, ioctx.write("foo", bl, sizeof(buf), 0));
184 ASSERT_EQ(0, ioctx.stat("foo", &size, &mtime));
185 ASSERT_EQ(sizeof(buf), size);
186 ASSERT_EQ(-ENOENT, ioctx.stat("nonexistent", &size, &mtime));
189 TEST_F(LibRadosStatEC, StatNS) {
191 memset(buf, 0xcc, sizeof(buf));
192 rados_ioctx_set_namespace(ioctx, "");
193 ASSERT_EQ(0, rados_write(ioctx, "foo", buf, sizeof(buf), 0));
194 ASSERT_EQ(0, rados_write(ioctx, "foo2", buf, sizeof(buf), 0));
197 memset(buf2, 0xcc, sizeof(buf2));
198 rados_ioctx_set_namespace(ioctx, "nspace");
199 ASSERT_EQ(0, rados_write(ioctx, "foo", buf2, sizeof(buf2), 0));
203 rados_ioctx_set_namespace(ioctx, "");
204 ASSERT_EQ(0, rados_stat(ioctx, "foo", &size, &mtime));
205 ASSERT_EQ(sizeof(buf), size);
206 ASSERT_EQ(-ENOENT, rados_stat(ioctx, "nonexistent", &size, &mtime));
208 rados_ioctx_set_namespace(ioctx, "nspace");
209 ASSERT_EQ(0, rados_stat(ioctx, "foo", &size, &mtime));
210 ASSERT_EQ(sizeof(buf2), size);
211 ASSERT_EQ(-ENOENT, rados_stat(ioctx, "nonexistent", &size, &mtime));
212 ASSERT_EQ(-ENOENT, rados_stat(ioctx, "foo2", &size, &mtime));
215 TEST_F(LibRadosStatECPP, StatPPNS) {
217 memset(buf, 0xcc, sizeof(buf));
219 bl.append(buf, sizeof(buf));
220 ioctx.set_namespace("");
221 ASSERT_EQ(0, ioctx.write("foo", bl, sizeof(buf), 0));
222 ASSERT_EQ(0, ioctx.write("foo2", bl, sizeof(buf), 0));
225 memset(buf2, 0xbb, sizeof(buf2));
227 bl2.append(buf2, sizeof(buf2));
228 ioctx.set_namespace("nspace");
229 ASSERT_EQ(0, ioctx.write("foo", bl2, sizeof(buf2), 0));
233 ioctx.set_namespace("");
234 ASSERT_EQ(0, ioctx.stat("foo", &size, &mtime));
235 ASSERT_EQ(sizeof(buf), size);
236 ASSERT_EQ(-ENOENT, ioctx.stat("nonexistent", &size, &mtime));
238 ioctx.set_namespace("nspace");
239 ASSERT_EQ(0, ioctx.stat("foo", &size, &mtime));
240 ASSERT_EQ(sizeof(buf2), size);
241 ASSERT_EQ(-ENOENT, ioctx.stat("nonexistent", &size, &mtime));
242 ASSERT_EQ(-ENOENT, ioctx.stat("foo2", &size, &mtime));
245 TEST_F(LibRadosStatEC, ClusterStat) {
246 struct rados_cluster_stat_t result;
247 ASSERT_EQ(0, rados_cluster_stat(cluster, &result));
250 TEST_F(LibRadosStatECPP, ClusterStatPP) {
251 cluster_stat_t cstat;
252 ASSERT_EQ(0, cluster.cluster_stat(cstat));
255 TEST_F(LibRadosStatEC, PoolStat) {
257 char actual_pool_name[80];
258 unsigned l = rados_ioctx_get_pool_name(ioctx, actual_pool_name, sizeof(actual_pool_name));
259 ASSERT_EQ(strlen(actual_pool_name), l);
260 ASSERT_EQ(0, strcmp(actual_pool_name, pool_name.c_str()));
261 memset(buf, 0xff, sizeof(buf));
262 ASSERT_EQ(0, rados_write(ioctx, "foo", buf, sizeof(buf), 0));
263 struct rados_pool_stat_t stats;
264 memset(&stats, 0, sizeof(stats));
265 ASSERT_EQ(0, rados_ioctx_pool_stat(ioctx, &stats));
268 TEST_F(LibRadosStatECPP, PoolStatPP) {
269 std::string n = ioctx.get_pool_name();
270 ASSERT_EQ(n, pool_name);
272 memset(buf, 0xff, sizeof(buf));
274 bl1.append(buf, sizeof(buf));
275 ASSERT_EQ(0, ioctx.write("foo", bl1, sizeof(buf), 0));
276 std::list<std::string> v;
277 std::map<std::string,stats_map> stats;
278 ASSERT_EQ(0, cluster.get_pool_stats(v, stats));