20 #include <ripple/basics/chrono.h>
21 #include <ripple/basics/random.h>
22 #include <ripple/beast/unit_test.h>
23 #include <ripple/resource/Consumer.h>
24 #include <ripple/resource/impl/Entry.h>
25 #include <ripple/resource/impl/Logic.h>
26 #include <test/unit_test/SuiteJournal.h>
28 #include <boost/utility/base_from_member.hpp>
37 class TestLogic :
private boost::base_from_member<TestStopwatch>,
42 using clock_type = boost::base_from_member<TestStopwatch>;
46 :
Logic(
beast::insight::NullCollector::New(), member, journal)
70 gossip.
items.reserve(n);
75 beast::IP::AddressV4::bytes_type d = {
78 gossip.
items.push_back(item);
88 testcase(
"Limited warn/drop");
90 testcase(
"Unlimited warn/drop");
104 std::placeholders::_1);
117 fail(
"Loop count exceeded without warning");
128 fail(
"Should loop forever with no warning");
140 fail(
"Loop count exceeded without dropping");
163 fail(
"Dropped consumer not put on blacklist");
171 bool readmitted =
false;
173 using namespace std::chrono_literals;
189 if (readmitted ==
false)
191 fail(
"Dropped Consumer left on blacklist too long");
206 for (
int i = 0; i < 5; ++i)
209 for (
int i = 0; i < 5; ++i)
225 beast::IP::AddressV4::bytes_type d = {{192, 0, 2, 1}};
227 g.
items.push_back(item);
249 for (
int i = 0; i < 128; ++i)
251 JLOG(j.
info()) <<
"Time= "
252 << logic.
clock().
now().time_since_epoch().count()
253 <<
", Balance = " << c.
balance();
265 for (
int i = 0; i < 128; ++i)
268 JLOG(j.
info()) <<
"Time= "
269 << logic.
clock().
now().time_since_epoch().count()
270 <<
", Balance = " << c.
balance();
TestLogic(beast::Journal journal)
bool disconnect(beast::Journal const &j)
Returns true if the consumer should be disconnected.
void testCharges(beast::Journal j)
Data format for exchanging consumption information across peers.
Consumer newInboundEndpoint(beast::IP::Endpoint const &address)
void testImport(beast::Journal j)
A namespace for easy access to logging severity values.
void createGossip(Gossip &gossip)
constexpr std::chrono::seconds secondsUntilExpiration
Disposition disposition() const
Returns the current disposition of this consumer.
std::string to_string() const
Return a human readable string uniquely identifying this consumer.
void testDrop(beast::Journal j, bool limited)
std::enable_if_t< std::is_integral< Integral >::value &&detail::is_engine< Engine >::value, Integral > rand_int(Engine &engine, Integral min, Integral max)
Return a uniformly distributed random integer.
void importConsumers(std::string const &origin, Gossip const &gossip)
std::vector< Item > items
int balance()
Returns the credit balance representing consumption.
A generic endpoint for log messages.
time_point now() const override
Returns the current time.
Describes a single consumer.
boost::asio::ip::address_v4 AddressV4
@ warn
Consumer should be disconnected for excess consumption.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void testImports(beast::Journal j)
Consumer newUnlimitedEndpoint(beast::IP::Endpoint const &address)
Create endpoint that should not have resource limits applied.
static Endpoint from_string(std::string const &s)
beast::IP::Endpoint address
An endpoint that consumes resources.
A version-independent IP address and port combination.
BEAST_DEFINE_TESTSUITE(ResourceManager, resource, ripple)
Disposition charge(Charge const &fee)
Apply a load charge to the consumer.