1 #define BOOST_TEST_MODULE CapacityTest_policy_t
2 #include <boost/test/unit_test.hpp>
4 #include "artdaq-utilities/Plugins/MakeParameterSet.hh"
5 #include "artdaq/RoutingPolicies/makeRoutingManagerPolicy.hh"
6 #include "fhiclcpp/ParameterSet.h"
8 BOOST_AUTO_TEST_SUITE(CapacityTest_policy_t)
12 TLOG(TLVL_INFO) <<
"CapacityTest_policy_t Test Case Simple BEGIN";
13 fhicl::ParameterSet ps = artdaq::make_pset(
"tokens_used_per_table_percent: 50");
17 ct->AddReceiverToken(1, 10);
18 ct->AddReceiverToken(2, 10);
19 ct->AddReceiverToken(3, 10);
20 ct->AddReceiverToken(4, 10);
21 BOOST_REQUIRE_EQUAL(ct->GetReceiverCount(), 4);
23 auto firstTable = ct->GetCurrentTable();
24 BOOST_REQUIRE_EQUAL(firstTable.size(), 20);
25 BOOST_REQUIRE_EQUAL(firstTable[0].destination_rank, 1);
26 BOOST_REQUIRE_EQUAL(firstTable[0].sequence_id, 1);
27 BOOST_REQUIRE_EQUAL(firstTable[firstTable.size() - 1].destination_rank, 2);
28 BOOST_REQUIRE_EQUAL(firstTable[firstTable.size() - 1].sequence_id, 20);
30 ct->ResetTokensUsedSinceLastUpdate();
33 ct->AddReceiverToken(1, 1);
34 ct->AddReceiverToken(3, 1);
35 ct->AddReceiverToken(2, 1);
36 ct->AddReceiverToken(4, 1);
37 ct->AddReceiverToken(2, 1);
38 auto secondTable = ct->GetCurrentTable();
39 BOOST_REQUIRE_EQUAL(secondTable.size(), 13);
40 BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 1);
41 BOOST_REQUIRE_EQUAL(secondTable[0].sequence_id, 21);
42 BOOST_REQUIRE_EQUAL(secondTable[1].destination_rank, 2);
43 BOOST_REQUIRE_EQUAL(secondTable[1].sequence_id, 22);
44 BOOST_REQUIRE_EQUAL(secondTable[2].destination_rank, 2);
45 BOOST_REQUIRE_EQUAL(secondTable[2].sequence_id, 23);
46 BOOST_REQUIRE_EQUAL(secondTable[3].destination_rank, 3);
47 BOOST_REQUIRE_EQUAL(secondTable[3].sequence_id, 24);
48 BOOST_REQUIRE_EQUAL(secondTable[4].destination_rank, 3);
49 BOOST_REQUIRE_EQUAL(secondTable[4].sequence_id, 25);
50 BOOST_REQUIRE_EQUAL(secondTable[5].destination_rank, 3);
51 BOOST_REQUIRE_EQUAL(secondTable[5].sequence_id, 26);
52 BOOST_REQUIRE_EQUAL(secondTable[6].destination_rank, 3);
53 BOOST_REQUIRE_EQUAL(secondTable[6].sequence_id, 27);
54 BOOST_REQUIRE_EQUAL(secondTable[7].destination_rank, 3);
55 BOOST_REQUIRE_EQUAL(secondTable[7].sequence_id, 28);
56 BOOST_REQUIRE_EQUAL(secondTable[8].destination_rank, 3);
57 BOOST_REQUIRE_EQUAL(secondTable[8].sequence_id, 29);
58 BOOST_REQUIRE_EQUAL(secondTable[9].destination_rank, 3);
59 BOOST_REQUIRE_EQUAL(secondTable[9].sequence_id, 30);
60 BOOST_REQUIRE_EQUAL(secondTable[10].destination_rank, 3);
61 BOOST_REQUIRE_EQUAL(secondTable[10].sequence_id, 31);
62 BOOST_REQUIRE_EQUAL(secondTable[11].destination_rank, 3);
63 BOOST_REQUIRE_EQUAL(secondTable[11].sequence_id, 32);
64 BOOST_REQUIRE_EQUAL(secondTable[12].destination_rank, 3);
65 BOOST_REQUIRE_EQUAL(secondTable[12].sequence_id, 33);
67 ct->ResetTokensUsedSinceLastUpdate();
69 ct->AddReceiverToken(1, 0);
70 auto thirdTable = ct->GetCurrentTable();
71 BOOST_REQUIRE_EQUAL(thirdTable.size(), 6);
72 BOOST_REQUIRE_EQUAL(thirdTable[0].destination_rank, 3);
73 BOOST_REQUIRE_EQUAL(thirdTable[0].sequence_id, 34);
74 BOOST_REQUIRE_EQUAL(thirdTable[1].destination_rank, 4);
75 BOOST_REQUIRE_EQUAL(thirdTable[1].sequence_id, 35);
76 BOOST_REQUIRE_EQUAL(thirdTable[2].destination_rank, 4);
77 BOOST_REQUIRE_EQUAL(thirdTable[2].sequence_id, 36);
78 BOOST_REQUIRE_EQUAL(thirdTable[3].destination_rank, 4);
79 BOOST_REQUIRE_EQUAL(thirdTable[3].sequence_id, 37);
80 BOOST_REQUIRE_EQUAL(thirdTable[4].destination_rank, 4);
81 BOOST_REQUIRE_EQUAL(thirdTable[4].sequence_id, 38);
82 BOOST_REQUIRE_EQUAL(thirdTable[5].destination_rank, 4);
83 BOOST_REQUIRE_EQUAL(thirdTable[5].sequence_id, 39);
85 ct->AddReceiverToken(1, 2);
86 ct->AddReceiverToken(2, 1);
87 ct->AddReceiverToken(3, 1);
88 ct->AddReceiverToken(4, 2);
89 ct->ResetTokensUsedSinceLastUpdate();
90 auto fourthTable = ct->GetCurrentTable();
91 BOOST_REQUIRE_EQUAL(fourthTable.size(), 6);
92 BOOST_REQUIRE_EQUAL(fourthTable[0].destination_rank, 1);
93 BOOST_REQUIRE_EQUAL(fourthTable[0].sequence_id, 40);
94 BOOST_REQUIRE_EQUAL(fourthTable[1].destination_rank, 1);
95 BOOST_REQUIRE_EQUAL(fourthTable[1].sequence_id, 41);
96 BOOST_REQUIRE_EQUAL(fourthTable[2].destination_rank, 2);
97 BOOST_REQUIRE_EQUAL(fourthTable[2].sequence_id, 42);
98 BOOST_REQUIRE_EQUAL(fourthTable[3].destination_rank, 3);
99 BOOST_REQUIRE_EQUAL(fourthTable[3].sequence_id, 43);
100 BOOST_REQUIRE_EQUAL(fourthTable[4].destination_rank, 4);
101 BOOST_REQUIRE_EQUAL(fourthTable[4].sequence_id, 44);
102 BOOST_REQUIRE_EQUAL(fourthTable[5].destination_rank, 4);
103 BOOST_REQUIRE_EQUAL(fourthTable[5].sequence_id, 45);
105 ct->AddReceiverToken(3, 1);
106 ct->ResetTokensUsedSinceLastUpdate();
107 auto fifthTable = ct->GetCurrentTable();
108 BOOST_REQUIRE_EQUAL(fifthTable.size(), 4);
109 BOOST_REQUIRE_EQUAL(fifthTable[0].destination_rank, 3);
110 BOOST_REQUIRE_EQUAL(fifthTable[0].sequence_id, 46);
111 BOOST_REQUIRE_EQUAL(fifthTable[1].destination_rank, 4);
112 BOOST_REQUIRE_EQUAL(fifthTable[1].sequence_id, 47);
113 BOOST_REQUIRE_EQUAL(fifthTable[2].destination_rank, 4);
114 BOOST_REQUIRE_EQUAL(fifthTable[2].sequence_id, 48);
115 BOOST_REQUIRE_EQUAL(fifthTable[3].destination_rank, 4);
116 BOOST_REQUIRE_EQUAL(fifthTable[3].sequence_id, 49);
119 ct->AddReceiverToken(1, 2);
120 ct->ResetTokensUsedSinceLastUpdate();
121 auto sixthTable = ct->GetCurrentTable();
122 BOOST_REQUIRE_EQUAL(sixthTable.size(), 1);
123 BOOST_REQUIRE_EQUAL(sixthTable[0].destination_rank, 1);
124 BOOST_REQUIRE_EQUAL(sixthTable[0].sequence_id, 1);
125 TLOG(TLVL_INFO) <<
"CapacityTest_policy_t Test Case Simple END";
130 TLOG(TLVL_INFO) <<
"CapacityTest_policy_t Test Case DataFlowMode BEGIN";
131 fhicl::ParameterSet ps = artdaq::make_pset(
"routing_manager_mode: DataFlow");
136 ct->AddReceiverToken(1, 3);
137 ct->AddReceiverToken(2, 3);
138 BOOST_REQUIRE_EQUAL(ct->GetReceiverCount(), 2);
139 auto route = ct->GetRouteForSequenceID(1, 4);
140 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
141 BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
144 route = ct->GetRouteForSequenceID(1, 5);
145 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
146 BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
149 route = ct->GetRouteForSequenceID(1, 5);
150 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
151 BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
153 route = ct->GetRouteForSequenceID(2, 4);
154 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
155 BOOST_REQUIRE_EQUAL(route.sequence_id, 2);
157 route = ct->GetRouteForSequenceID(2, 5);
158 BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
160 ct->AddReceiverToken(1, 1);
161 route = ct->GetRouteForSequenceID(2, 5);
162 BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
163 BOOST_REQUIRE_EQUAL(route.sequence_id, 2);
166 route = ct->GetRouteForSequenceID(1, 6);
167 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
168 BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
171 route = ct->GetRouteForSequenceID(10343, 4);
172 BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
173 BOOST_REQUIRE_EQUAL(route.sequence_id, 10343);
175 TLOG(TLVL_INFO) <<
"CapacityTest_policy_t Test Case DataFlowMode END";
180 TLOG(TLVL_INFO) <<
"CapacityTest_policy_t Test Case RequestBasedEventBuilding BEGIN";
181 fhicl::ParameterSet ps = artdaq::make_pset(
"routing_manager_mode: RequestBasedEventBuilding routing_cache_size: 2");
186 ct->AddReceiverToken(1, 3);
187 ct->AddReceiverToken(2, 3);
188 BOOST_REQUIRE_EQUAL(ct->GetReceiverCount(), 2);
190 auto route = ct->GetRouteForSequenceID(1, 4);
191 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
192 BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
195 route = ct->GetRouteForSequenceID(1, 5);
196 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
197 BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
200 auto firstTable = ct->GetCurrentTable();
201 BOOST_REQUIRE_EQUAL(firstTable.size(), 1);
202 BOOST_REQUIRE_EQUAL(firstTable[0].destination_rank, 1);
205 route = ct->GetRouteForSequenceID(12343, 4);
206 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
207 BOOST_REQUIRE_EQUAL(route.sequence_id, 12343);
210 route = ct->GetRouteForSequenceID(4, 5);
211 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
212 BOOST_REQUIRE_EQUAL(route.sequence_id, 4);
215 route = ct->GetRouteForSequenceID(1, 6);
216 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
217 BOOST_REQUIRE_EQUAL(route.sequence_id, 1);
220 route = ct->GetRouteForSequenceID(10, 4);
221 BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
222 BOOST_REQUIRE_EQUAL(route.sequence_id, 10);
223 route = ct->GetRouteForSequenceID(11, 4);
224 BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
225 BOOST_REQUIRE_EQUAL(route.sequence_id, 11);
226 route = ct->GetRouteForSequenceID(12, 4);
227 BOOST_REQUIRE_EQUAL(route.destination_rank, 2);
228 BOOST_REQUIRE_EQUAL(route.sequence_id, 12);
230 route = ct->GetRouteForSequenceID(50, 4);
231 BOOST_REQUIRE_EQUAL(route.destination_rank, -1);
233 ct->AddReceiverToken(1, 1);
234 route = ct->GetRouteForSequenceID(50, 4);
235 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
236 BOOST_REQUIRE_EQUAL(route.sequence_id, 50);
238 route = ct->GetRouteForSequenceID(50, 5);
239 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
240 BOOST_REQUIRE_EQUAL(route.sequence_id, 50);
243 auto secondTable = ct->GetCurrentTable();
244 BOOST_REQUIRE_EQUAL(secondTable.size(), 6);
245 BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 1);
246 BOOST_REQUIRE_EQUAL(secondTable[0].sequence_id, 4);
247 BOOST_REQUIRE_EQUAL(secondTable[1].destination_rank, 2);
248 BOOST_REQUIRE_EQUAL(secondTable[1].sequence_id, 10);
249 BOOST_REQUIRE_EQUAL(secondTable[2].destination_rank, 2);
250 BOOST_REQUIRE_EQUAL(secondTable[2].sequence_id, 11);
251 BOOST_REQUIRE_EQUAL(secondTable[3].destination_rank, 2);
252 BOOST_REQUIRE_EQUAL(secondTable[3].sequence_id, 12);
253 BOOST_REQUIRE_EQUAL(secondTable[4].destination_rank, 1);
254 BOOST_REQUIRE_EQUAL(secondTable[4].sequence_id, 50);
255 BOOST_REQUIRE_EQUAL(secondTable[5].destination_rank, 1);
256 BOOST_REQUIRE_EQUAL(secondTable[5].sequence_id, 12343);
259 BOOST_REQUIRE_EQUAL(ct->GetCacheSize(), 2);
260 auto thirdTable = ct->GetCurrentTable();
261 BOOST_REQUIRE_EQUAL(thirdTable.size(), 0);
263 BOOST_REQUIRE(ct->CacheHasRoute(50));
264 BOOST_REQUIRE(!ct->CacheHasRoute(4));
265 route = ct->GetRouteForSequenceID(50, 6);
266 BOOST_REQUIRE_EQUAL(route.destination_rank, 1);
267 BOOST_REQUIRE_EQUAL(route.sequence_id, 50);
269 TLOG(TLVL_INFO) <<
"CapacityTest_policy_t Test Case RequestBasedEventBuilding END";
272 BOOST_AUTO_TEST_SUITE_END()
std::shared_ptr< RoutingManagerPolicy > makeRoutingManagerPolicy(std::string const &policy_plugin_spec, fhicl::ParameterSet const &ps)
Load a RoutingManagerPolicy plugin.