20#include <test/unit_test/SuiteJournal.h>
22#include <xrpl/basics/chrono.h>
23#include <xrpl/basics/random.h>
24#include <xrpl/beast/unit_test.h>
25#include <xrpl/resource/Consumer.h>
26#include <xrpl/resource/detail/Entry.h>
27#include <xrpl/resource/detail/Logic.h>
29#include <boost/utility/base_from_member.hpp>
39 class TestLogic :
private boost::base_from_member<TestStopwatch>,
44 using clock_type = boost::base_from_member<TestStopwatch>;
48 :
Logic(
beast::insight::NullCollector::New(), member, journal)
72 gossip.
items.reserve(n);
77 beast::IP::AddressV4::bytes_type d = {
80 gossip.
items.push_back(item);
106 std::placeholders::_1);
119 fail(
"Loop count exceeded without warning");
130 fail(
"Should loop forever with no warning");
142 fail(
"Loop count exceeded without dropping");
165 fail(
"Dropped consumer not put on blacklist");
173 bool readmitted =
false;
175 using namespace std::chrono_literals;
191 if (readmitted ==
false)
193 fail(
"Dropped Consumer left on blacklist too long");
208 for (
int i = 0; i < 5; ++i)
211 for (
int i = 0; i < 5; ++i)
227 beast::IP::AddressV4::bytes_type d = {{192, 0, 2, 1}};
229 g.
items.push_back(item);
251 for (
int i = 0; i < 128; ++i)
253 JLOG(j.
info()) <<
"Time= "
254 << logic.
clock().
now().time_since_epoch().count()
255 <<
", Balance = " << c.
balance();
267 for (
int i = 0; i < 128; ++i)
270 JLOG(j.
info()) <<
"Time= "
271 << logic.
clock().
now().time_since_epoch().count()
272 <<
", Balance = " << c.
balance();
294BEAST_DEFINE_TESTSUITE(ResourceManager, resource,
ripple);
A version-independent IP address and port combination.
static Endpoint from_string(std::string const &s)
A generic endpoint for log messages.
time_point now() const override
Returns the current time.
void pass()
Record a successful test condition.
testcase_t testcase
Memberspace for declaring test cases.
void fail(String const &reason, char const *file, int line)
Record a failure.
An endpoint that consumes resources.
int balance()
Returns the credit balance representing consumption.
std::string to_string() const
Return a human readable string uniquely identifying this consumer.
bool disconnect(beast::Journal const &j)
Returns true if the consumer should be disconnected.
Disposition charge(Charge const &fee, std::string const &context={})
Apply a load charge to the consumer.
Disposition disposition() const
Returns the current disposition of this consumer.
Consumer newInboundEndpoint(beast::IP::Endpoint const &address)
void importConsumers(std::string const &origin, Gossip const &gossip)
Consumer newUnlimitedEndpoint(beast::IP::Endpoint const &address)
Create endpoint that should not have resource limits applied.
TestLogic(beast::Journal journal)
boost::base_from_member< TestStopwatch > clock_type
void testDrop(beast::Journal j, bool limited)
void testImport(beast::Journal j)
void run() override
Runs the suite.
void createGossip(Gossip &gossip)
void testCharges(beast::Journal j)
void testImports(beast::Journal j)
boost::asio::ip::address_v4 AddressV4
A namespace for easy access to logging severity values.
@ warn
Consumer should be disconnected for excess consumption.
std::chrono::seconds constexpr secondsUntilExpiration
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::enable_if_t< std::is_integral< Integral >::value, Integral > rand_int()
Describes a single consumer.
beast::IP::Endpoint address
Data format for exchanging consumption information across peers.
std::vector< Item > items