MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TestNonSequentialReads

Function TestNonSequentialReads

tensorflow/core/lib/io/recordio_test.cc:251–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

249}
250
251void TestNonSequentialReads(const RecordWriterOptions& writer_options,
252 const RecordReaderOptions& reader_options) {
253 string contents;
254 StringDest dst(&contents);
255 RecordWriter writer(&dst, writer_options);
256 for (int i = 0; i < 10; ++i) {
257 TF_ASSERT_OK(writer.WriteRecord(NumberString(i))) << i;
258 }
259 TF_ASSERT_OK(writer.Close());
260
261 StringSource file(&contents);
262 RecordReader reader(&file, reader_options);
263
264 string record;
265 // First read sequentially to fill in the offsets table.
266 uint64 offsets[10] = {0};
267 uint64 offset = 0;
268 for (int i = 0; i < 10; ++i) {
269 offsets[i] = offset;
270 TF_ASSERT_OK(reader.ReadRecord(&offset, &record)) << i;
271 }
272
273 // Read randomly: First go back to record #3 then forward to #8.
274 offset = offsets[3];
275 TF_ASSERT_OK(reader.ReadRecord(&offset, &record));
276 EXPECT_EQ("3.", record);
277 EXPECT_EQ(offsets[4], offset);
278
279 offset = offsets[8];
280 TF_ASSERT_OK(reader.ReadRecord(&offset, &record));
281 EXPECT_EQ("8.", record);
282 EXPECT_EQ(offsets[9], offset);
283}
284
285TEST_F(RecordioTest, NonSequentialReads) {
286 TestNonSequentialReads(RecordWriterOptions(), RecordReaderOptions());

Callers 1

TEST_FFunction · 0.85

Calls 4

NumberStringFunction · 0.85
WriteRecordMethod · 0.45
CloseMethod · 0.45
ReadRecordMethod · 0.45

Tested by

no test coverage detected