diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/test/mgr/test_ttlcache.cc | |
parent | Initial commit. (diff) | |
download | ceph-b26c4052f3542036551aa9dec9caa4226e456195.tar.xz ceph-b26c4052f3542036551aa9dec9caa4226e456195.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/mgr/test_ttlcache.cc')
-rw-r--r-- | src/test/mgr/test_ttlcache.cc | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/test/mgr/test_ttlcache.cc b/src/test/mgr/test_ttlcache.cc new file mode 100644 index 000000000..a1ee0a862 --- /dev/null +++ b/src/test/mgr/test_ttlcache.cc @@ -0,0 +1,70 @@ +#include <iostream> + +#include "mgr/TTLCache.h" +#include "gtest/gtest.h" + +using namespace std; + +TEST(TTLCache, Get) { + TTLCache<string, int> c{100}; + c.insert("foo", 1); + int foo = c.get("foo"); + ASSERT_EQ(foo, 1); +} + +TEST(TTLCache, Erase) { + TTLCache<string, int> c{100}; + c.insert("foo", 1); + int foo = c.get("foo"); + ASSERT_EQ(foo, 1); + c.erase("foo"); + try{ + foo = c.get("foo"); + FAIL(); + } catch (std::out_of_range& e) { + SUCCEED(); + } +} + +TEST(TTLCache, Clear) { + TTLCache<string, int> c{100}; + c.insert("foo", 1); + c.insert("foo2", 2); + c.clear(); + ASSERT_FALSE(c.size()); +} + +TEST(TTLCache, NoTTL) { + TTLCache<string, int> c{100}; + c.insert("foo", 1); + int foo = c.get("foo"); + ASSERT_EQ(foo, 1); + c.set_ttl(0); + c.insert("foo2", 2); + try{ + foo = c.get("foo2"); + FAIL(); + } catch (std::out_of_range& e) { + SUCCEED(); + } +} + +TEST(TTLCache, SizeLimit) { + TTLCache<string, int> c{100, 2}; + c.insert("foo", 1); + c.insert("foo2", 2); + c.insert("foo3", 3); + ASSERT_EQ(c.size(), 2); +} + +TEST(TTLCache, HitRatio) { + TTLCache<string, int> c{100}; + c.insert("foo", 1); + c.insert("foo2", 2); + c.insert("foo3", 3); + c.get("foo2"); + c.get("foo3"); + std::pair<uint64_t, uint64_t> hit_miss_ratio = c.get_hit_miss_ratio(); + ASSERT_EQ(std::get<1>(hit_miss_ratio), 3); + ASSERT_EQ(std::get<0>(hit_miss_ratio), 2); +} |