Implement FileCollector with concurrency and stress tests
This commit is contained in:
parent
d09fb340b7
commit
4c05fe8034
26 changed files with 1745 additions and 0 deletions
38
include/file_collector/file_collector.hpp
Normal file
38
include/file_collector/file_collector.hpp
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#pragma once
|
||||
|
||||
#include "file_collector/i_file_collector.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
namespace file_collector {
|
||||
namespace detail { class FaultInjector; }
|
||||
class FileCollectorImpl;
|
||||
|
||||
class FileCollector final : public IFileCollector {
|
||||
public:
|
||||
explicit FileCollector(
|
||||
std::size_t workers = 0,
|
||||
std::shared_ptr<detail::FaultInjector> fault_injector = {});
|
||||
~FileCollector() override;
|
||||
FileCollector(const FileCollector&) = delete;
|
||||
FileCollector& operator=(const FileCollector&) = delete;
|
||||
FileCollector(FileCollector&&) = delete;
|
||||
FileCollector& operator=(FileCollector&&) = delete;
|
||||
|
||||
void CollectFile(std::uint32_t file_id, std::size_t file_size) override;
|
||||
void OnNewChunk(std::uint32_t file_id, std::size_t pos, FileBytes&& chunk) override;
|
||||
[[nodiscard]] FileView GetFile(std::uint32_t file_id, bool check_complete = true) override;
|
||||
[[nodiscard]] FileView GetFile(std::uint32_t file_id, std::size_t pos,
|
||||
std::size_t length, bool check_complete = true) override;
|
||||
[[nodiscard]] MutableFile TakeFile(std::uint32_t file_id, bool check_complete = true) override;
|
||||
void RemoveFile(std::uint32_t file_id) override;
|
||||
void ClearFile(std::uint32_t file_id) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<FileCollectorImpl> impl_;
|
||||
};
|
||||
|
||||
} // namespace file_collector
|
||||
|
||||
30
include/file_collector/i_file_collector.hpp
Normal file
30
include/file_collector/i_file_collector.hpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace file_collector {
|
||||
|
||||
using FileBytes = std::vector<std::uint8_t>;
|
||||
using FileView = std::shared_ptr<const FileBytes>;
|
||||
using MutableFile = std::shared_ptr<FileBytes>;
|
||||
|
||||
class IFileCollector {
|
||||
public:
|
||||
virtual ~IFileCollector() = default;
|
||||
|
||||
virtual void CollectFile(std::uint32_t file_id, std::size_t file_size) = 0;
|
||||
virtual void OnNewChunk(std::uint32_t file_id, std::size_t pos, FileBytes&& chunk) = 0;
|
||||
[[nodiscard]] virtual FileView GetFile(std::uint32_t file_id, bool check_complete = true) = 0;
|
||||
[[nodiscard]] virtual FileView GetFile(
|
||||
std::uint32_t file_id, std::size_t pos, std::size_t length,
|
||||
bool check_complete = true) = 0;
|
||||
[[nodiscard]] virtual MutableFile TakeFile(std::uint32_t file_id, bool check_complete = true) = 0;
|
||||
virtual void RemoveFile(std::uint32_t file_id) = 0;
|
||||
virtual void ClearFile(std::uint32_t file_id) = 0;
|
||||
};
|
||||
|
||||
} // namespace file_collector
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue