1#include <xrpl/nodestore/Database.h>
3#include <xrpl/basics/ByteUtilities.h>
4#include <xrpl/basics/FileUtilities.h>
5#include <xrpl/basics/scope.h>
6#include <xrpl/beast/utility/Journal.h>
7#include <xrpl/beast/xor_shift_engine.h>
8#include <xrpl/config/BasicConfig.h>
9#include <xrpl/nodestore/DummyScheduler.h>
10#include <xrpl/nodestore/Manager.h>
11#include <xrpl/nodestore/NodeObject.h>
12#include <xrpl/nodestore/Types.h>
13#include <xrpl/protocol/SystemParameters.h>
15#include <gtest/gtest.h>
16#include <helpers/TestSink.h>
17#include <nodestore/TestBase.h>
33std::vector<std::string>
36#if XRPL_ROCKSDB_AVAILABLE
37 return {
"memory",
"nudb",
"rocksdb"};
39 return {
"memory",
"nudb"};
43std::vector<std::string>
46 std::vector<std::string> types{
"nudb"};
47#if XRPL_ROCKSDB_AVAILABLE
53std::vector<std::string>
56 std::vector<std::string> types{
"nudb"};
57#if XRPL_ROCKSDB_AVAILABLE
60#ifdef XRPL_ENABLE_SQLITE_BACKEND_TESTS
106 auto db = makeDatabase();
111 SCOPED_TRACE(
"read in original order");
113 EXPECT_EQ(batch_, copy);
117 SCOPED_TRACE(
"read in shuffled order");
121 EXPECT_EQ(batch_, copy);
128 auto db = makeDatabase();
133 auto db = makeDatabase();
138 EXPECT_EQ(batch_, copy);
145 auto db = makeDatabase();
154 ::testing::ValuesIn(allBackends()),
155 [](::testing::TestParamInfo<std::string>
const& info) {
return info.param; });
160 ::testing::ValuesIn(persistentBackends()),
161 [](::testing::TestParamInfo<std::string>
const& info) {
return info.param; });
163TEST(NodeStoreDatabase, memory_earliest_seq)
168 nodeParams.
set(
"type",
"memory");
169 nodeParams.
set(
"path", nodeDb.
path());
181 nodeParams.
set(
"earliest_seq",
"0");
186 FAIL() <<
"expected runtime_error for earliest_seq=0";
190 EXPECT_STREQ(e.
what(),
"Invalid earliest_seq");
196 nodeParams.
set(
"earliest_seq",
"1");
198 EXPECT_EQ(db->earliestLedgerSeq(), 1u);
231TEST(NodeStoreDatabase, stop_completes_every_read_once)
236 nodeParams.
set(
"type",
"memory");
237 nodeParams.
set(
"path", nodeDb.
path());
267 blocked.null = !object;
270 ASSERT_TRUE(waitFor([&] {
return entered.
load(); }));
274 queued.null = !object;
281 EXPECT_TRUE(waitFor([&] {
return queued.calls == 1; }));
282 EXPECT_TRUE(queued.null);
289 EXPECT_EQ(late.calls, 1);
290 EXPECT_TRUE(late.null);
296 EXPECT_EQ(blocked.calls, 1);
297 EXPECT_TRUE(blocked.null);
298 EXPECT_EQ(queued.calls, 1);
299 EXPECT_EQ(late.calls, 1);
308 auto const type = GetParam();
315 srcParams.
set(
"type", type);
316 srcParams.
set(
"path", srcDir.
path());
333 destParams.
set(
"type", type);
334 destParams.
set(
"path", destDir.
path());
339 dest->importDatabase(*src);
345 EXPECT_EQ(batch, copy);
351 ::testing::ValuesIn(importBackends()),
352 [](::testing::TestParamInfo<std::string>
const& info) {
return info.param; });
A generic endpoint for log messages.
Holds a collection of configuration values.
void set(std::string const &key, std::string const &value)
Set a key/value pair.
RAII temporary directory.
std::string path() const
Get the native path for the temporary directory.
static TestSink & instance()
Simple NodeStore Scheduler that just performs the tasks synchronously.
virtual std::unique_ptr< Database > makeDatabase(std::size_t burstSize, Scheduler &scheduler, int readThreads, Section const &backendParameters, beast::Journal journal)=0
Construct a NodeStore database.
static Manager & instance()
Returns the instance of the manager singleton.
std::unique_ptr< Database > makeDatabase()
beast::Journal const journal_
DummyScheduler scheduler_
T emplace_back(T... args)
detail::XorShiftEngine<> XorShiftEngine
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;})
TEST(NodeStoreBasics, predictable_batches)
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
static constexpr std::uint32_t kXrpLedgerEarliestSeq
The XRP ledger network's earliest allowed sequence.