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  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 
72  NodeStore::Database const&
73  db() const override
74  {
75  return *db_;
76  }
77 
78  beast::Journal const&
79  journal() override
80  {
81  return j_;
82  }
83 
85  {
86  return fbCache_;
87  }
88 
90  {
91  return tnCache_;
92  }
93 
94  void
95  sweep() override
96  {
97  fbCache_->sweep();
98  tnCache_->sweep();
99  }
100 
101  bool
102  isShardBacked() const override
103  {
104  return true;
105  }
106 
107  void
109  override
110  {
111  Throw<std::runtime_error>("missing node");
112  }
113 
114  void
116  override
117  {
118  Throw<std::runtime_error>("missing node");
119  }
120 
121  void
122  reset() override
123  {
124  fbCache_->reset();
125  tnCache_->reset();
126  }
127 
130  {
131  return clock_;
132  }
133 };
134 
135 } // namespace tests
136 } // namespace ripple
137 
138 #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:51
std::shared_ptr
STL class.
ripple::TaggedCache
Map/cache combination.
Definition: Application.h:64
ripple::tests::TestNodeFamily::db
NodeStore::Database & db() override
Definition: common.h:67
ripple::detail::BasicFullBelowCache
Remembers which tree keys have all descendants resident.
Definition: FullBelowCache.h:38
ripple::tests::TestNodeFamily::reset
void reset() override
Definition: common.h:122
ripple::tests::TestNodeFamily
Definition: common.h:32
ripple::tests::TestNodeFamily::journal
beast::Journal const & journal() override
Definition: common.h:79
ripple::tests::TestNodeFamily::sweep
void sweep() override
Definition: common.h:95
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::tests::TestNodeFamily::missingNodeAcquireBySeq
void missingNodeAcquireBySeq(std::uint32_t refNum, uint256 const &nodeHash) override
Acquire ledger that has a missing node by ledger sequence.
Definition: common.h:108
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:89
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:84
ripple::tests::TestNodeFamily::clock
beast::manual_clock< std::chrono::steady_clock > clock()
Definition: common.h:129
std
STL namespace.
ripple::tests::TestNodeFamily::isShardBacked
bool isShardBacked() const override
Definition: common.h:102
ripple::tests::TestNodeFamily::j_
const beast::Journal j_
Definition: common.h:43
ripple::tests::TestNodeFamily::missingNodeAcquireByHash
void missingNodeAcquireByHash(uint256 const &refHash, std::uint32_t refNum) override
Acquire ledger that has a missing node by ledger hash.
Definition: common.h:115
ripple::tests::TestNodeFamily::db
NodeStore::Database const & db() const override
Definition: common.h:73
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.