diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:17 +0300 |
commit | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch) | |
tree | dd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/messagebus/test/helper | |
parent | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff) | |
download | ydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/messagebus/test/helper')
-rw-r--r-- | library/cpp/messagebus/test/helper/alloc_counter.h | 10 | ||||
-rw-r--r-- | library/cpp/messagebus/test/helper/example.cpp | 28 | ||||
-rw-r--r-- | library/cpp/messagebus/test/helper/example.h | 200 | ||||
-rw-r--r-- | library/cpp/messagebus/test/helper/example_module.cpp | 8 | ||||
-rw-r--r-- | library/cpp/messagebus/test/helper/example_module.h | 44 | ||||
-rw-r--r-- | library/cpp/messagebus/test/helper/fixed_port.cpp | 2 | ||||
-rw-r--r-- | library/cpp/messagebus/test/helper/fixed_port.h | 14 | ||||
-rw-r--r-- | library/cpp/messagebus/test/helper/hanging_server.cpp | 2 | ||||
-rw-r--r-- | library/cpp/messagebus/test/helper/hanging_server.h | 2 | ||||
-rw-r--r-- | library/cpp/messagebus/test/helper/message_handler_error.h | 26 | ||||
-rw-r--r-- | library/cpp/messagebus/test/helper/object_count_check.h | 20 | ||||
-rw-r--r-- | library/cpp/messagebus/test/helper/wait_for.h | 8 |
12 files changed, 182 insertions, 182 deletions
diff --git a/library/cpp/messagebus/test/helper/alloc_counter.h b/library/cpp/messagebus/test/helper/alloc_counter.h index 7011b61b9d..ec9041cb15 100644 --- a/library/cpp/messagebus/test/helper/alloc_counter.h +++ b/library/cpp/messagebus/test/helper/alloc_counter.h @@ -4,14 +4,14 @@ #include <util/system/atomic.h> #include <util/system/yassert.h> -class TAllocCounter : TNonCopyable { +class TAllocCounter : TNonCopyable { private: TAtomic* CountPtr; - + public: - TAllocCounter(TAtomic* countPtr) - : CountPtr(countPtr) - { + TAllocCounter(TAtomic* countPtr) + : CountPtr(countPtr) + { AtomicIncrement(*CountPtr); } diff --git a/library/cpp/messagebus/test/helper/example.cpp b/library/cpp/messagebus/test/helper/example.cpp index 6260541e1b..7c6d704042 100644 --- a/library/cpp/messagebus/test/helper/example.cpp +++ b/library/cpp/messagebus/test/helper/example.cpp @@ -9,9 +9,9 @@ using namespace NBus::NTest; static void FillWithJunk(TArrayRef<char> data) { TStringBuf junk = - "01234567890123456789012345678901234567890123456789012345678901234567890123456789" - "01234567890123456789012345678901234567890123456789012345678901234567890123456789" - "01234567890123456789012345678901234567890123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789012345678901234567890123456789" "01234567890123456789012345678901234567890123456789012345678901234567890123456789"; for (size_t i = 0; i < data.size(); i += junk.size()) { @@ -37,8 +37,8 @@ TExampleRequest::TExampleRequest(TAtomic* counterPtr, size_t payloadSize) TExampleRequest::TExampleRequest(ECreateUninitialized, TAtomic* counterPtr) : TBusMessage(MESSAGE_CREATE_UNINITIALIZED) , AllocCounter(counterPtr) -{ -} +{ +} TExampleResponse::TExampleResponse(TAtomic* counterPtr, size_t payloadSize) : TBusMessage(79) @@ -50,8 +50,8 @@ TExampleResponse::TExampleResponse(TAtomic* counterPtr, size_t payloadSize) TExampleResponse::TExampleResponse(ECreateUninitialized, TAtomic* counterPtr) : TBusMessage(MESSAGE_CREATE_UNINITIALIZED) , AllocCounter(counterPtr) -{ -} +{ +} TExampleProtocol::TExampleProtocol(int port) : TBusProtocol("Example", port) @@ -60,8 +60,8 @@ TExampleProtocol::TExampleProtocol(int port) , RequestCountDeserialized(0) , ResponseCountDeserialized(0) , StartCount(0) -{ -} +{ +} TExampleProtocol::~TExampleProtocol() { if (UncaughtException()) { @@ -124,13 +124,13 @@ TExampleClient::TExampleClient(const TBusClientSessionConfig sessionConfig, int TExampleClient::~TExampleClient() { } -EMessageStatus TExampleClient::SendMessage(const TNetAddr* addr) { +EMessageStatus TExampleClient::SendMessage(const TNetAddr* addr) { TAutoPtr<TExampleRequest> message(new TExampleRequest(&Proto.RequestCount, DataSize)); message->SetCompressed(UseCompression); return Session->SendMessageAutoPtr(message, addr); } -void TExampleClient::SendMessages(size_t count, const TNetAddr* addr) { +void TExampleClient::SendMessages(size_t count, const TNetAddr* addr) { UNIT_ASSERT(MessageCount == 0); UNIT_ASSERT(RepliesCount == 0); UNIT_ASSERT(Errors == 0); @@ -184,7 +184,7 @@ void TExampleClient::WaitForError(EMessageStatus status) { UNIT_ASSERT_VALUES_EQUAL(status, error); } -void TExampleClient::SendMessagesWaitReplies(size_t count, const TNetAddr* addr) { +void TExampleClient::SendMessagesWaitReplies(size_t count, const TNetAddr* addr) { SendMessages(count, addr); WaitReplies(); } @@ -215,8 +215,8 @@ void TExampleClient::OnError(TAutoPtr<TBusMessage> mess, EMessageStatus status) } TExampleServer::TExampleServer( - const char* name, - const TBusServerSessionConfig& sessionConfig) + const char* name, + const TBusServerSessionConfig& sessionConfig) : UseCompression(false) , AckMessageBeforeSendReply(false) , ForgetRequest(false) diff --git a/library/cpp/messagebus/test/helper/example.h b/library/cpp/messagebus/test/helper/example.h index 819562719d..26b7475308 100644 --- a/library/cpp/messagebus/test/helper/example.h +++ b/library/cpp/messagebus/test/helper/example.h @@ -10,123 +10,123 @@ #include <util/system/event.h> -namespace NBus { - namespace NTest { - class TExampleRequest: public TBusMessage { - friend class TExampleProtocol; - - private: - TAllocCounter AllocCounter; - - public: - TString Data; - - public: - TExampleRequest(TAtomic* counterPtr, size_t payloadSize = 320); - TExampleRequest(ECreateUninitialized, TAtomic* counterPtr); - }; - - class TExampleResponse: public TBusMessage { - friend class TExampleProtocol; - - private: - TAllocCounter AllocCounter; - - public: - TString Data; - TExampleResponse(TAtomic* counterPtr, size_t payloadSize = 320); - TExampleResponse(ECreateUninitialized, TAtomic* counterPtr); - }; - - class TExampleProtocol: public TBusProtocol { - public: - TAtomic RequestCount; - TAtomic ResponseCount; - TAtomic RequestCountDeserialized; - TAtomic ResponseCountDeserialized; - TAtomic StartCount; - - TExampleProtocol(int port = 0); - - ~TExampleProtocol() override; - - void Serialize(const TBusMessage* message, TBuffer& buffer) override; - - TAutoPtr<TBusMessage> Deserialize(ui16 messageType, TArrayRef<const char> payload) override; - }; - - class TExampleClient: private TBusClientHandlerError { - public: - TExampleProtocol Proto; - bool UseCompression; - bool CrashOnError; - size_t DataSize; - - ssize_t MessageCount; - TAtomic RepliesCount; - TAtomic Errors; - EMessageStatus LastError; +namespace NBus { + namespace NTest { + class TExampleRequest: public TBusMessage { + friend class TExampleProtocol; + + private: + TAllocCounter AllocCounter; + + public: + TString Data; + + public: + TExampleRequest(TAtomic* counterPtr, size_t payloadSize = 320); + TExampleRequest(ECreateUninitialized, TAtomic* counterPtr); + }; + + class TExampleResponse: public TBusMessage { + friend class TExampleProtocol; + + private: + TAllocCounter AllocCounter; + + public: + TString Data; + TExampleResponse(TAtomic* counterPtr, size_t payloadSize = 320); + TExampleResponse(ECreateUninitialized, TAtomic* counterPtr); + }; + + class TExampleProtocol: public TBusProtocol { + public: + TAtomic RequestCount; + TAtomic ResponseCount; + TAtomic RequestCountDeserialized; + TAtomic ResponseCountDeserialized; + TAtomic StartCount; + + TExampleProtocol(int port = 0); + + ~TExampleProtocol() override; + + void Serialize(const TBusMessage* message, TBuffer& buffer) override; + + TAutoPtr<TBusMessage> Deserialize(ui16 messageType, TArrayRef<const char> payload) override; + }; + + class TExampleClient: private TBusClientHandlerError { + public: + TExampleProtocol Proto; + bool UseCompression; + bool CrashOnError; + size_t DataSize; + + ssize_t MessageCount; + TAtomic RepliesCount; + TAtomic Errors; + EMessageStatus LastError; TSystemEvent WorkDone; - TBusMessageQueuePtr Bus; - TBusClientSessionPtr Session; + TBusMessageQueuePtr Bus; + TBusClientSessionPtr Session; - public: - TExampleClient(const TBusClientSessionConfig sessionConfig = TBusClientSessionConfig(), int port = 0); - ~TExampleClient() override; + public: + TExampleClient(const TBusClientSessionConfig sessionConfig = TBusClientSessionConfig(), int port = 0); + ~TExampleClient() override; - EMessageStatus SendMessage(const TNetAddr* addr = nullptr); + EMessageStatus SendMessage(const TNetAddr* addr = nullptr); - void SendMessages(size_t count, const TNetAddr* addr = nullptr); - void SendMessages(size_t count, const TNetAddr& addr); + void SendMessages(size_t count, const TNetAddr* addr = nullptr); + void SendMessages(size_t count, const TNetAddr& addr); - void ResetCounters(); - void WaitReplies(); - EMessageStatus WaitForError(); - void WaitForError(EMessageStatus status); + void ResetCounters(); + void WaitReplies(); + EMessageStatus WaitForError(); + void WaitForError(EMessageStatus status); - void SendMessagesWaitReplies(size_t count, const TNetAddr* addr = nullptr); - void SendMessagesWaitReplies(size_t count, const TNetAddr& addr); + void SendMessagesWaitReplies(size_t count, const TNetAddr* addr = nullptr); + void SendMessagesWaitReplies(size_t count, const TNetAddr& addr); - void OnReply(TAutoPtr<TBusMessage> mess, TAutoPtr<TBusMessage> reply) override; + void OnReply(TAutoPtr<TBusMessage> mess, TAutoPtr<TBusMessage> reply) override; - void OnError(TAutoPtr<TBusMessage> mess, EMessageStatus) override; - }; + void OnError(TAutoPtr<TBusMessage> mess, EMessageStatus) override; + }; - class TExampleServer: private TBusServerHandlerError { - public: - TExampleProtocol Proto; - bool UseCompression; - bool AckMessageBeforeSendReply; - TMaybe<size_t> DataSize; // Nothing means use request size - bool ForgetRequest; + class TExampleServer: private TBusServerHandlerError { + public: + TExampleProtocol Proto; + bool UseCompression; + bool AckMessageBeforeSendReply; + TMaybe<size_t> DataSize; // Nothing means use request size + bool ForgetRequest; - TTestSync TestSync; + TTestSync TestSync; - TBusMessageQueuePtr Bus; - TBusServerSessionPtr Session; + TBusMessageQueuePtr Bus; + TBusServerSessionPtr Session; - public: - TExampleServer( - const char* name = "TExampleServer", - const TBusServerSessionConfig& sessionConfig = TBusServerSessionConfig()); + public: + TExampleServer( + const char* name = "TExampleServer", + const TBusServerSessionConfig& sessionConfig = TBusServerSessionConfig()); - TExampleServer(unsigned port, const char* name = "TExampleServer"); + TExampleServer(unsigned port, const char* name = "TExampleServer"); - ~TExampleServer() override; + ~TExampleServer() override; - public: - size_t GetInFlight() const; - unsigned GetActualListenPort() const; - // any of - TNetAddr GetActualListenAddr() const; + public: + size_t GetInFlight() const; + unsigned GetActualListenPort() const; + // any of + TNetAddr GetActualListenAddr() const; - void WaitForOnMessageCount(unsigned n); + void WaitForOnMessageCount(unsigned n); - protected: - void OnMessage(TOnMessageContext& mess) override; - }; + protected: + void OnMessage(TOnMessageContext& mess) override; + }; - } -} + } +} diff --git a/library/cpp/messagebus/test/helper/example_module.cpp b/library/cpp/messagebus/test/helper/example_module.cpp index 26dc184b16..65ecfcf73f 100644 --- a/library/cpp/messagebus/test/helper/example_module.cpp +++ b/library/cpp/messagebus/test/helper/example_module.cpp @@ -31,10 +31,10 @@ TBusServerSessionPtr TExampleServerModule::CreateExtSession(TBusMessageQueue& qu return r; } -TExampleClientModule::TExampleClientModule() - : Source() -{ -} +TExampleClientModule::TExampleClientModule() + : Source() +{ +} TBusServerSessionPtr TExampleClientModule::CreateExtSession(TBusMessageQueue& queue) { Source = CreateDefaultSource(queue, &Proto, TBusServerSessionConfig()); diff --git a/library/cpp/messagebus/test/helper/example_module.h b/library/cpp/messagebus/test/helper/example_module.h index 1f00b25990..a0b295f613 100644 --- a/library/cpp/messagebus/test/helper/example_module.h +++ b/library/cpp/messagebus/test/helper/example_module.h @@ -4,34 +4,34 @@ #include <library/cpp/messagebus/oldmodule/module.h> -namespace NBus { - namespace NTest { - struct TExampleModule: public TBusModule { - TExampleProtocol Proto; - TBusMessageQueuePtr Queue; +namespace NBus { + namespace NTest { + struct TExampleModule: public TBusModule { + TExampleProtocol Proto; + TBusMessageQueuePtr Queue; - TExampleModule(); + TExampleModule(); - void StartModule(); + void StartModule(); - bool Shutdown() override; + bool Shutdown() override; - // nop by default - TBusServerSessionPtr CreateExtSession(TBusMessageQueue& queue) override; - }; + // nop by default + TBusServerSessionPtr CreateExtSession(TBusMessageQueue& queue) override; + }; - struct TExampleServerModule: public TExampleModule { - TNetAddr ServerAddr; - TBusServerSessionPtr CreateExtSession(TBusMessageQueue& queue) override; - }; + struct TExampleServerModule: public TExampleModule { + TNetAddr ServerAddr; + TBusServerSessionPtr CreateExtSession(TBusMessageQueue& queue) override; + }; - struct TExampleClientModule: public TExampleModule { - TBusClientSessionPtr Source; + struct TExampleClientModule: public TExampleModule { + TBusClientSessionPtr Source; - TExampleClientModule(); + TExampleClientModule(); - TBusServerSessionPtr CreateExtSession(TBusMessageQueue& queue) override; - }; + TBusServerSessionPtr CreateExtSession(TBusMessageQueue& queue) override; + }; - } -} + } +} diff --git a/library/cpp/messagebus/test/helper/fixed_port.cpp b/library/cpp/messagebus/test/helper/fixed_port.cpp index 540fa7c39d..258da0d1a5 100644 --- a/library/cpp/messagebus/test/helper/fixed_port.cpp +++ b/library/cpp/messagebus/test/helper/fixed_port.cpp @@ -4,7 +4,7 @@ #include <stdlib.h> -bool NBus::NTest::IsFixedPortTestAllowed() { +bool NBus::NTest::IsFixedPortTestAllowed() { // TODO: report skipped tests to test return !GetEnv("MB_TESTS_SKIP_FIXED_PORT"); } diff --git a/library/cpp/messagebus/test/helper/fixed_port.h b/library/cpp/messagebus/test/helper/fixed_port.h index e59d933b2f..a9c61ebc63 100644 --- a/library/cpp/messagebus/test/helper/fixed_port.h +++ b/library/cpp/messagebus/test/helper/fixed_port.h @@ -1,11 +1,11 @@ #pragma once -namespace NBus { - namespace NTest { - bool IsFixedPortTestAllowed(); +namespace NBus { + namespace NTest { + bool IsFixedPortTestAllowed(); - // Must not be in range OS uses for bind on random port. - const unsigned FixedPort = 4927; + // Must not be in range OS uses for bind on random port. + const unsigned FixedPort = 4927; - } -} + } +} diff --git a/library/cpp/messagebus/test/helper/hanging_server.cpp b/library/cpp/messagebus/test/helper/hanging_server.cpp index b9c2f0571d..a35514b00d 100644 --- a/library/cpp/messagebus/test/helper/hanging_server.cpp +++ b/library/cpp/messagebus/test/helper/hanging_server.cpp @@ -4,7 +4,7 @@ using namespace NBus; -THangingServer::THangingServer(int port) { +THangingServer::THangingServer(int port) { BindResult = BindOnPort(port, false); } diff --git a/library/cpp/messagebus/test/helper/hanging_server.h b/library/cpp/messagebus/test/helper/hanging_server.h index 2804b81f6f..cc9fb274d8 100644 --- a/library/cpp/messagebus/test/helper/hanging_server.h +++ b/library/cpp/messagebus/test/helper/hanging_server.h @@ -7,7 +7,7 @@ class THangingServer { private: std::pair<unsigned, TVector<NBus::TBindResult>> BindResult; - + public: // listen on given port, and nothing else THangingServer(int port = 0); diff --git a/library/cpp/messagebus/test/helper/message_handler_error.h b/library/cpp/messagebus/test/helper/message_handler_error.h index 13097b771d..a314b10761 100644 --- a/library/cpp/messagebus/test/helper/message_handler_error.h +++ b/library/cpp/messagebus/test/helper/message_handler_error.h @@ -2,18 +2,18 @@ #include <library/cpp/messagebus/ybus.h> -namespace NBus { - namespace NTest { - struct TBusClientHandlerError: public IBusClientHandler { - void OnError(TAutoPtr<TBusMessage> pMessage, EMessageStatus status) override; - void OnMessageSentOneWay(TAutoPtr<TBusMessage> pMessage) override; - void OnReply(TAutoPtr<TBusMessage> pMessage, TAutoPtr<TBusMessage> pReply) override; - }; +namespace NBus { + namespace NTest { + struct TBusClientHandlerError: public IBusClientHandler { + void OnError(TAutoPtr<TBusMessage> pMessage, EMessageStatus status) override; + void OnMessageSentOneWay(TAutoPtr<TBusMessage> pMessage) override; + void OnReply(TAutoPtr<TBusMessage> pMessage, TAutoPtr<TBusMessage> pReply) override; + }; - struct TBusServerHandlerError: public IBusServerHandler { - void OnError(TAutoPtr<TBusMessage> pMessage, EMessageStatus status) override; - void OnMessage(TOnMessageContext& pMessage) override; - }; + struct TBusServerHandlerError: public IBusServerHandler { + void OnError(TAutoPtr<TBusMessage> pMessage, EMessageStatus status) override; + void OnMessage(TOnMessageContext& pMessage) override; + }; - } -} + } +} diff --git a/library/cpp/messagebus/test/helper/object_count_check.h b/library/cpp/messagebus/test/helper/object_count_check.h index 7843fb0f30..1c4756e58c 100644 --- a/library/cpp/messagebus/test/helper/object_count_check.h +++ b/library/cpp/messagebus/test/helper/object_count_check.h @@ -1,7 +1,7 @@ #pragma once #include <library/cpp/testing/unittest/registar.h> - + #include <library/cpp/messagebus/remote_client_connection.h> #include <library/cpp/messagebus/remote_client_session.h> #include <library/cpp/messagebus/remote_server_connection.h> @@ -23,15 +23,15 @@ struct TObjectCountCheck { struct TReset { TObjectCountCheck* const Thiz; - TReset(TObjectCountCheck* thiz) - : Thiz(thiz) - { - } + TReset(TObjectCountCheck* thiz) + : Thiz(thiz) + { + } - void operator()() { + void operator()() { long oldValue = TObjectCounter<T>::ResetObjectCount(); if (oldValue != 0) { - Cerr << "warning: previous counter: " << oldValue << " for " << TypeName<T>() << Endl; + Cerr << "warning: previous counter: " << oldValue << " for " << TypeName<T>() << Endl; Cerr << "won't check in this test" << Endl; Thiz->Enabled = false; } @@ -45,10 +45,10 @@ struct TObjectCountCheck { template <typename T> struct TCheckZero { - TCheckZero(TObjectCountCheck*) { - } + TCheckZero(TObjectCountCheck*) { + } - void operator()() { + void operator()() { UNIT_ASSERT_VALUES_EQUAL_C(0L, TObjectCounter<T>::ObjectCount(), TypeName<T>()); } }; diff --git a/library/cpp/messagebus/test/helper/wait_for.h b/library/cpp/messagebus/test/helper/wait_for.h index 029ab0da48..f09958d4c0 100644 --- a/library/cpp/messagebus/test/helper/wait_for.h +++ b/library/cpp/messagebus/test/helper/wait_for.h @@ -3,12 +3,12 @@ #include <util/datetime/base.h> #include <util/system/yassert.h> -#define UNIT_WAIT_FOR(condition) \ - do { \ +#define UNIT_WAIT_FOR(condition) \ + do { \ TInstant start(TInstant::Now()); \ while (!(condition) && (TInstant::Now() - start < TDuration::Seconds(10))) { \ - Sleep(TDuration::MilliSeconds(1)); \ + Sleep(TDuration::MilliSeconds(1)); \ } \ /* TODO: use UNIT_ASSERT if in unittest thread */ \ - Y_VERIFY(condition, "condition failed after 10 seconds wait"); \ + Y_VERIFY(condition, "condition failed after 10 seconds wait"); \ } while (0) |