67TEST_CASE(
"ranges closer than the gap are fetched in one read, on first use")
69 auto source = std::make_shared<RecordingSource>(1 << 20);
75 REQUIRE(
source->reads.empty());
77 auto bytes = plan.find(1150, 50);
78 REQUIRE(holds(
bytes, 1150));
79 REQUIRE(
source->reads == std::vector<std::pair<uint64_t, size_t>>{{1000, 310}, {5000, 200}});
80 REQUIRE(plan.bytesHeld() == 510);
82 REQUIRE(holds(plan.find(5100, 100), 5100));
83 REQUIRE(holds(plan.find(1000, 310), 1000));
84 REQUIRE(
source->reads.size() == 2);
87TEST_CASE(
"ranges which were never registered are not found")
89 auto source = std::make_shared<RecordingSource>(1 << 20);
92 REQUIRE(plan.find(900, 50).empty());
93 REQUIRE(plan.find(1050, 100).empty());
94 REQUIRE(plan.find(5000, 1).empty());
95 REQUIRE(
source->reads.size() == 1);
98TEST_CASE(
"ranges added after a fetch are fetched on their first use")
100 auto source = std::make_shared<RecordingSource>(1 << 20);
103 REQUIRE(holds(plan.find(1000, 100), 1000));
104 auto first = plan.find(1000, 100);
110 REQUIRE(holds(plan.find(1500, 100), 1500));
111 REQUIRE(holds(plan.find(500, 100), 500));
112 REQUIRE(
source->reads == std::vector<std::pair<uint64_t, size_t>>{{1000, 100}, {500, 100}, {1500, 100}});
114 REQUIRE(plan.find(1000, 100).data() ==
first.data());
115 REQUIRE(holds(
first, 1000));
128TEST_CASE(
"a planned source serves planned ranges from memory and the rest from the source")
130 auto source = std::make_shared<RecordingSource>(1 << 20);
131 auto plan = std::make_shared<ReadPlan>(
source, withGap(0));
132 plan->add(1000, 100);
135 REQUIRE(holds(planned.tryMap(1010, 20), 1010));
136 std::vector<uint8_t> out(30);
137 planned.readInto(1020, 30, out.data());
138 REQUIRE(holds(out, 1020));
139 REQUIRE(planned.tryMap(3000, 10).empty());
140 planned.readInto(3000, 30, out.data());
141 REQUIRE(holds(out, 3000));
142 REQUIRE(
source->reads == std::vector<std::pair<uint64_t, size_t>>{{1000, 100}, {3000, 30}});
143 REQUIRE(planned.readCalls() == 2);
virtual void readInto(uint64_t off, size_t len, void *dst)=0
Throws IoError, or CorruptData when the range is past the end of the file.