408 {
410 slice_directory sd(tempdir.
path(), 100, std::optional<uint32_t>(), std::optional<uint32_t>(), 0);
412
413
414 for (uint i = 0; i < 9; ++i) {
415 bool found = sd.find_or_create_trace_slice(i, open_state::write, slice);
416 BOOST_REQUIRE(!found);
418 BOOST_REQUIRE_EQUAL(fp.parent_path().generic_string(), tempdir.
path().
generic_string());
419 const std::string expected_filename = "trace_0000000" + std::to_string(i) + "00-0000000" + std::to_string(i+1) + "00.log";
420 BOOST_REQUIRE_EQUAL(fp.filename().generic_string(), expected_filename);
421 BOOST_REQUIRE(slice.
is_open());
422 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), 0);
423 BOOST_REQUIRE_EQUAL(slice.
tellp(), 0);
425 }
426
427
428 for (uint i = 0; i < 9; ++i) {
429 bool found = sd.find_or_create_index_slice(i, open_state::write, slice);
430 BOOST_REQUIRE(!found);
433 const std::string expected_filename = "trace_index_0000000" + std::to_string(i) + "00-0000000" + std::to_string(i+1) + "00.log";
435 BOOST_REQUIRE(slice.
is_open());
438 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), data.size());
439 BOOST_REQUIRE_EQUAL(slice.
tellp(), data.size());
441 }
442
443
444 bool found = sd.find_or_create_trace_slice(0, open_state::write, slice);
445 BOOST_REQUIRE(found);
448 std::string expected_filename = "trace_0000000000-0000000100.log";
450 BOOST_REQUIRE(slice.
is_open());
451 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), 0);
452 BOOST_REQUIRE_EQUAL(slice.
tellp(), 0);
453 uint64_t offset = append_store(bt_v1, slice);
454 BOOST_REQUIRE_EQUAL(offset, 0);
456 BOOST_REQUIRE(slice.
tellp() > 0);
457 BOOST_REQUIRE_EQUAL(data.size(), slice.
tellp());
458 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), slice.
tellp());
459 uint64_t trace_file_size = bfs::file_size(fp);
461
462
463 found = sd.find_or_create_trace_slice(0, open_state::read, slice);
464 BOOST_REQUIRE(found);
467 BOOST_REQUIRE(slice.
is_open());
468 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), trace_file_size);
469 BOOST_REQUIRE_EQUAL(slice.
tellp(), 0);
471
472
473 found = sd.find_or_create_trace_slice(0, open_state::write, slice);
474 BOOST_REQUIRE(found);
477 BOOST_REQUIRE(slice.
is_open());
478 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), trace_file_size);
479 BOOST_REQUIRE_EQUAL(slice.
tellp(), trace_file_size);
481
482
483 found = sd.find_or_create_index_slice(1, open_state::write, slice);
484 BOOST_REQUIRE(found);
487 expected_filename = "trace_index_0000000100-0000000200.log";
489 BOOST_REQUIRE(slice.
is_open());
493 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), header_size);
494 BOOST_REQUIRE_EQUAL(slice.
tellp(), header_size);
495 offset = append_store(be1, slice);
496 BOOST_REQUIRE_EQUAL(offset, header_size);
498 const auto be1_size = data.size();
499 BOOST_REQUIRE_EQUAL(header_size + be1_size, slice.
tellp());
500 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), slice.
tellp());
502
503 found = sd.find_or_create_index_slice(1, open_state::read, slice);
504 BOOST_REQUIRE(found);
507 BOOST_REQUIRE(slice.
is_open());
508 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), header_size + be1_size);
509 BOOST_REQUIRE_EQUAL(slice.
tellp(), header_size);
511
512 found = sd.find_or_create_index_slice(1, open_state::write, slice);
513 BOOST_REQUIRE(found);
516 BOOST_REQUIRE(slice.
is_open());
517 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), header_size + be1_size);
518 BOOST_REQUIRE_EQUAL(slice.
tellp(), header_size + be1_size);
519 offset = append_store(le1, slice);
520 BOOST_REQUIRE_EQUAL(offset, header_size + be1_size);
522 const auto le1_size = data.size();
523 BOOST_REQUIRE_EQUAL(header_size + be1_size + le1_size, slice.
tellp());
524 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), slice.
tellp());
526
527 found = sd.find_or_create_index_slice(1, open_state::read, slice);
528 BOOST_REQUIRE(found);
531 BOOST_REQUIRE(slice.
is_open());
532 BOOST_REQUIRE_EQUAL(bfs::file_size(fp), header_size + be1_size + le1_size);
533 BOOST_REQUIRE_EQUAL(slice.
tellp(), header_size);
535 }
fc::path get_file_path() const
wraps boost::filesystem::path to provide platform independent path manipulation.
fc::path parent_path() const
fc::path filename() const
std::string generic_string() const
constexpr size_t header_size
void pack(Stream &s, const std::deque< T > &value)
unsigned __int64 uint64_t