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>
39 :
private boost::base_from_member<TestStopwatch>
45 boost::base_from_member<TestStopwatch>;
49 :
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);
87 testcase(
"Limited warn/drop");
89 testcase(
"Unlimited warn/drop");
114 fail (
"Loop count exceeded without warning");
125 fail (
"Should loop forever with no warning");
137 fail (
"Loop count exceeded without dropping");
160 fail (
"Dropped consumer not put on blacklist");
168 bool readmitted =
false;
170 using namespace std::chrono_literals;
186 if (readmitted ==
false)
188 fail (
"Dropped Consumer left on blacklist too long");
196 testcase (
"Imports");
202 for (
int i = 0; i < 5; ++i)
205 for (
int i = 0; i < 5; ++i)
220 beast::IP::AddressV4::bytes_type d = {{192, 0, 2, 1}};
222 g.
items.push_back (item);
240 "Charging " << c.
to_string() <<
" " << fee <<
" per second";
242 for (
int i = 0; i < 128; ++i)
245 "Time= " << logic.
clock().
now().time_since_epoch().count() <<
256 "Charging " << c.
to_string() <<
" " << fee <<
" per second";
257 for (
int i = 0; i < 128; ++i)
261 "Time= " << logic.
clock().
now().time_since_epoch().count() <<
TestLogic(beast::Journal journal)
void testCharges(beast::Journal j)
Data format for exchanging consumption information across peers.
Consumer newInboundEndpoint(beast::IP::Endpoint const &address)
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 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)
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)
bool disconnect()
Returns true if the consumer should be disconnected.
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.