Skip to content

Commit 59c0795

Browse files
TheMarexoxidase
authored andcommitted
Add test case for writing and reading huge tar file
This test case is disabled by default because it needs too much storage, but serves as documentation for the future.
1 parent 3653e51 commit 59c0795

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

unit_tests/storage/tar.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "../common/range_tools.hpp"
44
#include "../common/temporary_file.hpp"
55

6+
#include <boost/function_output_iterator.hpp>
7+
#include <boost/iterator/function_input_iterator.hpp>
68
#include <boost/test/unit_test.hpp>
79

810
BOOST_AUTO_TEST_SUITE(tar)
@@ -187,4 +189,35 @@ BOOST_AUTO_TEST_CASE(continue_write_tar_file)
187189
CHECK_EQUAL_COLLECTIONS(result_64bit_vector, vector_64bit);
188190
}
189191

192+
// This test case is disabled by default because it needs 70 GiB of storage
193+
BOOST_AUTO_TEST_CASE(write_huge_tar_file, *boost::unit_test::disabled())
194+
{
195+
TemporaryFile tmp{TEST_DATA_DIR "/tar_huge_write_test.tar"};
196+
197+
std::uint64_t reference_checksum = 0;
198+
{
199+
storage::tar::FileWriter writer(tmp.path, storage::tar::FileWriter::GenerateFingerprint);
200+
std::uint64_t value = 0;
201+
const std::function<std::uint64_t()> encode_function = [&]() -> std::uint64_t {
202+
reference_checksum += value;
203+
return value++;
204+
};
205+
std::uint64_t num_elements = (70ULL * 1024ULL * 1024ULL * 1024ULL) / sizeof(std::uint64_t);
206+
writer.WriteStreaming<std::uint64_t>(
207+
"huge_data",
208+
boost::make_function_input_iterator(encode_function, boost::infinite()),
209+
num_elements);
210+
}
211+
212+
std::uint64_t checksum = 0;
213+
{
214+
storage::tar::FileReader reader(tmp.path, storage::tar::FileReader::VerifyFingerprint);
215+
reader.ReadStreaming<std::uint64_t>(
216+
"huge_data",
217+
boost::make_function_output_iterator([&](const auto &value) { checksum += value; }));
218+
}
219+
220+
BOOST_CHECK_EQUAL(checksum, reference_checksum);
221+
}
222+
190223
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)