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

Function VerifyFlush

tensorflow/core/lib/io/record_reader_writer_test.cc:54–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54void VerifyFlush(const io::RecordWriterOptions& options) {
55 std::vector<string> records = {
56 "abcdefghijklmnopqrstuvwxyz",
57 "ZYXWVUTSRQPONMLKJIHGFEDCBA0123456789!@#$%^&*()",
58 "G5SyohOL9UmXofSOOwWDrv9hoLLMYPJbG9r38t3uBRcHxHj2PdKcPDuZmKW62RIY",
59 "aaaaaaaaaaaaaaaaaaaaaaaaaa",
60 };
61
62 Env* env = Env::Default();
63 string fname = testing::TmpDir() + "/record_reader_writer_flush_test";
64
65 std::unique_ptr<WritableFile> file;
66 TF_CHECK_OK(env->NewWritableFile(fname, &file));
67 io::RecordWriter writer(file.get(), options);
68
69 std::unique_ptr<RandomAccessFile> read_file;
70 TF_CHECK_OK(env->NewRandomAccessFile(fname, &read_file));
71 io::RecordReaderOptions read_options = GetMatchingReaderOptions(options);
72 io::RecordReader reader(read_file.get(), read_options);
73
74 EXPECT_EQ(GetFileSize(fname), 0);
75 for (size_t i = 0; i < records.size(); i++) {
76 uint64 start_size = GetFileSize(fname);
77
78 // Write a new record.
79 TF_EXPECT_OK(writer.WriteRecord(records[i]));
80 TF_CHECK_OK(writer.Flush());
81 TF_CHECK_OK(file->Flush());
82
83 // Verify that file size has changed after file flush.
84 uint64 new_size = GetFileSize(fname);
85 EXPECT_GT(new_size, start_size);
86
87 // Verify that file has all records written so far and no more.
88 uint64 offset = 0;
89 string record;
90 for (size_t j = 0; j <= i; j++) {
91 // Check that j'th record is written correctly.
92 TF_CHECK_OK(reader.ReadRecord(&offset, &record));
93 EXPECT_EQ(record, records[j]);
94 }
95
96 // Verify that file has no more records.
97 CHECK_EQ(reader.ReadRecord(&offset, &record).code(), error::OUT_OF_RANGE);
98 }
99}
100
101} // namespace
102

Callers 1

TESTFunction · 0.85

Calls 12

DefaultFunction · 0.85
TmpDirFunction · 0.85
GetMatchingReaderOptionsFunction · 0.85
GetFileSizeFunction · 0.85
NewWritableFileMethod · 0.45
getMethod · 0.45
NewRandomAccessFileMethod · 0.45
sizeMethod · 0.45
WriteRecordMethod · 0.45
FlushMethod · 0.45
ReadRecordMethod · 0.45
codeMethod · 0.45

Tested by

no test coverage detected