MCPcopy Create free account
hub / github.com/facebook/CacheLib / TEST

Function TEST

cachelib/object_cache/tests/ObjectCacheTest.cpp:2089–2107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2087
2088using ObjectCache = ObjectCache<LruAllocator>;
2089TEST(ObjectCacheTest, LruEviction) {
2090 ObjectCache::Config config;
2091 config.setCacheName("test").setCacheCapacity(1024);
2092 config.setItemDestructor(
2093 [&](ObjectCacheDestructorData data) { data.deleteObject<Foo>(); });
2094 auto objcache = ObjectCache::create(config);
2095
2096 for (int i = 0; i < 1025; i++) {
2097 auto foo = std::make_unique<Foo>();
2098 foo->a = i;
2099 auto key = fmt::format("key_{}", i);
2100 objcache->insertOrReplace(key, std::move(foo));
2101 auto found = objcache->find<Foo>(key);
2102 ASSERT_NE(nullptr, found);
2103 EXPECT_EQ(i, found->a);
2104 }
2105 auto found = objcache->find<Foo>("key_0");
2106 EXPECT_EQ(nullptr, found);
2107}
2108
2109TEST(ObjectCacheTest, LruEvictionWithSizeControl) {
2110 ObjectCache::Config config;

Callers

nothing calls this directly

Calls 15

getNvmTestConfigFunction · 0.85
getTotalObjectSizeMethod · 0.80
setNumShardsMethod · 0.80
strMethod · 0.80
eventuallyTrueFunction · 0.50
insertOrReplaceMethod · 0.45
getNumEntriesMethod · 0.45
exportStatsMethod · 0.45

Tested by

no test coverage detected