mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
test: Add data transfer and checks to protocol tests
This commit is contained in:
parent
368d42cb32
commit
73558a1c95
|
@ -28,10 +28,26 @@ class Pull : public Device
|
||||||
|
|
||||||
auto Run() -> void override
|
auto Run() -> void override
|
||||||
{
|
{
|
||||||
auto msg = NewMessage();
|
int counter = 0;
|
||||||
|
|
||||||
if (Receive(msg, "data") >= 0)
|
auto msg1 = NewMessageFor("data", 0);
|
||||||
{
|
|
||||||
|
if (Receive(msg1, "data") >= 0) {
|
||||||
|
++counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto msg2 = NewMessageFor("data", 0);
|
||||||
|
|
||||||
|
auto ret = Receive(msg2, "data");
|
||||||
|
if (ret >= 0) {
|
||||||
|
auto content = std::string{static_cast<char*>(msg2->GetData()), msg2->GetSize()};
|
||||||
|
LOG(info) << "Transferred " << static_cast<std::size_t>(ret) << " bytes, msg size: " << msg2->GetSize() << ", content: " << content;
|
||||||
|
if (msg2->GetSize() == static_cast<std::size_t>(ret) && content == "testdata1234") {
|
||||||
|
++counter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (counter == 2) {
|
||||||
LOG(info) << "PUSH-PULL test successfull";
|
LOG(info) << "PUSH-PULL test successfull";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,8 +25,12 @@ class Push : public Device
|
||||||
|
|
||||||
auto Run() -> void override
|
auto Run() -> void override
|
||||||
{
|
{
|
||||||
auto msg = NewMessage();
|
// empty message
|
||||||
Send(msg, "data");
|
auto msg1 = NewMessageFor("data", 0);
|
||||||
|
Send(msg1, "data");
|
||||||
|
// message with short text data
|
||||||
|
auto msg2(NewSimpleMessageFor("data", 0, "testdata1234"));
|
||||||
|
Send(msg2, "data");
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2015-2022 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2015-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
|
@ -24,22 +24,40 @@ class Rep : public Device
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool check(signed long ret, const fair::mq::MessagePtr& msg)
|
||||||
|
{
|
||||||
|
auto content = std::string{static_cast<char*>(msg->GetData()), msg->GetSize()};
|
||||||
|
LOG(info) << "Transferred " << static_cast<std::size_t>(ret) << " bytes, msg size: " << msg->GetSize() << ", content: " << content;
|
||||||
|
return msg->GetSize() == static_cast<std::size_t>(ret) && content == "request";
|
||||||
|
}
|
||||||
|
|
||||||
auto Run() -> void override
|
auto Run() -> void override
|
||||||
{
|
{
|
||||||
auto request1 = NewMessage();
|
int counter = 0;
|
||||||
if (Receive(request1, "data") >= 0) {
|
auto req1 = NewMessage();
|
||||||
|
auto ret1 = Receive(req1, "data");
|
||||||
|
if (ret1 >= 0) {
|
||||||
LOG(info) << "Received request 1";
|
LOG(info) << "Received request 1";
|
||||||
auto reply = NewMessage();
|
if (check(ret1, req1)) {
|
||||||
|
++counter;
|
||||||
|
}
|
||||||
|
auto reply = NewSimpleMessageFor("data", 0, "reply");
|
||||||
Send(reply, "data");
|
Send(reply, "data");
|
||||||
}
|
}
|
||||||
auto request2 = NewMessage();
|
auto req2 = NewMessage();
|
||||||
if (Receive(request2, "data") >= 0) {
|
auto ret2 = Receive(req2, "data");
|
||||||
|
if (ret2 >= 0) {
|
||||||
LOG(info) << "Received request 2";
|
LOG(info) << "Received request 2";
|
||||||
auto reply = NewMessage();
|
if (check(ret2, req2)) {
|
||||||
|
++counter;
|
||||||
|
}
|
||||||
|
auto reply = NewSimpleMessageFor("data", 0, "reply");
|
||||||
Send(reply, "data");
|
Send(reply, "data");
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(info) << "REQ-REP test successfull";
|
if (counter == 2) {
|
||||||
|
LOG(info) << "REQ-REP test successfull";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2015-2022 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2015-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
|
@ -26,12 +26,17 @@ class Req : public Device
|
||||||
|
|
||||||
auto Run() -> void override
|
auto Run() -> void override
|
||||||
{
|
{
|
||||||
auto request = NewMessage();
|
auto request = NewSimpleMessageFor("data", 0, "request");
|
||||||
Send(request, "data");
|
Send(request, "data");
|
||||||
|
|
||||||
auto reply = NewMessage();
|
auto reply = NewMessage();
|
||||||
if (Receive(reply, "data") >= 0) {
|
if (Receive(reply, "data") >= 0) {
|
||||||
LOG(info) << "received reply";
|
LOG(info) << "received reply";
|
||||||
|
auto content = std::string{static_cast<char*>(reply->GetData()), reply->GetSize()};
|
||||||
|
LOG(info) << "Transferred reply of size: " << reply->GetSize() << ", content: " << content;
|
||||||
|
if (content != "reply") {
|
||||||
|
ChangeStateOrThrow(Transition::ErrorFound);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user