1#include <test/unit_test/SuiteJournal.h>
3#include <xrpl/basics/chrono.h>
4#include <xrpl/basics/random.h>
5#include <xrpl/beast/unit_test.h>
6#include <xrpl/resource/Consumer.h>
7#include <xrpl/resource/detail/Entry.h>
8#include <xrpl/resource/detail/Logic.h>
10#include <boost/utility/base_from_member.hpp>
20 class TestLogic :
private boost::base_from_member<TestStopwatch>,
public Logic
24 using clock_type = boost::base_from_member<TestStopwatch>;
28 :
Logic(
beast::insight::NullCollector::New(), member, journal)
52 gossip.
items.reserve(n);
57 beast::IP::AddressV4::bytes_type
const d = {
60 gossip.
items.push_back(item);
99 fail(
"Loop count exceeded without warning");
116 fail(
"Should loop forever with no warning");
130 fail(
"Loop count exceeded without dropping");
157 fail(
"Dropped consumer not put on blacklist");
168 bool readmitted =
false;
170 using namespace std::chrono_literals;
188 fail(
"Dropped Consumer left on blacklist too long");
203 for (
int i = 0; i < 5; ++i)
206 for (
int i = 0; i < 5; ++i)
222 beast::IP::AddressV4::bytes_type
const d = {{192, 0, 2, 1}};
224 g.
items.push_back(item);
242 JLOG(j.
info()) <<
"Charging " << c.
to_string() <<
" " << fee <<
" per second";
244 for (
int i = 0; i < 128; ++i)
246 JLOG(j.
info()) <<
"Time= " << logic.
clock().
now().time_since_epoch().count()
247 <<
", Balance = " << c.
balance();
256 JLOG(j.
info()) <<
"Charging " << c.
to_string() <<
" " << fee <<
" per second";
257 for (
int i = 0; i < 128; ++i)
260 JLOG(j.
info()) <<
"Time= " << logic.
clock().
now().time_since_epoch().count()
261 <<
", Balance = " << c.
balance();
283BEAST_DEFINE_TESTSUITE(ResourceManager, resource,
xrpl);
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.
bool disconnect(beast::Journal const &j)
Returns true if the consumer should be disconnected.
Disposition disposition() const
Returns the current disposition of this consumer.
std::string to_string() const
Return a human readable string uniquely identifying this consumer.
int balance()
Returns the credit balance representing consumption.
Disposition charge(Charge const &fee, std::string const &context={})
Apply a load charge to the consumer.
Consumer newInboundEndpoint(beast::IP::Endpoint const &address)
Consumer newUnlimitedEndpoint(beast::IP::Endpoint const &address)
Create endpoint that should not have resource limits applied.
void importConsumers(std::string const &origin, Gossip const &gossip)
TestLogic(beast::Journal journal)
boost::base_from_member< TestStopwatch > clock_type
void testImport(beast::Journal j)
void testCharges(beast::Journal j)
void run() override
Runs the suite.
static void createGossip(Gossip &gossip)
void testImports(beast::Journal j)
void testDrop(beast::Journal j, bool limited)
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