From fb1a771d2c68265bbfd8881e73cbd3f9bfa96222 Mon Sep 17 00:00:00 2001 From: Sergey Yakubov <sergey.yakubov@desy.de> Date: Thu, 28 Oct 2021 13:36:00 +0200 Subject: [PATCH] some more refactoring --- 3d_party/mongo-c-driver/install.sh | 1 + README.md | 17 +++++-- common/cpp/src/json_parser/rapid_json.cpp | 2 + consumer/tools/folder_to_db/src/main.cpp | 2 +- .../version-21.06.0/python/produce.py | 5 +- receiver/CMakeLists.txt | 2 - receiver/README.md | 14 ------ receiver/src/connection.cpp | 5 +- receiver/src/main.cpp | 32 ++++++------ receiver/src/receiver.cpp | 1 - receiver/src/receiver_config.cpp | 5 +- receiver/src/receiver_config.h | 9 ++++ receiver/src/receiver_config_factory.h | 20 -------- receiver/src/statistics/statistics.h | 2 +- .../statistics/statistics_sender_fluentd.cpp | 1 - receiver/unittests/mock_receiver_config.cpp | 10 ++-- .../statistics/test_receiver_statistics.cpp | 22 ++------ .../unittests/statistics/test_statistics.cpp | 20 ++------ .../test_statistics_sender_fluentd.cpp | 25 ++-------- .../test_statistics_sender_influx_db.cpp | 24 +-------- receiver/unittests/test_config.cpp | 27 ++-------- receiver/unittests/test_connection.cpp | 50 ++----------------- receiver/unittests/test_datacache.cpp | 11 +--- receiver/unittests/test_receiver.cpp | 26 ++-------- receiver/unittests/test_request.cpp | 38 +------------- .../asapo_fabric/parallel_data_transfer.cpp | 4 +- .../asapo_fabric/server_not_running.cpp | 2 +- .../asapo_fabric/simple_data_transfer.cpp | 2 +- tests/automatic/asapo_fabric/timeout_test.cpp | 4 +- .../asapo_fabric/wrong_memory_info.cpp | 4 +- .../consumer/consumer_api/consumer_api.cpp | 2 +- .../next_multithread_broker.cpp | 2 +- .../curl_httpclient_command.cpp | 2 +- .../send_recv_streams/send_recv_streams.cpp | 2 +- tests/automatic/mongo_db/auto_id/auto_id.cpp | 2 +- .../mongo_db/connect/connect_mongodb.cpp | 2 +- .../insert_retrieve_mongodb.cpp | 2 +- .../insert_retrieve_dataset_mongodb.cpp | 2 +- .../automatic/mongo_db/meta/meta_mongodb.cpp | 2 +- tests/automatic/producer/c_api/producer_api.c | 2 +- .../producer/cpp_api/producer_api.cpp | 2 +- .../spd_logger/console/spd_logger_console.cpp | 2 +- .../spd_logger/fluentd/spd_logger_fluentd.cpp | 2 +- .../client_serv/ip_tcp_network.cpp | 2 +- .../client_serv_multicon/multicon.cpp | 2 +- .../read_file_content/read_file_content.cpp | 4 +- .../read_folder_content.cpp | 4 +- .../read_string_from_file.cpp | 4 +- .../read_subdirectories.cpp | 4 +- .../resolve_hostname_to_ip.cpp | 2 +- .../write_data_to_file/write_data_to_file.cpp | 2 +- 51 files changed, 113 insertions(+), 324 deletions(-) delete mode 100644 receiver/README.md delete mode 100644 receiver/src/receiver_config_factory.h diff --git a/3d_party/mongo-c-driver/install.sh b/3d_party/mongo-c-driver/install.sh index 7d0f2b352..3280a302d 100755 --- a/3d_party/mongo-c-driver/install.sh +++ b/3d_party/mongo-c-driver/install.sh @@ -14,6 +14,7 @@ wget https://github.com/mongodb/mongo-c-driver/releases/download/1.17.2/mongo-c- tar xzf mongo-c-driver-1.17.2.tar.gz cd mongo-c-driver-1.17.2 +#you can add -DENABLE_ZSTD=OFF to disable lzstd cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_SSL=OFF -DENABLE_SASL=OFF -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF -DMONGOC_ENABLE_STATIC=ON . make -j 4 #sudo make install diff --git a/README.md b/README.md index 61156b508..c2c875b4b 100644 --- a/README.md +++ b/README.md @@ -23,11 +23,13 @@ ## Prepare dependencies +depending on configuration, you might need need curllib, mongoc, google tests + - cd 3d_party/mongo-c-driver - ./install.sh $(pwd) - - sudo make -C mongo-c-driver-1.15.2 install + - sudo make -C mongo-c-driver-1.17.2 install - - back in the aspo-dir: + - back in the asapo-dir: - mkdir build - (cd build; cmake ..) @@ -49,4 +51,13 @@ Need googletest >= [1.8.0](https://github.com/google/googletest/releases/tag/rel - cmake -DBUILD_TESTS=ON .. The software is MIT licensed (see LICENSE.txt) and uses third party libraries that are distributed under their own terms -(see LICENSE-3RD-PARTY.txt) \ No newline at end of file +(see LICENSE-3RD-PARTY.txt) + +## with non-standard 3rd party libraries paths +- cmake -Dlibmongoc-static-1.0_DIR=... -Dlibbson-static-1.0_DIR=... -Dgtest_SOURCE_DIR=... -DLIBCURL_DIR=... ... + +## compile + - make -j 4 + +or compile specific target only, e.g. + - make -j 4 receiver \ No newline at end of file diff --git a/common/cpp/src/json_parser/rapid_json.cpp b/common/cpp/src/json_parser/rapid_json.cpp index 03d9b6072..c21fa0f27 100644 --- a/common/cpp/src/json_parser/rapid_json.cpp +++ b/common/cpp/src/json_parser/rapid_json.cpp @@ -62,6 +62,8 @@ asapo::Error RapidJson::CheckValueType(const std::string& name, ValueType type, case ValueType::kArray: res = val->IsArray(); break; + default: + res = false; } if (!res) { return TextError("wrong type for: " + name + " in: " + json_); diff --git a/consumer/tools/folder_to_db/src/main.cpp b/consumer/tools/folder_to_db/src/main.cpp index aa21af1f8..d8dcf2b77 100644 --- a/consumer/tools/folder_to_db/src/main.cpp +++ b/consumer/tools/folder_to_db/src/main.cpp @@ -85,7 +85,7 @@ int main(int argc, char* argv[]) { &statistics); if (err != nullptr) { std::cout << "Error import to database: " << err->Explain() << std::endl; - return 1; + return EXIT_FAILURE; } std::cout << statistics << std::endl; diff --git a/docs/site/versioned_examples/version-21.06.0/python/produce.py b/docs/site/versioned_examples/version-21.06.0/python/produce.py index 0742fe3af..2a645631e 100644 --- a/docs/site/versioned_examples/version-21.06.0/python/produce.py +++ b/docs/site/versioned_examples/version-21.06.0/python/produce.py @@ -6,7 +6,7 @@ def callback(payload,err): print("could not send: ",payload,err) elif err is not None: # The data was sent, but there was some unexpected problem, e.g. the file was overwritten. - print("sent with warning":,payload,err) + print("sent with warning: ",payload,err) else: # all fine print("successfuly sent: ",payload) @@ -14,8 +14,7 @@ def callback(payload,err): endpoint = "localhost:8400" beamtime = "asapo_test" -producer = asapo_producer - .create_producer(endpoint, +producer = asapo_producer.create_producer(endpoint, 'processed', # should be 'processed' or 'raw', 'processed' writes to the core FS beamtime, # the folder should exist 'auto', # can be 'auto', if beamtime_id is given diff --git a/receiver/CMakeLists.txt b/receiver/CMakeLists.txt index 6d6ac3e8a..af41e773a 100644 --- a/receiver/CMakeLists.txt +++ b/receiver/CMakeLists.txt @@ -56,8 +56,6 @@ set(SOURCE_FILES ################################ # Library ################################ -#SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") - GET_PROPERTY(ASAPO_COMMON_FABRIC_LIBRARIES GLOBAL PROPERTY ASAPO_COMMON_FABRIC_LIBRARIES) add_library(${TARGET_NAME} STATIC ${SOURCE_FILES} $<TARGET_OBJECTS:system_io> $<TARGET_OBJECTS:curl_http_client> diff --git a/receiver/README.md b/receiver/README.md deleted file mode 100644 index 7f18fbae7..000000000 --- a/receiver/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# cpp-receiver - -This is the receiver implementation in c++ - -## Building this project - -### Requirements - - - TODO - -### How to build - - - TODO - diff --git a/receiver/src/connection.cpp b/receiver/src/connection.cpp index bd1a6d9c6..b0fcdca70 100644 --- a/receiver/src/connection.cpp +++ b/receiver/src/connection.cpp @@ -13,15 +13,13 @@ Connection::Connection(SocketDescriptor socket_fd, const std::string& address, io__{GenerateDefaultIO()}, statistics__{new ReceiverStatistics}, log__{GetDefaultReceiverLogger()}, -requests_dispatcher__{new RequestsDispatcher{socket_fd, address, statistics__.get(), cache}} { +requests_dispatcher__{new RequestsDispatcher{socket_fd, address, statistics__.get(), cache}} { socket_fd_ = socket_fd; address_ = address; statistics__->AddTag("connection_from", address); statistics__->AddTag("receiver_tag", std::move(receiver_tag)); } - - void Connection::ProcessStatisticsAfterRequest(const std::unique_ptr<Request>& request) const noexcept { statistics__->IncreaseRequestCounter(); statistics__->IncreaseRequestDataVolume(request->GetDataSize() + sizeof(GenericRequestHeader) + @@ -47,7 +45,6 @@ void Connection::Listen() const noexcept { log__->Info(LogMessageWithFields("disconnected from producer").Append("origin", HostFromUri(address_))); } - } diff --git a/receiver/src/main.cpp b/receiver/src/main.cpp index 4ac76015f..9f818218d 100644 --- a/receiver/src/main.cpp +++ b/receiver/src/main.cpp @@ -2,7 +2,6 @@ #include <utility> #include "receiver.h" -#include "receiver_config_factory.h" #include "receiver_config.h" #include "receiver_data_server/receiver_data_server_logger.h" @@ -15,13 +14,17 @@ #include "metrics/receiver_prometheus_metrics.h" #include "metrics/receiver_mongoose_server.h" -asapo::Error ReadConfigFile(int argc, char* argv[]) { +void ReadConfigFile(int argc, char* argv[]) { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " <config file>" << std::endl; exit(EXIT_FAILURE); } - asapo::ReceiverConfigFactory factory; - return factory.SetConfig(argv[1]); + asapo::ReceiverConfigManager config_manager; + auto err = config_manager.ReadConfigFromFile(argv[1]); + if (err) { + std::cerr << "cannot read config file:" << err->Explain() << std::endl; + exit(EXIT_FAILURE); + } } void AddDataServers(const asapo::ReceiverConfig* config, asapo::SharedCache, @@ -85,9 +88,9 @@ int StartReceiver(const asapo::ReceiverConfig* config, asapo::SharedCache cache, receiver->Listen(address, &err); if (err) { logger->Error("failed to start receiver: " + err->Explain()); - return 1; + return EXIT_FAILURE; } - return 0; + return EXIT_SUCCESS; } std::unique_ptr<std::thread> StartMetricsServer(const asapo::ReceiverMetricsConfig& config, @@ -108,18 +111,13 @@ std::unique_ptr<std::thread> StartMetricsServer(const asapo::ReceiverMetricsConf }; } + + int main(int argc, char* argv[]) { asapo::ExitAfterPrintVersionIfNeeded("ASAPO Receiver", argc, argv); - - auto err = ReadConfigFile(argc, argv); + ReadConfigFile(argc, argv); const auto& logger = asapo::GetDefaultReceiverLogger(); - if (err) { - logger->Error("cannot read config file: " + err->Explain()); - return 1; - } - auto config = asapo::GetReceiverConfig(); - logger->SetLogLevel(config->log_level); asapo::SharedCache cache = nullptr; @@ -128,13 +126,15 @@ int main(int argc, char* argv[]) { (float) config->datacache_reserved_share / 100}); } + asapo::Error err; auto dataServerThreads = StartDataServers(config, cache, &err); if (err) { logger->Error("cannot start data server: " + err->Explain()); - return 1; + return EXIT_FAILURE; } - auto t = StartMetricsServer(config->metrics, logger); + auto metrics_thread = StartMetricsServer(config->metrics, logger); auto exit_code = StartReceiver(config, cache, logger); +// todo: implement graceful exit, currently it never reaches this point return exit_code; } diff --git a/receiver/src/receiver.cpp b/receiver/src/receiver.cpp index 7038deceb..e3ef529d4 100644 --- a/receiver/src/receiver.cpp +++ b/receiver/src/receiver.cpp @@ -44,7 +44,6 @@ void Receiver::ProcessConnections(Error* err) { //TODO: Use InetAcceptConnectionWithTimeout auto client_info_tuple = io__->InetAcceptConnection(listener_fd_, err); if(*err) { - //TODO: this can produce a lot of error messages log__->Error("accepting an incoming connection: " + (*err)->Explain()); return; } diff --git a/receiver/src/receiver_config.cpp b/receiver/src/receiver_config.cpp index e78004925..c6cc78460 100644 --- a/receiver/src/receiver_config.cpp +++ b/receiver/src/receiver_config.cpp @@ -1,5 +1,4 @@ #include "receiver_config.h" -#include "receiver_config_factory.h" #include "asapo/io/io_factory.h" #include "asapo/json_parser/json_parser.h" @@ -9,11 +8,11 @@ namespace asapo { ReceiverConfig config; -ReceiverConfigFactory::ReceiverConfigFactory() : io__{GenerateDefaultIO()} { +ReceiverConfigManager::ReceiverConfigManager() : io__{GenerateDefaultIO()} { } -Error ReceiverConfigFactory::SetConfig(std::string file_name) { +Error ReceiverConfigManager::ReadConfigFromFile(std::string file_name) { JsonFileParser parser(file_name, &io__); std::string log_level; Error err; diff --git a/receiver/src/receiver_config.h b/receiver/src/receiver_config.h index 89c0d918f..0a054e2c1 100644 --- a/receiver/src/receiver_config.h +++ b/receiver/src/receiver_config.h @@ -29,6 +29,15 @@ struct ReceiverConfig { std::string discovery_server; }; +class ReceiverConfigManager { + public: + ReceiverConfigManager(); + Error ReadConfigFromFile(std::string file_name); + public: + std::unique_ptr<IO> io__; +}; + + const ReceiverConfig* GetReceiverConfig(); } diff --git a/receiver/src/receiver_config_factory.h b/receiver/src/receiver_config_factory.h deleted file mode 100644 index 6be2f933e..000000000 --- a/receiver/src/receiver_config_factory.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef ASAPO_RECEIVER_CONFIG_FACTORY__H -#define ASAPO_RECEIVER_CONFIG_FACTORY__H - -#include "asapo/io/io.h" -#include "asapo/common/error.h" - -namespace asapo { - -class ReceiverConfigFactory { - public: - ReceiverConfigFactory(); - Error SetConfig(std::string file_name); - public: - std::unique_ptr<IO> io__; -}; - -} - - -#endif //ASAPO_RECEIVER_CONFIG_FACTORY__H diff --git a/receiver/src/statistics/statistics.h b/receiver/src/statistics/statistics.h index e9fcbd3a2..c6dff9996 100644 --- a/receiver/src/statistics/statistics.h +++ b/receiver/src/statistics/statistics.h @@ -26,8 +26,8 @@ struct StatisticsToSend { class Statistics { public: - VIRTUAL void SendIfNeeded(bool send_always = false) noexcept; explicit Statistics(unsigned int write_interval = kDefaultStatisticWriteIntervalMs); + VIRTUAL void SendIfNeeded(bool send_always = false) noexcept; VIRTUAL void IncreaseRequestCounter() noexcept; VIRTUAL void IncreaseRequestDataVolume(uint64_t transferred_data_volume) noexcept; VIRTUAL void AddTag(const std::string& name, const std::string& value) noexcept; diff --git a/receiver/src/statistics/statistics_sender_fluentd.cpp b/receiver/src/statistics/statistics_sender_fluentd.cpp index b1a3ba9e4..9631cd75b 100644 --- a/receiver/src/statistics/statistics_sender_fluentd.cpp +++ b/receiver/src/statistics/statistics_sender_fluentd.cpp @@ -5,7 +5,6 @@ namespace asapo { StatisticsSenderFluentd::StatisticsSenderFluentd() : statistics_log__{asapo::CreateDefaultLoggerApi("receiver_stat", "localhost:8400/logs/")} { statistics_log__->SetLogLevel(LogLevel::Info); -// statistics_log__->EnableLocalLog(true); } void StatisticsSenderFluentd::SendStatistics(const asapo::StatisticsToSend& statistic) const noexcept { diff --git a/receiver/unittests/mock_receiver_config.cpp b/receiver/unittests/mock_receiver_config.cpp index 489fe8b96..2e02670b4 100644 --- a/receiver/unittests/mock_receiver_config.cpp +++ b/receiver/unittests/mock_receiver_config.cpp @@ -2,7 +2,7 @@ #include <gmock/gmock.h> #include "mock_receiver_config.h" -#include "../src/receiver_config_factory.h" +#include "../src/receiver_config.h" #include <asapo/unittests/MockIO.h> @@ -19,8 +19,8 @@ std::string Key(std::string value, std::string error_field) { Error SetReceiverConfig (const ReceiverConfig& config, std::string error_field) { MockIO mock_io; - ReceiverConfigFactory config_factory; - config_factory.io__ = std::unique_ptr<IO> {&mock_io}; + ReceiverConfigManager config_manager; + config_manager.io__ = std::unique_ptr<IO> {&mock_io}; std::string log_level; switch (config.log_level) { @@ -87,9 +87,9 @@ Error SetReceiverConfig (const ReceiverConfig& config, std::string error_field) testing::Return(config_string) ); - auto err = config_factory.SetConfig("fname"); + auto err = config_manager.ReadConfigFromFile("fname"); - config_factory.io__.release(); + config_manager.io__.release(); return err; } diff --git a/receiver/unittests/statistics/test_receiver_statistics.cpp b/receiver/unittests/statistics/test_receiver_statistics.cpp index d2bbe46e0..318acac37 100644 --- a/receiver/unittests/statistics/test_receiver_statistics.cpp +++ b/receiver/unittests/statistics/test_receiver_statistics.cpp @@ -8,25 +8,9 @@ #include "../../src/statistics/statistics_sender_fluentd.h" #include "../receiver_mocking.h" -using ::testing::Test; -using ::testing::Gt; -using ::testing::Ge; -using ::testing::Le; -using ::testing::Eq; -using ::testing::Ne; -using ::testing::Ref; -using ::testing::_; - -using asapo::ReceiverStatistics; -using asapo::Statistics; -using asapo::StatisticEntity; -using asapo::StatisticsSender; -using asapo::StatisticsSenderInfluxDb; -using asapo::StatisticsSenderFluentd; - -using asapo::StatisticsToSend; - -using asapo::MockStatisticsSender; + +using namespace testing; +using namespace asapo; namespace { diff --git a/receiver/unittests/statistics/test_statistics.cpp b/receiver/unittests/statistics/test_statistics.cpp index d31c2282f..74756dcd0 100644 --- a/receiver/unittests/statistics/test_statistics.cpp +++ b/receiver/unittests/statistics/test_statistics.cpp @@ -8,25 +8,11 @@ #include "../../src/statistics/statistics_sender_fluentd.h" #include "../receiver_mocking.h" #include "../../src/receiver_config.h" -#include "../../src/receiver_config_factory.h" #include "../mock_receiver_config.h" -using ::testing::Test; -using ::testing::Gt; -using ::testing::Ge; -using ::testing::Le; -using ::testing::Eq; -using ::testing::Ne; -using ::testing::Ref; -using ::testing::_; - -using asapo::Statistics; -using asapo::StatisticsSender; -using asapo::StatisticsSenderInfluxDb; -using asapo::StatisticsSenderFluentd; - -using asapo::StatisticsToSend; -using asapo::MockStatisticsSender; + +using namespace testing; +using namespace asapo; namespace { diff --git a/receiver/unittests/statistics/test_statistics_sender_fluentd.cpp b/receiver/unittests/statistics/test_statistics_sender_fluentd.cpp index 80247857a..5b749f55d 100644 --- a/receiver/unittests/statistics/test_statistics_sender_fluentd.cpp +++ b/receiver/unittests/statistics/test_statistics_sender_fluentd.cpp @@ -14,28 +14,9 @@ #include "../mock_receiver_config.h" #include "../../src/statistics/statistics_sender_fluentd.h" -using ::testing::Test; -using ::testing::Return; -using ::testing::_; -using ::testing::DoAll; -using ::testing::SetArgReferee; -using ::testing::Gt; -using ::testing::Eq; -using ::testing::Ne; -using ::testing::Mock; -using ::testing::NiceMock; -using ::testing::SaveArg; -using ::testing::HasSubstr; -using ::testing::AllOf; -using ::testing::SaveArgPointee; -using ::testing::InSequence; -using ::testing::SetArgPointee; - -using asapo::StatisticsSenderFluentd; -using asapo::MockHttpClient; -using asapo::StatisticsToSend; -using asapo::ReceiverConfig; -using asapo::SetReceiverConfig; + +using namespace testing; +using namespace asapo; namespace { diff --git a/receiver/unittests/statistics/test_statistics_sender_influx_db.cpp b/receiver/unittests/statistics/test_statistics_sender_influx_db.cpp index 222814629..cb7116bf5 100644 --- a/receiver/unittests/statistics/test_statistics_sender_influx_db.cpp +++ b/receiver/unittests/statistics/test_statistics_sender_influx_db.cpp @@ -14,28 +14,8 @@ #include "../mock_receiver_config.h" -using ::testing::Test; -using ::testing::Return; -using ::testing::_; -using ::testing::DoAll; -using ::testing::SetArgReferee; -using ::testing::Gt; -using ::testing::Eq; -using ::testing::Ne; -using ::testing::Mock; -using ::testing::NiceMock; -using ::testing::SaveArg; -using ::testing::HasSubstr; -using ::testing::AllOf; -using ::testing::SaveArgPointee; -using ::testing::InSequence; -using ::testing::SetArgPointee; - -using asapo::StatisticsSenderInfluxDb; -using asapo::MockHttpClient; -using asapo::StatisticsToSend; -using asapo::ReceiverConfig; -using asapo::SetReceiverConfig; +using namespace testing; +using namespace asapo; namespace { diff --git a/receiver/unittests/test_config.cpp b/receiver/unittests/test_config.cpp index 6e656529e..8ab74566a 100644 --- a/receiver/unittests/test_config.cpp +++ b/receiver/unittests/test_config.cpp @@ -3,31 +3,10 @@ #include <asapo/unittests/MockIO.h> #include "../src/receiver_config.h" -#include "../src/receiver_config_factory.h" #include "mock_receiver_config.h" -using ::testing::Test; -using ::testing::Return; -using ::testing::_; -using ::testing::DoAll; -using ::testing::SetArgReferee; -using ::testing::Gt; -using ::testing::Eq; -using ::testing::Ne; -using ::testing::Mock; -using ::testing::NiceMock; -using ::testing::SaveArg; -using ::testing::SaveArgPointee; -using ::testing::InSequence; -using ::testing::SetArgPointee; -using ::asapo::Error; -using ::asapo::ErrorInterface; -using ::asapo::FileDescriptor; -using ::asapo::SocketDescriptor; -using ::asapo::MockIO; - -using ::asapo::ReceiverConfigFactory; -using asapo::GetReceiverConfig; +using namespace testing; +using namespace asapo; namespace { @@ -35,7 +14,7 @@ namespace { class ConfigTests : public Test { public: MockIO mock_io; - ReceiverConfigFactory config_factory; + ReceiverConfigManager config_factory; asapo::ReceiverConfig test_config; void SetUp() override { config_factory.io__ = std::unique_ptr<asapo::IO> {&mock_io}; diff --git a/receiver/unittests/test_connection.cpp b/receiver/unittests/test_connection.cpp index fca987832..ee49f8c51 100644 --- a/receiver/unittests/test_connection.cpp +++ b/receiver/unittests/test_connection.cpp @@ -4,55 +4,11 @@ #include "asapo/unittests/MockIO.h" #include "asapo/unittests/MockLogger.h" #include "../src/connection.h" -#include "../src/receiver_error.h" -#include "../src/request.h" -#include "../src/statistics/receiver_statistics.h" #include "receiver_mocking.h" #include "../src/receiver_config.h" -#include "../src/receiver_config_factory.h" -#include "../src/request_handler/requests_dispatcher.h" - -#include "mock_receiver_config.h" - - -using ::testing::Test; -using ::testing::Return; -using ::testing::_; -using ::testing::DoAll; -using ::testing::SetArgReferee; -using ::testing::Gt; -using ::testing::Eq; -using ::testing::Ne; -using ::testing::Mock; -using ::testing::NiceMock; -using ::testing::SaveArg; -using ::testing::SaveArgPointee; -using ::testing::InSequence; -using ::testing::HasSubstr; -using ::testing::StrEq; -using ::testing::SetArgPointee; -using ::testing::AllOf; -using testing::Sequence; - -using asapo::Error; -using asapo::ErrorInterface; -using asapo::FileDescriptor; -using asapo::SocketDescriptor; -using asapo::GenericRequestHeader; -using asapo::SendResponse; -using asapo::GenericRequestHeader; -using asapo::GenericNetworkResponse; -using asapo::Opcode; -using asapo::Connection; -using asapo::MockIO; -using asapo::MockLogger; -using asapo::Request; -using asapo::ReceiverStatistics; -using asapo::StatisticEntity; -using asapo::MockStatistics; - -using asapo::ReceiverConfig; -using asapo::SetReceiverConfig; + +using namespace testing; +using namespace asapo; namespace { diff --git a/receiver/unittests/test_datacache.cpp b/receiver/unittests/test_datacache.cpp index d17f29276..ead69885b 100644 --- a/receiver/unittests/test_datacache.cpp +++ b/receiver/unittests/test_datacache.cpp @@ -4,15 +4,8 @@ #include "../src/data_cache.h" -using ::testing::Test; -using ::testing::Gt; -using ::testing::Ge; -using ::testing::Le; -using ::testing::Eq; -using ::testing::Ne; -using ::testing::Ref; -using ::testing::_; -using ::testing::ElementsAreArray; + +using namespace testing; using asapo::DataCache; using asapo::CacheMeta; diff --git a/receiver/unittests/test_receiver.cpp b/receiver/unittests/test_receiver.cpp index ff2f8c00f..49e7859cd 100644 --- a/receiver/unittests/test_receiver.cpp +++ b/receiver/unittests/test_receiver.cpp @@ -4,27 +4,11 @@ #include "asapo/unittests/MockIO.h" #include "asapo/unittests/MockLogger.h" #include "../src/receiver.h" -#include "../src/receiver_error.h" -#include "../src/connection.h" -#include "../src/data_cache.h" - -using ::testing::Return; -using ::testing::_; -using ::testing::DoAll; -using ::testing::SetArgReferee; -using ::testing::SetArgPointee; -using ::testing::Gt; -using ::testing::Eq; -using ::testing::Ne; -using ::testing::Mock; -using ::testing::InSequence; -using ::testing::HasSubstr; -using ::asapo::Error; -using ::asapo::FileDescriptor; -using ::asapo::ErrorInterface; -using ::asapo::Connection; -using ::asapo::SocketDescriptor; -using asapo::DataCache; + +using namespace testing; +using namespace asapo; + + namespace { TEST(Receiver, Constructor) { diff --git a/receiver/unittests/test_request.cpp b/receiver/unittests/test_request.cpp index 93d018c37..096ebe890 100644 --- a/receiver/unittests/test_request.cpp +++ b/receiver/unittests/test_request.cpp @@ -2,47 +2,13 @@ #include <gmock/gmock.h> #include <asapo/unittests/MockIO.h> #include "../src/connection.h" -#include "../src/receiver_error.h" -#include "../src/request.h" -#include "../src/request_handler/request_handler.h" -#include "../src/request_handler/request_handler_file_process.h" -#include "../src/request_handler/request_handler_db_write.h" #include "asapo/database/database.h" #include "receiver_mocking.h" #include "mock_receiver_config.h" -using ::testing::Test; -using ::testing::Return; -using ::testing::_; -using ::testing::DoAll; -using ::testing::SetArgReferee; -using ::testing::Gt; -using ::testing::Eq; -using ::testing::Ne; -using ::testing::Mock; -using ::testing::NiceMock; -using ::testing::InSequence; -using ::testing::SetArgPointee; -using ::asapo::Error; -using ::asapo::ErrorInterface; -using ::asapo::FileDescriptor; -using ::asapo::SocketDescriptor; -using ::asapo::GenericRequestHeader; -using ::asapo::SendResponse; -using ::asapo::GenericRequestHeader; -using ::asapo::GenericNetworkResponse; -using ::asapo::Opcode; -using ::asapo::Connection; -using ::asapo::MockIO; -using asapo::Request; -using asapo::MockStatistics; -using asapo::MockDataCache; -using asapo::StatisticEntity; - -using asapo::ReceiverConfig; -using asapo::SetReceiverConfig; -using asapo::RequestFactory; +using namespace testing; +using namespace asapo; namespace { diff --git a/tests/automatic/asapo_fabric/parallel_data_transfer.cpp b/tests/automatic/asapo_fabric/parallel_data_transfer.cpp index b7aed4413..41f2c82bb 100644 --- a/tests/automatic/asapo_fabric/parallel_data_transfer.cpp +++ b/tests/automatic/asapo_fabric/parallel_data_transfer.cpp @@ -140,7 +140,7 @@ int main(int argc, char* argv[]) { if (argc > 3) { std::cout << "Usage: " << argv[0] << " [<host>] [<port>]" << std::endl; - return 1; + return EXIT_FAILURE; } if (argc == 2) { hostname = argv[1]; @@ -165,5 +165,5 @@ int main(int argc, char* argv[]) { std::cout << "Done testing. Joining server" << std::endl; serverMasterThread.join(); - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/asapo_fabric/server_not_running.cpp b/tests/automatic/asapo_fabric/server_not_running.cpp index 698f80980..09db2139e 100644 --- a/tests/automatic/asapo_fabric/server_not_running.cpp +++ b/tests/automatic/asapo_fabric/server_not_running.cpp @@ -12,7 +12,7 @@ int main(int argc, char* argv[]) { if (argc > 3) { std::cout << "Usage: " << argv[0] << " [<host>] [<port>]" << std::endl; - return 1; + return EXIT_FAILURE; } if (argc == 2) { hostname = argv[1]; diff --git a/tests/automatic/asapo_fabric/simple_data_transfer.cpp b/tests/automatic/asapo_fabric/simple_data_transfer.cpp index b2d15f2dc..8999f6801 100644 --- a/tests/automatic/asapo_fabric/simple_data_transfer.cpp +++ b/tests/automatic/asapo_fabric/simple_data_transfer.cpp @@ -114,7 +114,7 @@ int main(int argc, char* argv[]) { if (argc > 3) { std::cout << "Usage: " << argv[0] << " [<host>] [<port>]" << std::endl; - return 1; + return EXIT_FAILURE; } if (argc == 2) { hostname = argv[1]; diff --git a/tests/automatic/asapo_fabric/timeout_test.cpp b/tests/automatic/asapo_fabric/timeout_test.cpp index f752af6ef..d938faf64 100644 --- a/tests/automatic/asapo_fabric/timeout_test.cpp +++ b/tests/automatic/asapo_fabric/timeout_test.cpp @@ -93,7 +93,7 @@ int main(int argc, char* argv[]) { if (argc > 3) { std::cout << "Usage: " << argv[0] << " [<host>] [<port>]" << std::endl; - return 1; + return EXIT_FAILURE; } if (argc == 2) { hostname = argv[1]; @@ -110,5 +110,5 @@ int main(int argc, char* argv[]) { std::cout << "Done testing. Joining server" << std::endl; serverThread.join(); - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/asapo_fabric/wrong_memory_info.cpp b/tests/automatic/asapo_fabric/wrong_memory_info.cpp index cb6c444a4..d3b9a5910 100644 --- a/tests/automatic/asapo_fabric/wrong_memory_info.cpp +++ b/tests/automatic/asapo_fabric/wrong_memory_info.cpp @@ -133,7 +133,7 @@ int main(int argc, char* argv[]) { if (argc > 3) { std::cout << "Usage: " << argv[0] << " [<host>] [<port>]" << std::endl; - return 1; + return EXIT_FAILURE; } if (argc == 2) { hostname = argv[1]; @@ -150,5 +150,5 @@ int main(int argc, char* argv[]) { std::cout << "Done testing. Joining server" << std::endl; serverThread.join(); - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/consumer/consumer_api/consumer_api.cpp b/tests/automatic/consumer/consumer_api/consumer_api.cpp index 64ce965b4..f388fd945 100644 --- a/tests/automatic/consumer/consumer_api/consumer_api.cpp +++ b/tests/automatic/consumer/consumer_api/consumer_api.cpp @@ -355,5 +355,5 @@ int main(int argc, char* argv[]) { auto args = GetArgs(argc, argv); TestAll(args); - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/consumer/next_multithread_broker/next_multithread_broker.cpp b/tests/automatic/consumer/next_multithread_broker/next_multithread_broker.cpp index eb8c03c6f..a369f4896 100644 --- a/tests/automatic/consumer/next_multithread_broker/next_multithread_broker.cpp +++ b/tests/automatic/consumer/next_multithread_broker/next_multithread_broker.cpp @@ -94,5 +94,5 @@ int main(int argc, char* argv[]) { auto args = GetArgs(argc, argv); TestAll(args); - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/curl_http_client/curl_http_client_command/curl_httpclient_command.cpp b/tests/automatic/curl_http_client/curl_http_client_command/curl_httpclient_command.cpp index 4bf11faac..875c054d1 100644 --- a/tests/automatic/curl_http_client/curl_http_client_command/curl_httpclient_command.cpp +++ b/tests/automatic/curl_http_client/curl_http_client_command/curl_httpclient_command.cpp @@ -95,5 +95,5 @@ int main(int argc, char* argv[]) { err = consumer_impl->httpclient__->Post(args.uri_fts + "/v0.1/transfer", cookie, transfer, "random", &code); M_AssertTrue(code == asapo::HttpCode::OK); - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/full_chain/send_recv_streams/send_recv_streams.cpp b/tests/automatic/full_chain/send_recv_streams/send_recv_streams.cpp index cce8e6007..a752a2ba2 100644 --- a/tests/automatic/full_chain/send_recv_streams/send_recv_streams.cpp +++ b/tests/automatic/full_chain/send_recv_streams/send_recv_streams.cpp @@ -109,7 +109,7 @@ int main(int argc, char* argv[]) { err = consumer->GetNext(group_id, &fi, nullptr, "stream1"); if (err != asapo::ConsumerErrorTemplates::kStreamFinished) { - return 1; + return EXIT_FAILURE; } auto err_data = static_cast<const asapo::ConsumerErrorData*>(err->GetCustomData()); diff --git a/tests/automatic/mongo_db/auto_id/auto_id.cpp b/tests/automatic/mongo_db/auto_id/auto_id.cpp index ed966436e..337360aa8 100644 --- a/tests/automatic/mongo_db/auto_id/auto_id.cpp +++ b/tests/automatic/mongo_db/auto_id/auto_id.cpp @@ -118,5 +118,5 @@ int main(int argc, char* argv[]) { db.DeleteStream("stream"); - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/mongo_db/connect/connect_mongodb.cpp b/tests/automatic/mongo_db/connect/connect_mongodb.cpp index 1adfa650c..070166913 100644 --- a/tests/automatic/mongo_db/connect/connect_mongodb.cpp +++ b/tests/automatic/mongo_db/connect/connect_mongodb.cpp @@ -45,7 +45,7 @@ int main(int argc, char* argv[]) { err = db.Connect(args.address, args.database_name); Assert(err, asapo::DBErrorTemplates::kAlreadyConnected.Generate()->Explain()); } - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/mongo_db/insert_retrieve/insert_retrieve_mongodb.cpp b/tests/automatic/mongo_db/insert_retrieve/insert_retrieve_mongodb.cpp index 411148140..0beb953e4 100644 --- a/tests/automatic/mongo_db/insert_retrieve/insert_retrieve_mongodb.cpp +++ b/tests/automatic/mongo_db/insert_retrieve/insert_retrieve_mongodb.cpp @@ -144,5 +144,5 @@ int main(int argc, char* argv[]) { M_AssertTrue(err == asapo::DBErrorTemplates::kWrongInput); - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/mongo_db/insert_retrieve_dataset/insert_retrieve_dataset_mongodb.cpp b/tests/automatic/mongo_db/insert_retrieve_dataset/insert_retrieve_dataset_mongodb.cpp index 3c5854147..ee9cea6c0 100644 --- a/tests/automatic/mongo_db/insert_retrieve_dataset/insert_retrieve_dataset_mongodb.cpp +++ b/tests/automatic/mongo_db/insert_retrieve_dataset/insert_retrieve_dataset_mongodb.cpp @@ -98,5 +98,5 @@ int main(int argc, char* argv[]) { } - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/mongo_db/meta/meta_mongodb.cpp b/tests/automatic/mongo_db/meta/meta_mongodb.cpp index 8c61b4e17..abae70c4e 100644 --- a/tests/automatic/mongo_db/meta/meta_mongodb.cpp +++ b/tests/automatic/mongo_db/meta/meta_mongodb.cpp @@ -97,5 +97,5 @@ int main(int argc, char* argv[]) { db.DeleteStream(stream_name); } - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/producer/c_api/producer_api.c b/tests/automatic/producer/c_api/producer_api.c index 317d647c8..2829064da 100644 --- a/tests/automatic/producer/c_api/producer_api.c +++ b/tests/automatic/producer/c_api/producer_api.c @@ -119,5 +119,5 @@ int main(int argc, char* argv[]) { asapo_free_handle(&err); asapo_free_handle(&cred); asapo_free_handle(&producer); - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/producer/cpp_api/producer_api.cpp b/tests/automatic/producer/cpp_api/producer_api.cpp index aa573f0bd..699c3978d 100644 --- a/tests/automatic/producer/cpp_api/producer_api.cpp +++ b/tests/automatic/producer/cpp_api/producer_api.cpp @@ -94,5 +94,5 @@ int main(int argc, char* argv[]) { auto args = GetArgs(argc, argv); TestAll(args); - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/spd_logger/console/spd_logger_console.cpp b/tests/automatic/spd_logger/console/spd_logger_console.cpp index bf6667457..68150452e 100644 --- a/tests/automatic/spd_logger/console/spd_logger_console.cpp +++ b/tests/automatic/spd_logger/console/spd_logger_console.cpp @@ -60,5 +60,5 @@ int main() { logger->Debug("test debug_nonelev"); - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/spd_logger/fluentd/spd_logger_fluentd.cpp b/tests/automatic/spd_logger/fluentd/spd_logger_fluentd.cpp index c1e61fb19..fd0c8bcf4 100644 --- a/tests/automatic/spd_logger/fluentd/spd_logger_fluentd.cpp +++ b/tests/automatic/spd_logger/fluentd/spd_logger_fluentd.cpp @@ -13,5 +13,5 @@ int main() { logger->Warning("test warning"); logger->Debug("test debug"); - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/system_io/ip_tcp_network/client_serv/ip_tcp_network.cpp b/tests/automatic/system_io/ip_tcp_network/client_serv/ip_tcp_network.cpp index a7f1edfd2..2e15db04e 100644 --- a/tests/automatic/system_io/ip_tcp_network/client_serv/ip_tcp_network.cpp +++ b/tests/automatic/system_io/ip_tcp_network/client_serv/ip_tcp_network.cpp @@ -208,5 +208,5 @@ int main() { remove("sent"); remove("received"); - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/system_io/ip_tcp_network/client_serv_multicon/multicon.cpp b/tests/automatic/system_io/ip_tcp_network/client_serv_multicon/multicon.cpp index 4ee84fe88..2022b66f4 100644 --- a/tests/automatic/system_io/ip_tcp_network/client_serv_multicon/multicon.cpp +++ b/tests/automatic/system_io/ip_tcp_network/client_serv_multicon/multicon.cpp @@ -130,5 +130,5 @@ int main() { std::cout << "server_thread->join()" << std::endl; server_thread->join(); - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/system_io/read_file_content/read_file_content.cpp b/tests/automatic/system_io/read_file_content/read_file_content.cpp index 289a0aab3..22a1a9a56 100644 --- a/tests/automatic/system_io/read_file_content/read_file_content.cpp +++ b/tests/automatic/system_io/read_file_content/read_file_content.cpp @@ -7,7 +7,7 @@ int main(int argc, char* argv[]) { if (argc != 3) { std::cout << "Wrong number of arguments" << std::endl; - return 1; + return EXIT_FAILURE; } std::string expect{argv[2]}; @@ -33,5 +33,5 @@ int main(int argc, char* argv[]) { } M_AssertContains(result, expect); - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/system_io/read_folder_content/read_folder_content.cpp b/tests/automatic/system_io/read_folder_content/read_folder_content.cpp index 8867f6d27..edabc0053 100644 --- a/tests/automatic/system_io/read_folder_content/read_folder_content.cpp +++ b/tests/automatic/system_io/read_folder_content/read_folder_content.cpp @@ -9,7 +9,7 @@ using asapo::Error; int main(int argc, char* argv[]) { if (argc != 3) { std::cout << "Wrong number of arguments" << std::endl; - return 1; + return EXIT_FAILURE; } std::string expect{argv[2]}; @@ -33,5 +33,5 @@ int main(int argc, char* argv[]) { M_AssertContains(result, expect); - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/system_io/read_string_from_file/read_string_from_file.cpp b/tests/automatic/system_io/read_string_from_file/read_string_from_file.cpp index 789943a29..31d3ff532 100644 --- a/tests/automatic/system_io/read_string_from_file/read_string_from_file.cpp +++ b/tests/automatic/system_io/read_string_from_file/read_string_from_file.cpp @@ -6,7 +6,7 @@ int main(int argc, char* argv[]) { if (argc != 3) { std::cout << "Wrong number of arguments" << std::endl; - return 1; + return EXIT_FAILURE; } std::string expect{argv[2]}; @@ -23,5 +23,5 @@ int main(int argc, char* argv[]) { } M_AssertContains(result, expect); - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/system_io/read_subdirectories/read_subdirectories.cpp b/tests/automatic/system_io/read_subdirectories/read_subdirectories.cpp index 1e134654e..d00d8761b 100644 --- a/tests/automatic/system_io/read_subdirectories/read_subdirectories.cpp +++ b/tests/automatic/system_io/read_subdirectories/read_subdirectories.cpp @@ -9,7 +9,7 @@ using asapo::Error; int main(int argc, char* argv[]) { if (argc != 3) { std::cout << "Wrong number of arguments" << std::endl; - return 1; + return EXIT_FAILURE; } std::string expect{argv[2]}; @@ -28,5 +28,5 @@ int main(int argc, char* argv[]) { M_AssertContains(result, expect); - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/system_io/resolve_hostname_to_ip/resolve_hostname_to_ip.cpp b/tests/automatic/system_io/resolve_hostname_to_ip/resolve_hostname_to_ip.cpp index 7e53dd64b..da90ded0b 100644 --- a/tests/automatic/system_io/resolve_hostname_to_ip/resolve_hostname_to_ip.cpp +++ b/tests/automatic/system_io/resolve_hostname_to_ip/resolve_hostname_to_ip.cpp @@ -34,5 +34,5 @@ int main() { // Fallthrough tests Check("123.123.123.123", "123.123.123.123"); Check("8.8.8.8", "8.8.8.8"); - return 0; + return EXIT_SUCCESS; } diff --git a/tests/automatic/system_io/write_data_to_file/write_data_to_file.cpp b/tests/automatic/system_io/write_data_to_file/write_data_to_file.cpp index 4e0bbfc2c..0c5c494db 100644 --- a/tests/automatic/system_io/write_data_to_file/write_data_to_file.cpp +++ b/tests/automatic/system_io/write_data_to_file/write_data_to_file.cpp @@ -67,5 +67,5 @@ int main(int argc, char* argv[]) { AssertBadResult(err, params); } - return 0; + return EXIT_SUCCESS; } -- GitLab