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
|
#include "include/rados/librados.h"
#include "test/librados/test.h"
#include "test/librados/TestCase.h"
#include "common/ceph_time.h"
#include <algorithm>
#include <errno.h>
#include "gtest/gtest.h"
typedef RadosTest LibRadosStat;
typedef RadosTestEC LibRadosStatEC;
TEST_F(LibRadosStat, Stat) {
char buf[128];
memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ(0, rados_write(ioctx, "foo", buf, sizeof(buf), 0));
uint64_t size;
time_t mtime;
ASSERT_EQ(0, rados_stat(ioctx, "foo", &size, &mtime));
ASSERT_EQ(sizeof(buf), size);
ASSERT_EQ(-ENOENT, rados_stat(ioctx, "nonexistent", &size, &mtime));
}
TEST_F(LibRadosStat, StatNS) {
char buf[128];
memset(buf, 0xcc, sizeof(buf));
rados_ioctx_set_namespace(ioctx, "");
ASSERT_EQ(0, rados_write(ioctx, "foo", buf, sizeof(buf), 0));
ASSERT_EQ(0, rados_write(ioctx, "foo2", buf, sizeof(buf), 0));
char buf2[64];
memset(buf2, 0xcc, sizeof(buf2));
rados_ioctx_set_namespace(ioctx, "nspace");
ASSERT_EQ(0, rados_write(ioctx, "foo", buf2, sizeof(buf2), 0));
uint64_t size;
time_t mtime;
rados_ioctx_set_namespace(ioctx, "");
ASSERT_EQ(0, rados_stat(ioctx, "foo", &size, &mtime));
ASSERT_EQ(sizeof(buf), size);
ASSERT_EQ(-ENOENT, rados_stat(ioctx, "nonexistent", &size, &mtime));
rados_ioctx_set_namespace(ioctx, "nspace");
ASSERT_EQ(0, rados_stat(ioctx, "foo", &size, &mtime));
ASSERT_EQ(sizeof(buf2), size);
ASSERT_EQ(-ENOENT, rados_stat(ioctx, "nonexistent", &size, &mtime));
ASSERT_EQ(-ENOENT, rados_stat(ioctx, "foo2", &size, &mtime));
}
TEST_F(LibRadosStat, ClusterStat) {
struct rados_cluster_stat_t result;
ASSERT_EQ(0, rados_cluster_stat(cluster, &result));
}
TEST_F(LibRadosStat, PoolStat) {
char buf[128];
char actual_pool_name[80];
unsigned l = rados_ioctx_get_pool_name(ioctx, actual_pool_name, sizeof(actual_pool_name));
ASSERT_EQ(strlen(actual_pool_name), l);
ASSERT_EQ(0, strcmp(actual_pool_name, pool_name.c_str()));
memset(buf, 0xff, sizeof(buf));
ASSERT_EQ(0, rados_write(ioctx, "foo", buf, sizeof(buf), 0));
struct rados_pool_stat_t stats;
memset(&stats, 0, sizeof(stats));
ASSERT_EQ(0, rados_ioctx_pool_stat(ioctx, &stats));
}
TEST_F(LibRadosStatEC, Stat) {
char buf[128];
memset(buf, 0xcc, sizeof(buf));
ASSERT_EQ(0, rados_write(ioctx, "foo", buf, sizeof(buf), 0));
uint64_t size;
time_t mtime;
ASSERT_EQ(0, rados_stat(ioctx, "foo", &size, &mtime));
ASSERT_EQ(sizeof(buf), size);
ASSERT_EQ(-ENOENT, rados_stat(ioctx, "nonexistent", &size, &mtime));
}
TEST_F(LibRadosStatEC, StatNS) {
char buf[128];
memset(buf, 0xcc, sizeof(buf));
rados_ioctx_set_namespace(ioctx, "");
ASSERT_EQ(0, rados_write(ioctx, "foo", buf, sizeof(buf), 0));
ASSERT_EQ(0, rados_write(ioctx, "foo2", buf, sizeof(buf), 0));
char buf2[64];
memset(buf2, 0xcc, sizeof(buf2));
rados_ioctx_set_namespace(ioctx, "nspace");
ASSERT_EQ(0, rados_write(ioctx, "foo", buf2, sizeof(buf2), 0));
uint64_t size;
time_t mtime;
rados_ioctx_set_namespace(ioctx, "");
ASSERT_EQ(0, rados_stat(ioctx, "foo", &size, &mtime));
ASSERT_EQ(sizeof(buf), size);
ASSERT_EQ(-ENOENT, rados_stat(ioctx, "nonexistent", &size, &mtime));
rados_ioctx_set_namespace(ioctx, "nspace");
ASSERT_EQ(0, rados_stat(ioctx, "foo", &size, &mtime));
ASSERT_EQ(sizeof(buf2), size);
ASSERT_EQ(-ENOENT, rados_stat(ioctx, "nonexistent", &size, &mtime));
ASSERT_EQ(-ENOENT, rados_stat(ioctx, "foo2", &size, &mtime));
}
TEST_F(LibRadosStatEC, ClusterStat) {
struct rados_cluster_stat_t result;
ASSERT_EQ(0, rados_cluster_stat(cluster, &result));
}
TEST_F(LibRadosStatEC, PoolStat) {
char buf[128];
char actual_pool_name[80];
unsigned l = rados_ioctx_get_pool_name(ioctx, actual_pool_name, sizeof(actual_pool_name));
ASSERT_EQ(strlen(actual_pool_name), l);
ASSERT_EQ(0, strcmp(actual_pool_name, pool_name.c_str()));
memset(buf, 0xff, sizeof(buf));
ASSERT_EQ(0, rados_write(ioctx, "foo", buf, sizeof(buf), 0));
struct rados_pool_stat_t stats;
memset(&stats, 0, sizeof(stats));
ASSERT_EQ(0, rados_ioctx_pool_stat(ioctx, &stats));
}
|