75 std::vector<fair::mq::Channel>
channels{
76 fair::mq::Channel(
"from_A_to_B")};
79 bool copyByDefault =
true;
85 .channel =
"from_A_to_B",
89 auto findChannelByName = [&
channels](std::string
const& channelName) -> fair::mq::Channel& {
91 if (channel.GetName() == channelName) {
95 throw std::runtime_error(
"Channel not found");
98 proxy.
bind({}, {},
routes, findChannelByName,
nullptr);
100 std::vector<std::vector<fair::mq::MessagePtr>> currentSetOfInputs;
101 std::vector<fair::mq::MessagePtr> messageSet;
103 auto transport = fair::mq::TransportFactory::CreateTransportFactory(
"zeromq");
104 fair::mq::MessagePtr payload(transport->CreateMessage());
105 auto channelAlloc = o2::pmr::getTransportAllocator(transport.get());
107 messageSet.emplace_back(std::move(header));
108 messageSet.emplace_back(std::move(payload));
110 currentSetOfInputs.emplace_back(std::move(messageSet));
112 auto spans = asSpans(currentSetOfInputs);
114 REQUIRE(
result.size() == 1);
118TEST_CASE(
"ForwardInputsSingleMessageSingleRouteNoConsume")
128 std::vector<fair::mq::Channel>
channels{
129 fair::mq::Channel(
"from_A_to_B")};
131 bool copyByDefault =
false;
137 .channel =
"from_A_to_B",
141 auto findChannelByName = [&
channels](std::string
const& channelName) -> fair::mq::Channel& {
143 if (channel.GetName() == channelName) {
147 throw std::runtime_error(
"Channel not found");
150 proxy.
bind({}, {},
routes, findChannelByName,
nullptr);
152 std::vector<std::vector<fair::mq::MessagePtr>> currentSetOfInputs;
153 std::vector<fair::mq::MessagePtr> messageSet;
155 auto transport = fair::mq::TransportFactory::CreateTransportFactory(
"zeromq");
156 fair::mq::MessagePtr payload(
nullptr);
157 REQUIRE(payload.get() ==
nullptr);
158 auto channelAlloc = o2::pmr::getTransportAllocator(transport.get());
160 messageSet.emplace_back(std::move(header));
161 messageSet.emplace_back(std::move(payload));
163 currentSetOfInputs.emplace_back(std::move(messageSet));
165 auto spans = asSpans(currentSetOfInputs);
167 REQUIRE(
result.size() == 1);
184 std::vector<fair::mq::Channel>
channels{
185 fair::mq::Channel(
"from_A_to_B")};
188 bool copyByDefault =
true;
194 .channel =
"from_A_to_B",
198 auto findChannelByName = [&
channels](std::string
const& channelName) -> fair::mq::Channel& {
200 if (channel.GetName() == channelName) {
204 throw std::runtime_error(
"Channel not found");
207 proxy.
bind({}, {},
routes, findChannelByName,
nullptr);
209 std::vector<std::vector<fair::mq::MessagePtr>> currentSetOfInputs;
210 std::vector<fair::mq::MessagePtr> messageSet;
212 auto transport = fair::mq::TransportFactory::CreateTransportFactory(
"zeromq");
213 fair::mq::MessagePtr payload(transport->CreateMessage());
214 auto channelAlloc = o2::pmr::getTransportAllocator(transport.get());
216 REQUIRE(o2::header::get<SourceInfoHeader*>(header->GetData()));
217 messageSet.emplace_back(std::move(header));
218 messageSet.emplace_back(std::move(payload));
220 currentSetOfInputs.emplace_back(std::move(messageSet));
222 auto spans = asSpans(currentSetOfInputs);
224 REQUIRE(
result.size() == 1);
231TEST_CASE(
"ForwardInputsSingleMessageSingleRouteWithOldestPossible")
244 std::vector<fair::mq::Channel>
channels{
245 fair::mq::Channel(
"from_A_to_B")};
248 bool copyByDefault =
true;
254 .channel =
"from_A_to_B",
258 auto findChannelByName = [&
channels](std::string
const& channelName) -> fair::mq::Channel& {
260 if (channel.GetName() == channelName) {
264 throw std::runtime_error(
"Channel not found");
267 proxy.
bind({}, {},
routes, findChannelByName,
nullptr);
269 std::vector<std::vector<fair::mq::MessagePtr>> currentSetOfInputs;
270 std::vector<fair::mq::MessagePtr> messageSet;
272 auto transport = fair::mq::TransportFactory::CreateTransportFactory(
"zeromq");
273 fair::mq::MessagePtr payload(transport->CreateMessage());
274 auto channelAlloc = o2::pmr::getTransportAllocator(transport.get());
276 REQUIRE(o2::header::get<DomainInfoHeader*>(header->GetData()));
277 messageSet.emplace_back(std::move(header));
278 messageSet.emplace_back(std::move(payload));
280 currentSetOfInputs.emplace_back(std::move(messageSet));
282 auto spans = asSpans(currentSetOfInputs);
284 REQUIRE(
result.size() == 1);
302 std::vector<fair::mq::Channel>
channels{
303 fair::mq::Channel(
"from_A_to_B"),
304 fair::mq::Channel(
"from_A_to_C"),
308 bool copyByDefault =
true;
310 std::vector<ForwardRoute>
routes{
315 .channel =
"from_A_to_B",
322 .channel =
"from_A_to_C",
326 auto findChannelByName = [&
channels](std::string
const& channelName) -> fair::mq::Channel& {
328 if (channel.GetName() == channelName) {
332 throw std::runtime_error(
"Channel not found");
335 proxy.
bind({}, {},
routes, findChannelByName,
nullptr);
337 std::vector<std::vector<fair::mq::MessagePtr>> currentSetOfInputs;
338 std::vector<fair::mq::MessagePtr> messageSet;
340 auto transport = fair::mq::TransportFactory::CreateTransportFactory(
"zeromq");
341 fair::mq::MessagePtr payload(transport->CreateMessage());
342 auto channelAlloc = o2::pmr::getTransportAllocator(transport.get());
344 messageSet.emplace_back(std::move(header));
345 messageSet.emplace_back(std::move(payload));
347 currentSetOfInputs.emplace_back(std::move(messageSet));
349 auto spans = asSpans(currentSetOfInputs);
351 REQUIRE(
result.size() == 2);
356TEST_CASE(
"ForwardInputsSingleMessageMultipleRoutesExternals")
367 std::vector<fair::mq::Channel>
channels{
368 fair::mq::Channel(
"external"),
369 fair::mq::Channel(
"from_A_to_C"),
373 bool copyByDefault =
true;
375 std::vector<ForwardRoute>
routes{
380 .channel =
"external",
387 .channel =
"from_A_to_C",
391 auto findChannelByName = [&
channels](std::string
const& channelName) -> fair::mq::Channel& {
393 if (channel.GetName() == channelName) {
397 throw std::runtime_error(
"Channel not found");
400 proxy.
bind({}, {},
routes, findChannelByName,
nullptr);
402 std::vector<std::vector<fair::mq::MessagePtr>> currentSetOfInputs;
403 std::vector<fair::mq::MessagePtr> messageSet;
405 auto transport = fair::mq::TransportFactory::CreateTransportFactory(
"zeromq");
406 fair::mq::MessagePtr payload(transport->CreateMessage());
407 auto channelAlloc = o2::pmr::getTransportAllocator(transport.get());
409 messageSet.emplace_back(std::move(header));
410 messageSet.emplace_back(std::move(payload));
412 currentSetOfInputs.emplace_back(std::move(messageSet));
414 auto spans = asSpans(currentSetOfInputs);
416 REQUIRE(
result.size() == 2);
439 std::vector<fair::mq::Channel>
channels{
440 fair::mq::Channel(
"from_A_to_B"),
441 fair::mq::Channel(
"from_A_to_C"),
445 bool copyByDefault =
true;
447 std::vector<ForwardRoute>
routes{
452 .channel =
"from_A_to_B",
459 .channel =
"from_A_to_C",
463 auto findChannelByName = [&
channels](std::string
const& channelName) -> fair::mq::Channel& {
465 if (channel.GetName() == channelName) {
469 throw std::runtime_error(
"Channel not found");
472 proxy.
bind({}, {},
routes, findChannelByName,
nullptr);
474 std::vector<std::vector<fair::mq::MessagePtr>> currentSetOfInputs;
476 auto transport = fair::mq::TransportFactory::CreateTransportFactory(
"zeromq");
477 fair::mq::MessagePtr payload1(transport->CreateMessage());
478 fair::mq::MessagePtr payload2(transport->CreateMessage());
479 auto channelAlloc = o2::pmr::getTransportAllocator(transport.get());
481 std::vector<fair::mq::MessagePtr> messageSet1;
482 messageSet1.emplace_back(std::move(header1));
483 messageSet1.emplace_back(std::move(payload1));
487 std::vector<fair::mq::MessagePtr> messageSet2;
488 messageSet2.emplace_back(std::move(header2));
489 messageSet2.emplace_back(std::move(payload2));
491 currentSetOfInputs.emplace_back(std::move(messageSet1));
492 currentSetOfInputs.emplace_back(std::move(messageSet2));
493 REQUIRE(currentSetOfInputs.size() == 2);
495 auto spans = asSpans(currentSetOfInputs);
497 REQUIRE(
result.size() == 2);
502TEST_CASE(
"ForwardInputsSingleMessageMultipleRoutesOnlyOneMatches")
513 std::vector<fair::mq::Channel>
channels{
514 fair::mq::Channel(
"from_A_to_B"),
515 fair::mq::Channel(
"from_A_to_C"),
519 bool copyByDefault =
true;
521 std::vector<ForwardRoute>
routes{
526 .channel =
"from_A_to_B",
533 .channel =
"from_A_to_C",
537 auto findChannelByName = [&
channels](std::string
const& channelName) -> fair::mq::Channel& {
539 if (channel.GetName() == channelName) {
543 throw std::runtime_error(
"Channel not found");
546 proxy.
bind({}, {},
routes, findChannelByName,
nullptr);
548 std::vector<std::vector<fair::mq::MessagePtr>> currentSetOfInputs;
549 std::vector<fair::mq::MessagePtr> messageSet;
551 auto transport = fair::mq::TransportFactory::CreateTransportFactory(
"zeromq");
552 fair::mq::MessagePtr payload(transport->CreateMessage());
553 auto channelAlloc = o2::pmr::getTransportAllocator(transport.get());
555 messageSet.emplace_back(std::move(header));
556 messageSet.emplace_back(std::move(payload));
558 currentSetOfInputs.emplace_back(std::move(messageSet));
560 auto spans = asSpans(currentSetOfInputs);
562 REQUIRE(
result.size() == 2);
585 std::vector<fair::mq::Channel>
channels{
586 fair::mq::Channel(
"from_A_to_B"),
587 fair::mq::Channel(
"from_A_to_C"),
591 bool copyByDefault =
true;
593 std::vector<ForwardRoute>
routes{
598 .channel =
"from_A_to_B",
605 .channel =
"from_A_to_C",
609 auto findChannelByName = [&
channels](std::string
const& channelName) -> fair::mq::Channel& {
611 if (channel.GetName() == channelName) {
615 throw std::runtime_error(
"Channel not found");
618 proxy.
bind({}, {},
routes, findChannelByName,
nullptr);
620 std::vector<std::vector<fair::mq::MessagePtr>> currentSetOfInputs;
621 std::vector<fair::mq::MessagePtr> messageSet;
623 auto transport = fair::mq::TransportFactory::CreateTransportFactory(
"zeromq");
624 fair::mq::MessagePtr payload1(transport->CreateMessage());
625 fair::mq::MessagePtr payload2(transport->CreateMessage());
626 auto channelAlloc = o2::pmr::getTransportAllocator(transport.get());
628 std::vector<std::unique_ptr<fair::mq::Message>> messages;
629 messages.push_back(std::move(header));
630 messages.push_back(std::move(payload1));
631 messages.push_back(std::move(payload2));
632 auto fillMessages = [&messages](
size_t t) -> fair::mq::MessagePtr {
633 return std::move(messages[t]);
635 for (
size_t i = 0;
i < 3; ++
i) {
636 messageSet.emplace_back(fillMessages(
i));
639 messageSet.emplace_back(std::move(header2));
640 messageSet.emplace_back(transport->CreateMessage());
643 currentSetOfInputs.emplace_back(std::move(messageSet));
645 auto spans = asSpans(currentSetOfInputs);
647 REQUIRE(
result.size() == 2);
670 std::vector<fair::mq::Channel>
channels{
671 fair::mq::Channel(
"from_A_to_B"),
672 fair::mq::Channel(
"from_A_to_C"),
676 bool copyByDefault =
true;
678 std::vector<ForwardRoute>
routes{
683 .channel =
"from_A_to_B",
690 .channel =
"from_A_to_C",
694 auto findChannelByName = [&
channels](std::string
const& channelName) -> fair::mq::Channel& {
696 if (channel.GetName() == channelName) {
700 throw std::runtime_error(
"Channel not found");
703 proxy.
bind({}, {},
routes, findChannelByName,
nullptr);
705 auto transport = fair::mq::TransportFactory::CreateTransportFactory(
"zeromq");
706 fair::mq::MessagePtr payload1(transport->CreateMessage());
707 fair::mq::MessagePtr payload2(transport->CreateMessage());
708 auto channelAlloc = o2::pmr::getTransportAllocator(transport.get());
710 std::vector<std::unique_ptr<fair::mq::Message>> messages;
711 messages.push_back(std::move(header));
712 messages.push_back(std::move(payload1));
713 messages.push_back(std::move(payload2));
715 messages.push_back(std::move(header2));
716 messages.push_back(transport->CreateMessage());
718 std::vector<fair::mq::Parts>
result(2);
719 auto span = std::span(messages);
721 REQUIRE(
result.size() == 2);
730 std::vector<fair::mq::Channel>
channels{
731 fair::mq::Channel(
"from_A_to_B")};
734 bool copyByDefault =
true;
740 .channel =
"from_A_to_B",
744 auto findChannelByName = [&
channels](std::string
const& channelName) -> fair::mq::Channel& {
746 if (channel.GetName() == channelName) {
750 throw std::runtime_error(
"Channel not found");
753 proxy.
bind({}, {},
routes, findChannelByName,
nullptr);
755 std::vector<std::vector<fair::mq::MessagePtr>> currentSetOfInputs;
756 std::vector<fair::mq::MessagePtr> messageSet;
758 auto transport = fair::mq::TransportFactory::CreateTransportFactory(
"zeromq");
759 fair::mq::MessagePtr payload(transport->CreateMessage());
760 auto channelAlloc = o2::pmr::getTransportAllocator(transport.get());
762 messageSet.emplace_back(std::move(header));
763 messageSet.emplace_back(std::move(payload));
765 currentSetOfInputs.emplace_back(std::move(messageSet));
767 auto spans = asSpans(currentSetOfInputs);
769 REQUIRE(
result.size() == 1);
777 std::vector<fair::mq::Channel>
channels{
778 fair::mq::Channel(
"from_A_to_B")};
781 bool copyByDefault =
true;
787 .channel =
"from_A_to_B",
791 auto findChannelByName = [&
channels](std::string
const& channelName) -> fair::mq::Channel& {
793 if (channel.GetName() == channelName) {
797 throw std::runtime_error(
"Channel not found");
800 proxy.
bind({}, {},
routes, findChannelByName,
nullptr);
802 std::vector<std::vector<fair::mq::MessagePtr>> currentSetOfInputs;
803 std::vector<fair::mq::MessagePtr> messageSet;
805 auto transport = fair::mq::TransportFactory::CreateTransportFactory(
"zeromq");
806 fair::mq::MessagePtr payload(transport->CreateMessage());
807 auto channelAlloc = o2::pmr::getTransportAllocator(transport.get());
809 messageSet.emplace_back(std::move(header));
810 messageSet.emplace_back(std::move(payload));
812 currentSetOfInputs.emplace_back(std::move(messageSet));
814 auto spans = asSpans(currentSetOfInputs);
816 REQUIRE(
result.size() == 1);
#define O2_DECLARE_DYNAMIC_LOG(name)
void bind(std::vector< OutputRoute > const &outputs, std::vector< InputRoute > const &inputs, std::vector< ForwardRoute > const &forwards, std::function< fair::mq::Channel &(std::string const &)> bindChannelByName, std::function< bool(void)> newStateRequestedCallback)
static std::vector< fair::mq::Parts > routeForwardedMessageSet(FairMQDeviceProxy &proxy, std::vector< std::span< fair::mq::MessagePtr > > ¤tSetOfInputs, bool copy, bool consume)
Helper to route messages for forwarding.
static void routeForwardedMessages(FairMQDeviceProxy &proxy, std::span< fair::mq::MessagePtr > ¤tSetOfInputs, std::vector< fair::mq::Parts > &forwardedParts, bool copy, bool consume)
Helper to route messages for forwarding.
a BaseHeader with domain information from the source