1#include <test/beast/IPEndpointCommon.h>
2#include <test/unit_test/SuiteJournal.h>
4#include <xrpld/peerfinder/detail/Livecache.h>
6#include <xrpl/basics/chrono.h>
7#include <xrpl/beast/clock/manual_clock.h>
8#include <xrpl/beast/unit_test.h>
10#include <boost/algorithm/string.hpp>
45 BEAST_EXPECT(c.
empty());
47 for (
auto i = 0; i < 10; ++i)
50 BEAST_EXPECT(!c.
empty());
51 BEAST_EXPECT(c.
size() == 10);
53 for (
auto i = 0; i < 10; ++i)
56 BEAST_EXPECT(!c.
empty());
57 BEAST_EXPECT(c.
size() == 20);
68 BEAST_EXPECT(c.
size() == 1);
70 BEAST_EXPECT((c.
hops.
begin() + 2)->begin()->hops == 2);
75 BEAST_EXPECT(c.
size() == 1);
77 BEAST_EXPECT((c.
hops.
begin() + 2)->begin()->hops == 2);
82 BEAST_EXPECT(c.
size() == 1);
84 BEAST_EXPECT((c.
hops.
begin() + 2)->begin()->hops == 2);
88 BEAST_EXPECT(c.
size() == 1);
90 BEAST_EXPECT((c.
hops.
begin() + 1)->begin()->hops == 1);
97 using namespace std::chrono_literals;
102 BEAST_EXPECT(c.
size() == 1);
104 BEAST_EXPECT(c.
size() == 1);
109 BEAST_EXPECT(c.
size() == 1);
113 BEAST_EXPECT(c.
empty());
120 constexpr auto num_eps = 40;
122 for (
auto i = 0; i < num_eps; ++i)
125 ripple::rand_int<std::uint32_t>());
127 if (!BEAST_EXPECT(!h.empty()))
130 boost::split(v, h, boost::algorithm::is_any_of(
","));
132 for (
auto const& n : v)
134 auto val = boost::lexical_cast<int>(boost::trim_copy(n));
136 BEAST_EXPECT(val >= 0);
138 BEAST_EXPECT(
sum == num_eps);
146 for (
auto i = 0; i < 100; ++i)
159 all_hops before_sorted;
162 ++i.first, ++i.second)
173 before_sorted[i.first].begin(),
174 before_sorted[i.first].end(),
181 all_hops after_sorted;
184 ++i.first, ++i.second)
195 after_sorted[i.first].begin(),
196 after_sorted[i.first].end(),
202 bool all_match =
true;
203 for (
auto i = 0; i < before.size(); ++i)
205 BEAST_EXPECT(before[i].size() ==
after[i].size());
206 all_match = all_match && (before[i] ==
after[i]);
207 BEAST_EXPECT(before_sorted[i] == after_sorted[i]);
209 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