2#include <test/jtx/envconfig.h>
4#include <xrpld/app/main/Application.h>
5#include <xrpld/app/main/NodeStoreScheduler.h>
6#include <xrpld/app/misc/SHAMapStore.h>
7#include <xrpld/app/rdb/backend/SQLiteDatabase.h>
8#include <xrpld/core/ConfigSections.h>
10#include <xrpl/nodestore/detail/DatabaseRotatingImp.h>
11#include <xrpl/protocol/jss.h>
41 json[jss::result][jss::ledger][jss::ledger_index] == ledgerID;
42 if (!good || !checkDB)
45 auto const seq =
json[jss::result][jss::ledger_index].asUInt();
63 auto const& ledger =
json[jss::result][jss::ledger];
64 return outHash == ledger[jss::ledger_hash].asString() && outSeq ==
seq &&
65 outParentHash == ledger[jss::parent_hash].asString() && outDrops == ledger[jss::total_coins].asString() &&
66 outCloseTime == ledger[jss::close_time].asUInt() &&
67 outParentCloseTime == ledger[jss::parent_close_time].asUInt() &&
68 outCloseTimeResolution == ledger[jss::close_time_resolution].asUInt() &&
69 outCloseFlags == ledger[jss::close_flags].asUInt() &&
70 outAccountHash == ledger[jss::account_hash].asString() &&
71 outTxHash == ledger[jss::transaction_hash].asString();
78 json[jss::result][jss::error_code] == error;
85 json.isMember(jss::result) &&
json[jss::result].isMember(jss::ledger) &&
86 json[jss::result][jss::ledger].isMember(jss::ledger_hash) &&
87 json[jss::result][jss::ledger][jss::ledger_hash].isString());
88 return json[jss::result][jss::ledger][jss::ledger_hash].asString();
94 auto const [actualRows, actualFirst, actualLast] =
97 BEAST_EXPECT(actualRows == rows);
98 BEAST_EXPECT(actualFirst == first);
99 BEAST_EXPECT(actualLast == first + rows - 1);
118 using namespace std::chrono_literals;
124 BEAST_EXPECT(!store.getLastRotated());
129 auto ledger = env.
rpc(
"ledger",
"validated");
132 BEAST_EXPECT(store.getLastRotated() == ledgerSeq - 1);
140 using namespace std::chrono_literals;
156 auto ledgerTmp = env.
rpc(
"ledger",
"0");
157 BEAST_EXPECT(
bad(ledgerTmp));
160 BEAST_EXPECT(
goodLedger(env, ledgers[1],
"1"));
163 BEAST_EXPECT(
goodLedger(env, ledgers[2],
"2"));
165 ledgerTmp = env.
rpc(
"ledger",
"current");
166 BEAST_EXPECT(
goodLedger(env, ledgerTmp,
"3"));
168 ledgerTmp = env.
rpc(
"ledger",
"4");
169 BEAST_EXPECT(
bad(ledgerTmp));
171 ledgerTmp = env.
rpc(
"ledger",
"100");
172 BEAST_EXPECT(
bad(ledgerTmp));
175 auto lastRotated = firstSeq - 1;
182 ledgerTmp = env.
rpc(
"ledger",
"current");
185 BEAST_EXPECT(store.getLastRotated() == lastRotated);
201 auto ledger = env.
rpc(
"ledger",
"current");
208 lastRotated = store.getLastRotated();
209 BEAST_EXPECT(lastRotated == 11);
217 for (
auto i = lastRotated - 1; i < lastRotated +
deleteInterval - 1; ++i)
221 ledgerTmp = env.
rpc(
"ledger",
"current");
225 BEAST_EXPECT(store.getLastRotated() == lastRotated || i == lastRotated +
deleteInterval - 2);
231 BEAST_EXPECT(store.getLastRotated() ==
deleteInterval + lastRotated);
241 testcase(
"automatic online_delete");
243 using namespace std::chrono_literals;
249 auto lastRotated = ledgerSeq - 1;
250 BEAST_EXPECT(store.getLastRotated() == lastRotated);
251 BEAST_EXPECT(lastRotated != 2);
255 auto const canDelete = env.
rpc(
"can_delete");
263 auto ledger = env.
rpc(
"ledger",
"validated");
272 BEAST_EXPECT(lastRotated == store.getLastRotated());
278 auto ledger = env.
rpc(
"ledger",
"validated");
284 ledgerCheck(env, ledgerSeq - lastRotated, lastRotated);
285 BEAST_EXPECT(lastRotated != store.getLastRotated());
287 lastRotated = store.getLastRotated();
294 auto ledger = env.
rpc(
"ledger",
"validated");
301 BEAST_EXPECT(lastRotated != store.getLastRotated());
307 testcase(
"online_delete with advisory_delete");
309 using namespace std::chrono_literals;
316 auto lastRotated = ledgerSeq - 1;
317 BEAST_EXPECT(store.getLastRotated() == lastRotated);
318 BEAST_EXPECT(lastRotated != 2);
320 auto canDelete = env.
rpc(
"can_delete");
322 BEAST_EXPECT(canDelete[jss::result][jss::can_delete] == 0);
324 canDelete = env.
rpc(
"can_delete",
"never");
326 BEAST_EXPECT(canDelete[jss::result][jss::can_delete] == 0);
329 for (; ledgerSeq < firstBatch; ++ledgerSeq)
333 auto ledger = env.
rpc(
"ledger",
"validated");
340 BEAST_EXPECT(lastRotated == store.getLastRotated());
345 BEAST_EXPECT(canDelete[jss::result][jss::can_delete] == ledgerSeq +
deleteInterval / 2);
350 BEAST_EXPECT(store.getLastRotated() == lastRotated);
356 auto ledger = env.
rpc(
"ledger",
"validated");
362 ledgerCheck(env, ledgerSeq - lastRotated, lastRotated);
364 BEAST_EXPECT(store.getLastRotated() == ledgerSeq - 1);
365 lastRotated = ledgerSeq - 1;
372 auto ledger = env.
rpc(
"ledger",
"validated");
378 BEAST_EXPECT(store.getLastRotated() == lastRotated);
384 auto ledger = env.
rpc(
"ledger",
"validated");
390 ledgerCheck(env, ledgerSeq - firstBatch, firstBatch);
392 BEAST_EXPECT(store.getLastRotated() == ledgerSeq - 1);
393 lastRotated = ledgerSeq - 1;
396 canDelete = env.
rpc(
"can_delete",
"always");
405 auto ledger = env.
rpc(
"ledger",
"validated");
411 BEAST_EXPECT(store.getLastRotated() == lastRotated);
417 auto ledger = env.
rpc(
"ledger",
"validated");
423 ledgerCheck(env, ledgerSeq - lastRotated, lastRotated);
425 BEAST_EXPECT(store.getLastRotated() == ledgerSeq - 1);
426 lastRotated = ledgerSeq - 1;
429 canDelete = env.
rpc(
"can_delete",
"now");
431 BEAST_EXPECT(canDelete[jss::result][jss::can_delete] == ledgerSeq - 1);
438 auto ledger = env.
rpc(
"ledger",
"validated");
444 BEAST_EXPECT(store.getLastRotated() == lastRotated);
450 auto ledger = env.
rpc(
"ledger",
"validated");
456 ledgerCheck(env, ledgerSeq - lastRotated, lastRotated);
458 BEAST_EXPECT(store.getLastRotated() == ledgerSeq - 1);
459 lastRotated = ledgerSeq - 1;
466 boost::filesystem::path newPath;
468 if (!BEAST_EXPECT(
path.size()))
471 section.set(
"path", newPath.string());
487 testcase(
"rotate with lock contention");
498 if (!nscfg.exists(
"cache_size"))
502 if (!nscfg.exists(
"cache_age"))
515 constexpr int readThreads = 4;
519 std::move(writableBackend),
520 std::move(archiveBackend),
526 using namespace std::chrono_literals;
533 BEAST_EXPECT(writableName ==
"1");
534 BEAST_EXPECT(archiveName ==
"write");
537 BEAST_EXPECT(dbr->getName() ==
"1");
540 dbr->rotate(std::move(newBackend), cb);
542 BEAST_EXPECT(threadNum == 1);
543 BEAST_EXPECT(dbr->getName() ==
"1");
549 BEAST_EXPECT(writableName ==
"3");
550 BEAST_EXPECT(archiveName ==
"2");
553 BEAST_EXPECT(dbr->getName() ==
"3");
556 BEAST_EXPECT(writableName ==
"2");
557 BEAST_EXPECT(archiveName ==
"1");
560 dbr->rotate(std::move(newBackend), cb);
563 dbr->rotate(std::move(newBackend), cbReentrant);
566 BEAST_EXPECT(threadNum == 3);
567 BEAST_EXPECT(dbr->getName() ==
"3");
testcase_t testcase
Memberspace for declaring test cases.
virtual Config & config()=0
virtual SHAMapStore & getSHAMapStore()=0
virtual JobQueue & getJobQueue()=0
virtual RelationalDatabase & getRelationalDatabase()=0
Section & section(std::string const &name)
Returns the section with the given name.
int getValueFor(SizedItem item, std::optional< std::size_t > node=std::nullopt) const
Retrieve the default value for the item at the specified node size.
beast::Journal journal(std::string const &name)
A NodeStore::Scheduler which uses the JobQueue.
static Manager & instance()
Returns the instance of the manager singleton.
virtual std::unique_ptr< Backend > make_Backend(Section const ¶meters, std::size_t burstSize, Scheduler &scheduler, beast::Journal journal)=0
Create a backend.
virtual std::optional< LedgerHeader > getLedgerInfoByIndex(LedgerIndex ledgerSeq)=0
getLedgerInfoByIndex Returns a ledger by its sequence.
class to create database, launch online delete thread, and related SQLite database
virtual void rendezvous() const =0
virtual std::size_t getAccountTransactionCount()=0
getAccountTransactionCount Returns the number of account transactions.
virtual std::size_t getTransactionCount()=0
getTransactionCount Returns the number of transactions.
Holds a collection of configuration values.
void set(std::string const &key, std::string const &value)
Set a key/value pair.
static auto const deleteInterval
static auto onlineDelete(std::unique_ptr< Config > cfg)
static auto advisoryDelete(std::unique_ptr< Config > cfg)
bool bad(Json::Value const &json, error_code_i error=rpcLGR_NOT_FOUND)
std::string getHash(Json::Value const &json)
std::unique_ptr< NodeStore::Backend > makeBackendRotating(jtx::Env &env, NodeStoreScheduler &scheduler, std::string path)
void ledgerCheck(jtx::Env &env, int const rows, int const first)
void accountTransactionCheck(jtx::Env &env, int const rows)
void run() override
Runs the suite.
bool goodLedger(jtx::Env &env, Json::Value const &json, std::string ledgerID, bool checkDB=false)
void transactionCheck(jtx::Env &env, int const rows)
int waitForReady(jtx::Env &env)
A transaction testing environment.
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
Json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
bool contains_error(Json::Value const &json)
Returns true if the json contains an rpc error specification.
XRP_t const XRP
Converts to XRP Issue or STAmount.
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string to_string(base_uint< Bits, Tag > const &a)
constexpr auto megabytes(T value) noexcept
static std::string nodeDatabase()
Set the sequence number on a JTx.
T time_since_epoch(T... args)