xrpld
Loading...
Searching...
No Matches
TestFamily.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 <cstdint>
18#include <memory>
19#include <stdexcept>
20
21namespace xrpl::test {
22
29class TestFamily : public Family
30{
31private:
38
39public:
41 : fbCache_(std::make_shared<FullBelowCache>("TestFamily full below cache", clock_, j))
42 , tnCache_(
43 std::make_shared<TreeNodeCache>(
44 "TestFamily tree node cache",
45 65536,
46 std::chrono::minutes{1},
47 clock_,
48 j))
49 , j_(j)
50 {
51 Section config;
52 config.set(Keys::kType, "memory");
53 config.set(Keys::kPath, "TestFamily");
55 }
56
58 db() override
59 {
60 return *db_;
61 }
62
63 [[nodiscard]] node_store::Database const&
64 db() const override
65 {
66 return *db_;
67 }
68
69 beast::Journal const&
70 journal() override
71 {
72 return j_;
73 }
74
77 {
78 return fbCache_;
79 }
80
83 {
84 return tnCache_;
85 }
86
87 void
88 sweep() override
89 {
90 fbCache_->sweep();
91 tnCache_->sweep();
92 }
93
94 void
95 missingNodeAcquireBySeq(std::uint32_t refNum, uint256 const& nodeHash) override
96 {
97 Throw<std::runtime_error>("TestFamily: missing node (by seq)");
98 }
99
100 void
101 missingNodeAcquireByHash(uint256 const& refHash, std::uint32_t refNum) override
102 {
103 Throw<std::runtime_error>("TestFamily: missing node (by hash)");
104 }
105
106 void
107 reset() override
108 {
109 (*fbCache_).reset();
110 (*tnCache_).reset();
111 }
112
118 {
119 return clock_;
120 }
121};
122
123} // namespace xrpl::test
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.
void missingNodeAcquireBySeq(std::uint32_t refNum, uint256 const &nodeHash) override
Acquire ledger that has a missing node by ledger sequence.
Definition TestFamily.h:95
void sweep() override
Definition TestFamily.h:88
std::shared_ptr< TreeNodeCache > getTreeNodeCache() override
Return a pointer to the Family Tree Node Cache.
Definition TestFamily.h:82
std::shared_ptr< FullBelowCache > getFullBelowCache() override
Return a pointer to the Family Full Below Cache.
Definition TestFamily.h:76
TestStopwatch & clock()
Access the test clock for time manipulation in tests.
Definition TestFamily.h:117
node_store::Database const & db() const override
Definition TestFamily.h:64
beast::Journal j_
Definition TestFamily.h:37
std::unique_ptr< node_store::Database > db_
Definition TestFamily.h:32
node_store::DummyScheduler scheduler_
Definition TestFamily.h:36
TestStopwatch clock_
Definition TestFamily.h:33
void missingNodeAcquireByHash(uint256 const &refHash, std::uint32_t refNum) override
Acquire ledger that has a missing node by ledger hash.
Definition TestFamily.h:101
std::shared_ptr< TreeNodeCache > tnCache_
Definition TestFamily.h:35
void reset() override
Definition TestFamily.h:107
beast::Journal const & journal() override
Definition TestFamily.h:70
node_store::Database & db() override
Definition TestFamily.h:58
TestFamily(beast::Journal j)
Definition TestFamily.h:40
std::shared_ptr< FullBelowCache > fbCache_
Definition TestFamily.h:34
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