]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
1 | // -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #include "include/types.h" | |
5 | #include "include/stringify.h" | |
6 | #include "compressor/Compressor.h" | |
7 | #include "msg/compressor_registry.h" | |
8 | #include "gtest/gtest.h" | |
9 | #include "common/ceph_context.h" | |
10 | #include "global/global_context.h" | |
11 | ||
12 | #include <sstream> | |
13 | ||
14 | TEST(CompressorRegistry, con_modes) | |
15 | { | |
16 | auto cct = g_ceph_context; | |
17 | CompressorRegistry reg(cct); | |
18 | std::vector<uint32_t> methods; | |
19 | uint32_t method; | |
20 | uint32_t mode; | |
21 | ||
22 | const std::vector<uint32_t> snappy_method = { Compressor::COMP_ALG_SNAPPY }; | |
23 | const std::vector<uint32_t> zlib_method = { Compressor::COMP_ALG_ZLIB }; | |
24 | const std::vector<uint32_t> both_methods = { Compressor::COMP_ALG_ZLIB, Compressor::COMP_ALG_SNAPPY}; | |
25 | const std::vector<uint32_t> no_method = { Compressor::COMP_ALG_NONE }; | |
26 | ||
27 | cct->_conf.set_val( | |
28 | "enable_experimental_unrecoverable_data_corrupting_features", "*"); | |
29 | ||
30 | // baseline: compression for communication with osd is enabled | |
31 | cct->_set_module_type(CEPH_ENTITY_TYPE_CLIENT); | |
32 | cct->_conf.set_val("ms_osd_compress_mode", "force"); | |
33 | cct->_conf.set_val("ms_osd_compression_algorithm", "snappy"); | |
34 | cct->_conf.set_val("ms_compress_secure", "false"); | |
35 | cct->_conf.apply_changes(NULL); | |
36 | ||
37 | ASSERT_EQ(reg.get_is_compress_secure(), false); | |
38 | ||
39 | methods = reg.get_methods(CEPH_ENTITY_TYPE_MON); | |
40 | ASSERT_EQ(methods.size(), 0); | |
41 | method = reg.pick_method(CEPH_ENTITY_TYPE_MON, both_methods); | |
42 | ASSERT_EQ(method, Compressor::COMP_ALG_NONE); | |
43 | mode = reg.get_mode(CEPH_ENTITY_TYPE_MON, false); | |
44 | ASSERT_EQ(mode, Compressor::COMP_NONE); | |
45 | ||
46 | methods = reg.get_methods(CEPH_ENTITY_TYPE_OSD); | |
47 | ASSERT_EQ(methods, snappy_method); | |
48 | const std::vector<uint32_t> rev_both_methods (both_methods.rbegin(), both_methods.rend()); | |
49 | method = reg.pick_method(CEPH_ENTITY_TYPE_OSD, rev_both_methods); | |
50 | ASSERT_EQ(method, Compressor::COMP_ALG_SNAPPY); | |
51 | mode = reg.get_mode(CEPH_ENTITY_TYPE_OSD, false); | |
52 | ASSERT_EQ(mode, Compressor::COMP_FORCE); | |
53 | mode = reg.get_mode(CEPH_ENTITY_TYPE_OSD, true); | |
54 | ASSERT_EQ(mode, Compressor::COMP_NONE); | |
55 | ||
56 | method = reg.pick_method(CEPH_ENTITY_TYPE_OSD, zlib_method); | |
57 | ASSERT_EQ(method, Compressor::COMP_ALG_NONE); | |
58 | ||
59 | // disable compression mode | |
60 | cct->_set_module_type(CEPH_ENTITY_TYPE_CLIENT); | |
61 | cct->_conf.set_val("ms_osd_compress_mode", "none"); | |
62 | cct->_conf.apply_changes(NULL); | |
63 | ||
64 | mode = reg.get_mode(CEPH_ENTITY_TYPE_OSD, false); | |
65 | ASSERT_EQ(mode, Compressor::COMP_NONE); | |
66 | ||
67 | // no compression methods | |
68 | cct->_conf.set_val("ms_osd_compress_mode", "force"); | |
69 | cct->_conf.set_val("ms_osd_compression_algorithm", "none"); | |
70 | cct->_conf.apply_changes(NULL); | |
71 | ||
72 | method = reg.pick_method(CEPH_ENTITY_TYPE_OSD, both_methods); | |
73 | ASSERT_EQ(method, Compressor::COMP_ALG_NONE); | |
74 | ||
75 | // min compression size | |
76 | cct->_conf.set_val("ms_osd_compress_min_size", "1024"); | |
77 | cct->_conf.apply_changes(NULL); | |
78 | ||
79 | uint32_t s = reg.get_min_compression_size(CEPH_ENTITY_TYPE_OSD); | |
80 | ASSERT_EQ(s, 1024); | |
81 | ||
82 | // allow secure with compression | |
83 | cct->_conf.set_val("ms_osd_compress_mode", "force"); | |
84 | cct->_conf.set_val("ms_osd_compression_algorithm", "snappy"); | |
85 | cct->_conf.set_val("ms_compress_secure", "true"); | |
86 | cct->_conf.apply_changes(NULL); | |
87 | ||
88 | ASSERT_EQ(reg.get_is_compress_secure(), true); | |
89 | ||
90 | mode = reg.get_mode(CEPH_ENTITY_TYPE_OSD, true); | |
91 | ASSERT_EQ(mode, Compressor::COMP_FORCE); | |
92 | ||
93 | mode = reg.get_mode(CEPH_ENTITY_TYPE_OSD, false); | |
94 | ASSERT_EQ(mode, Compressor::COMP_FORCE); | |
95 | ||
96 | // back to normalish, for the benefit of the next test(s) | |
97 | cct->_set_module_type(CEPH_ENTITY_TYPE_CLIENT); | |
98 | } |