]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/immutable_object_cache/test_object_store.cc
Import ceph 15.2.8
[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 <iostream>
5 #include <unistd.h>
6
7 #include <experimental/filesystem>
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 efs = std::experimental::filesystem;
22 using namespace ceph::immutable_obj_cache;
23
24 std::string test_cache_path("/tmp/test_ceph_immutable_shared_cache");
25
26 class TestObjectStore : public ::testing::Test {
27 public:
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;
34
35 TestObjectStore(): m_object_cache_store(nullptr), m_test_rados(nullptr), m_ceph_context(nullptr){}
36
37 ~TestObjectStore(){}
38
39 static void SetUpTestCase() {}
40 static void TearDownTestCase() {}
41
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()));
48
49 }
50
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);
58 }
59
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());
63 }
64
65 void shutdown_object_cache_store() {
66 ASSERT_EQ(0, m_object_cache_store->shutdown());
67 }
68
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, true,
72 cache_path);
73 }
74
75 void TearDown() override {
76 if(m_test_rados)
77 delete m_test_rados;
78 if(m_object_cache_store)
79 delete m_object_cache_store;
80 }
81 };
82
83 TEST_F(TestObjectStore, test_1) {
84 create_object_cache_store(1000);
85
86 std::string cache_path(test_cache_path);
87
88 efs::remove_all(test_cache_path);
89
90 init_object_cache_store(m_temp_pool_name, m_temp_volume_name, 1000, true);
91
92
93 // TODO add lookup interface testing
94
95 shutdown_object_cache_store();
96 }