From 95712c2b81da8d62f272a8e039bed1cdf23bbd0f Mon Sep 17 00:00:00 2001 From: Carsten Patzke <carsten.patzke@desy.de> Date: Wed, 8 Apr 2020 16:15:48 +0200 Subject: [PATCH] [RDS] Moved request to fist be the first argument --- .../src/receiver_data_server/net_server.h | 23 ------------------ .../src/receiver_data_server/rds_net_server.h | 24 +++++++++++++++++++ .../receiver_data_server.h | 4 ++-- .../receiver_data_server_request.h | 2 +- .../receiver_data_server_request_handler.cpp | 5 ++-- .../receiver_data_server_request_handler.h | 6 ++--- ...er_data_server_request_handler_factory.cpp | 4 ++-- ...iver_data_server_request_handler_factory.h | 6 ++--- .../src/receiver_data_server/tcp_server.cpp | 8 ++++--- .../src/receiver_data_server/tcp_server.h | 11 +++++---- .../receiver_dataserver_mocking.h | 18 +++++++------- .../test_receiver_data_server.cpp | 2 +- .../test_request_handler.cpp | 2 +- .../test_request_handler_factory.cpp | 2 +- .../receiver_data_server/test_tcp_server.cpp | 24 +++++++++---------- 15 files changed, 73 insertions(+), 68 deletions(-) delete mode 100644 receiver/src/receiver_data_server/net_server.h create mode 100644 receiver/src/receiver_data_server/rds_net_server.h diff --git a/receiver/src/receiver_data_server/net_server.h b/receiver/src/receiver_data_server/net_server.h deleted file mode 100644 index 727588921..000000000 --- a/receiver/src/receiver_data_server/net_server.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef ASAPO_NET_SERVER_H -#define ASAPO_NET_SERVER_H - -#include "common/error.h" - -#include "request/request.h" -#include "../data_cache.h" - -namespace asapo { - -class NetServer { - public: - virtual GenericRequests GetNewRequests(Error* err) const noexcept = 0; - virtual Error SendResponse(uint64_t source_id, GenericNetworkResponse* response) const noexcept = 0; - virtual Error SendResponseAndSlotData(uint64_t source_id, GenericNetworkResponse* response, - GenericRequestHeader* request, const CacheMeta* cache_slot) const noexcept = 0; - virtual void HandleAfterError(uint64_t source_id) const noexcept = 0; - virtual ~NetServer() = default; -}; - -} - -#endif //ASAPO_NET_SERVER_H diff --git a/receiver/src/receiver_data_server/rds_net_server.h b/receiver/src/receiver_data_server/rds_net_server.h new file mode 100644 index 000000000..7498f7794 --- /dev/null +++ b/receiver/src/receiver_data_server/rds_net_server.h @@ -0,0 +1,24 @@ +#ifndef ASAPO_RDS_NET_SERVER_H +#define ASAPO_RDS_NET_SERVER_H + +#include "../data_cache.h" +#include "common/error.h" +#include "receiver_data_server_request.h" + +namespace asapo { + +class RdsNetServer { + public: + virtual GenericRequests GetNewRequests(Error* err) const noexcept = 0; + virtual Error SendResponse(uint64_t source_id, const GenericNetworkResponse* response) const noexcept = 0; + virtual Error + SendResponseAndSlotData(const ReceiverDataServerRequest* request, uint64_t source_id, + const GenericNetworkResponse* response, + const CacheMeta* cache_slot) const noexcept = 0; + virtual void HandleAfterError(uint64_t source_id) const noexcept = 0; + virtual ~RdsNetServer() = default; +}; + +} + +#endif //ASAPO_RDS_NET_SERVER_H diff --git a/receiver/src/receiver_data_server/receiver_data_server.h b/receiver/src/receiver_data_server/receiver_data_server.h index c7edda3f3..889ce357c 100644 --- a/receiver/src/receiver_data_server/receiver_data_server.h +++ b/receiver/src/receiver_data_server/receiver_data_server.h @@ -3,7 +3,7 @@ #include <memory> -#include "net_server.h" +#include "rds_net_server.h" #include "request/request_pool.h" #include "logger/logger.h" #include "../data_cache.h" @@ -21,7 +21,7 @@ class ReceiverDataServer { explicit ReceiverDataServer(std::string address, LogLevel log_level, SharedCache data_cache, const ReceiverDataCenterConfig& config); std::unique_ptr<RequestPool> request_pool__; - std::unique_ptr<NetServer> net__; + std::unique_ptr<RdsNetServer> net__; const AbstractLogger* log__; void Run(); private: diff --git a/receiver/src/receiver_data_server/receiver_data_server_request.h b/receiver/src/receiver_data_server/receiver_data_server_request.h index 0a6d24f63..541e08ddd 100644 --- a/receiver/src/receiver_data_server/receiver_data_server_request.h +++ b/receiver/src/receiver_data_server/receiver_data_server_request.h @@ -7,7 +7,7 @@ namespace asapo { -class NetServer; +class RdsNetServer; class ReceiverDataServerRequest : public GenericRequest { public: diff --git a/receiver/src/receiver_data_server/receiver_data_server_request_handler.cpp b/receiver/src/receiver_data_server/receiver_data_server_request_handler.cpp index 2d911b111..c8668d763 100644 --- a/receiver/src/receiver_data_server/receiver_data_server_request_handler.cpp +++ b/receiver/src/receiver_data_server/receiver_data_server_request_handler.cpp @@ -4,7 +4,7 @@ namespace asapo { -ReceiverDataServerRequestHandler::ReceiverDataServerRequestHandler(const NetServer* server, +ReceiverDataServerRequestHandler::ReceiverDataServerRequestHandler(const RdsNetServer* server, DataCache* data_cache, Statistics* statistics): log__{GetDefaultReceiverDataServerLogger()}, statistics__{statistics}, server_{server}, data_cache_{data_cache} { @@ -27,7 +27,8 @@ Error ReceiverDataServerRequestHandler::SendResponseAndSlotData(const ReceiverDa GenericNetworkResponse response{}; response.op_code = kOpcodeGetBufferData; response.error_code = kNetErrorNoError; - return server_->SendResponseAndSlotData(request->source_id, &response, (GenericRequestHeader*) &request->header, meta); + return server_->SendResponseAndSlotData(request, request->source_id, &response, + meta); } CacheMeta* ReceiverDataServerRequestHandler::GetSlotAndLock(const ReceiverDataServerRequest* request) { diff --git a/receiver/src/receiver_data_server/receiver_data_server_request_handler.h b/receiver/src/receiver_data_server/receiver_data_server_request_handler.h index 7452d2e26..2fdc005d7 100644 --- a/receiver/src/receiver_data_server/receiver_data_server_request_handler.h +++ b/receiver/src/receiver_data_server/receiver_data_server_request_handler.h @@ -2,7 +2,7 @@ #define ASAPO_RECEIVER_DATA_SERVER_REQUEST_HANDLER_H #include "request/request_handler.h" -#include "net_server.h" +#include "rds_net_server.h" #include "../data_cache.h" #include "receiver_data_server_request.h" #include "receiver_data_server_logger.h" @@ -12,7 +12,7 @@ namespace asapo { class ReceiverDataServerRequestHandler: public RequestHandler { public: - explicit ReceiverDataServerRequestHandler(const NetServer* server, DataCache* data_cache, Statistics* statistics); + explicit ReceiverDataServerRequestHandler(const RdsNetServer* server, DataCache* data_cache, Statistics* statistics); bool ProcessRequestUnlocked(GenericRequest* request, bool* retry) override; bool ReadyProcessRequest() override; void PrepareProcessingRequestLocked() override; @@ -22,7 +22,7 @@ class ReceiverDataServerRequestHandler: public RequestHandler { const AbstractLogger* log__; Statistics* statistics__; private: - const NetServer* server_; + const RdsNetServer* server_; DataCache* data_cache_; bool CheckRequest(const ReceiverDataServerRequest* request); Error SendResponse(const ReceiverDataServerRequest* request, NetworkErrorCode code); diff --git a/receiver/src/receiver_data_server/receiver_data_server_request_handler_factory.cpp b/receiver/src/receiver_data_server/receiver_data_server_request_handler_factory.cpp index d3e259ff1..6bb83b77c 100644 --- a/receiver/src/receiver_data_server/receiver_data_server_request_handler_factory.cpp +++ b/receiver/src/receiver_data_server/receiver_data_server_request_handler_factory.cpp @@ -8,9 +8,9 @@ std::unique_ptr<RequestHandler> ReceiverDataServerRequestHandlerFactory::NewRequ uint64_t* shared_counter) { return std::unique_ptr<RequestHandler> {new ReceiverDataServerRequestHandler(server_, data_cache_, statistics_)}; } -ReceiverDataServerRequestHandlerFactory::ReceiverDataServerRequestHandlerFactory(const NetServer* server, +ReceiverDataServerRequestHandlerFactory::ReceiverDataServerRequestHandlerFactory(const RdsNetServer* server, DataCache* data_cache, Statistics* statistics) : server_{server}, data_cache_{data_cache}, statistics_{statistics} { } -} \ No newline at end of file +} diff --git a/receiver/src/receiver_data_server/receiver_data_server_request_handler_factory.h b/receiver/src/receiver_data_server/receiver_data_server_request_handler_factory.h index b84f80fc8..29e23e166 100644 --- a/receiver/src/receiver_data_server/receiver_data_server_request_handler_factory.h +++ b/receiver/src/receiver_data_server/receiver_data_server_request_handler_factory.h @@ -5,7 +5,7 @@ #include "request/request_handler.h" #include "preprocessor/definitions.h" -#include "net_server.h" +#include "rds_net_server.h" #include "../data_cache.h" #include "../statistics.h" @@ -13,10 +13,10 @@ namespace asapo { class ReceiverDataServerRequestHandlerFactory : public RequestHandlerFactory { public: - ReceiverDataServerRequestHandlerFactory (const NetServer* server, DataCache* data_cache, Statistics* statistics); + ReceiverDataServerRequestHandlerFactory (const RdsNetServer* server, DataCache* data_cache, Statistics* statistics); VIRTUAL std::unique_ptr<RequestHandler> NewRequestHandler(uint64_t thread_id, uint64_t* shared_counter) override; private: - const NetServer* server_; + const RdsNetServer* server_; DataCache* data_cache_; Statistics* statistics_; }; diff --git a/receiver/src/receiver_data_server/tcp_server.cpp b/receiver/src/receiver_data_server/tcp_server.cpp index f8f52b507..36c72c4fd 100644 --- a/receiver/src/receiver_data_server/tcp_server.cpp +++ b/receiver/src/receiver_data_server/tcp_server.cpp @@ -94,7 +94,7 @@ void TcpServer::HandleAfterError(uint64_t source_id) const noexcept { CloseSocket(source_id); } -Error TcpServer::SendResponse(uint64_t source_id, GenericNetworkResponse* response) const noexcept { +Error TcpServer::SendResponse(uint64_t source_id, const GenericNetworkResponse* response) const noexcept { Error err; io__->Send(source_id, response, sizeof(*response), &err); if (err) { @@ -103,8 +103,10 @@ Error TcpServer::SendResponse(uint64_t source_id, GenericNetworkResponse* respon return err; } -Error TcpServer::SendResponseAndSlotData(uint64_t source_id, GenericNetworkResponse* response, - GenericRequestHeader* /*request*/, const CacheMeta* cache_slot) const noexcept { +Error +TcpServer::SendResponseAndSlotData(const ReceiverDataServerRequest* request, uint64_t source_id, + const GenericNetworkResponse* response, + const CacheMeta* cache_slot) const noexcept { Error err; err = SendResponse(source_id, response); diff --git a/receiver/src/receiver_data_server/tcp_server.h b/receiver/src/receiver_data_server/tcp_server.h index 337b8bdb1..12d9aac11 100644 --- a/receiver/src/receiver_data_server/tcp_server.h +++ b/receiver/src/receiver_data_server/tcp_server.h @@ -1,7 +1,7 @@ #ifndef ASAPO_RDS_TCP_SERVER_H #define ASAPO_RDS_TCP_SERVER_H -#include "net_server.h" +#include "rds_net_server.h" #include "io/io.h" #include "logger/logger.h" #include "receiver_data_server_request.h" @@ -9,14 +9,15 @@ namespace asapo { const int kMaxPendingConnections = 5; -class TcpServer : public NetServer { +class TcpServer : public RdsNetServer { public: explicit TcpServer(std::string address); ~TcpServer() override; GenericRequests GetNewRequests(Error* err) const noexcept override ; - Error SendResponse(uint64_t source_id, GenericNetworkResponse* response) const noexcept override; - Error SendResponseAndSlotData(uint64_t source_id, GenericNetworkResponse* response, - GenericRequestHeader* request, const CacheMeta* cache_slot) const noexcept override; + Error SendResponse(uint64_t source_id, const GenericNetworkResponse* response) const noexcept override; + Error SendResponseAndSlotData(const ReceiverDataServerRequest* request, uint64_t source_id, + const GenericNetworkResponse* response, + const CacheMeta* cache_slot) const noexcept override; void HandleAfterError(uint64_t source_id) const noexcept override; std::unique_ptr<IO> io__; const AbstractLogger* log__; diff --git a/receiver/unittests/receiver_data_server/receiver_dataserver_mocking.h b/receiver/unittests/receiver_data_server/receiver_dataserver_mocking.h index 49cb7539a..bfe19e409 100644 --- a/receiver/unittests/receiver_data_server/receiver_dataserver_mocking.h +++ b/receiver/unittests/receiver_data_server/receiver_dataserver_mocking.h @@ -4,13 +4,13 @@ #include <gtest/gtest.h> #include <gmock/gmock.h> -#include "../../src/receiver_data_server/net_server.h" +#include "../../src/receiver_data_server/rds_net_server.h" #include "request/request_pool.h" #include "../../src/receiver_data_server/receiver_data_server_request.h" namespace asapo { -class MockNetServer : public NetServer { +class MockNetServer : public RdsNetServer { public: GenericRequests GetNewRequests(Error* err) const noexcept override { ErrorInterface* error = nullptr; @@ -27,17 +27,19 @@ class MockNetServer : public NetServer { MOCK_CONST_METHOD1(GetNewRequests_t, std::vector<ReceiverDataServerRequest> (ErrorInterface** error)); - Error SendResponse(uint64_t source_id, GenericNetworkResponse* response) const noexcept override { + Error SendResponse(uint64_t source_id, const GenericNetworkResponse* response) const noexcept override { return Error{SendResponse_t(source_id, response)}; }; - MOCK_CONST_METHOD2(SendResponse_t, ErrorInterface * (uint64_t source_id, GenericNetworkResponse* response)); + MOCK_CONST_METHOD2(SendResponse_t, ErrorInterface * (uint64_t source_id, const GenericNetworkResponse* response)); - Error SendResponseAndSlotData(uint64_t source_id, GenericNetworkResponse* response, GenericRequestHeader* request, + Error SendResponseAndSlotData(const ReceiverDataServerRequest* request, uint64_t source_id, + const GenericNetworkResponse* response, const CacheMeta* cache_slot) const noexcept override { - return Error{SendResponseAndSlotData_t(source_id, response, request, cache_slot)}; + return Error{SendResponseAndSlotData_t(request, source_id, response, cache_slot)}; }; - MOCK_CONST_METHOD4(SendResponseAndSlotData_t, ErrorInterface * (uint64_t source_id, GenericNetworkResponse* response, - GenericRequestHeader* request, const CacheMeta* cache_slot)); + MOCK_CONST_METHOD4(SendResponseAndSlotData_t, ErrorInterface * (const ReceiverDataServerRequest* request, + uint64_t source_id, const GenericNetworkResponse* response, + const CacheMeta* cache_slot)); void HandleAfterError(uint64_t source_id) const noexcept override { HandleAfterError_t(source_id); diff --git a/receiver/unittests/receiver_data_server/test_receiver_data_server.cpp b/receiver/unittests/receiver_data_server/test_receiver_data_server.cpp index 50017308c..17f798369 100644 --- a/receiver/unittests/receiver_data_server/test_receiver_data_server.cpp +++ b/receiver/unittests/receiver_data_server/test_receiver_data_server.cpp @@ -59,7 +59,7 @@ class ReceiverDataServerTests : public Test { NiceMock<asapo::MockLogger> mock_logger; NiceMock<asapo::MockStatistics> mock_statistics; void SetUp() override { - data_server.net__ = std::unique_ptr<asapo::NetServer> {&mock_net}; + data_server.net__ = std::unique_ptr<asapo::RdsNetServer> {&mock_net}; data_server.request_pool__ = std::unique_ptr<asapo::RequestPool> {&mock_pool}; data_server.log__ = &mock_logger; data_server.statistics__ = std::unique_ptr<asapo::Statistics> {&mock_statistics};; diff --git a/receiver/unittests/receiver_data_server/test_request_handler.cpp b/receiver/unittests/receiver_data_server/test_request_handler.cpp index 195008219..7334eb182 100644 --- a/receiver/unittests/receiver_data_server/test_request_handler.cpp +++ b/receiver/unittests/receiver_data_server/test_request_handler.cpp @@ -97,9 +97,9 @@ void RequestHandlerTests::MockSendResponse(asapo::NetworkErrorCode expected_resp void RequestHandlerTests::MockSendResponseAndSlotData(asapo::NetworkErrorCode expected_response_code, bool return_without_error) { EXPECT_CALL(mock_net, SendResponseAndSlotData_t( + &request, expected_source_id, M_CheckResponse(asapo::kOpcodeGetBufferData, expected_response_code, ""), - &request.header, &expected_meta )).WillOnce( Return(return_without_error ? nullptr : asapo::IOErrorTemplates::kUnknownIOError.Generate().release()) diff --git a/receiver/unittests/receiver_data_server/test_request_handler_factory.cpp b/receiver/unittests/receiver_data_server/test_request_handler_factory.cpp index 770804c8f..44ecc6462 100644 --- a/receiver/unittests/receiver_data_server/test_request_handler_factory.cpp +++ b/receiver/unittests/receiver_data_server/test_request_handler_factory.cpp @@ -35,7 +35,7 @@ TEST(ReceiverDataServerRequestHandlerFactory, Constructor) { config.nthreads = 4; ReceiverDataServer data_server{"", asapo::LogLevel::Debug, nullptr, config}; asapo::Statistics stat; - ReceiverDataServerRequestHandlerFactory factory((asapo::NetServer*)&data_server, nullptr, &stat); + ReceiverDataServerRequestHandlerFactory factory((asapo::RdsNetServer*)&data_server, nullptr, &stat); auto handler = factory.NewRequestHandler(1, nullptr); ASSERT_THAT(dynamic_cast<const asapo::ReceiverDataServerRequestHandler*>(handler.get()), Ne(nullptr)); } diff --git a/receiver/unittests/receiver_data_server/test_tcp_server.cpp b/receiver/unittests/receiver_data_server/test_tcp_server.cpp index eb5c1dd53..1d9127a50 100644 --- a/receiver/unittests/receiver_data_server/test_tcp_server.cpp +++ b/receiver/unittests/receiver_data_server/test_tcp_server.cpp @@ -255,21 +255,21 @@ TEST_F(TCPServerTests, SendResponseAndSlotData_SendResponseError) { asapo::GenericNetworkResponse tmp {}; - asapo::GenericRequestHeader expectedRequest {}; + asapo::ReceiverDataServerRequest expectedRequest {{}, 30}; asapo::CacheMeta expectedMeta {}; expectedMeta.id = 20; expectedMeta.addr = (void*)0x9234; expectedMeta.size = 50; expectedMeta.lock = 123; - EXPECT_CALL(mock_io, Send_t(1, &tmp, sizeof(asapo::GenericNetworkResponse), _)) + EXPECT_CALL(mock_io, Send_t(30, &tmp, sizeof(asapo::GenericNetworkResponse), _)) .WillOnce(DoAll( testing::SetArgPointee<3>(asapo::IOErrorTemplates::kUnknownIOError.Generate().release()), Return(0) )); EXPECT_CALL(mock_logger, Error(HasSubstr("cannot send"))); - auto err = tcp_server.SendResponseAndSlotData(1, &tmp, &expectedRequest, &expectedMeta); + auto err = tcp_server.SendResponseAndSlotData(&expectedRequest, 30, &tmp, &expectedMeta); ASSERT_THAT(err, Ne(nullptr)); } @@ -277,17 +277,16 @@ TEST_F(TCPServerTests, SendResponseAndSlotData_SendResponseError) { TEST_F(TCPServerTests, SendResponseAndSlotData_SendDataError) { asapo::GenericNetworkResponse tmp {}; - - asapo::GenericRequestHeader expectedRequest {}; + asapo::ReceiverDataServerRequest expectedRequest {{}, 30}; asapo::CacheMeta expectedMeta {}; expectedMeta.id = 20; expectedMeta.addr = (void*)0x9234; expectedMeta.size = 50; expectedMeta.lock = 123; - EXPECT_CALL(mock_io, Send_t(1, &tmp, sizeof(asapo::GenericNetworkResponse), _)) + EXPECT_CALL(mock_io, Send_t(30, &tmp, sizeof(asapo::GenericNetworkResponse), _)) .WillOnce(Return(1)); - EXPECT_CALL(mock_io, Send_t(1, expectedMeta.addr, expectedMeta.size, _)) + EXPECT_CALL(mock_io, Send_t(30, expectedMeta.addr, expectedMeta.size, _)) .WillOnce( DoAll( testing::SetArgPointee<3>(asapo::IOErrorTemplates::kUnknownIOError.Generate().release()), @@ -296,7 +295,7 @@ TEST_F(TCPServerTests, SendResponseAndSlotData_SendDataError) { EXPECT_CALL(mock_logger, Error(HasSubstr("cannot send"))); - auto err = tcp_server.SendResponseAndSlotData(1, &tmp, &expectedRequest, &expectedMeta); + auto err = tcp_server.SendResponseAndSlotData(&expectedRequest, 30, &tmp, &expectedMeta); ASSERT_THAT(err, Ne(nullptr)); } @@ -304,20 +303,19 @@ TEST_F(TCPServerTests, SendResponseAndSlotData_SendDataError) { TEST_F(TCPServerTests, SendResponseAndSlotData_Ok) { asapo::GenericNetworkResponse tmp {}; - - asapo::GenericRequestHeader expectedRequest {}; + asapo::ReceiverDataServerRequest expectedRequest {{}, 30}; asapo::CacheMeta expectedMeta {}; expectedMeta.id = 20; expectedMeta.addr = (void*)0x9234; expectedMeta.size = 50; expectedMeta.lock = 123; - EXPECT_CALL(mock_io, Send_t(1, &tmp, sizeof(asapo::GenericNetworkResponse), _)) + EXPECT_CALL(mock_io, Send_t(30, &tmp, sizeof(asapo::GenericNetworkResponse), _)) .WillOnce(Return(1)); - EXPECT_CALL(mock_io, Send_t(1, expectedMeta.addr, expectedMeta.size, _)) + EXPECT_CALL(mock_io, Send_t(30, expectedMeta.addr, expectedMeta.size, _)) .WillOnce(Return(expectedMeta.size)); - auto err = tcp_server.SendResponseAndSlotData(1, &tmp, &expectedRequest, &expectedMeta); + auto err = tcp_server.SendResponseAndSlotData(&expectedRequest, 30, &tmp, &expectedMeta); ASSERT_THAT(err, Eq(nullptr)); } -- GitLab