1#include <xrpl/nodestore/Backend.h>
3#include <xrpl/basics/ByteUtilities.h>
4#include <xrpl/basics/FileUtilities.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/beast/xor_shift_engine.h>
7#include <xrpl/config/BasicConfig.h>
8#include <xrpl/nodestore/DummyScheduler.h>
9#include <xrpl/nodestore/Manager.h>
10#include <xrpl/nodestore/NodeObject.h>
11#include <xrpl/nodestore/Types.h>
13#include <gtest/gtest.h>
14#include <helpers/TestSink.h>
15#include <nodestore/TestBase.h>
30std::vector<std::string>
33 std::vector<std::string> types{
"nudb"};
34#if XRPL_ROCKSDB_AVAILABLE
37#ifdef XRPL_ENABLE_SQLITE_BACKEND_TESTS
48parallelFor(std::size_t n, std::size_t numThreads, Work work)
50 std::atomic<std::size_t>
next{0};
51 auto const runner = [&] {
52 for (std::size_t i = next++; i < n; i =
next++)
56 auto threads = std::views::iota(std::size_t{0}, numThreads) |
57 std::views::transform([&](std::size_t) {
return std::thread{runner}; }) |
58 std::ranges::to<std::vector>();
71 params_.set(
"type", GetParam());
95 auto backend = makeOpenBackend();
99 SCOPED_TRACE(
"read in original order");
101 EXPECT_EQ(batch_, copy);
105 SCOPED_TRACE(
"read in shuffled order");
109 EXPECT_EQ(batch_, copy);
116 auto backend = makeOpenBackend();
121 auto backend = makeOpenBackend();
125 EXPECT_EQ(batch_, copy);
133 auto backend = makeOpenBackend();
146 if (GetParam() ==
"sqlite")
147 GTEST_SKIP() <<
"sqlite backend is not exercised under concurrency";
149 for (
auto const numThreads : {4uz, 8uz})
153 auto backend = makeOpenBackend();
156 parallelFor(batch_.size(), numThreads, [&](
std::size_t i) { backend->store(batch_[i]); });
162 parallelFor(batch_.size(), numThreads, [&](
std::size_t i) {
163 std::shared_ptr<NodeObject> result;
164 if (backend->fetch(batch_[i]->getHash(), &result) != Status::Ok || !result ||
165 !isSame(result, batch_[i]))
170 EXPECT_EQ(mismatches.load(), 0u);
179 ::testing::ValuesIn(backendTypes()),
180 [](::testing::TestParamInfo<std::string>
const& info) {
return info.param; });
A generic endpoint for log messages.
Holds a collection of configuration values.
RAII temporary directory.
static TestSink & instance()
beast::Journal const journal_
std::unique_ptr< Backend > makeOpenBackend()
DummyScheduler scheduler_
Simple NodeStore Scheduler that just performs the tasks synchronously.
virtual std::unique_ptr< Backend > makeBackend(Section const ¶meters, std::size_t burstSize, Scheduler &scheduler, beast::Journal journal)=0
Create a backend.
static Manager & instance()
Returns the instance of the manager singleton.
T emplace_back(T... args)
detail::XorShiftEngine<> xor_shift_engine
XOR-shift Generator.
constexpr std::uint64_t kSeedValue
TEST_P(BackendTypeTest, store_and_fetch)
INSTANTIATE_TEST_SUITE_P(BackendTypes, BackendTypeTest, ::testing::ValuesIn(backendTypes()), [](::testing::TestParamInfo< std::string > const &info) { return info.param;})
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)
void fetchMissing(Backend &backend, Batch const &batch)
Batch fetchCopyOfBatch(Backend &backend, Batch const &batch)
constexpr auto megabytes(T value) noexcept