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

Function TEST

cachelib/navy/block_cache/tests/BlockCacheTest.cpp:188–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186} // namespace
187
188TEST(BlockCache, InsertLookup) {
189 std::vector<CacheEntry> log;
190
191 std::vector<uint32_t> hits(4);
192 auto policy = std::make_unique<NiceMock<MockPolicy>>(&hits);
193 auto device = createMemoryDevice(kDeviceSize, nullptr /* encryption */);
194 auto ex = makeJobScheduler();
195 auto config = makeConfig(std::move(policy), *device);
196 auto engine = makeEngine(std::move(config));
197 auto driver = makeDriver(std::move(engine), std::move(ex));
198
199 BufferGen bg;
200 {
201 CacheEntry e{bg.gen(8), bg.gen(800)};
202 EXPECT_EQ(Status::Ok,
203 driver->insertAsync(e.key(), e.value(), nullptr, 0 /* poolId */,
204 0 /* expiryTime */));
205 // Flush the first region
206 driver->flush();
207 Buffer value;
208 uint32_t lat = 0;
209 EXPECT_EQ(Status::Ok, driver->lookup(e.key(), value, lat));
210
211 driver->getCounters({[](folly::StringPiece name, double count,
212 CounterVisitor::CounterType type) {
213 if (name == "navy_bc_lookups" &&
214 type == CounterVisitor::CounterType::RATE) {
215 EXPECT_EQ(1, count);
216 }
217 }});
218
219 EXPECT_EQ(e.value(), value.view());
220 log.push_back(std::move(e));
221 EXPECT_EQ(1, hits[0]);
222 }
223
224 // After 15 more we fill region fully. Before adding 16th, block cache adds
225 // region to tracked.
226 for (size_t i = 0; i < 16; i++) {
227 CacheEntry e{bg.gen(8), bg.gen(800)};
228 EXPECT_EQ(Status::Ok,
229 driver->insertAsync(e.key(), e.value(), nullptr, 0 /* poolId */,
230 0 /* expiryTime */));
231 log.push_back(std::move(e));
232 }
233 driver->flush();
234
235 for (size_t i = 0; i < 17; i++) {
236 Buffer value;
237 uint32_t lat = 0;
238 EXPECT_EQ(Status::Ok, driver->lookup(log[i].key(), value, lat));
239 EXPECT_EQ(log[i].value(), value.view());
240 }
241 EXPECT_EQ(2, hits[0]);
242 EXPECT_EQ(16, hits[1]);
243 EXPECT_EQ(0, hits[2]);
244 EXPECT_EQ(0, hits[3]);
245}

Callers

nothing calls this directly

Calls 15

createMemoryDeviceFunction · 0.85
makeConfigFunction · 0.85
makeEngineFunction · 0.85
makeDriverFunction · 0.85
strzBufferFunction · 0.85
makeHKFunction · 0.85
makeViewFunction · 0.85
toCallbackFunction · 0.85
CollisionCreatorClass · 0.85
makePctReinsertionConfigFunction · 0.85
finishAllJobsFunction · 0.85

Tested by

no test coverage detected