1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_TEST_RADOS_TESTCASE_H
5 #define CEPH_TEST_RADOS_TESTCASE_H
7 #include "include/rados/librados.h"
8 #include "include/rados/librados.hpp"
9 #include "gtest/gtest.h"
14 * These test cases create a temporary pool that lives as long as the
15 * test case. We initially use the default namespace and assume
16 * test will whatever namespaces it wants. After each test all objects
19 * Since pool creation and deletion is slow, this allows many tests to
22 class RadosTestNS : public ::testing::Test {
24 RadosTestNS(bool c=false) : cleanup(c) {}
25 ~RadosTestNS() override {}
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29 static void cleanup_all_objects(rados_ioctx_t ioctx);
30 static rados_t s_cluster;
31 static std::string pool_name;
33 void SetUp() override;
34 void TearDown() override;
40 struct RadosTestNSCleanup : public RadosTestNS {
41 RadosTestNSCleanup() : RadosTestNS(true) {}
44 class RadosTestPPNS : public ::testing::Test {
46 RadosTestPPNS(bool c=false) : cluster(s_cluster), cleanup(c) {}
47 ~RadosTestPPNS() override {}
49 static void SetUpTestCase();
50 static void TearDownTestCase();
51 static void cleanup_all_objects(librados::IoCtx ioctx);
52 static librados::Rados s_cluster;
53 static std::string pool_name;
55 void SetUp() override;
56 void TearDown() override;
57 librados::Rados &cluster;
58 librados::IoCtx ioctx;
62 struct RadosTestPPNSCleanup : public RadosTestPPNS {
63 RadosTestPPNSCleanup() : RadosTestPPNS(true) {}
66 class RadosTestParamPPNS : public ::testing::TestWithParam<const char*> {
68 RadosTestParamPPNS(bool c=false) : cluster(s_cluster), cleanup(c) {}
69 ~RadosTestParamPPNS() override {}
70 static void SetUpTestCase();
71 static void TearDownTestCase();
73 static void cleanup_all_objects(librados::IoCtx ioctx);
74 static librados::Rados s_cluster;
75 static std::string pool_name;
76 static std::string cache_pool_name;
78 void SetUp() override;
79 void TearDown() override;
80 librados::Rados &cluster;
81 librados::IoCtx ioctx;
85 class RadosTestECNS : public RadosTestNS {
87 RadosTestECNS(bool c=false) : cleanup(c) {}
88 ~RadosTestECNS() override {}
90 static void SetUpTestCase();
91 static void TearDownTestCase();
92 static rados_t s_cluster;
93 static std::string pool_name;
95 void SetUp() override;
96 void TearDown() override;
103 struct RadosTestECNSCleanup : public RadosTestECNS {
104 RadosTestECNSCleanup() : RadosTestECNS(true) {}
107 class RadosTestECPPNS : public RadosTestPPNS {
109 RadosTestECPPNS(bool c=false) : cluster(s_cluster), cleanup(c) {}
110 ~RadosTestECPPNS() override {}
112 static void SetUpTestCase();
113 static void TearDownTestCase();
114 static librados::Rados s_cluster;
115 static std::string pool_name;
117 void SetUp() override;
118 void TearDown() override;
119 librados::Rados &cluster;
120 librados::IoCtx ioctx;
125 struct RadosTestECPPNSCleanup : public RadosTestECPPNS {
126 RadosTestECPPNSCleanup() : RadosTestECPPNS(true) {}
130 * These test cases create a temporary pool that lives as long as the
131 * test case. Each test within a test case gets a new ioctx set to a
132 * unique namespace within the pool.
134 * Since pool creation and deletion is slow, this allows many tests to
137 class RadosTest : public ::testing::Test {
139 RadosTest(bool c=false) : cleanup(c) {}
140 ~RadosTest() override {}
142 static void SetUpTestCase();
143 static void TearDownTestCase();
144 static void cleanup_default_namespace(rados_ioctx_t ioctx);
145 static void cleanup_namespace(rados_ioctx_t ioctx, std::string ns);
146 static rados_t s_cluster;
147 static std::string pool_name;
149 void SetUp() override;
150 void TearDown() override;
157 class RadosTestPP : public ::testing::Test {
159 RadosTestPP(bool c=false) : cluster(s_cluster), cleanup(c) {}
160 ~RadosTestPP() override {}
162 static void SetUpTestCase();
163 static void TearDownTestCase();
164 static void cleanup_default_namespace(librados::IoCtx ioctx);
165 static void cleanup_namespace(librados::IoCtx ioctx, std::string ns);
166 static librados::Rados s_cluster;
167 static std::string pool_name;
169 void SetUp() override;
170 void TearDown() override;
171 librados::Rados &cluster;
172 librados::IoCtx ioctx;
177 class RadosTestParamPP : public ::testing::TestWithParam<const char*> {
179 RadosTestParamPP(bool c=false) : cluster(s_cluster), cleanup(c) {}
180 ~RadosTestParamPP() override {}
181 static void SetUpTestCase();
182 static void TearDownTestCase();
184 static void cleanup_default_namespace(librados::IoCtx ioctx);
185 static void cleanup_namespace(librados::IoCtx ioctx, std::string ns);
186 static librados::Rados s_cluster;
187 static std::string pool_name;
188 static std::string cache_pool_name;
190 void SetUp() override;
191 void TearDown() override;
192 librados::Rados &cluster;
193 librados::IoCtx ioctx;
198 class RadosTestEC : public RadosTest {
200 RadosTestEC(bool c=false) : cleanup(c) {}
201 ~RadosTestEC() override {}
203 static void SetUpTestCase();
204 static void TearDownTestCase();
205 static rados_t s_cluster;
206 static std::string pool_name;
208 void SetUp() override;
209 void TearDown() override;
217 class RadosTestECPP : public RadosTestPP {
219 RadosTestECPP(bool c=false) : cluster(s_cluster), cleanup(c) {}
220 ~RadosTestECPP() override {}
222 static void SetUpTestCase();
223 static void TearDownTestCase();
224 static librados::Rados s_cluster;
225 static std::string pool_name;
227 void SetUp() override;
228 void TearDown() override;
229 librados::Rados &cluster;
230 librados::IoCtx ioctx;
237 * Test case without creating a temporary pool in advance.
238 * This is necessary for scenarios such that we need to
239 * manually create a pool, start some long-runing tasks and
240 * then the related pool is suddenly gone.
242 class RadosTestNP: public ::testing::Test {
245 ~RadosTestNP() override {}