summaryrefslogtreecommitdiffstats
path: root/src/test/msgr/test_comp_registry.cc
blob: d5513e2e4fab98350bf27eb106a8798da632c481 (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
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include "include/types.h"
#include "include/stringify.h"
#include "compressor/Compressor.h"
#include "msg/compressor_registry.h"
#include "gtest/gtest.h"
#include "common/ceph_context.h"
#include "global/global_context.h"

#include <sstream>

TEST(CompressorRegistry, con_modes)
{
  auto cct = g_ceph_context;
  CompressorRegistry reg(cct);
  std::vector<uint32_t> methods;
  uint32_t method;
  uint32_t mode;

  const std::vector<uint32_t> snappy_method = { Compressor::COMP_ALG_SNAPPY };
  const std::vector<uint32_t> zlib_method = { Compressor::COMP_ALG_ZLIB };
  const std::vector<uint32_t> both_methods = { Compressor::COMP_ALG_ZLIB, Compressor::COMP_ALG_SNAPPY};
  const std::vector<uint32_t> no_method = { Compressor::COMP_ALG_NONE };

  cct->_conf.set_val(
    "enable_experimental_unrecoverable_data_corrupting_features", "*");

  // baseline: compression for communication with osd is enabled
  cct->_set_module_type(CEPH_ENTITY_TYPE_CLIENT);
  cct->_conf.set_val("ms_osd_compress_mode", "force");
  cct->_conf.set_val("ms_osd_compression_algorithm", "snappy");
  cct->_conf.set_val("ms_compress_secure", "false");
  cct->_conf.apply_changes(NULL);

  ASSERT_EQ(reg.get_is_compress_secure(), false);

  methods = reg.get_methods(CEPH_ENTITY_TYPE_MON);
  ASSERT_EQ(methods.size(), 0);
  method = reg.pick_method(CEPH_ENTITY_TYPE_MON, both_methods);
  ASSERT_EQ(method, Compressor::COMP_ALG_NONE);
  mode = reg.get_mode(CEPH_ENTITY_TYPE_MON, false);
  ASSERT_EQ(mode, Compressor::COMP_NONE);

  methods = reg.get_methods(CEPH_ENTITY_TYPE_OSD);
  ASSERT_EQ(methods, snappy_method);
  const std::vector<uint32_t> rev_both_methods (both_methods.rbegin(), both_methods.rend());
  method = reg.pick_method(CEPH_ENTITY_TYPE_OSD, rev_both_methods);
  ASSERT_EQ(method, Compressor::COMP_ALG_SNAPPY);
  mode = reg.get_mode(CEPH_ENTITY_TYPE_OSD, false);
  ASSERT_EQ(mode, Compressor::COMP_FORCE);
  mode = reg.get_mode(CEPH_ENTITY_TYPE_OSD, true);
  ASSERT_EQ(mode, Compressor::COMP_NONE);

  method = reg.pick_method(CEPH_ENTITY_TYPE_OSD, zlib_method);
  ASSERT_EQ(method, Compressor::COMP_ALG_NONE);

  // disable compression mode
  cct->_set_module_type(CEPH_ENTITY_TYPE_CLIENT);
  cct->_conf.set_val("ms_osd_compress_mode", "none");
  cct->_conf.apply_changes(NULL);

  mode = reg.get_mode(CEPH_ENTITY_TYPE_OSD, false);
  ASSERT_EQ(mode, Compressor::COMP_NONE);

  // no compression methods
  cct->_conf.set_val("ms_osd_compress_mode", "force");
  cct->_conf.set_val("ms_osd_compression_algorithm", "none");
  cct->_conf.apply_changes(NULL);

  method = reg.pick_method(CEPH_ENTITY_TYPE_OSD, both_methods);
  ASSERT_EQ(method, Compressor::COMP_ALG_NONE);

  // min compression size
  cct->_conf.set_val("ms_osd_compress_min_size", "1024");
  cct->_conf.apply_changes(NULL);

  uint32_t s = reg.get_min_compression_size(CEPH_ENTITY_TYPE_OSD);
  ASSERT_EQ(s, 1024);

  // allow secure with compression
  cct->_conf.set_val("ms_osd_compress_mode", "force");
  cct->_conf.set_val("ms_osd_compression_algorithm", "snappy");
  cct->_conf.set_val("ms_compress_secure", "true");
  cct->_conf.apply_changes(NULL);

  ASSERT_EQ(reg.get_is_compress_secure(), true);

  mode = reg.get_mode(CEPH_ENTITY_TYPE_OSD, true);
  ASSERT_EQ(mode, Compressor::COMP_FORCE);

  mode = reg.get_mode(CEPH_ENTITY_TYPE_OSD, false);
  ASSERT_EQ(mode, Compressor::COMP_FORCE);
  
  // back to normalish, for the benefit of the next test(s)
  cct->_set_module_type(CEPH_ENTITY_TYPE_CLIENT);  
}