xrpld
Loading...
Searching...
No Matches
common.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
10namespace xrpl::tests {
11
12class TestNodeFamily : public Family
13{
14private:
16
19
22
24
25public:
27 : fbCache_(std::make_shared<FullBelowCache>("App family full below cache", clock_, j))
28 , tnCache_(
29 std::make_shared<TreeNodeCache>(
30 "App family tree node cache",
31 65536,
32 std::chrono::minutes{1},
33 clock_,
34 j))
35 , j_(j)
36 {
37 Section testSection;
38 testSection.set(Keys::kType, "memory");
39 testSection.set(Keys::kPath, "SHAMap_test");
41 megabytes(4), scheduler_, 1, testSection, j);
42 }
43
45 db() override
46 {
47 return *db_;
48 }
49
50 [[nodiscard]] NodeStore::Database const&
51 db() const override
52 {
53 return *db_;
54 }
55
56 beast::Journal const&
57 journal() override
58 {
59 return j_;
60 }
61
64 {
65 return fbCache_;
66 }
67
70 {
71 return tnCache_;
72 }
73
74 void
75 sweep() override
76 {
77 fbCache_->sweep();
78 tnCache_->sweep();
79 }
80
81 void
82 missingNodeAcquireBySeq(std::uint32_t refNum, uint256 const& nodeHash) override
83 {
84 Throw<std::runtime_error>("missing node");
85 }
86
87 void
88 missingNodeAcquireByHash(uint256 const& refHash, std::uint32_t refNum) override
89 {
90 Throw<std::runtime_error>("missing node");
91 }
92
93 void
94 reset() override
95 {
96 (*fbCache_).reset();
97 (*tnCache_).reset();
98 }
99
102 {
103 return clock_;
104 }
105};
106
107} // namespace xrpl::tests
A generic endpoint for log messages.
Definition Journal.h:38
Manual clock implementation.
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.
std::shared_ptr< TreeNodeCache > tnCache_
Definition common.h:18
std::unique_ptr< NodeStore::Database > db_
Definition common.h:15
void missingNodeAcquireByHash(uint256 const &refHash, std::uint32_t refNum) override
Acquire ledger that has a missing node by ledger hash.
Definition common.h:88
NodeStore::Database const & db() const override
Definition common.h:51
std::shared_ptr< FullBelowCache > getFullBelowCache() override
Return a pointer to the Family Full Below Cache.
Definition common.h:63
std::shared_ptr< TreeNodeCache > getTreeNodeCache() override
Return a pointer to the Family Tree Node Cache.
Definition common.h:69
beast::Journal const j_
Definition common.h:23
beast::ManualClock< std::chrono::steady_clock > clock()
Definition common.h:101
TestNodeFamily(beast::Journal j)
Definition common.h:26
std::shared_ptr< FullBelowCache > fbCache_
Definition common.h:17
void sweep() override
Definition common.h:75
NodeStore::DummyScheduler scheduler_
Definition common.h:21
TestStopwatch clock_
Definition common.h:20
void missingNodeAcquireBySeq(std::uint32_t refNum, uint256 const &nodeHash) override
Acquire ledger that has a missing node by ledger sequence.
Definition common.h:82
beast::Journal const & journal() override
Definition common.h:57
NodeStore::Database & db() override
Definition common.h:45
void reset() override
Definition common.h:94
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