1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
7 #include <experimental/filesystem>
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 efs
= std::experimental::filesystem
;
22 using namespace ceph::immutable_obj_cache
;
24 std::string
test_cache_path("/tmp/test_ceph_immutable_shared_cache");
26 class TestObjectStore
: public ::testing::Test
{
28 ObjectCacheStore
* m_object_cache_store
;
29 librados::Rados
* m_test_rados
;
30 CephContext
* m_ceph_context
;
31 librados::IoCtx m_local_io_ctx
;
32 std::string m_temp_pool_name
;
33 std::string m_temp_volume_name
;
35 TestObjectStore(): m_object_cache_store(nullptr), m_test_rados(nullptr), m_ceph_context(nullptr){}
39 static void SetUpTestCase() {}
40 static void TearDownTestCase() {}
42 void SetUp() override
{
43 m_test_rados
= new librados::Rados();
44 ASSERT_EQ("", connect_cluster_pp(*m_test_rados
));
45 ASSERT_EQ(0, m_test_rados
->conf_set("rbd_cache", "false"));
46 ASSERT_EQ(0, m_test_rados
->conf_set("immutable_object_cache_max_size", "1024"));
47 ASSERT_EQ(0, m_test_rados
->conf_set("immutable_object_cache_path", test_cache_path
.c_str()));
51 void create_object_cache_store(uint64_t entry_num
) {
52 m_temp_pool_name
= get_temp_pool_name("test_pool_");
53 ASSERT_EQ(0, m_test_rados
->pool_create(m_temp_pool_name
.c_str()));
54 ASSERT_EQ(0, m_test_rados
->ioctx_create(m_temp_pool_name
.c_str(), m_local_io_ctx
));
55 m_temp_volume_name
= "test_volume";
56 m_ceph_context
= reinterpret_cast<CephContext
*>(m_test_rados
->cct());
57 m_object_cache_store
= new ObjectCacheStore(m_ceph_context
);
60 void init_object_cache_store(std::string pool_name
, std::string vol_name
, uint64_t vol_size
, bool reset
) {
61 ASSERT_EQ(0, m_object_cache_store
->init(reset
));
62 ASSERT_EQ(0, m_object_cache_store
->init_cache());
65 void shutdown_object_cache_store() {
66 ASSERT_EQ(0, m_object_cache_store
->shutdown());
69 void lookup_object_cache_store(std::string pool_name
, std::string vol_name
, std::string obj_name
, int& ret
) {
70 std::string cache_path
;
71 ret
= m_object_cache_store
->lookup_object(pool_name
, 1, 2, obj_name
, cache_path
);
74 void TearDown() override
{
77 if(m_object_cache_store
)
78 delete m_object_cache_store
;
82 TEST_F(TestObjectStore
, test_1
) {
83 create_object_cache_store(1000);
85 std::string
cache_path(test_cache_path
);
87 efs::remove_all(test_cache_path
);
89 init_object_cache_store(m_temp_pool_name
, m_temp_volume_name
, 1000, true);
92 // TODO add lookup interface testing
94 shutdown_object_cache_store();