mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-16 10:01:47 +00:00
Tests for MQ examples
This commit is contained in:
@@ -15,27 +15,52 @@
|
||||
#include <memory> // unique_ptr
|
||||
|
||||
#include "FairMQExample6Sink.h"
|
||||
#include "FairMQPoller.h"
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQProgOptions.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQExample6Sink::FairMQExample6Sink()
|
||||
: fReceivedData(false)
|
||||
, fReceivedBroadcast(false)
|
||||
, fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
{
|
||||
OnData("broadcast", &FairMQExample6Sink::HandleBroadcast);
|
||||
OnData("data", &FairMQExample6Sink::HandleData);
|
||||
}
|
||||
|
||||
void FairMQExample6Sink::InitTask()
|
||||
{
|
||||
fMaxIterations = fConfig->GetValue<uint64_t>("max-iterations");
|
||||
}
|
||||
|
||||
bool FairMQExample6Sink::HandleBroadcast(FairMQMessagePtr& msg, int /*index*/)
|
||||
{
|
||||
LOG(INFO) << "Received broadcast: \"" << string(static_cast<char*>(msg->GetData()), msg->GetSize()) << "\"";
|
||||
fReceivedBroadcast = true;
|
||||
|
||||
return true;
|
||||
return CheckIterations();
|
||||
}
|
||||
|
||||
bool FairMQExample6Sink::HandleData(FairMQMessagePtr& msg, int /*index*/)
|
||||
{
|
||||
LOG(INFO) << "Received message: \"" << string(static_cast<char*>(msg->GetData()), msg->GetSize()) << "\"";
|
||||
fReceivedData = true;
|
||||
|
||||
return CheckIterations();
|
||||
}
|
||||
|
||||
bool FairMQExample6Sink::CheckIterations()
|
||||
{
|
||||
if (fMaxIterations > 0)
|
||||
{
|
||||
if (fReceivedData && fReceivedBroadcast && ++fNumIterations >= fMaxIterations)
|
||||
{
|
||||
LOG(INFO) << "Configured maximum number of iterations reached & Received messages from both sources. Leaving RUNNING state.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user