20#include <test/nodestore/TestBase.h>
21#include <test/unit_test/SuiteJournal.h>
23#include <xrpl/basics/BasicConfig.h>
24#include <xrpl/basics/ByteUtilities.h>
25#include <xrpl/beast/utility/temp_dir.h>
26#include <xrpl/nodestore/DummyScheduler.h>
27#include <xrpl/nodestore/Manager.h>
43 params.
set(
"type",
"nudb");
44 params.
set(
"path", path);
45 if (!blockSize.empty())
46 params.
set(
"nudb_block_size", blockSize);
62 params,
megabytes(4), scheduler, journal);
64 if (!BEAST_EXPECT(backend))
67 if (!BEAST_EXPECT(backend->getBlockSize() == expectedBlocksize))
72 if (!BEAST_EXPECT(backend->isOpen()))
104 params,
megabytes(4), scheduler, journal);
107 BEAST_EXPECT(logOutput.
find(expectedMessage) != std::string::npos);
122 params,
megabytes(4), scheduler, journal);
126 logOutput.
find(
"Invalid nudb_block_size") != std::string::npos;
128 BEAST_EXPECT(hasWarning == !shouldWork);
135 testcase(
"Default block size (no nudb_block_size specified)");
151 for (
auto const& size : validSizes)
186 for (
auto const& size : invalidSizes)
201 for (
auto const& size : whitespaceInvalidSizes)
214 testcase(
"Log message verification");
224 "Using custom NuDB block size: 8192");
239 params,
megabytes(4), scheduler, journal);
246 logOutput.find(
"Invalid nudb_block_size: 5000") !=
250 "Must be power of 2 between 4096 and 32768") !=
267 params,
megabytes(4), scheduler, journal);
275 logOutput.find(
"Invalid nudb_block_size value: invalid") !=
284 testcase(
"Power of 2 validation logic");
299 for (
auto const& [size, shouldWork] : testCases)
313 params,
megabytes(4), scheduler, journal);
314 BEAST_EXPECT(shouldWork);
320 logOutput.find(
"Invalid nudb_block_size") !=
329 testcase(
"Both constructor variants work with custom block size");
340 params,
megabytes(4), scheduler, journal);
341 BEAST_EXPECT(backend1 !=
nullptr);
354 testcase(
"Configuration parsing edge cases");
371 for (
auto const& format : validFormats)
381 params,
megabytes(4), scheduler, journal);
385 bool hasSuccessMessage =
386 logOutput.
find(
"Using custom NuDB block size") !=
388 BEAST_EXPECT(hasSuccessMessage);
393 for (
auto const& format : whitespaceFormats)
406 params,
megabytes(4), scheduler, journal);
420 testcase(
"Data persistence with different block sizes");
423 "4096",
"8192",
"16384",
"32768"};
425 for (
auto const& size : blockSizes)
439 params,
megabytes(4), scheduler, journal);
448 params,
megabytes(4), scheduler, journal);
A generic endpoint for log messages.
RAII temporary directory.
std::string path() const
Get the native path for the temporary directory.
testcase_t testcase
Memberspace for declaring test cases.
void fail(String const &reason, char const *file, int line)
Record a failure.
Simple NodeStore Scheduler that just peforms the tasks synchronously.
virtual std::unique_ptr< Backend > make_Backend(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.
void testBothConstructorVariants()
void testInvalidBlockSizes()
Section createSection(std::string const &path, std::string const &blockSize="")
void testDefaultBlockSize()
void testPowerOfTwoValidation()
void testLogMessage(Section const ¶ms, beast::severities::Severity level, std::string const &expectedMessage)
void run() override
Runs the suite.
void testPowerOfTwoValidation(std::string const &size, bool shouldWork)
void testConfigurationParsing()
bool testBackendFunctionality(Section const ¶ms, std::size_t expectedBlocksize)
void testDataPersistence()
void testValidBlockSizes()
static Batch createPredictableBatch(int numObjects, std::uint64_t seed)
static bool areBatchesEqual(Batch const &lhs, Batch const &rhs)
void fetchCopyOfBatch(Backend &backend, Batch *pCopy, Batch const &batch)
void storeBatch(Backend &backend, Batch const &batch)
Holds a collection of configuration values.
void set(std::string const &key, std::string const &value)
Set a key/value pair.
std::stringstream const & messages() const
Severity
Severity level / threshold of a Journal message.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr auto megabytes(T value) noexcept
std::string to_string(base_uint< Bits, Tag > const &a)