]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/immutable_object_cache/test_object_store.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / test / immutable_object_cache / test_object_store.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include <filesystem>
5 #include <iostream>
6 #include <unistd.h>
7
8
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"
18
19 #include "tools/immutable_object_cache/ObjectCacheStore.h"
20
21 namespace fs = std::filesystem;
22
23 using namespace ceph::immutable_obj_cache;
24
25 std::string test_cache_path("/tmp/test_ceph_immutable_shared_cache");
26
27 class TestObjectStore : public ::testing::Test {
28 public:
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;
35
36 TestObjectStore(): m_object_cache_store(nullptr), m_test_rados(nullptr), m_ceph_context(nullptr){}
37
38 ~TestObjectStore(){}
39
40 static void SetUpTestCase() {}
41 static void TearDownTestCase() {}
42
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()));
49
50 }
51
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);
59 }
60
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());
65 }
66
67 void shutdown_object_cache_store() {
68 ASSERT_EQ(0, m_object_cache_store->shutdown());
69 }
70
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);
76 }
77
78 void TearDown() override {
79 if(m_test_rados)
80 delete m_test_rados;
81 if(m_object_cache_store)
82 delete m_object_cache_store;
83 }
84 };
85
86 TEST_F(TestObjectStore, test_1) {
87 create_object_cache_store(1000);
88
89 std::string cache_path(test_cache_path);
90
91 fs::remove_all(test_cache_path);
92
93 init_object_cache_store(m_temp_pool_name, m_temp_volume_name, 1000, true);
94
95
96 // TODO add lookup interface testing
97
98 shutdown_object_cache_store();
99 }