rippled
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 <ripple/basics/chrono.h>
24 #include <ripple/nodestore/DatabaseShard.h>
25 #include <ripple/nodestore/DummyScheduler.h>
26 #include <ripple/nodestore/Manager.h>
27 #include <ripple/shamap/Family.h>
28 
29 namespace ripple {
30 namespace tests {
31 
32 class TestNodeFamily : public Family
33 {
34 private:
36 
39 
42 
44 
45 public:
47  : fbCache_(std::make_shared<FullBelowCache>(
48  "App family full below cache",
49  clock_))
50  , tnCache_(std::make_shared<TreeNodeCache>(
51  "App family tree node cache",
52  65536,
53  std::chrono::minutes{1},
54  clock_,
55  j))
56  , j_(j)
57  {
58  Section testSection;
59  testSection.set("type", "memory");
60  testSection.set("path", "SHAMap_test");
62  megabytes(4), scheduler_, 1, testSection, j);
63  }
64 
66  db() override
67  {
68  return *db_;
69  }
70 
71  NodeStore::Database const&
72  db() const override
73  {
74  return *db_;
75  }
76 
77  beast::Journal const&
78  journal() override
79  {
80  return j_;
81  }
82 
84  {
85  return fbCache_;
86  }
87 
89  {
90  return tnCache_;
91  }
92 
93  void
94  sweep() override
95  {
96  fbCache_->sweep();
97  tnCache_->sweep();
98  }
99 
100  bool
101  isShardBacked() const override
102  {
103  return true;
104  }
105 
106  void
107  missingNode(std::uint32_t refNum) override
108  {
109  Throw<std::runtime_error>("missing node");
110  }
111 
112  void
113  missingNode(uint256 const& refHash, std::uint32_t refNum) override
114  {
115  Throw<std::runtime_error>("missing node");
116  }
117 
118  void
119  reset() override
120  {
121  fbCache_->reset();
122  tnCache_->reset();
123  }
124 
127  {
128  return clock_;
129  }
130 };
131 
132 } // namespace tests
133 } // namespace ripple
134 
135 #endif
ripple::NodeStore::DummyScheduler
Simple NodeStore Scheduler that just peforms the tasks synchronously.
Definition: DummyScheduler.h:29
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:42
ripple::NodeStore::Database
Persistency layer for NodeObject.
Definition: Database.h:52
std::shared_ptr
STL class.
ripple::tests::TestNodeFamily::missingNode
void missingNode(uint256 const &refHash, std::uint32_t refNum) override
Definition: common.h:113
ripple::TaggedCache
Map/cache combination.
Definition: TaggedCache.h:52
ripple::tests::TestNodeFamily::db
NodeStore::Database & db() override
Definition: common.h:66
ripple::detail::BasicFullBelowCache
Remembers which tree keys have all descendants resident.
Definition: FullBelowCache.h:37
ripple::tests::TestNodeFamily::reset
void reset() override
Definition: common.h:119
ripple::tests::TestNodeFamily
Definition: common.h:32
ripple::tests::TestNodeFamily::missingNode
void missingNode(std::uint32_t refNum) override
Definition: common.h:107
ripple::tests::TestNodeFamily::journal
beast::Journal const & journal() override
Definition: common.h:78
ripple::tests::TestNodeFamily::sweep
void sweep() override
Definition: common.h:94
ripple::tests::TestNodeFamily::fbCache_
std::shared_ptr< FullBelowCache > fbCache_
Definition: common.h:37
ripple::base_uint< 256 >
ripple::tests::TestNodeFamily::clock_
TestStopwatch clock_
Definition: common.h:40
ripple::megabytes
constexpr auto megabytes(T value) noexcept
Definition: ByteUtilities.h:34
ripple::tests::TestNodeFamily::getTreeNodeCache
std::shared_ptr< TreeNodeCache > getTreeNodeCache(std::uint32_t) override
Return a pointer to the Family Tree Node Cache.
Definition: common.h:88
ripple::Family
Definition: Family.h:32
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
ripple::tests::TestNodeFamily::TestNodeFamily
TestNodeFamily(beast::Journal j)
Definition: common.h:46
ripple::tests::TestNodeFamily::db_
std::unique_ptr< NodeStore::Database > db_
Definition: common.h:35
ripple::tests::TestNodeFamily::scheduler_
NodeStore::DummyScheduler scheduler_
Definition: common.h:41
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Section::set
void set(std::string const &key, std::string const &value)
Set a key/value pair.
Definition: BasicConfig.cpp:32
ripple::tests::TestNodeFamily::getFullBelowCache
std::shared_ptr< FullBelowCache > getFullBelowCache(std::uint32_t) override
Return a pointer to the Family Full Below Cache.
Definition: common.h:83
ripple::tests::TestNodeFamily::clock
beast::manual_clock< std::chrono::steady_clock > clock()
Definition: common.h:126
std
STL namespace.
ripple::tests::TestNodeFamily::isShardBacked
bool isShardBacked() const override
Definition: common.h:101
ripple::tests::TestNodeFamily::j_
const beast::Journal j_
Definition: common.h:43
ripple::tests::TestNodeFamily::db
NodeStore::Database const & db() const override
Definition: common.h:72
ripple::tests::TestNodeFamily::tnCache_
std::shared_ptr< TreeNodeCache > tnCache_
Definition: common.h:38
beast::manual_clock< std::chrono::steady_clock >
ripple::NodeStore::Manager::instance
static Manager & instance()
Returns the instance of the manager singleton.
Definition: ManagerImp.cpp:120
ripple::NodeStore::Manager::make_Database
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.
std::unique_ptr
STL class.