JayBeams  0.1
Another project to have fun coding.
ut_offline_feed_statistics.cpp
Go to the documentation of this file.
2 
3 #include <boost/test/unit_test.hpp>
4 
5 /**
6  * @test Verify that jb::offline_feed_statistics works as expected.
7  */
8 BOOST_AUTO_TEST_CASE(offline_feed_statististics_simple) {
10  jb::offline_feed_statistics stats(cfg);
11 
12  stats.sample(std::chrono::seconds(1), std::chrono::microseconds(1));
13  stats.sample(
14  std::chrono::seconds(1) + std::chrono::microseconds(1),
15  std::chrono::microseconds(1));
16  stats.sample(
17  std::chrono::seconds(1) + std::chrono::microseconds(2),
18  std::chrono::microseconds(1));
19  stats.sample(
20  std::chrono::seconds(1) + std::chrono::microseconds(3),
21  std::chrono::microseconds(1));
22 
23  stats.sample(
24  std::chrono::seconds(601) + std::chrono::microseconds(1),
25  std::chrono::microseconds(2));
26 }
27 
28 /**
29  * @test Test jb::offline_feed_statistics csv output.
30  */
31 BOOST_AUTO_TEST_CASE(offline_feed_statististics_print_csv) {
33  jb::offline_feed_statistics stats(cfg);
34  std::ostringstream header;
35  stats.print_csv_header(header);
36  BOOST_CHECK_EQUAL(header.str().substr(0, 5), std::string("Name,"));
37 
38  std::string h = header.str();
39  int nheaders = std::count(h.begin(), h.end(), ',');
40 
41  std::ostringstream body;
42  stats.print_csv("testing", body);
43  BOOST_CHECK_EQUAL(body.str().substr(0, 10), std::string("testing,0,"));
44  std::string b = body.str();
45  int nfields = std::count(b.begin(), b.end(), ',');
46  BOOST_CHECK_EQUAL(nfields, nheaders);
47 
48  stats.sample(std::chrono::seconds(600), std::chrono::microseconds(2));
49  stats.sample(std::chrono::seconds(601), std::chrono::microseconds(2));
50  stats.sample(std::chrono::seconds(602), std::chrono::microseconds(2));
51  stats.sample(std::chrono::seconds(603), std::chrono::microseconds(2));
52 
53  body.str("");
54  stats.print_csv("testing", body);
55  BOOST_CHECK_EQUAL(body.str().substr(0, 10), std::string("testing,4,"));
56  b = body.str();
57  nfields = std::count(b.begin(), b.end(), ',');
58  BOOST_CHECK_EQUAL(nfields, nheaders);
59 
60  BOOST_TEST_MESSAGE("CSV Output for inspection: \n" << h << b);
61 }
62 
63 /**
64  * @test Verify that jb::offline_feed_statistics::config works as expected.
65  */
66 BOOST_AUTO_TEST_CASE(offline_feed_statististics_config_simple) {
68 
69  BOOST_CHECK_NO_THROW(config().validate());
70  BOOST_CHECK_THROW(config().max_messages_per_second(-7).validate(), jb::usage);
71  BOOST_CHECK_THROW(
72  config().max_messages_per_millisecond(-7).validate(), jb::usage);
73  BOOST_CHECK_THROW(
74  config().max_messages_per_microsecond(-7).validate(), jb::usage);
75  BOOST_CHECK_THROW(
76  config().max_interarrival_time_nanoseconds(-7).validate(), jb::usage);
77  BOOST_CHECK_THROW(
78  config().max_processing_latency_nanoseconds(-7).validate(), jb::usage);
79  BOOST_CHECK_THROW(
80  config().reporting_interval_seconds(-1).validate(), jb::usage);
81  BOOST_CHECK_NO_THROW(config().reporting_interval_seconds(0).validate());
82 }
83 
84 /**
85  * @test Test corner cases in jb::offline_feed_statistics to improve
86  * code coverage.
87  */
88 BOOST_AUTO_TEST_CASE(offline_feed_statististics_coverage) {
90  jb::offline_feed_statistics stats(cfg);
91 
92  stats.sample(std::chrono::seconds(1), std::chrono::microseconds(1));
93  BOOST_CHECK_NO_THROW(stats.log_final_progress());
94 
95  stats.sample(
96  std::chrono::seconds(1) + std::chrono::microseconds(2),
97  std::chrono::microseconds(2));
98  stats.sample(
99  std::chrono::seconds(1) + std::chrono::microseconds(3),
100  std::chrono::microseconds(3));
101  stats.sample(
102  std::chrono::seconds(1) + std::chrono::microseconds(1002),
103  std::chrono::microseconds(4));
104  stats.sample(
105  std::chrono::seconds(1) + std::chrono::microseconds(1003),
106  std::chrono::microseconds(5));
107  stats.sample(
108  std::chrono::seconds(2) + std::chrono::microseconds(2),
109  std::chrono::microseconds(4));
110  stats.sample(
111  std::chrono::seconds(2) + std::chrono::microseconds(3),
112  std::chrono::microseconds(5));
113  BOOST_CHECK_NO_THROW(stats.log_final_progress());
114 }
std::int64_t max_interarrival_time_nanoseconds
Keep statistics about a feed and its offline processor.
void sample(event_timestamp_t ts, duration_t processing_latency)
Record a sample, that is process a message received at the given timestamp.
void print_csv(std::string const &name, std::ostream &os) const
Print all the measurements in CSV format.
A simple class to communicate the result of parsing the options.
Definition: usage.hpp:11
BOOST_AUTO_TEST_CASE(offline_feed_statististics_simple)
void log_final_progress() const
Final progress report at the end of the input.
static void print_csv_header(std::ostream &os)
Print a CSV header.
Configure an offline_feed_statistics object.