mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Format first-party source according to .clang-format
This commit is contained in:
committed by
manojsdoshi
parent
65dfc5d19e
commit
50760c6935
@@ -17,81 +17,82 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/basics/chrono.h>
|
||||
#include <ripple/basics/KeyCache.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <ripple/basics/chrono.h>
|
||||
#include <ripple/beast/clock/manual_clock.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
class KeyCache_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void run () override
|
||||
void
|
||||
run() override
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
TestStopwatch clock;
|
||||
clock.set (0);
|
||||
clock.set(0);
|
||||
|
||||
using Key = std::string;
|
||||
using Cache = KeyCache <Key>;
|
||||
using Cache = KeyCache<Key>;
|
||||
|
||||
// Insert an item, retrieve it, and age it so it gets purged.
|
||||
{
|
||||
Cache c ("test", clock, 1, 2s);
|
||||
Cache c("test", clock, 1, 2s);
|
||||
|
||||
BEAST_EXPECT(c.size () == 0);
|
||||
BEAST_EXPECT(c.insert ("one"));
|
||||
BEAST_EXPECT(! c.insert ("one"));
|
||||
BEAST_EXPECT(c.size () == 1);
|
||||
BEAST_EXPECT(c.exists ("one"));
|
||||
BEAST_EXPECT(c.touch_if_exists ("one"));
|
||||
BEAST_EXPECT(c.size() == 0);
|
||||
BEAST_EXPECT(c.insert("one"));
|
||||
BEAST_EXPECT(!c.insert("one"));
|
||||
BEAST_EXPECT(c.size() == 1);
|
||||
BEAST_EXPECT(c.exists("one"));
|
||||
BEAST_EXPECT(c.touch_if_exists("one"));
|
||||
++clock;
|
||||
c.sweep ();
|
||||
BEAST_EXPECT(c.size () == 1);
|
||||
BEAST_EXPECT(c.exists ("one"));
|
||||
c.sweep();
|
||||
BEAST_EXPECT(c.size() == 1);
|
||||
BEAST_EXPECT(c.exists("one"));
|
||||
++clock;
|
||||
c.sweep ();
|
||||
BEAST_EXPECT(c.size () == 0);
|
||||
BEAST_EXPECT(! c.exists ("one"));
|
||||
BEAST_EXPECT(! c.touch_if_exists ("one"));
|
||||
c.sweep();
|
||||
BEAST_EXPECT(c.size() == 0);
|
||||
BEAST_EXPECT(!c.exists("one"));
|
||||
BEAST_EXPECT(!c.touch_if_exists("one"));
|
||||
}
|
||||
|
||||
// Insert two items, have one expire
|
||||
{
|
||||
Cache c ("test", clock, 2, 2s);
|
||||
Cache c("test", clock, 2, 2s);
|
||||
|
||||
BEAST_EXPECT(c.insert ("one"));
|
||||
BEAST_EXPECT(c.size () == 1);
|
||||
BEAST_EXPECT(c.insert ("two"));
|
||||
BEAST_EXPECT(c.size () == 2);
|
||||
BEAST_EXPECT(c.insert("one"));
|
||||
BEAST_EXPECT(c.size() == 1);
|
||||
BEAST_EXPECT(c.insert("two"));
|
||||
BEAST_EXPECT(c.size() == 2);
|
||||
++clock;
|
||||
c.sweep ();
|
||||
BEAST_EXPECT(c.size () == 2);
|
||||
BEAST_EXPECT(c.touch_if_exists ("two"));
|
||||
c.sweep();
|
||||
BEAST_EXPECT(c.size() == 2);
|
||||
BEAST_EXPECT(c.touch_if_exists("two"));
|
||||
++clock;
|
||||
c.sweep ();
|
||||
BEAST_EXPECT(c.size () == 1);
|
||||
BEAST_EXPECT(c.exists ("two"));
|
||||
c.sweep();
|
||||
BEAST_EXPECT(c.size() == 1);
|
||||
BEAST_EXPECT(c.exists("two"));
|
||||
}
|
||||
|
||||
// Insert three items (1 over limit), sweep
|
||||
{
|
||||
Cache c ("test", clock, 2, 3s);
|
||||
Cache c("test", clock, 2, 3s);
|
||||
|
||||
BEAST_EXPECT(c.insert ("one"));
|
||||
BEAST_EXPECT(c.insert("one"));
|
||||
++clock;
|
||||
BEAST_EXPECT(c.insert ("two"));
|
||||
BEAST_EXPECT(c.insert("two"));
|
||||
++clock;
|
||||
BEAST_EXPECT(c.insert ("three"));
|
||||
BEAST_EXPECT(c.insert("three"));
|
||||
++clock;
|
||||
BEAST_EXPECT(c.size () == 3);
|
||||
c.sweep ();
|
||||
BEAST_EXPECT(c.size () < 3);
|
||||
BEAST_EXPECT(c.size() == 3);
|
||||
c.sweep();
|
||||
BEAST_EXPECT(c.size() < 3);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(KeyCache,common,ripple);
|
||||
BEAST_DEFINE_TESTSUITE(KeyCache, common, ripple);
|
||||
|
||||
}
|
||||
} // namespace ripple
|
||||
|
||||
Reference in New Issue
Block a user