summaryrefslogtreecommitdiffstats
path: root/src/test/immutable_object_cache/test_object_store.cc
blob: f4d75274e1a349dfba3b1e65c675b9ce8982a4f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include <filesystem>
#include <iostream>
#include <unistd.h>


#include "gtest/gtest.h"
#include "include/Context.h"
#include "include/rados/librados.hpp"
#include "include/rbd/librbd.hpp"
#include "librbd/ImageCtx.h"
#include "test/librados/test.h"
#include "global/global_init.h"
#include "global/global_context.h"
#include "test/librados/test_cxx.h"

#include "tools/immutable_object_cache/ObjectCacheStore.h"

namespace fs = std::filesystem;

using namespace ceph::immutable_obj_cache;

std::string test_cache_path("/tmp/test_ceph_immutable_shared_cache");

class TestObjectStore : public ::testing::Test {
public:
  ObjectCacheStore* m_object_cache_store;
  librados::Rados* m_test_rados;
  CephContext* m_ceph_context;
  librados::IoCtx m_local_io_ctx;
  std::string m_temp_pool_name;
  std::string m_temp_volume_name;

  TestObjectStore(): m_object_cache_store(nullptr), m_test_rados(nullptr), m_ceph_context(nullptr){}

  ~TestObjectStore(){}

  static void SetUpTestCase() {}
  static void TearDownTestCase() {}

  void SetUp() override {
    m_test_rados = new librados::Rados();
    ASSERT_EQ("", connect_cluster_pp(*m_test_rados));
    ASSERT_EQ(0, m_test_rados->conf_set("rbd_cache", "false"));
    ASSERT_EQ(0, m_test_rados->conf_set("immutable_object_cache_max_size", "1024"));
    ASSERT_EQ(0, m_test_rados->conf_set("immutable_object_cache_path", test_cache_path.c_str()));

  }

  void create_object_cache_store(uint64_t entry_num) {
    m_temp_pool_name = get_temp_pool_name("test_pool_");
    ASSERT_EQ(0, m_test_rados->pool_create(m_temp_pool_name.c_str()));
    ASSERT_EQ(0, m_test_rados->ioctx_create(m_temp_pool_name.c_str(), m_local_io_ctx));
    m_temp_volume_name = "test_volume";
    m_ceph_context = reinterpret_cast<CephContext*>(m_test_rados->cct());
    m_object_cache_store = new ObjectCacheStore(m_ceph_context);
  }

  void init_object_cache_store(std::string pool_name, std::string vol_name,
                              uint64_t vol_size, bool reset) {
    ASSERT_EQ(0, m_object_cache_store->init(reset));
    ASSERT_EQ(0, m_object_cache_store->init_cache());
  }

  void shutdown_object_cache_store() {
    ASSERT_EQ(0, m_object_cache_store->shutdown());
  }

  void lookup_object_cache_store(std::string pool_name, std::string vol_name,
                                std::string obj_name, int& ret) {
    std::string cache_path;
    ret = m_object_cache_store->lookup_object(pool_name, 1, 2, 3,
                                            obj_name, true, cache_path);
  }

  void TearDown() override {
    if(m_test_rados)
      delete m_test_rados;
    if(m_object_cache_store)
      delete m_object_cache_store;
  }
};

TEST_F(TestObjectStore, test_1) {
  create_object_cache_store(1000);

  std::string cache_path(test_cache_path);

  fs::remove_all(test_cache_path);

  init_object_cache_store(m_temp_pool_name, m_temp_volume_name, 1000, true);


  // TODO add lookup interface testing

  shutdown_object_cache_store();
}