20#include <test/beast/IPEndpointCommon.h>
21#include <test/unit_test/SuiteJournal.h>
22#include <xrpld/peerfinder/detail/Livecache.h>
23#include <xrpl/basics/chrono.h>
24#include <xrpl/basics/safe_cast.h>
25#include <xrpl/beast/clock/manual_clock.h>
26#include <xrpl/beast/unit_test.h>
27#include <boost/algorithm/string.hpp>
62 BEAST_EXPECT(c.
empty());
64 for (
auto i = 0; i < 10; ++i)
67 BEAST_EXPECT(!c.
empty());
68 BEAST_EXPECT(c.
size() == 10);
70 for (
auto i = 0; i < 10; ++i)
73 BEAST_EXPECT(!c.
empty());
74 BEAST_EXPECT(c.
size() == 20);
85 BEAST_EXPECT(c.
size() == 1);
87 BEAST_EXPECT((c.
hops.
begin() + 2)->begin()->hops == 2);
92 BEAST_EXPECT(c.
size() == 1);
94 BEAST_EXPECT((c.
hops.
begin() + 2)->begin()->hops == 2);
99 BEAST_EXPECT(c.
size() == 1);
101 BEAST_EXPECT((c.
hops.
begin() + 2)->begin()->hops == 2);
105 BEAST_EXPECT(c.
size() == 1);
107 BEAST_EXPECT((c.
hops.
begin() + 1)->begin()->hops == 1);
114 using namespace std::chrono_literals;
119 BEAST_EXPECT(c.
size() == 1);
121 BEAST_EXPECT(c.
size() == 1);
126 BEAST_EXPECT(c.
size() == 1);
130 BEAST_EXPECT(c.
empty());
137 constexpr auto num_eps = 40;
139 for (
auto i = 0; i < num_eps; ++i)
142 ripple::rand_int<std::uint32_t>());
144 if (!BEAST_EXPECT(!h.empty()))
147 boost::split(v, h, boost::algorithm::is_any_of(
","));
149 for (
auto const& n : v)
151 auto val = boost::lexical_cast<int>(boost::trim_copy(n));
153 BEAST_EXPECT(val >= 0);
155 BEAST_EXPECT(
sum == num_eps);
163 for (
auto i = 0; i < 100; ++i)
176 all_hops before_sorted;
179 ++i.first, ++i.second)
190 before_sorted[i.first].begin(),
191 before_sorted[i.first].end(),
198 all_hops after_sorted;
201 ++i.first, ++i.second)
212 after_sorted[i.first].begin(),
213 after_sorted[i.first].end(),
219 bool all_match =
true;
220 for (
auto i = 0; i < before.size(); ++i)
222 BEAST_EXPECT(before[i].size() ==
after[i].size());
223 all_match = all_match && (before[i] ==
after[i]);
224 BEAST_EXPECT(before_sorted[i] == after_sorted[i]);
226 BEAST_EXPECT(!all_match);
T back_inserter(T... args)
A version-independent IP address and port combination.
void advance(std::chrono::duration< Rep, Period > const &elapsed)
Advance the clock by a duration.
testcase_t testcase
Memberspace for declaring test cases.
void shuffle()
Shuffle each hop list.
std::string histogram() const
void run() override
Runs the suite.
test::SuiteJournal journal_
void add(beast::IP::Endpoint ep, C &c, std::uint32_t hops=0)
The Livecache holds the short-lived relayed Endpoint messages.
cache_type::size_type size() const
Returns the number of entries in the cache.
void expire()
Erase entries whose time has expired.
void insert(Endpoint const &ep)
Creates or updates an existing Element based on a new message.
class ripple::PeerFinder::Livecache::hops_t hops
bool empty() const
Returns true if the cache is empty.
Endpoint randomEP(bool v4=true)
std::chrono::seconds constexpr liveCacheSecondsToLive(30)
std::uint32_t constexpr maxHops
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< Integral >::value, Integral > rand_int()
static bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Describes a connectible peer address along with some metadata.
beast::IP::Endpoint address