1 #define BOOST_TEST_MODULE RoundRobin_policy_t
2 #include <boost/test/auto_unit_test.hpp>
4 #include "artdaq/Application/Routing/makeRoutingMasterPolicy.hh"
5 #include "fhiclcpp/ParameterSet.h"
6 #include "fhiclcpp/make_ParameterSet.h"
9 BOOST_AUTO_TEST_SUITE(RoundRobin_policy_t)
13 fhicl::ParameterSet ps;
14 fhicl::make_ParameterSet(
"receiver_ranks: [1,2,3,4]", ps);
18 BOOST_REQUIRE_EQUAL(rr->GetReceiverCount(), 4);
21 rr->AddReceiverToken(1, 1);
22 rr->AddReceiverToken(3, 1);
23 rr->AddReceiverToken(2, 1);
24 rr->AddReceiverToken(4, 1);
25 rr->AddReceiverToken(2, 1);
26 auto secondTable = rr->GetCurrentTable();
27 BOOST_REQUIRE_EQUAL(secondTable.size(), 4);
28 BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 1);
29 BOOST_REQUIRE_EQUAL(secondTable[1].destination_rank, 2);
30 BOOST_REQUIRE_EQUAL(secondTable[2].destination_rank, 3);
31 BOOST_REQUIRE_EQUAL(secondTable[3].destination_rank, 4);
32 BOOST_REQUIRE_EQUAL(secondTable[0].sequence_id, 1);
33 BOOST_REQUIRE_EQUAL(secondTable[1].sequence_id, 2);
34 BOOST_REQUIRE_EQUAL(secondTable[2].sequence_id, 3);
35 BOOST_REQUIRE_EQUAL(secondTable[3].sequence_id, 4);
37 rr->AddReceiverToken(1, 0);
39 auto thirdTable = rr->GetCurrentTable();
40 BOOST_REQUIRE_EQUAL(thirdTable.size(), 0);
42 rr->AddReceiverToken(1, 2);
43 rr->AddReceiverToken(2, 1);
44 rr->AddReceiverToken(3, 1);
45 rr->AddReceiverToken(4, 2);
46 auto fourthTable = rr->GetCurrentTable();
47 BOOST_REQUIRE_EQUAL(fourthTable.size(), 4);
48 BOOST_REQUIRE_EQUAL(fourthTable[0].destination_rank, 1);
50 rr->AddReceiverToken(3, 1);
51 auto fifthTable = rr->GetCurrentTable();
52 BOOST_REQUIRE_EQUAL(fifthTable.size(), 4);
53 BOOST_REQUIRE_EQUAL(fifthTable[0].destination_rank, 1);
59 fhicl::ParameterSet ps;
60 fhicl::make_ParameterSet(
"receiver_ranks: [1,2,3,4] minimum_participants: 2", ps);
64 BOOST_REQUIRE_EQUAL(rr->GetReceiverCount(), 4);
67 rr->AddReceiverToken(1, 1);
68 rr->AddReceiverToken(3, 1);
69 rr->AddReceiverToken(2, 1);
70 rr->AddReceiverToken(4, 1);
71 rr->AddReceiverToken(2, 1);
72 auto secondTable = rr->GetCurrentTable();
73 BOOST_REQUIRE_EQUAL(secondTable.size(), 4);
74 BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 1);
75 BOOST_REQUIRE_EQUAL(secondTable[1].destination_rank, 2);
76 BOOST_REQUIRE_EQUAL(secondTable[2].destination_rank, 3);
77 BOOST_REQUIRE_EQUAL(secondTable[3].destination_rank, 4);
78 BOOST_REQUIRE_EQUAL(secondTable[0].sequence_id, 1);
79 BOOST_REQUIRE_EQUAL(secondTable[1].sequence_id, 2);
80 BOOST_REQUIRE_EQUAL(secondTable[2].sequence_id, 3);
81 BOOST_REQUIRE_EQUAL(secondTable[3].sequence_id, 4);
83 rr->AddReceiverToken(1, 0);
85 auto thirdTable = rr->GetCurrentTable();
86 BOOST_REQUIRE_EQUAL(thirdTable.size(), 0);
89 rr->AddReceiverToken(1, 1);
90 auto fourthTable = rr->GetCurrentTable();
91 BOOST_REQUIRE_EQUAL(fourthTable.size(), 2);
93 BOOST_REQUIRE_EQUAL(fourthTable[0].destination_rank, 1);
94 BOOST_REQUIRE_EQUAL(fourthTable[1].destination_rank, 2);
95 BOOST_REQUIRE_EQUAL(fourthTable[0].sequence_id, 5);
96 BOOST_REQUIRE_EQUAL(fourthTable[1].sequence_id, 6);
98 rr->AddReceiverToken(1, 2);
99 rr->AddReceiverToken(2, 2);
100 rr->AddReceiverToken(3, 1);
101 rr->AddReceiverToken(4, 2);
102 auto fifthTable = rr->GetCurrentTable();
103 BOOST_REQUIRE_EQUAL(fifthTable.size(), 7);
104 BOOST_REQUIRE_EQUAL(fifthTable[0].destination_rank, 1);
106 rr->AddReceiverToken(3, 1);
107 auto sixthTable = rr->GetCurrentTable();
108 BOOST_REQUIRE_EQUAL(sixthTable.size(), 0);
112 BOOST_AUTO_TEST_SUITE_END()
std::unique_ptr< RoutingMasterPolicy > makeRoutingMasterPolicy(std::string const &policy_plugin_spec, fhicl::ParameterSet const &ps)
Load a RoutingMasterPolicy plugin.