Line data Source code
1 : /**
2 : * @file test_ratelimiter_app.cxx Test application for
3 : * ratelimiter implementation
4 : *
5 : * This is part of the DUNE DAQ Application Framework, copyright 2020.
6 : * Licensing/copyright details are in the COPYING file that you should have
7 : * received with this code.
8 : */
9 : #include "datahandlinglibs/utils/RateLimiter.hpp"
10 :
11 : #include "logging/Logging.hpp"
12 :
13 : #include "datahandlinglibs/ReadoutTypes.hpp"
14 :
15 : #include "folly/ConcurrentSkipList.h"
16 :
17 : #include <atomic>
18 : #include <chrono>
19 : #include <memory>
20 : #include <random>
21 : #include <set>
22 : #include <string>
23 : #include <utility>
24 : #include <vector>
25 :
26 : using namespace dunedaq::datahandlinglibs;
27 : using namespace folly;
28 :
29 : int
30 0 : main(int /*argc*/, char** /*argv[]*/)
31 : {
32 :
33 : // ConcurrentSkipList from Folly
34 0 : typedef ConcurrentSkipList<types::DUMMY_FRAME_STRUCT> SkipListT;
35 0 : typedef SkipListT::Accessor SkipListTAcc;
36 0 : typedef SkipListT::iterator SkipListTIter;
37 : // typedef SkipListT::Skipper SkipListTSkip; //Skipper accessor to test
38 :
39 : // Skiplist instance
40 0 : auto head_height = 2;
41 0 : std::shared_ptr<SkipListT> skl(SkipListT::createInstance(head_height));
42 :
43 0 : TLOG() << "Composite key test...";
44 0 : types::DUMMY_FRAME_STRUCT payload1;
45 0 : payload1.set_timestamp(12340);
46 0 : payload1.set_another_key(1);
47 :
48 0 : types::DUMMY_FRAME_STRUCT payload2;
49 0 : payload2.set_timestamp(12342);
50 0 : payload2.set_another_key(2);
51 :
52 0 : types::DUMMY_FRAME_STRUCT payload3; // equivalent to payload 2
53 0 : payload3.set_timestamp(12342);
54 0 : payload3.set_another_key(2);
55 :
56 0 : types::DUMMY_FRAME_STRUCT payload4;
57 0 : payload4.set_timestamp(12342);
58 0 : payload4.set_another_key(3);
59 :
60 0 : types::DUMMY_FRAME_STRUCT payload5;
61 0 : payload5.set_timestamp(12345);
62 0 : payload5.set_another_key(4);
63 :
64 0 : types::DUMMY_FRAME_STRUCT payload6;
65 0 : payload6.set_timestamp(12342);
66 0 : payload6.set_another_key(1);
67 :
68 0 : {
69 0 : SkipListTAcc acc(skl);
70 0 : auto ret = acc.insert(std::move(payload4));
71 0 : TLOG() << "Payload4 insertion success? -> " << ret.second;
72 0 : ret = acc.insert(std::move(payload2));
73 0 : TLOG() << "Payload2 insertion success? -> " << ret.second;
74 0 : ret = acc.insert(std::move(payload3)); // This payload is equivalent with payload2. Insert fails!
75 0 : TLOG() << "Payload3 (equivalent with payload2) insertion success? (Should fail) -> " << ret.second;
76 0 : ret = acc.insert(std::move(payload1));
77 0 : TLOG() << "Payload1 insertion success? -> " << ret.second;
78 0 : ret = acc.insert(std::move(payload5));
79 0 : TLOG() << "Payload5 insertion success? -> " << ret.second;
80 0 : ret = acc.insert(std::move(payload6));
81 0 : TLOG() << "Payload6 insertion success? -> " << ret.second;
82 :
83 0 : TLOG() << "SkipList size: " << acc.size();
84 0 : }
85 :
86 0 : {
87 0 : types::DUMMY_FRAME_STRUCT findpayload;
88 0 : findpayload.set_timestamp(12342);
89 0 : findpayload.set_another_key(2);
90 :
91 0 : SkipListTAcc acc(skl);
92 0 : auto lb = acc.lower_bound(findpayload);
93 0 : auto foundptr = reinterpret_cast<const types::DUMMY_FRAME_STRUCT*>(&(*lb)); // NOLINT
94 0 : auto foundts = foundptr->get_timestamp();
95 0 : TLOG() << "Found element 1 lower bound to 12342 in skiplist with timestamp --> " << foundts;
96 :
97 0 : lb++;
98 0 : foundptr = reinterpret_cast<const types::DUMMY_FRAME_STRUCT*>(&(*lb)); // NOLINT
99 0 : foundts = foundptr->get_timestamp();
100 0 : TLOG() << "Found element 2 lower bound to 12342 in skiplist with timestamp --> " << foundts;
101 :
102 0 : TLOG() << "Dumping SkipList content:";
103 0 : SkipListTIter node = acc.find(payload1);
104 0 : while(node != acc.end()) {
105 0 : auto nodeptr = reinterpret_cast<const types::DUMMY_FRAME_STRUCT*>(&(*node)); // NOLINT
106 0 : auto nodets = nodeptr->get_timestamp();
107 0 : auto nodeck = nodeptr->another_key;
108 0 : TLOG() << " --> Element with timestamp: " << (unsigned)nodets << " other key: " << (unsigned)nodeck;
109 0 : node++;
110 : }
111 0 : }
112 :
113 0 : return 0;
114 0 : } // NOLINT(readability/fn_size)
|