summaryrefslogtreecommitdiffstats
path: root/src/test/immutable_object_cache/test_message.cc
blob: bbd6ad165b91ad85cb4c09176b928a343f1bced2 (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
#include "gtest/gtest.h"
#include "tools/immutable_object_cache/Types.h"
#include "tools/immutable_object_cache/SocketCommon.h"

using namespace ceph::immutable_obj_cache;

TEST(test_for_message, test_1) 
{
  std::string pool_nspace("this is a pool namespace");
  std::string oid_name("this is a oid name");
  std::string cache_file_path("/temp/ceph_immutable_object_cache");

  uint16_t type = RBDSC_READ;
  uint64_t seq = 123456UL;
  uint64_t read_offset = 222222UL;
  uint64_t read_len = 333333UL;
  uint64_t pool_id = 444444UL;
  uint64_t snap_id = 555555UL;
  uint64_t object_size = 666666UL;

  // ObjectRequest --> bufferlist
  ObjectCacheRequest* req = new ObjectCacheReadData(type, seq, read_offset, read_len,
                                    pool_id, snap_id, object_size, oid_name, pool_nspace);
  req->encode();
  auto payload_bl = req->get_payload_bufferlist();

  uint32_t data_len = get_data_len(payload_bl.c_str());
  ASSERT_EQ(payload_bl.length(), data_len + get_header_size());
  ASSERT_TRUE(payload_bl.c_str() != nullptr);

  // bufferlist --> ObjectCacheRequest
  ObjectCacheRequest* req_decode = decode_object_cache_request(payload_bl);

  ASSERT_EQ(req_decode->get_request_type(), RBDSC_READ);

  ASSERT_EQ(req_decode->type, RBDSC_READ);
  ASSERT_EQ(req_decode->seq, 123456UL);
  ASSERT_EQ(((ObjectCacheReadData*)req_decode)->type, RBDSC_READ);
  ASSERT_EQ(((ObjectCacheReadData*)req_decode)->seq, 123456UL);
  ASSERT_EQ(((ObjectCacheReadData*)req_decode)->read_offset, 222222UL);
  ASSERT_EQ(((ObjectCacheReadData*)req_decode)->read_len, 333333UL);
  ASSERT_EQ(((ObjectCacheReadData*)req_decode)->pool_id, 444444UL);
  ASSERT_EQ(((ObjectCacheReadData*)req_decode)->snap_id, 555555UL);
  ASSERT_EQ(((ObjectCacheReadData*)req_decode)->oid, oid_name);
  ASSERT_EQ(((ObjectCacheReadData*)req_decode)->pool_namespace, pool_nspace);
  ASSERT_EQ(((ObjectCacheReadData*)req_decode)->object_size, 666666UL);

  delete req;
  delete req_decode;
}