aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/cache/ut
diff options
context:
space:
mode:
authorarcadia-devtools <arcadia-devtools@yandex-team.ru>2022-02-18 16:35:49 +0300
committerarcadia-devtools <arcadia-devtools@yandex-team.ru>2022-02-18 16:35:49 +0300
commitedefa564e11987d4aa60fff0a2378785deb03b54 (patch)
tree66e32a4d0284fb784a73d76f5531b708cd72be44 /library/cpp/cache/ut
parent04182a7d083f485a3364f570da83470e580c78ac (diff)
downloadydb-edefa564e11987d4aa60fff0a2378785deb03b54.tar.gz
intermediate changes
ref:5a427ceffcbeddcbaed23c62818445bd98632b96
Diffstat (limited to 'library/cpp/cache/ut')
-rw-r--r--library/cpp/cache/ut/cache_ut.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/library/cpp/cache/ut/cache_ut.cpp b/library/cpp/cache/ut/cache_ut.cpp
index 329872cfde..33731988c1 100644
--- a/library/cpp/cache/ut/cache_ut.cpp
+++ b/library/cpp/cache/ut/cache_ut.cpp
@@ -355,6 +355,54 @@ Y_UNIT_TEST_SUITE(TCacheTest) {
s.Insert(3, "789");
UNIT_ASSERT(s.Find(1) != s.End()); // Key 2 should have been deleted
}
+
+ class TMoveOnlyInt {
+ public:
+ ui32 Value = 0;
+
+ explicit TMoveOnlyInt(ui32 value = 0) : Value(value) {}
+ TMoveOnlyInt(TMoveOnlyInt&&) = default;
+ TMoveOnlyInt& operator=(TMoveOnlyInt&&) = default;
+
+ TMoveOnlyInt(const TMoveOnlyInt&) = delete;
+ TMoveOnlyInt& operator=(const TMoveOnlyInt&) = delete;
+
+ bool operator==(const TMoveOnlyInt& rhs) const {
+ return Value == rhs.Value;
+ }
+
+ explicit operator size_t() const {
+ return Value;
+ }
+ };
+
+ Y_UNIT_TEST(MoveOnlySimpleTest) {
+ typedef TLRUCache<TMoveOnlyInt, TMoveOnlyInt> TCache;
+ TCache s(2); // size 2
+ s.Insert(TMoveOnlyInt(1), TMoveOnlyInt(0x11111111));
+ TMoveOnlyInt lookup1(1), lookup2(2), lookup3(3);
+ UNIT_ASSERT(s.Find(lookup1) != s.End());
+ UNIT_ASSERT_EQUAL(s.Find(lookup1)->Value, 0x11111111);
+ s.Insert(TMoveOnlyInt(2), TMoveOnlyInt(0x22222222));
+ UNIT_ASSERT(s.GetOldest().Value == 0x11111111);
+ s.Insert(TMoveOnlyInt(3), TMoveOnlyInt(0x33333333));
+ UNIT_ASSERT(s.GetOldest().Value == 0x22222222);
+ // key 1 will be deleted
+ UNIT_ASSERT(s.Find(lookup1) == s.End());
+ UNIT_ASSERT(s.Find(lookup2) != s.End());
+ UNIT_ASSERT(s.Find(lookup2)->Value == 0x22222222);
+ UNIT_ASSERT(s.Find(lookup3) != s.End());
+ UNIT_ASSERT(s.Find(lookup3)->Value == 0x33333333);
+
+ UNIT_ASSERT(!s.Insert(TMoveOnlyInt(3), TMoveOnlyInt(0x11111111)));
+ UNIT_ASSERT(s.Find(lookup3)->Value == 0x33333333);
+ s.Update(TMoveOnlyInt(3), TMoveOnlyInt(0x11111111));
+ UNIT_ASSERT(s.Find(lookup3)->Value == 0x11111111);
+
+ TCache::TIterator it = s.Find(lookup3);
+ s.Erase(it);
+ UNIT_ASSERT(s.Find(lookup3) == s.End());
+ }
}
Y_UNIT_TEST_SUITE(TThreadSafeCacheTest) {