Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
space_handler_fixture Struct Reference
Collaboration diagram for space_handler_fixture:

Classes

struct  mock_space_provider
 

Public Types

using file_space_handler_t = file_space_handler<mock_space_provider>
 

Public Member Functions

 space_handler_fixture ()
 
void add_file_system (const bfs::path &path_name)
 
void set_threshold (uint32_t threshold, uint32_t warning_threshold)
 
void set_sleep_time (uint32_t sleep_time)
 
void set_shutdown_on_exceeded (bool shutdown_on_exceeded)
 
bool is_threshold_exceeded ()
 
void space_monitor_loop ()
 
bool test_loop_common (int num_loops, int interval)
 

Public Attributes

boost::asio::io_context ctx
 
std::function< bfs::space_info(const bfs::path &p, boost::system::error_code &ec)> mock_get_space
 
std::function< int(const char *path, struct stat *buf)> mock_get_stat
 
file_space_handler_t space_handler
 

Detailed Description

Definition at line 12 of file test_monitor_loop.cpp.

Member Typedef Documentation

◆ file_space_handler_t

Constructor & Destructor Documentation

◆ space_handler_fixture()

space_handler_fixture::space_handler_fixture ( )
inline

Definition at line 32 of file test_monitor_loop.cpp.

33 : space_handler(mock_space_provider( *this ), ctx)
34 {
35 }
boost::asio::io_context ctx
file_space_handler_t space_handler

Member Function Documentation

◆ add_file_system()

void space_handler_fixture::add_file_system ( const bfs::path & path_name)
inline

Definition at line 37 of file test_monitor_loop.cpp.

37 {
38 space_handler.add_file_system( path_name );
39 }
void add_file_system(const bfs::path &path_name)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_threshold_exceeded()

bool space_handler_fixture::is_threshold_exceeded ( )
inline

Definition at line 53 of file test_monitor_loop.cpp.

Here is the call graph for this function:

◆ set_shutdown_on_exceeded()

void space_handler_fixture::set_shutdown_on_exceeded ( bool shutdown_on_exceeded)
inline

Definition at line 49 of file test_monitor_loop.cpp.

49 {
50 space_handler.set_shutdown_on_exceeded(shutdown_on_exceeded);
51 }
void set_shutdown_on_exceeded(bool new_shutdown_on_exceeded)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_sleep_time()

void space_handler_fixture::set_sleep_time ( uint32_t sleep_time)
inline

Definition at line 45 of file test_monitor_loop.cpp.

45 {
46 space_handler.set_sleep_time( sleep_time );
47 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_threshold()

void space_handler_fixture::set_threshold ( uint32_t threshold,
uint32_t warning_threshold )
inline

Definition at line 41 of file test_monitor_loop.cpp.

41 {
42 space_handler.set_threshold( threshold, warning_threshold );
43 }
void set_threshold(uint32_t new_threshold, uint32_t new_warning_threshold)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ space_monitor_loop()

void space_handler_fixture::space_monitor_loop ( )
inline

Definition at line 57 of file test_monitor_loop.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_loop_common()

bool space_handler_fixture::test_loop_common ( int num_loops,
int interval )
inline

Definition at line 61 of file test_monitor_loop.cpp.

62 {
63 mock_get_space = [ i = 0, num_loops ]( const bfs::path& p, boost::system::error_code& ec) mutable -> bfs::space_info {
64 ec = boost::system::errc::make_error_code(errc::success);
65
66 bfs::space_info rc;
67 rc.capacity = 1000000;
68
69 if ( i < num_loops + 1 ) { // "+ 1" for the get_space in add_file_system
70 rc.available = 300000;
71 } else {
72 rc.available = 100000;
73 }
74
75 i++;
76
77 return rc;
78 };
79
80 mock_get_stat = []( const char *path, struct stat *buf ) -> int {
81 buf->st_dev = 0;
82 return 0;
83 };
84
85 set_threshold(80, 75);
87 set_sleep_time(interval);
88 add_file_system("/test");
89
90 auto start = std::chrono::system_clock::now();
91
92 auto monitor_thread = std::thread( [this] {
94 ctx.run();
95 });
96
97 monitor_thread.join();
98
99 auto end = std::chrono::system_clock::now();
100 std::chrono::duration<double> test_duration = end - start;
101
102 // For tests to be repeatable on any platforms under any loads,
103 // particularly for longer runs,
104 // we just make sure the test duration is longer than a margin
105 // of theroretical duration.
106 bool finished_in_time = (test_duration >= std::chrono::duration<double>((num_loops - 1) * interval));
107
108 return finished_in_time;
109 }
const mie::Vuint & p
Definition bn.cpp:27
wraps boost::filesystem::path to provide platform independent path manipulation.
std::function< bfs::space_info(const bfs::path &p, boost::system::error_code &ec)> mock_get_space
void set_threshold(uint32_t threshold, uint32_t warning_threshold)
void set_sleep_time(uint32_t sleep_time)
void set_shutdown_on_exceeded(bool shutdown_on_exceeded)
void add_file_system(const bfs::path &path_name)
std::function< int(const char *path, struct stat *buf)> mock_get_stat
uint8_t buf[2048]
yh_rc rc
Here is the call graph for this function:

Member Data Documentation

◆ ctx

boost::asio::io_context space_handler_fixture::ctx

Definition at line 29 of file test_monitor_loop.cpp.

◆ mock_get_space

std::function<bfs::space_info(const bfs::path& p, boost::system::error_code& ec)> space_handler_fixture::mock_get_space

Definition at line 112 of file test_monitor_loop.cpp.

◆ mock_get_stat

std::function<int(const char *path, struct stat *buf)> space_handler_fixture::mock_get_stat

Definition at line 113 of file test_monitor_loop.cpp.

◆ space_handler

file_space_handler_t space_handler_fixture::space_handler

Definition at line 115 of file test_monitor_loop.cpp.


The documentation for this struct was generated from the following file: