rippled
Loading...
Searching...
No Matches
common.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_SHAMAP_TESTS_COMMON_H_INCLUDED
21#define RIPPLE_SHAMAP_TESTS_COMMON_H_INCLUDED
22
23#include <xrpld/nodestore/DummyScheduler.h>
24#include <xrpld/nodestore/Manager.h>
25#include <xrpld/shamap/Family.h>
26
27#include <xrpl/basics/chrono.h>
28
29namespace ripple {
30namespace tests {
31
32class TestNodeFamily : public Family
33{
34private:
36
39
42
44
45public:
47 : fbCache_(std::make_shared<FullBelowCache>(
48 "App family full below cache",
49 clock_,
50 j))
51 , tnCache_(std::make_shared<TreeNodeCache>(
52 "App family tree node cache",
53 65536,
54 std::chrono::minutes{1},
55 clock_,
56 j))
57 , j_(j)
58 {
59 Section testSection;
60 testSection.set("type", "memory");
61 testSection.set("path", "SHAMap_test");
63 megabytes(4), scheduler_, 1, testSection, j);
64 }
65
67 db() override
68 {
69 return *db_;
70 }
71
73 db() const override
74 {
75 return *db_;
76 }
77
78 beast::Journal const&
79 journal() override
80 {
81 return j_;
82 }
83
86 {
87 return fbCache_;
88 }
89
92 {
93 return tnCache_;
94 }
95
96 void
97 sweep() override
98 {
99 fbCache_->sweep();
100 tnCache_->sweep();
101 }
102
103 void
105 override
106 {
107 Throw<std::runtime_error>("missing node");
108 }
109
110 void
112 override
113 {
114 Throw<std::runtime_error>("missing node");
115 }
116
117 void
118 reset() override
119 {
120 fbCache_->reset();
121 tnCache_->reset();
122 }
123
126 {
127 return clock_;
128 }
129};
130
131} // namespace tests
132} // namespace ripple
133
134#endif
A generic endpoint for log messages.
Definition: Journal.h:60
Persistency layer for NodeObject.
Definition: Database.h:52
Simple NodeStore Scheduler that just peforms the tasks synchronously.
virtual std::unique_ptr< Database > make_Database(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.
Definition: ManagerImp.cpp:116
Holds a collection of configuration values.
Definition: BasicConfig.h:45
void set(std::string const &key, std::string const &value)
Set a key/value pair.
Definition: BasicConfig.cpp:41
Map/cache combination.
Definition: TaggedCache.h:62
Remembers which tree keys have all descendants resident.
TestNodeFamily(beast::Journal j)
Definition: common.h:46
std::unique_ptr< NodeStore::Database > db_
Definition: common.h:35
void reset() override
Definition: common.h:118
beast::Journal const & journal() override
Definition: common.h:79
NodeStore::Database & db() override
Definition: common.h:67
std::shared_ptr< FullBelowCache > fbCache_
Definition: common.h:37
TestStopwatch clock_
Definition: common.h:40
std::shared_ptr< TreeNodeCache > getTreeNodeCache() override
Return a pointer to the Family Tree Node Cache.
Definition: common.h:91
void missingNodeAcquireBySeq(std::uint32_t refNum, uint256 const &nodeHash) override
Acquire ledger that has a missing node by ledger sequence.
Definition: common.h:104
void sweep() override
Definition: common.h:97
void missingNodeAcquireByHash(uint256 const &refHash, std::uint32_t refNum) override
Acquire ledger that has a missing node by ledger hash.
Definition: common.h:111
std::shared_ptr< TreeNodeCache > tnCache_
Definition: common.h:38
NodeStore::Database const & db() const override
Definition: common.h:73
std::shared_ptr< FullBelowCache > getFullBelowCache() override
Return a pointer to the Family Full Below Cache.
Definition: common.h:85
NodeStore::DummyScheduler scheduler_
Definition: common.h:41
beast::Journal const j_
Definition: common.h:43
beast::manual_clock< std::chrono::steady_clock > clock()
Definition: common.h:125
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:25
constexpr auto megabytes(T value) noexcept
Definition: ByteUtilities.h:34
STL namespace.