1#include <test/beast/IPEndpointCommon.h>
2#include <test/unit_test/SuiteJournal.h>
4#include <xrpld/peerfinder/PeerfinderManager.h>
5#include <xrpld/peerfinder/detail/Livecache.h>
6#include <xrpld/peerfinder/detail/Tuning.h>
8#include <xrpl/basics/chrono.h>
9#include <xrpl/basics/random.h>
10#include <xrpl/beast/net/IPEndpoint.h>
11#include <xrpl/beast/unit_test/suite.h>
13#include <boost/algorithm/string/classification.hpp>
14#include <boost/algorithm/string/split.hpp>
15#include <boost/algorithm/string/trim.hpp>
16#include <boost/lexical_cast.hpp>
57 BEAST_EXPECT(c.
empty());
59 for (
auto i = 0; i < 10; ++i)
62 BEAST_EXPECT(!c.
empty());
63 BEAST_EXPECT(c.
size() == 10);
65 for (
auto i = 0; i < 10; ++i)
68 BEAST_EXPECT(!c.
empty());
69 BEAST_EXPECT(c.
size() == 20);
80 BEAST_EXPECT(c.
size() == 1);
82 BEAST_EXPECT((c.
hops.
begin() + 2)->begin()->hops == 2);
87 BEAST_EXPECT(c.
size() == 1);
89 BEAST_EXPECT((c.
hops.
begin() + 2)->begin()->hops == 2);
94 BEAST_EXPECT(c.
size() == 1);
96 BEAST_EXPECT((c.
hops.
begin() + 2)->begin()->hops == 2);
100 BEAST_EXPECT(c.
size() == 1);
102 BEAST_EXPECT((c.
hops.
begin() + 1)->begin()->hops == 1);
109 using namespace std::chrono_literals;
114 BEAST_EXPECT(c.
size() == 1);
116 BEAST_EXPECT(c.
size() == 1);
121 BEAST_EXPECT(c.
size() == 1);
125 BEAST_EXPECT(c.
empty());
132 static constexpr auto kNumEps = 40;
134 for (
auto i = 0; i < kNumEps; ++i)
137 if (!BEAST_EXPECT(!h.empty()))
140 boost::split(v, h, boost::algorithm::is_any_of(
","));
142 for (
auto const& n : v)
144 auto val = boost::lexical_cast<int>(boost::trim_copy(n));
146 BEAST_EXPECT(val >= 0);
148 BEAST_EXPECT(
sum == kNumEps);
156 for (
auto i = 0; i < 100; ++i)
163 return (b.hops < a.
hops || (b.hops == a.
hops && b.address < a.
address));
166 all_hops beforeSorted;
168 ++i.first, ++i.second)
178 all_hops afterSorted;
180 ++i.first, ++i.second)
189 bool allMatch =
true;
190 for (
auto i = 0; i < before.size(); ++i)
192 BEAST_EXPECT(before[i].size() ==
after[i].size());
193 allMatch = allMatch && (before[i] ==
after[i]);
194 BEAST_EXPECT(beforeSorted[i] == afterSorted[i]);
196 BEAST_EXPECT(!allMatch);
T back_inserter(T... args)
A version-independent IP address and port combination.
TestcaseT testcase
Memberspace for declaring test cases.
void shuffle()
Shuffle each hop list.
std::string histogram() const
void add(beast::IP::Endpoint ep, C &c, std::uint32_t hops=0)
void run() override
Runs the suite.
test::SuiteJournal journal_
The Livecache holds the short-lived relayed Endpoint messages.
cache_type::size_type size() const
Returns the number of entries in the cache.
class xrpl::PeerFinder::Livecache::HopsT hops
void expire()
Erase entries whose time has expired.
void insert(Endpoint const &ep)
Creates or updates an existing Element based on a new message.
bool empty() const
Returns true if the cache is empty.
Endpoint randomEP(bool v4=true)
constexpr std::uint32_t kMaxHops
constexpr std::chrono::seconds kLiveCacheSecondsToLive(30)
BEAST_DEFINE_TESTSUITE(Livecache, peerfinder, xrpl)
bool operator==(Endpoint const &a, Endpoint const &b)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static auto sum(TCollection const &col)
std::enable_if_t< std::is_integral_v< Integral > &&detail::is_engine< Engine >::value, Integral > randInt(Engine &engine, Integral min, Integral max)
Return a uniformly distributed random integer.
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
beast::ManualClock< std::chrono::steady_clock > TestStopwatch
A manual Stopwatch for unit tests.
Describes a connectable peer address along with some metadata.
beast::IP::Endpoint address