add a new test case

This commit is contained in:
lgbo-ustc 2021-12-29 15:38:58 +08:00 committed by liangjiabiao
parent 5f85f77266
commit 0d474069b5

View File

@ -115,6 +115,38 @@ TEST(LRUResourceCache, evict_on_weight_v2)
ASSERT_TRUE(val != nullptr);
}
TEST(LRUResourceCache, evict_on_weight_v3)
{
using MyCache = DB::LRUResourceCache<int, int, MyWeight>;
auto mcache = MyCache(5, 10);
int x = 2;
auto load_int = [&] { return std::make_shared<int>(x); };
auto val = mcache.acquire(1, load_int);
mcache.release(1);
val = mcache.acquire(2, load_int);
mcache.release(2);
val = mcache.acquire(1, load_int);
mcache.release(1);
x = 3;
val = mcache.acquire(3, load_int);
ASSERT_TRUE(val != nullptr);
auto w = mcache.weight();
ASSERT_EQ(w, 5);
auto n = mcache.size();
ASSERT_EQ(n, 2);
val = mcache.acquire(1);
ASSERT_TRUE(val != nullptr);
val = mcache.acquire(2);
ASSERT_TRUE(val == nullptr);
val = mcache.acquire(3);
ASSERT_TRUE(val != nullptr);
}
TEST(LRUResourceCache, evict_on_size)
{
using MyCache = DB::LRUResourceCache<int, int>;