]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/monitoring/statistics_test.cc
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / rocksdb / monitoring / statistics_test.cc
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
5 //
6
7 #include "rocksdb/statistics.h"
8
9 #include "port/stack_trace.h"
10 #include "rocksdb/convenience.h"
11 #include "rocksdb/utilities/options_type.h"
12 #include "test_util/testharness.h"
13 #include "test_util/testutil.h"
14
15 namespace ROCKSDB_NAMESPACE {
16
17 class StatisticsTest : public testing::Test {};
18
19 // Sanity check to make sure that contents and order of TickersNameMap
20 // match Tickers enum
21 TEST_F(StatisticsTest, SanityTickers) {
22 EXPECT_EQ(static_cast<size_t>(Tickers::TICKER_ENUM_MAX),
23 TickersNameMap.size());
24
25 for (uint32_t t = 0; t < Tickers::TICKER_ENUM_MAX; t++) {
26 auto pair = TickersNameMap[static_cast<size_t>(t)];
27 ASSERT_EQ(pair.first, t) << "Miss match at " << pair.second;
28 }
29 }
30
31 // Sanity check to make sure that contents and order of HistogramsNameMap
32 // match Tickers enum
33 TEST_F(StatisticsTest, SanityHistograms) {
34 EXPECT_EQ(static_cast<size_t>(Histograms::HISTOGRAM_ENUM_MAX),
35 HistogramsNameMap.size());
36
37 for (uint32_t h = 0; h < Histograms::HISTOGRAM_ENUM_MAX; h++) {
38 auto pair = HistogramsNameMap[static_cast<size_t>(h)];
39 ASSERT_EQ(pair.first, h) << "Miss match at " << pair.second;
40 }
41 }
42
43 TEST_F(StatisticsTest, NoNameStats) {
44 static std::unordered_map<std::string, OptionTypeInfo> no_name_opt_info = {
45 #ifndef ROCKSDB_LITE
46 {"inner",
47 OptionTypeInfo::AsCustomSharedPtr<Statistics>(
48 0, OptionVerificationType::kByName,
49 OptionTypeFlags::kAllowNull | OptionTypeFlags::kCompareNever)},
50 #endif // ROCKSDB_LITE
51 };
52
53 class DefaultNameStatistics : public Statistics {
54 public:
55 DefaultNameStatistics(const std::shared_ptr<Statistics>& stats = nullptr)
56 : inner(stats) {
57 RegisterOptions("", &inner, &no_name_opt_info);
58 }
59
60 uint64_t getTickerCount(uint32_t /*tickerType*/) const override {
61 return 0;
62 }
63 void histogramData(uint32_t /*type*/,
64 HistogramData* const /*data*/) const override {}
65 void recordTick(uint32_t /*tickerType*/, uint64_t /*count*/) override {}
66 void setTickerCount(uint32_t /*tickerType*/, uint64_t /*count*/) override {}
67 uint64_t getAndResetTickerCount(uint32_t /*tickerType*/) override {
68 return 0;
69 }
70 std::shared_ptr<Statistics> inner;
71 };
72 ConfigOptions options;
73 options.ignore_unsupported_options = false;
74 auto stats = std::make_shared<DefaultNameStatistics>();
75 ASSERT_STREQ(stats->Name(), "");
76 #ifndef ROCKSDB_LITE
77 ASSERT_EQ("", stats->ToString(
78 options)); // A stats with no name with have no options...
79 ASSERT_OK(stats->ConfigureFromString(options, "inner="));
80 ASSERT_EQ("", stats->ToString(
81 options)); // A stats with no name with have no options...
82 ASSERT_NE(stats->inner, nullptr);
83 ASSERT_NE("", stats->inner->ToString(options)); // ... even if it does...
84 #endif // ROCKSDB_LITE
85 }
86 } // namespace ROCKSDB_NAMESPACE
87
88 int main(int argc, char** argv) {
89 ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
90 ::testing::InitGoogleTest(&argc, argv);
91 return RUN_ALL_TESTS();
92 }