20 #ifndef RIPPLE_NODESTORE_BASE_H_INCLUDED
21 #define RIPPLE_NODESTORE_BASE_H_INCLUDED
23 #include <ripple/basics/StringUtilities.h>
24 #include <ripple/basics/random.h>
25 #include <ripple/beast/unit_test.h>
26 #include <ripple/beast/utility/rngfill.h>
27 #include <ripple/beast/xor_shift_engine.h>
28 #include <ripple/nodestore/Backend.h>
29 #include <ripple/nodestore/Database.h>
30 #include <ripple/nodestore/Types.h>
31 #include <boost/algorithm/string.hpp>
51 return lhs->getHash() < rhs->getHash();
61 return (lhs->getType() == rhs->getType()) &&
62 (lhs->getHash() == rhs->getHash()) &&
63 (lhs->getData() == rhs->getData());
68 class TestBase :
public beast::unit_test::suite
87 for (
int i = 0; i < numObjects; ++i)
126 for (
int i = 0; i < lhs.
size(); ++i)
128 if (!
isSame(lhs[i], rhs[i]))
147 for (
int i = 0; i < batch.
size(); ++i)
149 backend.
store(batch[i]);
160 for (
int i = 0; i < batch.
size(); ++i)
165 backend.
fetch(batch[i]->getHash().cbegin(), &
object);
167 BEAST_EXPECT(status ==
ok);
171 BEAST_EXPECT(
object !=
nullptr);
181 for (
int i = 0; i < batch.
size(); ++i)
186 backend.
fetch(batch[i]->getHash().cbegin(), &
object);
196 for (
int i = 0; i < batch.
size(); ++i)
200 Blob data(object->getData());
217 for (
int i = 0; i < batch.
size(); ++i)
222 if (
object !=
nullptr)
Persistency layer for NodeObject.
static const std::size_t maxPayloadBytes
NodeObjectType
The types of node objects.
Binary function that satisfies the strict-weak-ordering requirement.
static std::shared_ptr< NodeObject > createObject(NodeObjectType type, Blob &&data, uint256 const &hash)
Create an object from fields.
virtual void store(NodeObjectType type, Blob &&data, uint256 const &hash, std::uint32_t ledgerSeq)=0
Store the object.
virtual void store(std::shared_ptr< NodeObject > const &object)=0
Store a single object.
constexpr static std::size_t size()
static bool areBatchesEqual(Batch const &lhs, Batch const &rhs)
std::enable_if_t< std::is_integral< Integral >::value &&detail::is_engine< Engine >::value, Integral > rand_int(Engine &engine, Integral min, Integral max)
Return a uniformly distributed random integer.
static void storeBatch(Database &db, Batch const &batch)
void fetchMissing(Backend &backend, Batch const &batch)
void fetchCopyOfBatch(Backend &backend, Batch *pCopy, Batch const &batch)
Status
Return codes from Backend operations.
static const int numObjectsToTest
static Batch createPredictableBatch(int numObjects, std::uint64_t seed)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool operator()(std::shared_ptr< NodeObject > const &lhs, std::shared_ptr< NodeObject > const &rhs) const noexcept
static const std::size_t minPayloadBytes
void rngfill(void *buffer, std::size_t bytes, Generator &g)
static void fetchCopyOfBatch(Database &db, Batch *pCopy, Batch const &batch)
bool isSame(std::shared_ptr< NodeObject > const &lhs, std::shared_ptr< NodeObject > const &rhs)
Returns true if objects are identical.
void storeBatch(Backend &backend, Batch const &batch)
std::shared_ptr< NodeObject > fetchNodeObject(uint256 const &hash, std::uint32_t ledgerSeq=0, FetchType fetchType=FetchType::synchronous, bool duplicate=false)
Fetch a node object.
std::uint32_t earliestLedgerSeq() const noexcept
virtual Status fetch(void const *key, std::shared_ptr< NodeObject > *pObject)=0
Fetch a single object.
A backend used for the NodeStore.