3#include <xrpl/basics/Blob.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/basics/random.h>
6#include <xrpl/beast/utility/rngfill.h>
7#include <xrpl/beast/xor_shift_engine.h>
8#include <xrpl/nodestore/Backend.h>
9#include <xrpl/nodestore/Database.h>
10#include <xrpl/nodestore/NodeObject.h>
11#include <xrpl/nodestore/Types.h>
13#include <gtest/gtest.h>
36 return lhs->getHash() < rhs->getHash();
40[[nodiscard]]
inline bool
43 return (lhs->getType() == rhs->getType()) && (lhs->getHash() == rhs->getHash()) &&
44 (lhs->getData() == rhs->getData());
47[[nodiscard]]
inline Batch
55 for (
auto i = 0uz; i < numObjects; ++i)
87 for (
auto const& obj : batch)
91[[nodiscard]]
inline Batch
95 copy.reserve(batch.
size());
97 for (
auto i = 0uz; i < batch.
size(); ++i)
101 Status const status = backend.
fetch(batch[i]->getHash(), &
object);
105 EXPECT_NE(
object,
nullptr);
106 copy.emplace_back(
object);
115 for (
auto i = 0uz; i < batch.
size(); ++i)
119 Status const status = backend.
fetch(batch[i]->getHash(), &
object);
127 for (
auto const& obj : batch)
129 Blob data(obj->getData());
134[[nodiscard]]
inline Batch
138 copy.reserve(batch.
size());
140 for (
auto const& obj : batch)
143 if (result !=
nullptr)
144 copy.emplace_back(result);
152 for (
auto i = 0uz; i < batch.
size(); ++i)
154 SCOPED_TRACE(
"fetchMissing(Database) index=" +
std::to_string(i));
163[[nodiscard]]
inline bool
static constexpr std::size_t size()
static std::shared_ptr< NodeObject > createObject(NodeObjectType type, Blob &&data, uint256 const &hash)
Create an object from fields.
A backend used for the NodeStore.
virtual void store(std::shared_ptr< NodeObject > const &object)=0
Store a single object.
virtual Status fetch(uint256 const &hash, std::shared_ptr< NodeObject > *pObject)=0
Fetch a single object.
Persistency layer for NodeObject.
std::uint32_t earliestLedgerSeq() const noexcept
virtual void store(NodeObjectType type, Blob &&data, uint256 const &hash, std::uint32_t ledgerSeq)=0
Store the object.
std::shared_ptr< NodeObject > fetchNodeObject(uint256 const &hash, std::uint32_t ledgerSeq=0, FetchType fetchType=FetchType::Synchronous, bool duplicate=false)
Fetch a node object.
T emplace_back(T... args)
detail::XorShiftEngine<> xor_shift_engine
XOR-shift Generator.
void rngfill(void *const buffer, std::size_t const bytes, Generator &g)
constexpr std::size_t kMinPayloadBytes
constexpr std::uint64_t kSeedValue
constexpr std::size_t kMaxPayloadBytes
bool isSame(std::shared_ptr< NodeObject > const &lhs, std::shared_ptr< NodeObject > const &rhs)
std::vector< std::shared_ptr< NodeObject > > Batch
A batch of NodeObjects to write at once.
Batch createPredictableBatch(std::size_t numObjects, std::uint64_t seed)
constexpr int kNumObjects
void storeBatch(Backend &backend, Batch const &batch)
Status
Return codes from Backend operations.
constexpr int kNumObjectsToTest
void fetchMissing(Backend &backend, Batch const &batch)
Batch fetchCopyOfBatch(Backend &backend, Batch const &batch)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr bool operator==(BaseUInt< Bits, Tag > const &lhs, BaseUInt< Bits, Tag > const &rhs)
NodeObjectType
The types of node objects.
std::vector< unsigned char > Blob
Storage for linear binary data.
bool operator()(std::shared_ptr< NodeObject > const &lhs, std::shared_ptr< NodeObject > const &rhs) const noexcept