1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
9 #include "gtest/gtest.h"
10 #include "include/Context.h"
11 #include "include/rados/librados.hpp"
12 #include "include/rbd/librbd.hpp"
13 #include "librbd/ImageCtx.h"
14 #include "test/librados/test.h"
15 #include "global/global_init.h"
16 #include "global/global_context.h"
17 #include "test/librados/test_cxx.h"
19 #include "tools/immutable_object_cache/ObjectCacheStore.h"
21 namespace fs
= std::filesystem
;
23 using namespace ceph::immutable_obj_cache
;
25 std::string
test_cache_path("/tmp/test_ceph_immutable_shared_cache");
27 class TestObjectStore
: public ::testing::Test
{
29 ObjectCacheStore
* m_object_cache_store
;
30 librados::Rados
* m_test_rados
;
31 CephContext
* m_ceph_context
;
32 librados::IoCtx m_local_io_ctx
;
33 std::string m_temp_pool_name
;
34 std::string m_temp_volume_name
;
36 TestObjectStore(): m_object_cache_store(nullptr), m_test_rados(nullptr), m_ceph_context(nullptr){}
40 static void SetUpTestCase() {}
41 static void TearDownTestCase() {}
43 void SetUp() override
{
44 m_test_rados
= new librados::Rados();
45 ASSERT_EQ("", connect_cluster_pp(*m_test_rados
));
46 ASSERT_EQ(0, m_test_rados
->conf_set("rbd_cache", "false"));
47 ASSERT_EQ(0, m_test_rados
->conf_set("immutable_object_cache_max_size", "1024"));
48 ASSERT_EQ(0, m_test_rados
->conf_set("immutable_object_cache_path", test_cache_path
.c_str()));
52 void create_object_cache_store(uint64_t entry_num
) {
53 m_temp_pool_name
= get_temp_pool_name("test_pool_");
54 ASSERT_EQ(0, m_test_rados
->pool_create(m_temp_pool_name
.c_str()));
55 ASSERT_EQ(0, m_test_rados
->ioctx_create(m_temp_pool_name
.c_str(), m_local_io_ctx
));
56 m_temp_volume_name
= "test_volume";
57 m_ceph_context
= reinterpret_cast<CephContext
*>(m_test_rados
->cct());
58 m_object_cache_store
= new ObjectCacheStore(m_ceph_context
);
61 void init_object_cache_store(std::string pool_name
, std::string vol_name
,
62 uint64_t vol_size
, bool reset
) {
63 ASSERT_EQ(0, m_object_cache_store
->init(reset
));
64 ASSERT_EQ(0, m_object_cache_store
->init_cache());
67 void shutdown_object_cache_store() {
68 ASSERT_EQ(0, m_object_cache_store
->shutdown());
71 void lookup_object_cache_store(std::string pool_name
, std::string vol_name
,
72 std::string obj_name
, int& ret
) {
73 std::string cache_path
;
74 ret
= m_object_cache_store
->lookup_object(pool_name
, 1, 2, 3,
75 obj_name
, true, cache_path
);
78 void TearDown() override
{
81 if(m_object_cache_store
)
82 delete m_object_cache_store
;
86 TEST_F(TestObjectStore
, test_1
) {
87 create_object_cache_store(1000);
89 std::string
cache_path(test_cache_path
);
91 fs::remove_all(test_cache_path
);
93 init_object_cache_store(m_temp_pool_name
, m_temp_volume_name
, 1000, true);
96 // TODO add lookup interface testing
98 shutdown_object_cache_store();