20#include <test/unit_test/SuiteJournal.h>
21#include <xrpl/basics/chrono.h>
22#include <xrpl/basics/random.h>
23#include <xrpl/beast/unit_test.h>
24#include <xrpl/resource/Consumer.h>
25#include <xrpl/resource/detail/Entry.h>
26#include <xrpl/resource/detail/Logic.h>
28#include <boost/utility/base_from_member.hpp>
38 class TestLogic :
private boost::base_from_member<TestStopwatch>,
43 using clock_type = boost::base_from_member<TestStopwatch>;
47 :
Logic(
beast::insight::NullCollector::New(), member, journal)
71 gossip.
items.reserve(n);
76 beast::IP::AddressV4::bytes_type d = {
79 gossip.
items.push_back(item);
105 std::placeholders::_1);
118 fail(
"Loop count exceeded without warning");
129 fail(
"Should loop forever with no warning");
141 fail(
"Loop count exceeded without dropping");
164 fail(
"Dropped consumer not put on blacklist");
172 bool readmitted =
false;
174 using namespace std::chrono_literals;
190 if (readmitted ==
false)
192 fail(
"Dropped Consumer left on blacklist too long");
207 for (
int i = 0; i < 5; ++i)
210 for (
int i = 0; i < 5; ++i)
226 beast::IP::AddressV4::bytes_type d = {{192, 0, 2, 1}};
228 g.
items.push_back(item);
250 for (
int i = 0; i < 128; ++i)
252 JLOG(j.
info()) <<
"Time= "
253 << logic.
clock().
now().time_since_epoch().count()
254 <<
", Balance = " << c.
balance();
266 for (
int i = 0; i < 128; ++i)
269 JLOG(j.
info()) <<
"Time= "
270 << logic.
clock().
now().time_since_epoch().count()
271 <<
", Balance = " << c.
balance();
293BEAST_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