MCPcopy Create free account
hub / github.com/bytedance/bolt / TEST

Function TEST

bolt/common/caching/tests/SsdFileTrackerTest.cpp:36–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34using namespace bytedance::bolt::cache;
35
36TEST(SsdFileTrackerTest, tracker) {
37 constexpr int32_t kNumRegions = 16;
38 SsdFileTracker tracker;
39 tracker.resize(kNumRegions);
40 // Simulate a sequence of access that periodically adds a new region and keeps
41 // accessing the 4 most recently added regions.
42 for (auto lastRegion = 0; lastRegion < kNumRegions; ++lastRegion) {
43 tracker.regionFilled(lastRegion);
44 for (auto i = 0; i < 2000; ++i) {
45 for (auto region = std::max(lastRegion - 3, 0); region <= lastRegion;
46 ++region) {
47 // fileTouched means a lookup. This decays scores so that new uses are
48 // more relevant than old ones. The actual read is tracked by
49 // regionRead()..
50 tracker.fileTouched(10000);
51 tracker.regionRead(region, 100000);
52 }
53 }
54 }
55 std::vector<int32_t> pins(kNumRegions);
56 pins[2] = 1;
57 pins[3] = 2;
58 // Get up to 10 low-use regions out of kNumRegions used regions, excluding
59 // regions that have a non-zero in 'pins'.
60 auto candidates =
61 tracker.findEvictionCandidates(kNumRegions, kNumRegions, pins);
62 std::vector<int32_t> expected{0, 1, 4, 5, 6, 7, 8, 9};
63 EXPECT_EQ(candidates, expected);
64}

Callers

nothing calls this directly

Calls 6

regionFilledMethod · 0.80
fileTouchedMethod · 0.80
maxFunction · 0.50
resizeMethod · 0.45
regionReadMethod · 0.45

Tested by

no test coverage detected