userver: userver/testsuite/dump_control.hpp Source File
Loading...
Searching...
No Matches
dump_control.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/testsuite/dump_control.hpp
4/// @brief @copybrief testsuite::DumpControl
5
6#include <functional>
7#include <unordered_map>
8#include <vector>
9
10#include <userver/components/component_fwd.hpp>
11#include <userver/concurrent/variable.hpp>
12#include <userver/dump/dumper.hpp>
13#include <userver/utils/not_null.hpp>
14
15USERVER_NAMESPACE_BEGIN
16
17namespace testsuite {
18
19/// @brief Dumper control interface for testsuite
20/// @details All methods are coro-safe.
21class DumpControl final {
22 public:
23 enum class PeriodicsMode { kDisabled, kEnabled };
24
25 explicit DumpControl(PeriodicsMode periodics_mode);
26
27 PeriodicsMode GetPeriodicsMode() const;
28
29 void WriteCacheDumps(const std::vector<std::string>& dumper_names);
30
31 void ReadCacheDumps(const std::vector<std::string>& dumper_names);
32
33 private:
34 friend class DumperRegistrationHolder;
35
36 void RegisterDumper(dump::Dumper& dumper);
37
38 void UnregisterDumper(dump::Dumper& dumper);
39
40 dump::Dumper& FindDumper(const std::string& name) const;
41
42 PeriodicsMode periodics_mode_;
43 concurrent::Variable<
44 std::unordered_map<std::string, utils::NotNull<dump::Dumper*>>>
45 dumpers_;
46};
47
48/// RAII helper for testsuite registration
49class DumperRegistrationHolder final {
50 public:
51 DumperRegistrationHolder(DumpControl&, dump::Dumper&);
52
53 DumperRegistrationHolder(DumperRegistrationHolder&&) = delete;
54 DumperRegistrationHolder& operator=(DumperRegistrationHolder&&) = delete;
55 ~DumperRegistrationHolder();
56
57 private:
58 DumpControl& control_;
59 dump::Dumper& dumper_;
60};
61
62} // namespace testsuite
63
64USERVER_NAMESPACE_END