niyue commented on a change in pull request #11486:
URL: https://github.com/apache/arrow/pull/11486#discussion_r740214639
##########
File path: cpp/src/arrow/ipc/read_write_test.cc
##########
@@ -925,6 +926,64 @@ TEST_F(RecursionLimits, StressLimit) {
}
#endif // !defined(_WIN32) || defined(NDEBUG)
+struct MockFileWriterHelper {
+ MockFileWriterHelper(const std::string& file_name) : file_name_(file_name) {}
+
+ Status Init(const std::shared_ptr<Schema>& schema, const IpcWriteOptions&
options,
+ const std::shared_ptr<const KeyValueMetadata>& metadata =
nullptr) {
+ num_batches_written_ = 0;
+
+ mock_fs_ = std::make_shared<fs::internal::MockFileSystem>(fs::kNoTime);
+ RETURN_NOT_OK(mock_fs_->CreateFile(file_name_, ""));
+ ARROW_ASSIGN_OR_RAISE(sink_, mock_fs_->OpenOutputStream(file_name_));
+ ARROW_ASSIGN_OR_RAISE(writer_,
+ MakeFileWriter(sink_.get(), schema, options,
metadata));
+ return Status::OK();
+ }
+
+ Status WriteBatch(const std::shared_ptr<RecordBatch>& batch) {
+ RETURN_NOT_OK(writer_->WriteRecordBatch(*batch));
+ num_batches_written_++;
+ return Status::OK();
+ }
+
+ Status Finish(WriteStats* out_stats = nullptr) {
+ RETURN_NOT_OK(writer_->Close());
+ if (out_stats) {
+ *out_stats = writer_->stats();
+ }
+ RETURN_NOT_OK(sink_->Close());
+ return Status::OK();
+ }
+
+ Status ReadBatches(const IpcReadOptions& options, RecordBatchVector*
out_batches,
+ ReadStats* out_stats = nullptr,
+ std::vector<io::ReadRange>* io_stats = nullptr) {
+ ARROW_ASSIGN_OR_RAISE(auto ipc_file, mock_fs_->OpenInputFile(file_name_));
+ ARROW_ASSIGN_OR_RAISE(auto reader, RecordBatchFileReader::Open(ipc_file,
options));
+
+ EXPECT_EQ(num_batches_written_, reader->num_record_batches());
+ for (int i = 0; i < num_batches_written_; ++i) {
+ ARROW_ASSIGN_OR_RAISE(std::shared_ptr<RecordBatch> chunk,
+ reader->ReadRecordBatch(i));
+ out_batches->push_back(chunk);
+ }
+ if (out_stats) {
+ *out_stats = reader->stats();
+ }
+ if (io_stats) {
+ ARROW_ASSIGN_OR_RAISE(*io_stats, mock_fs_->GetRecordedReads(ipc_file));
Review comment:
mock file system is used for writing record batch, reading the batch,
and retrieving the recorded read IOs for unit testing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]