artdaq  v3_00_01
RoundRobin_policy_t.cc
1 #define BOOST_TEST_MODULE RoundRobin_policy_t
2 #include <boost/test/auto_unit_test.hpp>
3 
4 #include "artdaq/Application/Routing/makeRoutingMasterPolicy.hh"
5 #include "fhiclcpp/ParameterSet.h"
6 #include "fhiclcpp/make_ParameterSet.h"
7 
8 
9 BOOST_AUTO_TEST_SUITE(RoundRobin_policy_t)
10 
11 BOOST_AUTO_TEST_CASE(Simple)
12 {
13  fhicl::ParameterSet ps;
14  fhicl::make_ParameterSet("receiver_ranks: [1,2,3,4]", ps);
15 
16  auto rr = artdaq::makeRoutingMasterPolicy("RoundRobin", ps);
17 
18  BOOST_REQUIRE_EQUAL(rr->GetReceiverCount(), 4);
19 
20  rr->Reset();
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, 0);
33  BOOST_REQUIRE_EQUAL(secondTable[1].sequence_id, 1);
34  BOOST_REQUIRE_EQUAL(secondTable[2].sequence_id, 2);
35  BOOST_REQUIRE_EQUAL(secondTable[3].sequence_id, 3);
36 
37  rr->AddReceiverToken(1, 0);
38 
39  auto thirdTable = rr->GetCurrentTable();
40  BOOST_REQUIRE_EQUAL(thirdTable.size(), 0);
41 
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);
49 
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);
54 
55 }
56 
57 BOOST_AUTO_TEST_SUITE_END()
std::unique_ptr< RoutingMasterPolicy > makeRoutingMasterPolicy(std::string const &policy_plugin_spec, fhicl::ParameterSet const &ps)
Load a RoutingMasterPolicy plugin.