xrpld
Loading...
Searching...
No Matches
common.h
1#pragma once
2
3#include <xrpl/basics/ByteUtilities.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/basics/chrono.h>
6#include <xrpl/basics/contract.h>
7#include <xrpl/beast/utility/Journal.h>
8#include <xrpl/config/BasicConfig.h>
9#include <xrpl/config/Constants.h>
10#include <xrpl/nodestore/Database.h>
11#include <xrpl/nodestore/DummyScheduler.h>
12#include <xrpl/nodestore/Manager.h>
13#include <xrpl/shamap/Family.h>
14#include <xrpl/shamap/FullBelowCache.h>
15#include <xrpl/shamap/TreeNodeCache.h>
16
17#include <chrono>
18#include <cstdint>
19#include <memory>
20#include <stdexcept>
21
22namespace xrpl::tests {
23
24class TestNodeFamily : public Family
25{
26private:
28
31
34
36
37public:
39 : fbCache_(std::make_shared<FullBelowCache>("App family full below cache", clock_, j))
40 , tnCache_(
41 std::make_shared<TreeNodeCache>(
42 "App family tree node cache",
43 65536,
44 std::chrono::minutes{1},
45 clock_,
46 j))
47 , j_(j)
48 {
49 Section testSection;
50 testSection.set(Keys::kType, "memory");
51 testSection.set(Keys::kPath, "SHAMap_test");
53 megabytes(4), scheduler_, 1, testSection, j);
54 }
55
57 db() override
58 {
59 return *db_;
60 }
61
62 [[nodiscard]] node_store::Database const&
63 db() const override
64 {
65 return *db_;
66 }
67
68 beast::Journal const&
69 journal() override
70 {
71 return j_;
72 }
73
76 {
77 return fbCache_;
78 }
79
82 {
83 return tnCache_;
84 }
85
86 void
87 sweep() override
88 {
89 fbCache_->sweep();
90 tnCache_->sweep();
91 }
92
93 void
95 [[maybe_unused]] std::uint32_t refNum,
96 [[maybe_unused]] uint256 const& nodeHash) override
97 {
98 Throw<std::runtime_error>("missing node");
99 }
100
101 void
103 [[maybe_unused]] uint256 const& refHash,
104 [[maybe_unused]] std::uint32_t refNum) override
105 {
106 Throw<std::runtime_error>("missing node");
107 }
108
109 void
110 reset() override
111 {
112 (*fbCache_).reset();
113 (*tnCache_).reset();
114 }
115
118 {
119 return clock_;
120 }
121};
122
123} // namespace xrpl::tests
A generic endpoint for log messages.
Definition Journal.h:44
Family(Family const &)=delete
Holds a collection of configuration values.
Definition BasicConfig.h:29
void set(std::string const &key, std::string const &value)
Set a key/value pair.
Persistency layer for NodeObject.
Definition Database.h:45
Simple NodeStore Scheduler that just performs the tasks synchronously.
virtual std::unique_ptr< Database > makeDatabase(std::size_t burstSize, Scheduler &scheduler, int readThreads, Section const &backendParameters, beast::Journal journal)=0
Construct a NodeStore database.
static Manager & instance()
Returns the instance of the manager singleton.
node_store::Database const & db() const override
Definition common.h:63
std::shared_ptr< TreeNodeCache > tnCache_
Definition common.h:30
TestStopwatch & clock()
Definition common.h:117
node_store::Database & db() override
Definition common.h:57
void missingNodeAcquireByHash(uint256 const &refHash, std::uint32_t refNum) override
Acquire ledger that has a missing node by ledger hash.
Definition common.h:102
std::shared_ptr< FullBelowCache > getFullBelowCache() override
Return a pointer to the Family Full Below Cache.
Definition common.h:75
std::shared_ptr< TreeNodeCache > getTreeNodeCache() override
Return a pointer to the Family Tree Node Cache.
Definition common.h:81
beast::Journal const j_
Definition common.h:35
TestNodeFamily(beast::Journal j)
Definition common.h:38
std::shared_ptr< FullBelowCache > fbCache_
Definition common.h:29
void sweep() override
Definition common.h:87
TestStopwatch clock_
Definition common.h:32
std::unique_ptr< node_store::Database > db_
Definition common.h:27
void missingNodeAcquireBySeq(std::uint32_t refNum, uint256 const &nodeHash) override
Acquire ledger that has a missing node by ledger sequence.
Definition common.h:94
beast::Journal const & journal() override
Definition common.h:69
void reset() override
Definition common.h:110
node_store::DummyScheduler scheduler_
Definition common.h:33
STL namespace.
detail::BasicFullBelowCache FullBelowCache
TaggedCache< uint256, SHAMapTreeNode, false, intr_ptr::SharedWeakUnionPtr< SHAMapTreeNode >, SHAMapTreeNodePtr > TreeNodeCache
constexpr auto megabytes(T value) noexcept
beast::ManualClock< std::chrono::steady_clock > TestStopwatch
A manual Stopwatch for unit tests.
Definition chrono.h:95
BaseUInt< 256 > uint256
Definition base_uint.h:580
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:52
static constexpr auto kType
Definition Constants.h:173
static constexpr auto kPath
Definition Constants.h:143