1#include <xrpld/app/misc/setup_HashRouter.h>
2#include <xrpld/core/Config.h>
4#include <xrpl/basics/chrono.h>
5#include <xrpl/beast/unit_test/suite.h>
6#include <xrpl/config/Constants.h>
7#include <xrpl/core/HashRouter.h>
33 using namespace std::chrono_literals;
75 using namespace std::chrono_literals;
89 BEAST_EXPECT(key1 != key2 && key2 != key3 && key3 != key4);
161 using namespace std::chrono_literals;
169 BEAST_EXPECT(key1 != key2 && key2 != key3 && key3 != key4);
190 using namespace std::chrono_literals;
204 using namespace std::chrono_literals;
213 BEAST_EXPECT(peers && peers->empty());
225 BEAST_EXPECT(peers && peers->size() == 3);
236 BEAST_EXPECT(peers && peers->size() == 2);
241 BEAST_EXPECT(peers && peers->empty());
248 using namespace std::chrono_literals;
267 using namespace std::chrono_literals;
272 BEAST_EXPECT(setup.holdTime == 300s);
273 BEAST_EXPECT(setup.relayTime == 30s);
282 BEAST_EXPECT(setup.holdTime == 600s);
283 BEAST_EXPECT(setup.relayTime == 15s);
292 BEAST_EXPECT(setup.holdTime == 400s);
293 BEAST_EXPECT(setup.relayTime == 400s);
309 "HashRouter relay time must be less than or equal to hold "
311 BEAST_EXPECT(e.
what() == expected);
328 "HashRouter hold time must be at least 12 seconds (the "
329 "approximate validation time for three "
331 BEAST_EXPECT(e.
what() == expected);
348 "HashRouter relay time must be at least 8 seconds (the "
349 "approximate validation time for two ledgers).";
350 BEAST_EXPECT(e.
what() == expected);
362 BEAST_EXPECT(setup.holdTime == 300s);
363 BEAST_EXPECT(setup.relayTime == 30s);
375 HF
const f1 = HF::BAD;
376 HF
const f2 = HF::SAVED;
377 HF
const combined = f1 | f2;
379 BEAST_EXPECT(
static_cast<UHF
>(combined) == (
static_cast<UHF
>(f1) |
static_cast<UHF
>(f2)));
383 BEAST_EXPECT(temp == combined);
385 HF
const intersect = combined & f1;
386 BEAST_EXPECT(intersect == f1);
390 BEAST_EXPECT(temp2 == f1);
392 BEAST_EXPECT(
any(f1));
393 BEAST_EXPECT(
any(f2));
394 BEAST_EXPECT(
any(combined));
395 BEAST_EXPECT(!
any(HF::UNDEFINED));
void fail(String const &reason, char const *file, int line)
Record a failure.
TestcaseT testcase
Memberspace for declaring test cases.
Section & section(std::string const &name)
Returns the section with the given name.
Routing table for objects identified by hash.
std::optional< std::set< PeerShortID > > shouldRelay(uint256 const &key)
Determines whether the hashed item should be relayed.
HashRouterFlags getFlags(uint256 const &key)
bool addSuppressionPeer(uint256 const &key, PeerShortID peer)
bool setFlags(uint256 const &key, HashRouterFlags flags)
Set the flags on a hash.
bool shouldProcess(uint256 const &key, PeerShortID peer, HashRouterFlags &flags, std::chrono::seconds txInterval)
void addSuppression(uint256 const &key)
std::uint32_t PeerShortID
void set(std::string const &key, std::string const &value)
Set a key/value pair.
static HashRouter::Setup getSetup(std::chrono::seconds hold, std::chrono::seconds relay)
void run() override
Runs the suite.
BEAST_DEFINE_TESTSUITE(AMMClawback, app, xrpl)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Stopwatch & stopwatch()
Returns an instance of a wall clock.
HashRouter::Setup setupHashRouter(Config const &config)
Create HashRouter setup from configuration.
beast::ManualClock< std::chrono::steady_clock > TestStopwatch
A manual Stopwatch for unit tests.
constexpr bool any(HashRouterFlags flags)
Structure used to customize HashRouter behavior.
seconds holdTime
Expiration time for a hash entry.
seconds relayTime
Amount of time required before a relayed item will be relayed again.
static constexpr auto kRelayTime
static constexpr auto kHoldTime
static constexpr auto kHashrouter