aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/test/ut/moduletest.h
diff options
context:
space:
mode:
authorvladimir <vladimir@yandex-team.ru>2022-02-10 16:50:29 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:29 +0300
commit4bac7bacd041dac72ece081598805d03d2e80a3e (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/messagebus/test/ut/moduletest.h
parent3e7ff6e4ee637c04455854159e84850e613ebc16 (diff)
downloadydb-4bac7bacd041dac72ece081598805d03d2e80a3e.tar.gz
Restoring authorship annotation for <vladimir@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/messagebus/test/ut/moduletest.h')
-rw-r--r--library/cpp/messagebus/test/ut/moduletest.h78
1 files changed, 39 insertions, 39 deletions
diff --git a/library/cpp/messagebus/test/ut/moduletest.h b/library/cpp/messagebus/test/ut/moduletest.h
index a128d3ab21..d5da72c0cb 100644
--- a/library/cpp/messagebus/test/ut/moduletest.h
+++ b/library/cpp/messagebus/test/ut/moduletest.h
@@ -1,9 +1,9 @@
#pragma once
-
-///////////////////////////////////////////////////////////////////
-/// \file
-/// \brief Example of using local session for communication.
-
+
+///////////////////////////////////////////////////////////////////
+/// \file
+/// \brief Example of using local session for communication.
+
#include <library/cpp/messagebus/test/helper/alloc_counter.h>
#include <library/cpp/messagebus/test/helper/example.h>
#include <library/cpp/messagebus/test/helper/message_handler_error.h>
@@ -14,10 +14,10 @@
namespace NBus {
namespace NTest {
using namespace std;
-
+
#define TYPE_HOSTINFOREQUEST 100
-#define TYPE_HOSTINFORESPONSE 101
-
+#define TYPE_HOSTINFORESPONSE 101
+
////////////////////////////////////////////////////////////////////
/// \brief DupDetect protocol that common between client and server
////////////////////////////////////////////////////////////////////
@@ -32,11 +32,11 @@ namespace NBus {
: TBusMessage(MESSAGE_CREATE_UNINITIALIZED)
{
}
-
+
~THostInfoMessage() override {
}
};
-
+
////////////////////////////////////////////////////////////////////
/// \brief HostInfo reply class
class THostInfoReply: public TBusMessage {
@@ -49,11 +49,11 @@ namespace NBus {
: TBusMessage(MESSAGE_CREATE_UNINITIALIZED)
{
}
-
+
~THostInfoReply() override {
}
};
-
+
////////////////////////////////////////////////////////////////////
/// \brief HostInfo protocol that common between client and server
class THostInfoProtocol: public TBusProtocol {
@@ -67,7 +67,7 @@ namespace NBus {
Y_UNUSED(data);
Y_UNUSED(mess);
}
-
+
/// deserialized TBusData into new instance of the message
TAutoPtr<TBusMessage> Deserialize(ui16 messageType, TArrayRef<const char> payload) override {
Y_UNUSED(payload);
@@ -81,23 +81,23 @@ namespace NBus {
}
}
};
-
+
//////////////////////////////////////////////////////////////
/// \brief HostInfo handler (should convert it to module too)
struct THostInfoHandler: public TBusServerHandlerError {
TBusServerSessionPtr Session;
TBusServerSessionConfig HostInfoConfig;
THostInfoProtocol HostInfoProto;
-
+
THostInfoHandler(TBusMessageQueue* queue) {
Session = TBusServerSession::Create(&HostInfoProto, this, HostInfoConfig, queue);
}
-
+
void OnMessage(TOnMessageContext& mess) override {
usleep(10 * 1000); /// pretend we are doing something
-
+
TAutoPtr<THostInfoReply> reply(new THostInfoReply());
-
+
mess.SendReplyMove(reply);
}
@@ -105,7 +105,7 @@ namespace NBus {
return TNetAddr("localhost", Session->GetActualListenPort());
}
};
-
+
//////////////////////////////////////////////////////////////
/// \brief DupDetect handler (should convert it to module too)
struct TDupDetectHandler: public TBusClientHandlerError {
@@ -114,34 +114,34 @@ namespace NBus {
TBusClientSessionPtr DupDetect;
TBusClientSessionConfig DupDetectConfig;
TExampleProtocol DupDetectProto;
-
+
int NumMessages;
int NumReplies;
-
+
TDupDetectHandler(const TNetAddr& serverAddr, TBusMessageQueuePtr queue)
: ServerAddr(serverAddr)
{
DupDetect = TBusClientSession::Create(&DupDetectProto, this, DupDetectConfig, queue);
DupDetect->RegisterService("localhost");
}
-
+
void Work() {
NumMessages = 10;
NumReplies = 0;
-
+
for (int i = 0; i < NumMessages; i++) {
TExampleRequest* mess = new TExampleRequest(&DupDetectProto.RequestCount);
DupDetect->SendMessage(mess, &ServerAddr);
}
}
-
+
void OnReply(TAutoPtr<TBusMessage> mess, TAutoPtr<TBusMessage> reply) override {
Y_UNUSED(mess);
Y_UNUSED(reply);
NumReplies++;
}
};
-
+
/////////////////////////////////////////////////////////////////
/// \brief DupDetect module
@@ -151,12 +151,12 @@ namespace NBus {
TBusClientSessionPtr HostInfoClientSession;
TBusClientSessionConfig HostInfoConfig;
THostInfoProtocol HostInfoProto;
-
+
TExampleProtocol DupDetectProto;
TBusServerSessionConfig DupDetectConfig;
-
+
TNetAddr ListenAddr;
-
+
TDupDetectModule(const TNetAddr& hostInfoAddr)
: TBusModule("DUPDETECTMODULE")
, HostInfoAddr(hostInfoAddr)
@@ -166,10 +166,10 @@ namespace NBus {
bool Init(TBusMessageQueue* queue) {
HostInfoClientSession = CreateDefaultSource(*queue, &HostInfoProto, HostInfoConfig);
HostInfoClientSession->RegisterService("localhost");
-
+
return TBusModule::CreatePrivateSessions(queue);
}
-
+
TBusServerSessionPtr CreateExtSession(TBusMessageQueue& queue) override {
TBusServerSessionPtr session = CreateDefaultDestination(queue, &DupDetectProto, DupDetectConfig);
@@ -177,14 +177,14 @@ namespace NBus {
return session;
}
-
+
/// entry point into module, first function to call
TJobHandler Start(TBusJob* job, TBusMessage* mess) override {
TExampleRequest* dmess = dynamic_cast<TExampleRequest*>(mess);
Y_UNUSED(dmess);
-
+
THostInfoMessage* hmess = new THostInfoMessage();
-
+
/// send message to imaginary hostinfo server
job->Send(hmess, HostInfoClientSession, TReplyHandler(), 0, HostInfoAddr);
@@ -195,27 +195,27 @@ namespace NBus {
TJobHandler ProcessHostInfo(TBusJob* job, TBusMessage* mess) {
TExampleRequest* dmess = dynamic_cast<TExampleRequest*>(mess);
Y_UNUSED(dmess);
-
+
THostInfoMessage* hmess = job->Get<THostInfoMessage>();
THostInfoReply* hreply = job->Get<THostInfoReply>();
EMessageStatus hstatus = job->GetStatus<THostInfoMessage>();
Y_ASSERT(hmess != nullptr);
Y_ASSERT(hreply != nullptr);
Y_ASSERT(hstatus == MESSAGE_OK);
-
+
return TJobHandler(&TDupDetectModule::Finish);
}
/// last handler sends reply and returns NULL
TJobHandler Finish(TBusJob* job, TBusMessage* mess) {
Y_UNUSED(mess);
-
+
TExampleResponse* reply = new TExampleResponse(&DupDetectProto.ResponseCount);
job->SendReply(reply);
-
+
return nullptr;
}
};
-
- }
+
+ }
}