mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Skip List unit test (RIPD-926)
This commit is contained in:
committed by
Vinnie Falco
parent
70ccdabf7c
commit
8d1b169f5a
@@ -2365,6 +2365,10 @@
|
|||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\ripple\ledger\tests\SkipList_test.cpp">
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\ripple\ledger\tests\View_test.cpp">
|
<ClCompile Include="..\..\src\ripple\ledger\tests\View_test.cpp">
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
||||||
|
|||||||
@@ -3096,6 +3096,9 @@
|
|||||||
<ClCompile Include="..\..\src\ripple\ledger\tests\PaymentSandbox_test.cpp">
|
<ClCompile Include="..\..\src\ripple\ledger\tests\PaymentSandbox_test.cpp">
|
||||||
<Filter>ripple\ledger\tests</Filter>
|
<Filter>ripple\ledger\tests</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\ripple\ledger\tests\SkipList_test.cpp">
|
||||||
|
<Filter>ripple\ledger\tests</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\ripple\ledger\tests\View_test.cpp">
|
<ClCompile Include="..\..\src\ripple\ledger\tests\View_test.cpp">
|
||||||
<Filter>ripple\ledger\tests</Filter>
|
<Filter>ripple\ledger\tests</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|||||||
112
src/ripple/ledger/tests/SkipList_test.cpp
Normal file
112
src/ripple/ledger/tests/SkipList_test.cpp
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
This file is part of rippled: https://github.com/ripple/rippled
|
||||||
|
Copyright (c) 2012, 2015 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 <BeastConfig.h>
|
||||||
|
#include <ripple/app/ledger/Ledger.h>
|
||||||
|
#include <ripple/ledger/View.h>
|
||||||
|
#include <ripple/basics/Log.h>
|
||||||
|
#include <beast/unit_test/suite.h>
|
||||||
|
|
||||||
|
namespace ripple {
|
||||||
|
namespace test {
|
||||||
|
|
||||||
|
class SkipList_test : public beast::unit_test::suite
|
||||||
|
{
|
||||||
|
void
|
||||||
|
testSkipList()
|
||||||
|
{
|
||||||
|
beast::Journal const j;
|
||||||
|
std::vector<std::shared_ptr<Ledger>> history;
|
||||||
|
{
|
||||||
|
Config const config;
|
||||||
|
auto prev =
|
||||||
|
std::make_shared<Ledger>(create_genesis, config);
|
||||||
|
history.push_back(prev);
|
||||||
|
for (auto i = 0; i < 1023; ++i)
|
||||||
|
{
|
||||||
|
auto next = std::make_shared<Ledger>(
|
||||||
|
open_ledger, *prev);
|
||||||
|
next->updateSkipList();
|
||||||
|
next->setClosed();
|
||||||
|
history.push_back(next);
|
||||||
|
prev = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto l = *(std::next(std::begin(history)));
|
||||||
|
expect((*std::begin(history))->info().seq <
|
||||||
|
l->info().seq);
|
||||||
|
expect(hashOfSeq(*l, l->info().seq + 1,
|
||||||
|
j) == boost::none);
|
||||||
|
expect(hashOfSeq(*l, l->info().seq,
|
||||||
|
j) == l->info().hash);
|
||||||
|
expect(hashOfSeq(*l, l->info().seq - 1,
|
||||||
|
j) == l->info().parentHash);
|
||||||
|
expect(hashOfSeq(*history.back(),
|
||||||
|
l->info().seq, j) == boost::none);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ledger skip lists store up to the previous 256 hashes
|
||||||
|
for (auto i = history.crbegin();
|
||||||
|
i != history.crend(); i += 256)
|
||||||
|
{
|
||||||
|
for (auto n = i;
|
||||||
|
n != std::next(i,
|
||||||
|
(*i)->info().seq - 256 > 1 ? 257 : 256);
|
||||||
|
++n)
|
||||||
|
{
|
||||||
|
expect(hashOfSeq(**i,
|
||||||
|
(*n)->info().seq, j) ==
|
||||||
|
(*n)->info().hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
// edge case accessing beyond 256
|
||||||
|
expect(hashOfSeq(**i,
|
||||||
|
(*i)->info().seq - 258, j) ==
|
||||||
|
boost::none);
|
||||||
|
}
|
||||||
|
|
||||||
|
// every 256th hash beyond the first 256 is stored
|
||||||
|
for (auto i = history.crbegin();
|
||||||
|
i != std::next(history.crend(), -512);
|
||||||
|
i += 256)
|
||||||
|
{
|
||||||
|
for (auto n = std::next(i, 512);
|
||||||
|
n != history.crend();
|
||||||
|
n += 256)
|
||||||
|
{
|
||||||
|
expect(hashOfSeq(**i,
|
||||||
|
(*n)->info().seq, j) ==
|
||||||
|
(*n)->info().hash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void run()
|
||||||
|
{
|
||||||
|
LogSquelcher l;
|
||||||
|
testSkipList();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
BEAST_DEFINE_TESTSUITE(SkipList,ledger,ripple);
|
||||||
|
|
||||||
|
} // test
|
||||||
|
} // ripple
|
||||||
@@ -31,6 +31,7 @@
|
|||||||
#include <ripple/ledger/impl/TxMeta.cpp>
|
#include <ripple/ledger/impl/TxMeta.cpp>
|
||||||
#include <ripple/ledger/impl/View.cpp>
|
#include <ripple/ledger/impl/View.cpp>
|
||||||
|
|
||||||
#include <ripple/ledger/tests/PaymentSandbox_test.cpp>
|
|
||||||
#include <ripple/ledger/tests/View_test.cpp>
|
|
||||||
#include <ripple/ledger/tests/Directory_test.cpp>
|
#include <ripple/ledger/tests/Directory_test.cpp>
|
||||||
|
#include <ripple/ledger/tests/PaymentSandbox_test.cpp>
|
||||||
|
#include <ripple/ledger/tests/SkipList_test.cpp>
|
||||||
|
#include <ripple/ledger/tests/View_test.cpp>
|
||||||
|
|||||||
Reference in New Issue
Block a user