xrpld
Loading...
Searching...
No Matches
TestFamily.h
1#pragma once
2
3#include <xrpl/basics/chrono.h>
4#include <xrpl/config/BasicConfig.h>
5#include <xrpl/config/Constants.h>
6#include <xrpl/nodestore/DummyScheduler.h>
7#include <xrpl/nodestore/Manager.h>
8#include <xrpl/shamap/Family.h>
9
10#include <memory>
11
12namespace xrpl::test {
13
19class TestFamily : public Family
20{
21private:
28
29public:
31 : fbCache_(std::make_shared<FullBelowCache>("TestFamily full below cache", clock_, j))
32 , tnCache_(
33 std::make_shared<TreeNodeCache>(
34 "TestFamily tree node cache",
35 65536,
36 std::chrono::minutes{1},
37 clock_,
38 j))
39 , j_(j)
40 {
41 Section config;
42 config.set(Keys::kType, "memory");
43 config.set(Keys::kPath, "TestFamily");
45 }
46
48 db() override
49 {
50 return *db_;
51 }
52
53 [[nodiscard]] NodeStore::Database const&
54 db() const override
55 {
56 return *db_;
57 }
58
59 beast::Journal const&
60 journal() override
61 {
62 return j_;
63 }
64
67 {
68 return fbCache_;
69 }
70
73 {
74 return tnCache_;
75 }
76
77 void
78 sweep() override
79 {
80 fbCache_->sweep();
81 tnCache_->sweep();
82 }
83
84 void
85 missingNodeAcquireBySeq(std::uint32_t refNum, uint256 const& nodeHash) override
86 {
87 Throw<std::runtime_error>("TestFamily: missing node (by seq)");
88 }
89
90 void
91 missingNodeAcquireByHash(uint256 const& refHash, std::uint32_t refNum) override
92 {
93 Throw<std::runtime_error>("TestFamily: missing node (by hash)");
94 }
95
96 void
97 reset() override
98 {
99 (*fbCache_).reset();
100 (*tnCache_).reset();
101 }
102
106 {
107 return clock_;
108 }
109};
110
111} // namespace xrpl::test
A generic endpoint for log messages.
Definition Journal.h:38
Family(Family const &)=delete
Persistency layer for NodeObject.
Definition Database.h:32
Simple NodeStore Scheduler that just performs the tasks synchronously.
static Manager & instance()
Returns the instance of the manager singleton.
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.
Holds a collection of configuration values.
Definition BasicConfig.h:24
void set(std::string const &key, std::string const &value)
Set a key/value pair.
void missingNodeAcquireBySeq(std::uint32_t refNum, uint256 const &nodeHash) override
Acquire ledger that has a missing node by ledger sequence.
Definition TestFamily.h:85
void sweep() override
Definition TestFamily.h:78
NodeStore::DummyScheduler scheduler_
Definition TestFamily.h:26
std::shared_ptr< TreeNodeCache > getTreeNodeCache() override
Return a pointer to the Family Tree Node Cache.
Definition TestFamily.h:72
std::shared_ptr< FullBelowCache > getFullBelowCache() override
Return a pointer to the Family Full Below Cache.
Definition TestFamily.h:66
TestStopwatch & clock()
Access the test clock for time manipulation in tests.
Definition TestFamily.h:105
beast::Journal j_
Definition TestFamily.h:27
TestStopwatch clock_
Definition TestFamily.h:23
void missingNodeAcquireByHash(uint256 const &refHash, std::uint32_t refNum) override
Acquire ledger that has a missing node by ledger hash.
Definition TestFamily.h:91
NodeStore::Database const & db() const override
Definition TestFamily.h:54
std::unique_ptr< NodeStore::Database > db_
Definition TestFamily.h:22
NodeStore::Database & db() override
Definition TestFamily.h:48
std::shared_ptr< TreeNodeCache > tnCache_
Definition TestFamily.h:25
void reset() override
Definition TestFamily.h:97
beast::Journal const & journal() override
Definition TestFamily.h:60
TestFamily(beast::Journal j)
Definition TestFamily.h:30
std::shared_ptr< FullBelowCache > fbCache_
Definition TestFamily.h:24
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:90
BaseUInt< 256 > uint256
Definition base_uint.h:562
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:49
static constexpr auto kType
Definition Constants.h:170
static constexpr auto kPath
Definition Constants.h:140