mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-28 06:55:50 +00:00
Add validators aged container test
This commit is contained in:
@@ -3573,6 +3573,9 @@
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\validators\Source.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\ripple\validators\tests\Validators.test.cpp">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\ripple\validators\Types.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\db\builder.cc">
|
||||
@@ -3936,6 +3939,57 @@
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\rocksdb\third-party\rapidjson\reader.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\backupable\backupable_db.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\document\document_db.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\document\json_document.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\geodb\geodb_impl.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\geodb\geodb_impl.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\merge_operators.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\merge_operators\put.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\merge_operators\string_append\stringappend.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\merge_operators\string_append\stringappend.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\merge_operators\string_append\stringappend2.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\merge_operators\string_append\stringappend2.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\merge_operators\uint64add.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\redis\redis_lists.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\redis\redis_lists.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\redis\redis_list_exception.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\redis\redis_list_iterator.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\spatialdb\spatial_db.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\spatialdb\utils.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\ttl\db_ttl_impl.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\ttl\db_ttl_impl.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\util\arena.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
@@ -4109,57 +4163,6 @@
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\util\xxhash.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\backupable\backupable_db.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\document\document_db.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\document\json_document.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\geodb\geodb_impl.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\geodb\geodb_impl.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\merge_operators.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\merge_operators\put.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\merge_operators\string_append\stringappend.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\merge_operators\string_append\stringappend.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\merge_operators\string_append\stringappend2.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\merge_operators\string_append\stringappend2.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\merge_operators\uint64add.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\redis\redis_lists.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\redis\redis_lists.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\redis\redis_list_exception.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\redis\redis_list_iterator.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\spatialdb\spatial_db.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\spatialdb\utils.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\ttl\db_ttl_impl.cc">
|
||||
<ExcludedFromBuild>True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\ttl\db_ttl_impl.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\snappy\config\snappy-stubs-public.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\snappy\snappy\snappy-internal.h">
|
||||
|
||||
@@ -541,6 +541,9 @@
|
||||
<Filter Include="ripple\validators\impl">
|
||||
<UniqueIdentifier>{3D1F0CBE-9B69-D29E-EAAE-E5A1204068BC}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="ripple\validators\tests">
|
||||
<UniqueIdentifier>{663AE0EE-6781-C2F4-8D04-0D5D30AC0773}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="rocksdb">
|
||||
<UniqueIdentifier>{A6DBE85A-1595-E8FB-25F1-D5A133237168}</UniqueIdentifier>
|
||||
</Filter>
|
||||
@@ -4935,6 +4938,9 @@
|
||||
<ClInclude Include="..\..\src\ripple\validators\Source.h">
|
||||
<Filter>ripple\validators</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\ripple\validators\tests\Validators.test.cpp">
|
||||
<Filter>ripple\validators\tests</Filter>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\ripple\validators\Types.h">
|
||||
<Filter>ripple\validators</Filter>
|
||||
</ClInclude>
|
||||
@@ -5397,6 +5403,66 @@
|
||||
<ClInclude Include="..\..\src\rocksdb\third-party\rapidjson\reader.h">
|
||||
<Filter>rocksdb\third-party\rapidjson</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\backupable\backupable_db.cc">
|
||||
<Filter>rocksdb\utilities\backupable</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\document\document_db.cc">
|
||||
<Filter>rocksdb\utilities\document</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\document\json_document.cc">
|
||||
<Filter>rocksdb\utilities\document</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\geodb\geodb_impl.cc">
|
||||
<Filter>rocksdb\utilities\geodb</Filter>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\geodb\geodb_impl.h">
|
||||
<Filter>rocksdb\utilities\geodb</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\merge_operators.h">
|
||||
<Filter>rocksdb\utilities</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\merge_operators\put.cc">
|
||||
<Filter>rocksdb\utilities\merge_operators</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\merge_operators\string_append\stringappend.cc">
|
||||
<Filter>rocksdb\utilities\merge_operators\string_append</Filter>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\merge_operators\string_append\stringappend.h">
|
||||
<Filter>rocksdb\utilities\merge_operators\string_append</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\merge_operators\string_append\stringappend2.cc">
|
||||
<Filter>rocksdb\utilities\merge_operators\string_append</Filter>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\merge_operators\string_append\stringappend2.h">
|
||||
<Filter>rocksdb\utilities\merge_operators\string_append</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\merge_operators\uint64add.cc">
|
||||
<Filter>rocksdb\utilities\merge_operators</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\redis\redis_lists.cc">
|
||||
<Filter>rocksdb\utilities\redis</Filter>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\redis\redis_lists.h">
|
||||
<Filter>rocksdb\utilities\redis</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\redis\redis_list_exception.h">
|
||||
<Filter>rocksdb\utilities\redis</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\redis\redis_list_iterator.h">
|
||||
<Filter>rocksdb\utilities\redis</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\spatialdb\spatial_db.cc">
|
||||
<Filter>rocksdb\utilities\spatialdb</Filter>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\spatialdb\utils.h">
|
||||
<Filter>rocksdb\utilities\spatialdb</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\ttl\db_ttl_impl.cc">
|
||||
<Filter>rocksdb\utilities\ttl</Filter>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\ttl\db_ttl_impl.h">
|
||||
<Filter>rocksdb\utilities\ttl</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\util\arena.cc">
|
||||
<Filter>rocksdb\util</Filter>
|
||||
</ClCompile>
|
||||
@@ -5601,66 +5667,6 @@
|
||||
<ClInclude Include="..\..\src\rocksdb\util\xxhash.h">
|
||||
<Filter>rocksdb\util</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\backupable\backupable_db.cc">
|
||||
<Filter>rocksdb\utilities\backupable</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\document\document_db.cc">
|
||||
<Filter>rocksdb\utilities\document</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\document\json_document.cc">
|
||||
<Filter>rocksdb\utilities\document</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\geodb\geodb_impl.cc">
|
||||
<Filter>rocksdb\utilities\geodb</Filter>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\geodb\geodb_impl.h">
|
||||
<Filter>rocksdb\utilities\geodb</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\merge_operators.h">
|
||||
<Filter>rocksdb\utilities</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\merge_operators\put.cc">
|
||||
<Filter>rocksdb\utilities\merge_operators</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\merge_operators\string_append\stringappend.cc">
|
||||
<Filter>rocksdb\utilities\merge_operators\string_append</Filter>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\merge_operators\string_append\stringappend.h">
|
||||
<Filter>rocksdb\utilities\merge_operators\string_append</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\merge_operators\string_append\stringappend2.cc">
|
||||
<Filter>rocksdb\utilities\merge_operators\string_append</Filter>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\merge_operators\string_append\stringappend2.h">
|
||||
<Filter>rocksdb\utilities\merge_operators\string_append</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\merge_operators\uint64add.cc">
|
||||
<Filter>rocksdb\utilities\merge_operators</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\redis\redis_lists.cc">
|
||||
<Filter>rocksdb\utilities\redis</Filter>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\redis\redis_lists.h">
|
||||
<Filter>rocksdb\utilities\redis</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\redis\redis_list_exception.h">
|
||||
<Filter>rocksdb\utilities\redis</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\redis\redis_list_iterator.h">
|
||||
<Filter>rocksdb\utilities\redis</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\spatialdb\spatial_db.cc">
|
||||
<Filter>rocksdb\utilities\spatialdb</Filter>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\spatialdb\utils.h">
|
||||
<Filter>rocksdb\utilities\spatialdb</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\rocksdb\utilities\ttl\db_ttl_impl.cc">
|
||||
<Filter>rocksdb\utilities\ttl</Filter>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\rocksdb\utilities\ttl\db_ttl_impl.h">
|
||||
<Filter>rocksdb\utilities\ttl</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\snappy\config\snappy-stubs-public.h">
|
||||
<Filter>snappy\config</Filter>
|
||||
</ClInclude>
|
||||
|
||||
@@ -59,4 +59,4 @@
|
||||
#include <ripple/validators/impl/Tests.cpp>
|
||||
#include <ripple/validators/impl/Utilities.cpp>
|
||||
|
||||
//#include <ripple/validators/tests/validator.test.cpp>
|
||||
#include <ripple/validators/tests/Validators.test.cpp>
|
||||
|
||||
@@ -43,10 +43,8 @@ private:
|
||||
// Holds the Entry of all recent ledgers for this validator.
|
||||
#if 1
|
||||
typedef beast::aged_unordered_map <RippleLedgerHash, Entry,
|
||||
std::chrono::seconds,
|
||||
//beast::hardened_hash<>,
|
||||
std::hash<RippleLedgerHash>,
|
||||
RippleLedgerHash::key_equal> Table;
|
||||
std::chrono::seconds, beast::hardened_hash<>,
|
||||
RippleLedgerHash::key_equal> Table;
|
||||
#else
|
||||
typedef beast::aged_map <RippleLedgerHash, Entry,
|
||||
std::chrono::seconds, std::less<>> Table;
|
||||
@@ -97,6 +95,7 @@ public:
|
||||
void
|
||||
on_validation (RippleLedgerHash const& ledgerHash)
|
||||
{
|
||||
//expire();
|
||||
auto const result (table_.insert (
|
||||
std::make_pair (ledgerHash, Entry())));
|
||||
auto& entry (result.first->second);
|
||||
@@ -107,19 +106,19 @@ public:
|
||||
{
|
||||
--count_.expected;
|
||||
++count_.closed;
|
||||
//table_.erase (result.first);
|
||||
table_.erase (result.first);
|
||||
}
|
||||
else
|
||||
{
|
||||
++count_.received;
|
||||
}
|
||||
//expire();
|
||||
}
|
||||
|
||||
/** Called when a ledger is closed. */
|
||||
void
|
||||
on_ledger (RippleLedgerHash const& ledgerHash)
|
||||
{
|
||||
//expire();
|
||||
auto const result (table_.insert (
|
||||
std::make_pair (ledgerHash, Entry())));
|
||||
auto& entry (result.first->second);
|
||||
@@ -130,13 +129,12 @@ public:
|
||||
{
|
||||
--count_.received;
|
||||
++count_.closed;
|
||||
//table_.erase (result.first);
|
||||
table_.erase (result.first);
|
||||
}
|
||||
else
|
||||
{
|
||||
++count_.expected;
|
||||
}
|
||||
//expire();
|
||||
}
|
||||
|
||||
/** Prunes old entries. */
|
||||
@@ -145,22 +143,6 @@ public:
|
||||
{
|
||||
beast::expire (table_, std::chrono::minutes(5));
|
||||
}
|
||||
|
||||
private:
|
||||
void dump ()
|
||||
{
|
||||
std::cout << "Validator: " << this << std::endl;
|
||||
std::cout << "Size: " << table_.size() << std::endl;
|
||||
std::cout << "end at: " << &(*table_.end()) << std::endl;
|
||||
for (auto const& ledgerKeyAndState : table_)
|
||||
{
|
||||
std::cout << "keyAndState at: " << &ledgerKeyAndState.first << std::endl;
|
||||
std::cout << " Hash: " << ledgerKeyAndState.first << std::endl;
|
||||
std::cout << " closed: " << ledgerKeyAndState.second.closed <<
|
||||
" received: " << ledgerKeyAndState.second.received <<
|
||||
std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
127
src/ripple/validators/tests/Validators.test.cpp
Normal file
127
src/ripple/validators/tests/Validators.test.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/common/seconds_clock.h>
|
||||
#include <ripple/types/api/RippleLedgerHash.h>
|
||||
#include <beast/container/aged_unordered_map.h>
|
||||
#include <random>
|
||||
#include <utility>
|
||||
|
||||
namespace ripple {
|
||||
namespace Validators {
|
||||
|
||||
class Validators_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
struct Entry
|
||||
{
|
||||
bool closed = false; // `true` if the ledger was closed
|
||||
bool received = false; // `true` if we got a validation
|
||||
};
|
||||
|
||||
typedef beast::aged_unordered_map <RippleLedgerHash, Entry,
|
||||
std::chrono::seconds, beast::hardened_hash<>,
|
||||
RippleLedgerHash::key_equal> Table;
|
||||
|
||||
template <class Gen>
|
||||
static
|
||||
void
|
||||
fillrand (void* buffer, std::size_t bytes, Gen& gen)
|
||||
{
|
||||
auto p = reinterpret_cast<std::uint8_t*>(buffer);
|
||||
typedef typename Gen::result_type result_type;
|
||||
while (bytes >= sizeof(result_type))
|
||||
{
|
||||
*reinterpret_cast<result_type*>(p) = gen();
|
||||
p += sizeof(result_type);
|
||||
bytes -= sizeof(result_type);
|
||||
}
|
||||
if (bytes > 0)
|
||||
{
|
||||
auto const v = gen();
|
||||
memcpy (p, &v, bytes);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
test_aged_insert()
|
||||
{
|
||||
testcase ("aged insert");
|
||||
std::random_device rng;
|
||||
std::mt19937_64 gen {rng()};
|
||||
Table table (get_seconds_clock());
|
||||
for (int i = 0; i < 10000; ++i)
|
||||
{
|
||||
std::array <std::uint8_t, RippleLedgerHash::size> buf;
|
||||
fillrand (buf.data(), buf.size(), gen);
|
||||
RippleLedgerHash h (buf.data(), buf.data() + buf.size());
|
||||
auto const result (table.insert (std::make_pair (h, Entry())));
|
||||
}
|
||||
pass();
|
||||
}
|
||||
|
||||
void
|
||||
test_Validators()
|
||||
{
|
||||
int const N (5);
|
||||
testcase ("Validators");
|
||||
typedef hardened_hash_map <int, Validator> Validators;
|
||||
Validators vv;
|
||||
for (int i = 0; i < N; ++i)
|
||||
vv.emplace (i, Validator{});
|
||||
std::random_device rng;
|
||||
std::mt19937_64 gen {rng()};
|
||||
std::array <std::uint8_t, RippleLedgerHash::size> buf;
|
||||
fillrand (buf.data(), buf.size(), gen);
|
||||
for (int i = 0; i < 100000; ++i)
|
||||
{
|
||||
// maybe change the ledger hash
|
||||
if ((gen() % 20) == 0)
|
||||
fillrand (buf.data(), buf.size(), gen);
|
||||
RippleLedgerHash h (buf.data(), buf.data() + buf.size());
|
||||
// choose random validator
|
||||
Validator& v (vv[gen() % vv.size()]);
|
||||
// choose random operation
|
||||
//int const choice = gen() % 2;
|
||||
int const choice = 1;
|
||||
switch (choice)
|
||||
{
|
||||
case 0:
|
||||
v.on_ledger(h);
|
||||
break;
|
||||
case 1:
|
||||
v.on_validation(h);
|
||||
break;
|
||||
};
|
||||
}
|
||||
pass();
|
||||
}
|
||||
|
||||
void
|
||||
run ()
|
||||
{
|
||||
test_aged_insert();
|
||||
test_Validators();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(Validators,validators,ripple);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user