20#include <test/beast/IPEndpointCommon.h>
21#include <test/unit_test/SuiteJournal.h>
23#include <xrpld/peerfinder/detail/Livecache.h>
25#include <xrpl/basics/chrono.h>
26#include <xrpl/beast/clock/manual_clock.h>
27#include <xrpl/beast/unit_test.h>
29#include <boost/algorithm/string.hpp>
64 BEAST_EXPECT(c.
empty());
66 for (
auto i = 0; i < 10; ++i)
69 BEAST_EXPECT(!c.
empty());
70 BEAST_EXPECT(c.
size() == 10);
72 for (
auto i = 0; i < 10; ++i)
75 BEAST_EXPECT(!c.
empty());
76 BEAST_EXPECT(c.
size() == 20);
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);
101 BEAST_EXPECT(c.
size() == 1);
103 BEAST_EXPECT((c.
hops.
begin() + 2)->begin()->hops == 2);
107 BEAST_EXPECT(c.
size() == 1);
109 BEAST_EXPECT((c.
hops.
begin() + 1)->begin()->hops == 1);
116 using namespace std::chrono_literals;
121 BEAST_EXPECT(c.
size() == 1);
123 BEAST_EXPECT(c.
size() == 1);
128 BEAST_EXPECT(c.
size() == 1);
132 BEAST_EXPECT(c.
empty());
139 constexpr auto num_eps = 40;
141 for (
auto i = 0; i < num_eps; ++i)
144 ripple::rand_int<std::uint32_t>());
146 if (!BEAST_EXPECT(!h.empty()))
149 boost::split(v, h, boost::algorithm::is_any_of(
","));
151 for (
auto const& n : v)
153 auto val = boost::lexical_cast<int>(boost::trim_copy(n));
155 BEAST_EXPECT(val >= 0);
157 BEAST_EXPECT(
sum == num_eps);
165 for (
auto i = 0; i < 100; ++i)
178 all_hops before_sorted;
181 ++i.first, ++i.second)
192 before_sorted[i.first].begin(),
193 before_sorted[i.first].end(),
200 all_hops after_sorted;
203 ++i.first, ++i.second)
214 after_sorted[i.first].begin(),
215 after_sorted[i.first].end(),
221 bool all_match =
true;
222 for (
auto i = 0; i < before.size(); ++i)
224 BEAST_EXPECT(before[i].size() ==
after[i].size());
225 all_match = all_match && (before[i] ==
after[i]);
226 BEAST_EXPECT(before_sorted[i] == after_sorted[i]);
228 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()
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