mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-16 18:11:49 +00:00
Add tests for poller.
This commit is contained in:
committed by
Mohammad Al-Turany
parent
6b221d950c
commit
9288a2c3d5
133
fairmq/test/helper/devices/TestPollIn.cxx
Normal file
133
fairmq/test/helper/devices/TestPollIn.cxx
Normal file
@@ -0,0 +1,133 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2015-2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <FairMQDevice.h>
|
||||
#include <FairMQLogger.h>
|
||||
#include <options/FairMQProgOptions.h>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
|
||||
class PollIn : public FairMQDevice
|
||||
{
|
||||
public:
|
||||
PollIn()
|
||||
: fPollType(0)
|
||||
{}
|
||||
|
||||
protected:
|
||||
auto Init() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Reset() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
auto InitTask() -> void override
|
||||
{
|
||||
fPollType = fConfig->GetValue<int>("poll-type");
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
vector<const FairMQChannel*> chans;
|
||||
|
||||
chans.push_back(&fChannels.at("data1").at(0));
|
||||
chans.push_back(&fChannels.at("data2").at(0));
|
||||
|
||||
FairMQPollerPtr poller = nullptr;
|
||||
|
||||
if (fPollType == 0)
|
||||
{
|
||||
poller = NewPoller(chans);
|
||||
}
|
||||
else if (fPollType == 1)
|
||||
{
|
||||
poller = NewPoller("data1", "data2");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(ERROR) << "wrong poll type provided: " << fPollType;
|
||||
}
|
||||
|
||||
bool arrived1 = false;
|
||||
bool arrived2 = false;
|
||||
bool bothArrived = false;
|
||||
|
||||
FairMQMessagePtr msg1(NewMessage());
|
||||
FairMQMessagePtr msg2(NewMessage());
|
||||
|
||||
while (!bothArrived)
|
||||
{
|
||||
poller->Poll(100);
|
||||
|
||||
if (fPollType == 0)
|
||||
{
|
||||
if (poller->CheckInput(0))
|
||||
{
|
||||
LOG(DEBUG) << "CheckInput(0) triggered";
|
||||
if (Receive(msg1, "data1", 0) >= 0)
|
||||
{
|
||||
arrived1 = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (poller->CheckInput(1))
|
||||
{
|
||||
LOG(DEBUG) << "CheckInput(1) triggered";
|
||||
if (Receive(msg2, "data2", 0) >= 0)
|
||||
{
|
||||
arrived2 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (fPollType == 1)
|
||||
{
|
||||
if (poller->CheckInput("data1", 0))
|
||||
{
|
||||
LOG(DEBUG) << "CheckInput(\"data1\", 0) triggered";
|
||||
if (Receive(msg1, "data1", 0) >= 0)
|
||||
{
|
||||
arrived1 = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (poller->CheckInput("data2", 0))
|
||||
{
|
||||
LOG(DEBUG) << "CheckInput(\"data2\", 0) triggered";
|
||||
if (Receive(msg2, "data2", 0) >= 0)
|
||||
{
|
||||
arrived2 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (arrived1 && arrived2)
|
||||
{
|
||||
bothArrived = true;
|
||||
LOG(INFO) << "POLL test successfull";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
int fPollType;
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace mq
|
||||
} // namespace fair
|
42
fairmq/test/helper/devices/TestPollOut.cxx
Normal file
42
fairmq/test/helper/devices/TestPollOut.cxx
Normal file
@@ -0,0 +1,42 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2015-2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <FairMQDevice.h>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
class PollOut : public FairMQDevice
|
||||
{
|
||||
protected:
|
||||
auto Init() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Reset() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
auto msg1 = FairMQMessagePtr{NewMessage()};
|
||||
auto msg2 = FairMQMessagePtr{NewMessage()};
|
||||
Send(msg1, "data1");
|
||||
Send(msg2, "data2");
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace mq
|
||||
} // namespace fair
|
@@ -6,6 +6,8 @@
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "devices/TestPollIn.cxx"
|
||||
#include "devices/TestPollOut.cxx"
|
||||
#include "devices/TestPub.cxx"
|
||||
#include "devices/TestPull.cxx"
|
||||
#include "devices/TestPush.cxx"
|
||||
@@ -22,6 +24,8 @@ namespace bpo = boost::program_options;
|
||||
|
||||
auto addCustomOptions(bpo::options_description& options) -> void
|
||||
{
|
||||
options.add_options()
|
||||
("poll-type", bpo::value<int>()->default_value(0), "Poll type switch(0 - vector of (sub-)channels, 1 - vector of channel names)");
|
||||
}
|
||||
|
||||
auto getDevice(const FairMQProgOptions& config) -> FairMQDevicePtr
|
||||
@@ -58,6 +62,14 @@ auto getDevice(const FairMQProgOptions& config) -> FairMQDevicePtr
|
||||
{
|
||||
return new TransferTimeout;
|
||||
}
|
||||
else if (0 == id.find("pollout_"))
|
||||
{
|
||||
return new PollOut;
|
||||
}
|
||||
else if (0 == id.find("pollin_"))
|
||||
{
|
||||
return new PollIn;
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "Don't know id '" << id << "'" << endl;
|
||||
|
Reference in New Issue
Block a user