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 
43 
45 
46 public:
48  : fbCache_(std::make_shared<FullBelowCache>(
49  "App family full below cache",
50  clock_))
51  , tnCache_(std::make_shared<TreeNodeCache>(
52  "App family tree node cache",
53  65536,
54  std::chrono::minutes{1},
55  clock_,
56  j))
57  , parent_("TestRootStoppable")
58  , j_(j)
59  {
60  Section testSection;
61  testSection.set("type", "memory");
62  testSection.set("Path", "SHAMap_test");
64  "test", megabytes(4), scheduler_, 1, parent_, testSection, j);
65  }
66 
68  db() override
69  {
70  return *db_;
71  }
72 
73  NodeStore::Database const&
74  db() const override
75  {
76  return *db_;
77  }
78 
79  beast::Journal const&
80  journal() override
81  {
82  return j_;
83  }
84 
86  {
87  return fbCache_;
88  }
89 
91  {
92  return tnCache_;
93  }
94 
95  void
96  sweep() override
97  {
98  fbCache_->sweep();
99  tnCache_->sweep();
100  }
101 
102  bool
103  isShardBacked() const override
104  {
105  return true;
106  }
107 
108  void
109  missingNode(std::uint32_t refNum) override
110  {
111  Throw<std::runtime_error>("missing node");
112  }
113 
114  void
115  missingNode(uint256 const& refHash, std::uint32_t refNum) override
116  {
117  Throw<std::runtime_error>("missing node");
118  }
119 
120  void
121  reset() override
122  {
123  fbCache_->reset();
124  tnCache_->reset();
125  }
126 
129  {
130  return clock_;
131  }
132 };
133 
134 } // namespace tests
135 } // namespace ripple
136 
137 #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:43
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:115
ripple::TaggedCache
Map/cache combination.
Definition: TaggedCache.h:52
ripple::NodeStore::Manager::make_Database
virtual std::unique_ptr< Database > make_Database(std::string const &name, std::size_t burstSize, Scheduler &scheduler, int readThreads, Stoppable &parent, Section const &backendParameters, beast::Journal journal)=0
Construct a NodeStore database.
ripple::tests::TestNodeFamily::parent_
RootStoppable parent_
Definition: common.h:42
ripple::tests::TestNodeFamily::db
NodeStore::Database & db() override
Definition: common.h:68
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:121
ripple::tests::TestNodeFamily
Definition: common.h:32
ripple::tests::TestNodeFamily::missingNode
void missingNode(std::uint32_t refNum) override
Definition: common.h:109
ripple::tests::TestNodeFamily::journal
beast::Journal const & journal() override
Definition: common.h:80
ripple::tests::TestNodeFamily::sweep
void sweep() override
Definition: common.h:96
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::RootStoppable
Definition: Stoppable.h:353
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:90
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:47
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:85
ripple::tests::TestNodeFamily::clock
beast::manual_clock< std::chrono::steady_clock > clock()
Definition: common.h:128
std
STL namespace.
ripple::tests::TestNodeFamily::isShardBacked
bool isShardBacked() const override
Definition: common.h:103
ripple::tests::TestNodeFamily::j_
const beast::Journal j_
Definition: common.h:44
ripple::tests::TestNodeFamily::db
NodeStore::Database const & db() const override
Definition: common.h:74
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:119
std::unique_ptr
STL class.