summaryrefslogtreecommitdiffstats
path: root/src/test/librados/cls_remote_reads.cc
blob: 4256c072f9849d03523d78045c159d3166e29e01 (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
#include <set>
#include <string>

#include "common/ceph_json.h"
#include "gtest/gtest.h"
#include "test/librados/test_cxx.h"

#include "crimson_utils.h"

using namespace librados;

TEST(ClsTestRemoteReads, TestGather) {
  SKIP_IF_CRIMSON();
  Rados cluster;
  std::string pool_name = get_temp_pool_name();
  ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
  IoCtx ioctx;
  cluster.ioctx_create(pool_name.c_str(), ioctx);

  bufferlist in, out;
  int object_size = 4096;
  char buf[object_size];
  memset(buf, 1, sizeof(buf));

  // create source objects from which data are gathered
  in.append(buf, sizeof(buf));
  ASSERT_EQ(0, ioctx.write_full("src_object.1", in));
  in.append(buf, sizeof(buf));
  ASSERT_EQ(0, ioctx.write_full("src_object.2", in));
  in.append(buf, sizeof(buf));
  ASSERT_EQ(0, ioctx.write_full("src_object.3", in));

  // construct JSON request passed to "test_gather" method, and in turn, to "test_read" method
  JSONFormatter *formatter = new JSONFormatter(true);
  formatter->open_object_section("foo");
  std::set<std::string> src_objects;
  src_objects.insert("src_object.1");
  src_objects.insert("src_object.2");
  src_objects.insert("src_object.3");
  encode_json("src_objects", src_objects, formatter);
  encode_json("cls", "test_remote_reads", formatter);
  encode_json("method", "test_read", formatter);
  encode_json("pool", pool_name, formatter);
  formatter->close_section();
  in.clear();
  formatter->flush(in);

  // create target object by combining data gathered from source objects using "test_read" method
  ASSERT_EQ(0, ioctx.exec("tgt_object", "test_remote_reads", "test_gather", in, out));

  // read target object and check its size
  ASSERT_EQ(3*object_size, ioctx.read("tgt_object", out, 0, 0));

  ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}