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 TestFamily : public Family
33 {
34 private:
43 
44 public:
46  : treecache_("TreeNodeCache", 65536, std::chrono::minutes{1}, clock_, j)
47  , fullbelow_("full_below", clock_)
48  , parent_("TestRootStoppable")
49  , j_(j)
50  {
51  Section testSection;
52  testSection.set("type", "memory");
53  testSection.set("Path", "SHAMap_test");
55  "test", scheduler_, 1, parent_, testSection, j);
56  shardBacked_ =
57  dynamic_cast<NodeStore::DatabaseShard*>(db_.get()) != nullptr;
58  }
59 
62  {
63  return clock_;
64  }
65 
66  beast::Journal const&
67  journal() override
68  {
69  return j_;
70  }
71 
73  fullbelow() override
74  {
75  return fullbelow_;
76  }
77 
78  FullBelowCache const&
79  fullbelow() const override
80  {
81  return fullbelow_;
82  }
83 
85  treecache() override
86  {
87  return treecache_;
88  }
89 
90  TreeNodeCache const&
91  treecache() const override
92  {
93  return treecache_;
94  }
95 
97  db() override
98  {
99  return *db_;
100  }
101 
102  NodeStore::Database const&
103  db() const override
104  {
105  return *db_;
106  }
107 
108  bool
109  isShardBacked() const override
110  {
111  return shardBacked_;
112  }
113 
114  void
115  missing_node(std::uint32_t refNum) override
116  {
117  Throw<std::runtime_error>("missing node");
118  }
119 
120  void
121  missing_node(uint256 const& refHash, std::uint32_t refNum) override
122  {
123  Throw<std::runtime_error>("missing node");
124  }
125 
126  void
127  reset() override
128  {
129  fullbelow_.reset();
130  treecache_.reset();
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::tests::TestFamily::journal
beast::Journal const & journal() override
Definition: common.h:67
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:43
ripple::tests::TestFamily::db
NodeStore::Database const & db() const override
Definition: common.h:103
ripple::NodeStore::Database
Persistency layer for NodeObject.
Definition: Database.h:53
ripple::tests::TestFamily::parent_
RootStoppable parent_
Definition: common.h:39
ripple::TaggedCache< uint256, SHAMapAbstractNode >
ripple::tests::TestFamily::missing_node
void missing_node(uint256 const &refHash, std::uint32_t refNum) override
Definition: common.h:121
ripple::tests::TestFamily::treecache
TreeNodeCache const & treecache() const override
Definition: common.h:91
ripple::tests::TestFamily::fullbelow
FullBelowCache const & fullbelow() const override
Definition: common.h:79
ripple::tests::TestFamily
Definition: common.h:32
ripple::detail::BasicFullBelowCache< uint256 >
ripple::tests::TestFamily::treecache
TreeNodeCache & treecache() override
Definition: common.h:85
ripple::tests::TestFamily::fullbelow_
FullBelowCache fullbelow_
Definition: common.h:38
ripple::detail::BasicFullBelowCache::reset
void reset()
Definition: FullBelowCache.h:134
ripple::tests::TestFamily::treecache_
TreeNodeCache treecache_
Definition: common.h:37
ripple::tests::TestFamily::clock
beast::manual_clock< std::chrono::steady_clock > clock()
Definition: common.h:61
ripple::base_uint< 256 >
ripple::tests::TestFamily::TestFamily
TestFamily(beast::Journal j)
Definition: common.h:45
ripple::tests::TestFamily::isShardBacked
bool isShardBacked() const override
Definition: common.h:109
ripple::RootStoppable
Definition: Stoppable.h:352
ripple::TaggedCache::reset
void reset()
Definition: TaggedCache.h:159
ripple::NodeStore::DatabaseShard
A collection of historical shards.
Definition: DatabaseShard.h:37
ripple::tests::TestFamily::j_
beast::Journal j_
Definition: common.h:42
ripple::Family
Definition: Family.h:32
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
ripple::tests::TestFamily::fullbelow
FullBelowCache & fullbelow() override
Definition: common.h:73
ripple::tests::TestFamily::db_
std::unique_ptr< NodeStore::Database > db_
Definition: common.h:40
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::tests::TestFamily::scheduler_
NodeStore::DummyScheduler scheduler_
Definition: common.h:36
ripple::Section::set
void set(std::string const &key, std::string const &value)
Set a key/value pair.
Definition: BasicConfig.cpp:32
ripple::tests::TestFamily::shardBacked_
bool shardBacked_
Definition: common.h:41
std
STL namespace.
ripple::tests::TestFamily::reset
void reset() override
Definition: common.h:127
ripple::tests::TestFamily::missing_node
void missing_node(std::uint32_t refNum) override
Definition: common.h:115
beast::manual_clock< std::chrono::steady_clock >
ripple::NodeStore::Manager::make_Database
virtual std::unique_ptr< Database > make_Database(std::string const &name, Scheduler &scheduler, int readThreads, Stoppable &parent, Section const &backendParameters, beast::Journal journal)=0
Construct a NodeStore database.
ripple::NodeStore::Manager::instance
static Manager & instance()
Returns the instance of the manager singleton.
Definition: ManagerImp.cpp:117
ripple::tests::TestFamily::db
NodeStore::Database & db() override
Definition: common.h:97
std::unique_ptr
STL class.
ripple::tests::TestFamily::clock_
TestStopwatch clock_
Definition: common.h:35