artdaq  v3_10_02
CapacityTest_policy_t.cc
1 #define BOOST_TEST_MODULE CapacityTest_policy_t
2 #include <boost/test/unit_test.hpp>
3 
4 #include "artdaq/RoutingPolicies/makeRoutingManagerPolicy.hh"
5 #include "fhiclcpp/ParameterSet.h"
6 #include "artdaq-utilities/Plugins/MakeParameterSet.hh"
7 
8 BOOST_AUTO_TEST_SUITE(CapacityTest_policy_t)
9 
10 BOOST_AUTO_TEST_CASE(Simple)
11 {
12  fhicl::ParameterSet ps = artdaq::make_pset("receiver_ranks: [1,2,3,4] tokens_used_per_table_percent: 50");
13 
14  auto ct = artdaq::makeRoutingManagerPolicy("CapacityTest", ps);
15 
16  BOOST_REQUIRE_EQUAL(ct->GetReceiverCount(), 4);
17 
18  ct->AddReceiverToken(1, 10);
19  ct->AddReceiverToken(2, 10);
20  ct->AddReceiverToken(3, 10);
21  ct->AddReceiverToken(4, 10);
22  auto firstTable = ct->GetCurrentTable();
23  BOOST_REQUIRE_EQUAL(firstTable.size(), 20);
24  BOOST_REQUIRE_EQUAL(firstTable[0].destination_rank, 1);
25  BOOST_REQUIRE_EQUAL(firstTable[0].sequence_id, 1);
26  BOOST_REQUIRE_EQUAL(firstTable[firstTable.size() - 1].destination_rank, 2);
27  BOOST_REQUIRE_EQUAL(firstTable[firstTable.size() - 1].sequence_id, 20);
28 
29  //ct->Reset();
30  ct->AddReceiverToken(1, 1);
31  ct->AddReceiverToken(3, 1);
32  ct->AddReceiverToken(2, 1);
33  ct->AddReceiverToken(4, 1);
34  ct->AddReceiverToken(2, 1);
35  auto secondTable = ct->GetCurrentTable();
36  BOOST_REQUIRE_EQUAL(secondTable.size(), 13);
37  BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 1);
38  BOOST_REQUIRE_EQUAL(secondTable[0].sequence_id, 21);
39  BOOST_REQUIRE_EQUAL(secondTable[1].destination_rank, 2);
40  BOOST_REQUIRE_EQUAL(secondTable[1].sequence_id, 22);
41  BOOST_REQUIRE_EQUAL(secondTable[2].destination_rank, 2);
42  BOOST_REQUIRE_EQUAL(secondTable[2].sequence_id, 23);
43  BOOST_REQUIRE_EQUAL(secondTable[3].destination_rank, 3);
44  BOOST_REQUIRE_EQUAL(secondTable[3].sequence_id, 24);
45  BOOST_REQUIRE_EQUAL(secondTable[4].destination_rank, 3);
46  BOOST_REQUIRE_EQUAL(secondTable[4].sequence_id, 25);
47  BOOST_REQUIRE_EQUAL(secondTable[5].destination_rank, 3);
48  BOOST_REQUIRE_EQUAL(secondTable[5].sequence_id, 26);
49  BOOST_REQUIRE_EQUAL(secondTable[6].destination_rank, 3);
50  BOOST_REQUIRE_EQUAL(secondTable[6].sequence_id, 27);
51  BOOST_REQUIRE_EQUAL(secondTable[7].destination_rank, 3);
52  BOOST_REQUIRE_EQUAL(secondTable[7].sequence_id, 28);
53  BOOST_REQUIRE_EQUAL(secondTable[8].destination_rank, 3);
54  BOOST_REQUIRE_EQUAL(secondTable[8].sequence_id, 29);
55  BOOST_REQUIRE_EQUAL(secondTable[9].destination_rank, 3);
56  BOOST_REQUIRE_EQUAL(secondTable[9].sequence_id, 30);
57  BOOST_REQUIRE_EQUAL(secondTable[10].destination_rank, 3);
58  BOOST_REQUIRE_EQUAL(secondTable[10].sequence_id, 31);
59  BOOST_REQUIRE_EQUAL(secondTable[11].destination_rank, 3);
60  BOOST_REQUIRE_EQUAL(secondTable[11].sequence_id, 32);
61  BOOST_REQUIRE_EQUAL(secondTable[12].destination_rank, 3);
62  BOOST_REQUIRE_EQUAL(secondTable[12].sequence_id, 33);
63 
64  //ct->Reset();
65  ct->AddReceiverToken(1, 0);
66  auto thirdTable = ct->GetCurrentTable();
67  BOOST_REQUIRE_EQUAL(thirdTable.size(), 6);
68  BOOST_REQUIRE_EQUAL(thirdTable[0].destination_rank, 3);
69  BOOST_REQUIRE_EQUAL(thirdTable[0].sequence_id, 34);
70  BOOST_REQUIRE_EQUAL(thirdTable[1].destination_rank, 4);
71  BOOST_REQUIRE_EQUAL(thirdTable[1].sequence_id, 35);
72  BOOST_REQUIRE_EQUAL(thirdTable[2].destination_rank, 4);
73  BOOST_REQUIRE_EQUAL(thirdTable[2].sequence_id, 36);
74  BOOST_REQUIRE_EQUAL(thirdTable[3].destination_rank, 4);
75  BOOST_REQUIRE_EQUAL(thirdTable[3].sequence_id, 37);
76  BOOST_REQUIRE_EQUAL(thirdTable[4].destination_rank, 4);
77  BOOST_REQUIRE_EQUAL(thirdTable[4].sequence_id, 38);
78  BOOST_REQUIRE_EQUAL(thirdTable[5].destination_rank, 4);
79  BOOST_REQUIRE_EQUAL(thirdTable[5].sequence_id, 39);
80 
81  ct->AddReceiverToken(1, 2);
82  ct->AddReceiverToken(2, 1);
83  ct->AddReceiverToken(3, 1);
84  ct->AddReceiverToken(4, 2);
85  auto fourthTable = ct->GetCurrentTable();
86  BOOST_REQUIRE_EQUAL(fourthTable.size(), 6);
87  BOOST_REQUIRE_EQUAL(fourthTable[0].destination_rank, 1);
88  BOOST_REQUIRE_EQUAL(fourthTable[0].sequence_id, 40);
89  BOOST_REQUIRE_EQUAL(fourthTable[1].destination_rank, 1);
90  BOOST_REQUIRE_EQUAL(fourthTable[1].sequence_id, 41);
91  BOOST_REQUIRE_EQUAL(fourthTable[2].destination_rank, 2);
92  BOOST_REQUIRE_EQUAL(fourthTable[2].sequence_id, 42);
93  BOOST_REQUIRE_EQUAL(fourthTable[3].destination_rank, 3);
94  BOOST_REQUIRE_EQUAL(fourthTable[3].sequence_id, 43);
95  BOOST_REQUIRE_EQUAL(fourthTable[4].destination_rank, 4);
96  BOOST_REQUIRE_EQUAL(fourthTable[4].sequence_id, 44);
97  BOOST_REQUIRE_EQUAL(fourthTable[5].destination_rank, 4);
98  BOOST_REQUIRE_EQUAL(fourthTable[5].sequence_id, 45);
99 
100  ct->AddReceiverToken(3, 1);
101  auto fifthTable = ct->GetCurrentTable();
102  BOOST_REQUIRE_EQUAL(fifthTable.size(), 4);
103  BOOST_REQUIRE_EQUAL(fifthTable[0].destination_rank, 3);
104  BOOST_REQUIRE_EQUAL(fifthTable[0].sequence_id, 46);
105  BOOST_REQUIRE_EQUAL(fifthTable[1].destination_rank, 4);
106  BOOST_REQUIRE_EQUAL(fifthTable[1].sequence_id, 47);
107  BOOST_REQUIRE_EQUAL(fifthTable[2].destination_rank, 4);
108  BOOST_REQUIRE_EQUAL(fifthTable[2].sequence_id, 48);
109  BOOST_REQUIRE_EQUAL(fifthTable[3].destination_rank, 4);
110  BOOST_REQUIRE_EQUAL(fifthTable[3].sequence_id, 49);
111 
112  ct->Reset();
113  ct->AddReceiverToken(1, 2);
114  auto sixthTable = ct->GetCurrentTable();
115  BOOST_REQUIRE_EQUAL(sixthTable.size(), 1);
116  BOOST_REQUIRE_EQUAL(sixthTable[0].destination_rank, 1);
117  BOOST_REQUIRE_EQUAL(sixthTable[0].sequence_id, 1);
118 }
119 
120 BOOST_AUTO_TEST_SUITE_END()
std::shared_ptr< RoutingManagerPolicy > makeRoutingManagerPolicy(std::string const &policy_plugin_spec, fhicl::ParameterSet const &ps)
Load a RoutingManagerPolicy plugin.