From 2c4694ac173c50ebf1fafca9761dc5955c9ade5d Mon Sep 17 00:00:00 2001 From: Sergey Yakubov <sergey.yakubov@desy.de> Date: Mon, 9 Apr 2018 18:52:05 +0200 Subject: [PATCH] move http_client to common --- CMakeLists.txt | 5 ++ common/cpp/CMakeLists.txt | 2 + .../include/http_client}/curl_http_client.h | 0 .../cpp/include/http_client}/http_client.h | 4 +- .../cpp/include/http_client}/http_error.h | 0 common/cpp/src/http_client/CMakeLists.txt | 16 +++++++ .../cpp/src/http_client}/curl_http_client.cpp | 4 +- receiver/CMakeLists.txt | 14 +++--- receiver/src/statistics.cpp | 9 ++-- receiver/src/statistics.h | 8 ++-- receiver/src/statistics_sender.h | 2 +- receiver/src/statistics_sender_influx_db.cpp | 5 ++ receiver/src/statistics_sender_influx_db.h | 9 +++- receiver/unittests/mock_statistics.h | 48 +++++++++---------- receiver/unittests/test_request.cpp | 4 +- receiver/unittests/test_statistics.cpp | 44 ++++++++--------- .../test_statistics_sender_influx_db.cpp | 36 ++++++++++++++ tests/automatic/CMakeLists.txt | 1 + .../automatic/curl_http_client/CMakeLists.txt | 1 + .../curl_http_client_get/CMakeLists.txt | 0 .../curl_httpclient_get.cpp | 0 tests/automatic/worker/CMakeLists.txt | 2 - .../worker/connect_multithread/CMakeLists.txt | 1 - .../next_multithread_broker/CMakeLists.txt | 2 +- .../next_multithread_folder/CMakeLists.txt | 1 - worker/api/cpp/CMakeLists.txt | 18 ++----- worker/api/cpp/src/http_client.cpp | 29 ----------- worker/api/cpp/src/http_error.cpp | 7 --- worker/api/cpp/src/server_data_broker.cpp | 30 +++++++++++- worker/api/cpp/src/server_data_broker.h | 8 ++-- worker/api/cpp/unittests/MockHttpClient.h | 2 +- .../api/cpp/unittests/test_server_broker.cpp | 4 +- 32 files changed, 183 insertions(+), 133 deletions(-) rename {worker/api/cpp/src => common/cpp/include/http_client}/curl_http_client.h (100%) rename {worker/api/cpp/src => common/cpp/include/http_client}/http_client.h (96%) rename {worker/api/cpp/src => common/cpp/include/http_client}/http_error.h (100%) create mode 100644 common/cpp/src/http_client/CMakeLists.txt rename {worker/api/cpp/src => common/cpp/src/http_client}/curl_http_client.cpp (94%) create mode 100644 receiver/unittests/test_statistics_sender_influx_db.cpp create mode 100644 tests/automatic/curl_http_client/CMakeLists.txt rename tests/automatic/{worker => curl_http_client}/curl_http_client_get/CMakeLists.txt (100%) rename tests/automatic/{worker => curl_http_client}/curl_http_client_get/curl_httpclient_get.cpp (100%) delete mode 100644 worker/api/cpp/src/http_client.cpp delete mode 100644 worker/api/cpp/src/http_error.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d4e6c35a3..e50c24502 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,11 @@ set (HIDRA2_CXX_COMMON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/common/cpp/includ find_package (Threads) +set (CMAKE_PREFIX_PATH "${LIBCURL_DIR}") +find_package (CURL REQUIRED) +message (STATUS "Found cURL libraries: ${CURL_LIBRARIES}") +message (STATUS "cURL include: ${CURL_INCLUDE_DIRS}") + # format sources include(astyle) diff --git a/common/cpp/CMakeLists.txt b/common/cpp/CMakeLists.txt index 2e79b345e..981bb1f44 100644 --- a/common/cpp/CMakeLists.txt +++ b/common/cpp/CMakeLists.txt @@ -6,6 +6,8 @@ add_subdirectory(src/json_parser) add_subdirectory(src/data_structs) +add_subdirectory(src/http_client) + if(BUILD_MONGODB_CLIENTLIB) add_subdirectory(src/database) endif() diff --git a/worker/api/cpp/src/curl_http_client.h b/common/cpp/include/http_client/curl_http_client.h similarity index 100% rename from worker/api/cpp/src/curl_http_client.h rename to common/cpp/include/http_client/curl_http_client.h diff --git a/worker/api/cpp/src/http_client.h b/common/cpp/include/http_client/http_client.h similarity index 96% rename from worker/api/cpp/src/http_client.h rename to common/cpp/include/http_client/http_client.h index 31b838a62..ff4c1395b 100644 --- a/worker/api/cpp/src/http_client.h +++ b/common/cpp/include/http_client/http_client.h @@ -1,7 +1,7 @@ #ifndef HIDRA2_HTTP_CLIENT_H #define HIDRA2_HTTP_CLIENT_H -#include <hidra2_worker.h> +#include "common/error.h" namespace hidra2 { @@ -14,8 +14,6 @@ class HttpClient { }; -Error HttpCodeToWorkerError(const HttpCode& code); - enum class HttpCode : int { Continue = 100, SwitchingProtocols = 101, diff --git a/worker/api/cpp/src/http_error.h b/common/cpp/include/http_client/http_error.h similarity index 100% rename from worker/api/cpp/src/http_error.h rename to common/cpp/include/http_client/http_error.h diff --git a/common/cpp/src/http_client/CMakeLists.txt b/common/cpp/src/http_client/CMakeLists.txt new file mode 100644 index 000000000..b274c9319 --- /dev/null +++ b/common/cpp/src/http_client/CMakeLists.txt @@ -0,0 +1,16 @@ +set(TARGET_NAME curl_http_client) +set(SOURCE_FILES + curl_http_client.cpp + ) + + +################################ +# Library +################################ +add_library(${TARGET_NAME} OBJECT ${SOURCE_FILES}) +IF(WIN32) + target_compile_definitions(${TARGET_NAME} PUBLIC -DCURL_STATICLIB) +ENDIF() +target_include_directories(${TARGET_NAME} PUBLIC ${HIDRA2_CXX_COMMON_INCLUDE_DIR} ${CURL_INCLUDE_DIRS}) + + diff --git a/worker/api/cpp/src/curl_http_client.cpp b/common/cpp/src/http_client/curl_http_client.cpp similarity index 94% rename from worker/api/cpp/src/curl_http_client.cpp rename to common/cpp/src/http_client/curl_http_client.cpp index 364b87cd1..fc9904e49 100644 --- a/worker/api/cpp/src/curl_http_client.cpp +++ b/common/cpp/src/http_client/curl_http_client.cpp @@ -1,4 +1,4 @@ -#include "curl_http_client.h" +#include "http_client/curl_http_client.h" #include <cstring> @@ -56,7 +56,7 @@ Error ProcessCurlResponse(CURL* curl, CURLcode res, const char* errbuf, return nullptr; } else { *buffer = GetCurlError(curl, res, errbuf); - return TextError(std::string(WorkerErrorMessage::kErrorReadingSource) + ": " + *buffer); + return TextError("Curl client error: " + *buffer); } } diff --git a/receiver/CMakeLists.txt b/receiver/CMakeLists.txt index 66e3f2877..371b917b0 100644 --- a/receiver/CMakeLists.txt +++ b/receiver/CMakeLists.txt @@ -13,19 +13,18 @@ set(SOURCE_FILES ################################ # Library ################################ -add_library(${TARGET_NAME} STATIC ${SOURCE_FILES} $<TARGET_OBJECTS:system_io>) + + +add_library(${TARGET_NAME} STATIC ${SOURCE_FILES} $<TARGET_OBJECTS:system_io> $<TARGET_OBJECTS:curl_http_client>) set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX) -target_include_directories(${TARGET_NAME} PUBLIC ${HIDRA2_CXX_COMMON_INCLUDE_DIR}) +target_include_directories(${TARGET_NAME} PUBLIC ${HIDRA2_CXX_COMMON_INCLUDE_DIR} ${CURL_INCLUDE_DIRS}) +target_link_libraries(${TARGET_NAME} ${CURL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) + add_executable(${TARGET_NAME}-bin src/main.cpp) set_target_properties(${TARGET_NAME}-bin PROPERTIES OUTPUT_NAME ${TARGET_NAME}) target_link_libraries(${TARGET_NAME}-bin ${TARGET_NAME}) -#Add all necessary common libraries -GET_PROPERTY(HIDRA2_COMMON_IO_LIBRARIES GLOBAL PROPERTY HIDRA2_COMMON_IO_LIBRARIES) -target_link_libraries(${TARGET_NAME}-bin ${HIDRA2_COMMON_IO_LIBRARIES}) -set_target_properties(${TARGET_NAME}-bin PROPERTIES LINKER_LANGUAGE CXX) - ################################ # Testing ################################ @@ -38,6 +37,7 @@ set(TEST_SOURCE_FILES unittests/test_statistics.cpp unittests/test_request.cpp unittests/test_request_handler_file_write.cpp + unittests/test_statistics_sender_influx_db.cpp ) # set(TEST_LIBRARIES "${TARGET_NAME};system_io") diff --git a/receiver/src/statistics.cpp b/receiver/src/statistics.cpp index 5d1443963..ddb8c6b4e 100644 --- a/receiver/src/statistics.cpp +++ b/receiver/src/statistics.cpp @@ -18,15 +18,15 @@ StatisticsToSend Statistics::PrepareStatisticsToSend() const noexcept { stat.n_requests = nrequests_; stat.data_volume = volume_counter_; stat.elapsed_ms = GetTotalElapsedMs(); - for (auto i=0;i<kNStatisticEntities;i++){ - stat.entity_shares[i] = double(GetElapsedMs(StatisticEntity(i)))/stat.elapsed_ms; + for (auto i = 0; i < kNStatisticEntities; i++) { + stat.entity_shares[i] = double(GetElapsedMs(StatisticEntity(i))) / stat.elapsed_ms; } return stat; } uint64_t Statistics::GetTotalElapsedMs() const noexcept { return std::chrono::duration_cast<std::chrono::milliseconds> - ( high_resolution_clock::now() - last_timepoint_).count(); + ( high_resolution_clock::now() - last_timepoint_).count(); } uint64_t Statistics::GetElapsedMs(StatisticEntity entity) const noexcept { @@ -50,7 +50,8 @@ void Statistics::IncreaseRequestCounter() noexcept { nrequests_++; } -Statistics::Statistics(unsigned int write_frequency) : statistics_sender__{new StatisticsSenderInfluxDb},write_interval_{write_frequency}{ +Statistics::Statistics(unsigned int write_frequency) : statistics_sender__{new StatisticsSenderInfluxDb}, +write_interval_{write_frequency} { ResetStatistics(); } diff --git a/receiver/src/statistics.h b/receiver/src/statistics.h index 78efec123..cd3cb2986 100644 --- a/receiver/src/statistics.h +++ b/receiver/src/statistics.h @@ -16,10 +16,10 @@ enum StatisticEntity : int { }; struct StatisticsToSend { - double entity_shares[kNStatisticEntities]; - uint64_t elapsed_ms; - uint64_t data_volume; - uint64_t n_requests; + double entity_shares[kNStatisticEntities]; + uint64_t elapsed_ms; + uint64_t data_volume; + uint64_t n_requests; }; class Statistics { diff --git a/receiver/src/statistics_sender.h b/receiver/src/statistics_sender.h index a079f4f5b..2cf12b272 100644 --- a/receiver/src/statistics_sender.h +++ b/receiver/src/statistics_sender.h @@ -8,7 +8,7 @@ namespace hidra2 { struct StatisticsToSend; class StatisticsSender { - public: + public: virtual void SendStatistics(const StatisticsToSend& statistic) const noexcept = 0; virtual ~StatisticsSender() = default; }; diff --git a/receiver/src/statistics_sender_influx_db.cpp b/receiver/src/statistics_sender_influx_db.cpp index bcdafda4f..0ac7e8b41 100644 --- a/receiver/src/statistics_sender_influx_db.cpp +++ b/receiver/src/statistics_sender_influx_db.cpp @@ -1,5 +1,6 @@ #include "statistics_sender_influx_db.h" #include "statistics.h" +#include "http_client/curl_http_client.h" namespace hidra2 { @@ -7,5 +8,9 @@ void StatisticsSenderInfluxDb::SendStatistics(const StatisticsToSend& statistic) } +StatisticsSenderInfluxDb::StatisticsSenderInfluxDb(): httpclient__{new CurlHttpClient} { + +}; + } diff --git a/receiver/src/statistics_sender_influx_db.h b/receiver/src/statistics_sender_influx_db.h index 908bfeafc..e59954f46 100644 --- a/receiver/src/statistics_sender_influx_db.h +++ b/receiver/src/statistics_sender_influx_db.h @@ -1,12 +1,17 @@ #ifndef HIDRA2_STATISTICS_SENDER_INFLUX_DB_H #define HIDRA2_STATISTICS_SENDER_INFLUX_DB_H +#include "http_client/http_client.h" #include "statistics_sender.h" + namespace hidra2 { -class StatisticsSenderInfluxDb : public StatisticsSender{ - virtual void SendStatistics(const StatisticsToSend& statistic) const noexcept override; +class StatisticsSenderInfluxDb : public StatisticsSender { + public: + StatisticsSenderInfluxDb(); + virtual void SendStatistics(const StatisticsToSend& statistic) const noexcept override; + std::unique_ptr<HttpClient> httpclient__; }; } diff --git a/receiver/unittests/mock_statistics.h b/receiver/unittests/mock_statistics.h index 1d7077fad..6c34db0e5 100644 --- a/receiver/unittests/mock_statistics.h +++ b/receiver/unittests/mock_statistics.h @@ -9,30 +9,30 @@ namespace hidra2 { class MockStatistics : public hidra2::Statistics { - public: - void SendIfNeeded() noexcept override { - SendIfNeeded_t(); - } - void IncreaseRequestCounter() noexcept override { - IncreaseRequestCounter_t(); - } - void StartTimer(const hidra2::StatisticEntity &entity) noexcept override { - StartTimer_t(entity); - } - void IncreaseRequestDataVolume(uint64_t transferred_data_volume) noexcept override { - IncreaseRequestDataVolume_t(transferred_data_volume); - } - void StopTimer() noexcept override { - StopTimer_t(); - } - - MOCK_METHOD0(SendIfNeeded_t, void()); - MOCK_METHOD0(IncreaseRequestCounter_t, void()); - MOCK_METHOD0(StopTimer_t, void()); - MOCK_METHOD1(IncreaseRequestDataVolume_t, void (uint64_t - transferred_data_volume)); - MOCK_METHOD1(StartTimer_t, void( - const hidra2::StatisticEntity &entity)); + public: + void SendIfNeeded() noexcept override { + SendIfNeeded_t(); + } + void IncreaseRequestCounter() noexcept override { + IncreaseRequestCounter_t(); + } + void StartTimer(const hidra2::StatisticEntity& entity) noexcept override { + StartTimer_t(entity); + } + void IncreaseRequestDataVolume(uint64_t transferred_data_volume) noexcept override { + IncreaseRequestDataVolume_t(transferred_data_volume); + } + void StopTimer() noexcept override { + StopTimer_t(); + } + + MOCK_METHOD0(SendIfNeeded_t, void()); + MOCK_METHOD0(IncreaseRequestCounter_t, void()); + MOCK_METHOD0(StopTimer_t, void()); + MOCK_METHOD1(IncreaseRequestDataVolume_t, void (uint64_t + transferred_data_volume)); + MOCK_METHOD1(StartTimer_t, void( + const hidra2::StatisticEntity& entity)); }; diff --git a/receiver/unittests/test_request.cpp b/receiver/unittests/test_request.cpp index 278e149a5..085e24602 100644 --- a/receiver/unittests/test_request.cpp +++ b/receiver/unittests/test_request.cpp @@ -45,7 +45,7 @@ class MockReqestHandler : public hidra2::RequestHandler { } StatisticEntity GetStatisticEntity() const { - return StatisticEntity::kDisk; + return StatisticEntity::kDisk; } MOCK_CONST_METHOD1(ProcessRequest_t, ErrorInterface * (const Request& request)); @@ -135,7 +135,7 @@ TEST_F(RequestTests, HandleProcessesRequests) { MockReqestHandler mock_request_handler; MockStatistics mock_statistics; - auto stat = std::unique_ptr<hidra2::Statistics>{&mock_statistics}; + auto stat = std::unique_ptr<hidra2::Statistics> {&mock_statistics}; EXPECT_CALL(mock_request_handler, ProcessRequest_t(_)).WillOnce( Return(nullptr) diff --git a/receiver/unittests/test_statistics.cpp b/receiver/unittests/test_statistics.cpp index c85f2eaf4..530289696 100644 --- a/receiver/unittests/test_statistics.cpp +++ b/receiver/unittests/test_statistics.cpp @@ -32,25 +32,25 @@ TEST(StatisticTestsConstructor, Constructor) { class MockStatisticsSender: public StatisticsSender { - public: - void SendStatistics(const StatisticsToSend& statistics) const noexcept override { - SendStatistics_t(statistics); - } - MOCK_CONST_METHOD1(SendStatistics_t, void (const StatisticsToSend&)); + public: + void SendStatistics(const StatisticsToSend& statistics) const noexcept override { + SendStatistics_t(statistics); + } + MOCK_CONST_METHOD1(SendStatistics_t, void (const StatisticsToSend&)); }; class StatisticTests : public Test { - public: - Statistics statistics{0}; - void TestTimer(const StatisticEntity& entity); - MockStatisticsSender mock_statistics_sender; - void SetUp() override { - statistics.statistics_sender__.reset(&mock_statistics_sender); - } - void TearDown() override { - statistics.statistics_sender__.release(); - } - StatisticsToSend ExtractStat(); + public: + Statistics statistics{0}; + void TestTimer(const StatisticEntity& entity); + MockStatisticsSender mock_statistics_sender; + void SetUp() override { + statistics.statistics_sender__.reset(&mock_statistics_sender); + } + void TearDown() override { + statistics.statistics_sender__.release(); + } + StatisticsToSend ExtractStat(); }; @@ -59,7 +59,7 @@ ACTION_P(SaveArg1ToSendStat, value) { value->n_requests = resp.n_requests; value->data_volume = resp.data_volume; value->elapsed_ms = resp.elapsed_ms; - for (int i=0;i<hidra2::kNStatisticEntities;i++){ + for (int i = 0; i < hidra2::kNStatisticEntities; i++) { value->entity_shares[i] = resp.entity_shares[i]; } @@ -72,12 +72,12 @@ StatisticsToSend StatisticTests::ExtractStat() { stat.elapsed_ms = 0; stat.n_requests = 0; stat.data_volume = 0; - for (int i=0;i<hidra2::kNStatisticEntities;i++){ + for (int i = 0; i < hidra2::kNStatisticEntities; i++) { stat.entity_shares[i] = 0.0; } - EXPECT_CALL(mock_statistics_sender,SendStatistics_t(_)). - WillOnce(SaveArg1ToSendStat(&stat)); + EXPECT_CALL(mock_statistics_sender, SendStatistics_t(_)). + WillOnce(SaveArg1ToSendStat(&stat)); statistics.SendIfNeeded(); return stat; @@ -130,7 +130,7 @@ TEST_F(StatisticTests, DataVolumeZeroAtInit) { ASSERT_THAT(stat.data_volume, Eq(0)); } -void StatisticTests::TestTimer(const StatisticEntity& entity){ +void StatisticTests::TestTimer(const StatisticEntity& entity) { statistics.StartTimer(entity); std::this_thread::sleep_for(std::chrono::milliseconds(10)); @@ -158,7 +158,7 @@ TEST_F(StatisticTests, TimerForDisk) { TEST_F(StatisticTests, SendStaticsDoesCallsSender) { statistics.SetWriteInterval(1000); - EXPECT_CALL(mock_statistics_sender,SendStatistics_t(_)).Times(0); + EXPECT_CALL(mock_statistics_sender, SendStatistics_t(_)).Times(0); statistics.SendIfNeeded(); } diff --git a/receiver/unittests/test_statistics_sender_influx_db.cpp b/receiver/unittests/test_statistics_sender_influx_db.cpp new file mode 100644 index 000000000..6690e981e --- /dev/null +++ b/receiver/unittests/test_statistics_sender_influx_db.cpp @@ -0,0 +1,36 @@ +#include <gtest/gtest.h> +#include <gmock/gmock.h> +#include <unittests/MockIO.h> + +#include "../src/statistics_sender_influx_db.h" +#include "../src/statistics_sender.h" +#include "http_client/curl_http_client.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 hidra2::StatisticsSenderInfluxDb; + + +namespace { + +TEST(SenderInfluxDb, Constructor) { + StatisticsSenderInfluxDb sender; + ASSERT_THAT(dynamic_cast<hidra2::CurlHttpClient*>(sender.httpclient__.get()), Ne(nullptr)); +} + + + +} diff --git a/tests/automatic/CMakeLists.txt b/tests/automatic/CMakeLists.txt index 1c613b855..b0a661944 100644 --- a/tests/automatic/CMakeLists.txt +++ b/tests/automatic/CMakeLists.txt @@ -18,5 +18,6 @@ endif() add_subdirectory(worker) +add_subdirectory(curl_http_client) add_subdirectory(producer_receiver) \ No newline at end of file diff --git a/tests/automatic/curl_http_client/CMakeLists.txt b/tests/automatic/curl_http_client/CMakeLists.txt new file mode 100644 index 000000000..c375a144d --- /dev/null +++ b/tests/automatic/curl_http_client/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(curl_http_client_get) diff --git a/tests/automatic/worker/curl_http_client_get/CMakeLists.txt b/tests/automatic/curl_http_client/curl_http_client_get/CMakeLists.txt similarity index 100% rename from tests/automatic/worker/curl_http_client_get/CMakeLists.txt rename to tests/automatic/curl_http_client/curl_http_client_get/CMakeLists.txt diff --git a/tests/automatic/worker/curl_http_client_get/curl_httpclient_get.cpp b/tests/automatic/curl_http_client/curl_http_client_get/curl_httpclient_get.cpp similarity index 100% rename from tests/automatic/worker/curl_http_client_get/curl_httpclient_get.cpp rename to tests/automatic/curl_http_client/curl_http_client_get/curl_httpclient_get.cpp diff --git a/tests/automatic/worker/CMakeLists.txt b/tests/automatic/worker/CMakeLists.txt index e5145961a..f8a2dd315 100644 --- a/tests/automatic/worker/CMakeLists.txt +++ b/tests/automatic/worker/CMakeLists.txt @@ -4,8 +4,6 @@ add_subdirectory(next_multithread_folder) add_subdirectory(next_multithread_broker) add_subdirectory(connect_multithread) -add_subdirectory(curl_http_client_get) - if(BUILD_WORKER_TOOLS) add_subdirectory(folder_to_db) endif() diff --git a/tests/automatic/worker/connect_multithread/CMakeLists.txt b/tests/automatic/worker/connect_multithread/CMakeLists.txt index abe83367d..64224018b 100644 --- a/tests/automatic/worker/connect_multithread/CMakeLists.txt +++ b/tests/automatic/worker/connect_multithread/CMakeLists.txt @@ -7,7 +7,6 @@ set(SOURCE_FILES content_multithread.cpp) ################################ add_executable(${TARGET_NAME} ${SOURCE_FILES}) target_link_libraries(${TARGET_NAME} test_common hidra2-worker ${HIDRA2_COMMON_IO_LIBRARIES}) -set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX) if (CMAKE_COMPILER_IS_GNUCXX) set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS_DEBUG "--coverage") endif() diff --git a/tests/automatic/worker/next_multithread_broker/CMakeLists.txt b/tests/automatic/worker/next_multithread_broker/CMakeLists.txt index 15b5b8ebb..9c22693a5 100644 --- a/tests/automatic/worker/next_multithread_broker/CMakeLists.txt +++ b/tests/automatic/worker/next_multithread_broker/CMakeLists.txt @@ -6,7 +6,7 @@ set(SOURCE_FILES next_multithread_broker.cpp) # Executable and link ################################ add_executable(${TARGET_NAME} ${SOURCE_FILES}) -target_link_libraries(${TARGET_NAME} test_common hidra2-worker ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(${TARGET_NAME} test_common hidra2-worker) ################################ # Testing diff --git a/tests/automatic/worker/next_multithread_folder/CMakeLists.txt b/tests/automatic/worker/next_multithread_folder/CMakeLists.txt index eed3cc9b9..b0920c971 100644 --- a/tests/automatic/worker/next_multithread_folder/CMakeLists.txt +++ b/tests/automatic/worker/next_multithread_folder/CMakeLists.txt @@ -12,7 +12,6 @@ GET_PROPERTY(HIDRA2_COMMON_IO_LIBRARIES GLOBAL PROPERTY HIDRA2_COMMON_IO_LIBRARI target_link_libraries(${TARGET_NAME} ${HIDRA2_COMMON_IO_LIBRARIES}) target_link_libraries(${TARGET_NAME} test_common hidra2-worker) -set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX) if (CMAKE_COMPILER_IS_GNUCXX) set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS_DEBUG "--coverage") endif() diff --git a/worker/api/cpp/CMakeLists.txt b/worker/api/cpp/CMakeLists.txt index 914d87840..f60a32686 100644 --- a/worker/api/cpp/CMakeLists.txt +++ b/worker/api/cpp/CMakeLists.txt @@ -2,33 +2,23 @@ set(TARGET_NAME hidra2-worker) set(SOURCE_FILES src/data_broker.cpp - src/http_client.cpp src/folder_data_broker.cpp src/server_data_broker.cpp - src/curl_http_client.cpp - src/http_error.cpp) +) ################################ # Library ################################ add_library(${TARGET_NAME} STATIC ${SOURCE_FILES} $<TARGET_OBJECTS:system_io> - $<TARGET_OBJECTS:json_parser> $<TARGET_OBJECTS:data_structs> ) - -set (CMAKE_PREFIX_PATH "${LIBCURL_DIR}") -find_package (CURL REQUIRED) -message (STATUS "Found cURL libraries: ${CURL_LIBRARIES}") -message (STATUS "cURL include: ${CURL_INCLUDE_DIRS}") - + $<TARGET_OBJECTS:json_parser> $<TARGET_OBJECTS:data_structs> $<TARGET_OBJECTS:curl_http_client> ) target_include_directories(${TARGET_NAME} PUBLIC include ${HIDRA2_CXX_COMMON_INCLUDE_DIR} ${CURL_INCLUDE_DIRS}) -IF(WIN32) - target_compile_definitions(${TARGET_NAME} PUBLIC -DCURL_STATICLIB) -ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "GNU") +IF(CMAKE_C_COMPILER_ID STREQUAL "GNU") SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++") -ENDIF(WIN32) +ENDIF() target_link_libraries(${TARGET_NAME} ${CURL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) diff --git a/worker/api/cpp/src/http_client.cpp b/worker/api/cpp/src/http_client.cpp deleted file mode 100644 index d5c86c6c0..000000000 --- a/worker/api/cpp/src/http_client.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "http_client.h" -#include "http_error.h" -namespace hidra2 { - -Error HttpCodeToWorkerError(const HttpCode& code) { - const char* message; - switch (code) { - case HttpCode::OK: - return nullptr; - case HttpCode::BadRequest: - message = WorkerErrorMessage::kWrongInput; - break; - case HttpCode::InternalServerError: - message = WorkerErrorMessage::kErrorReadingSource; - break; - case HttpCode::NoContent: - message = WorkerErrorMessage::kNoData; - return TextErrorWithType(message, ErrorType::kEndOfFile); - case HttpCode::NotFound: - message = WorkerErrorMessage::kSourceNotFound; - break; - default: - message = WorkerErrorMessage::kErrorReadingSource; - break; - } - return Error{new HttpError(message, code)}; -} - -} diff --git a/worker/api/cpp/src/http_error.cpp b/worker/api/cpp/src/http_error.cpp deleted file mode 100644 index 72189fc37..000000000 --- a/worker/api/cpp/src/http_error.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "http_error.h" - -namespace hidra2 { - - - -} \ No newline at end of file diff --git a/worker/api/cpp/src/server_data_broker.cpp b/worker/api/cpp/src/server_data_broker.cpp index 0298c82db..0b739e6e7 100644 --- a/worker/api/cpp/src/server_data_broker.cpp +++ b/worker/api/cpp/src/server_data_broker.cpp @@ -1,9 +1,37 @@ #include "server_data_broker.h" #include "io/io_factory.h" -#include "curl_http_client.h" +#include "http_client/curl_http_client.h" +#include "http_client/http_error.h" + namespace hidra2 { +Error HttpCodeToWorkerError(const HttpCode& code) { + const char* message; + switch (code) { + case HttpCode::OK: + return nullptr; + case HttpCode::BadRequest: + message = WorkerErrorMessage::kWrongInput; + break; + case HttpCode::InternalServerError: + message = WorkerErrorMessage::kErrorReadingSource; + break; + case HttpCode::NoContent: + message = WorkerErrorMessage::kNoData; + return TextErrorWithType(message, ErrorType::kEndOfFile); + case HttpCode::NotFound: + message = WorkerErrorMessage::kSourceNotFound; + break; + default: + message = WorkerErrorMessage::kErrorReadingSource; + break; + } + return Error{new HttpError(message, code)}; +} + + + ServerDataBroker::ServerDataBroker(const std::string& server_uri, const std::string& source_name): io__{GenerateDefaultIO()}, httpclient__{new CurlHttpClient}, diff --git a/worker/api/cpp/src/server_data_broker.h b/worker/api/cpp/src/server_data_broker.h index 2081261b8..5be1b4236 100644 --- a/worker/api/cpp/src/server_data_broker.h +++ b/worker/api/cpp/src/server_data_broker.h @@ -3,18 +3,20 @@ #include "worker/data_broker.h" #include "io/io.h" -#include "http_client.h" +#include "http_client/http_client.h" namespace hidra2 { +Error HttpCodeToWorkerError(const HttpCode& code); + class ServerDataBroker final : public hidra2::DataBroker { public: explicit ServerDataBroker(const std::string& server_uri, const std::string& source_name); Error Connect() override; Error GetNext(FileInfo* info, FileData* data) override; - std::unique_ptr<hidra2::IO> io__; // modified in testings to mock system calls,otherwise do not touch - std::unique_ptr<hidra2::HttpClient> httpclient__; + std::unique_ptr<IO> io__; // modified in testings to mock system calls,otherwise do not touch + std::unique_ptr<HttpClient> httpclient__; private: Error GetFileInfoFromServer(FileInfo* info, const std::string& operation); std::string server_uri_; diff --git a/worker/api/cpp/unittests/MockHttpClient.h b/worker/api/cpp/unittests/MockHttpClient.h index a386321db..ba4454162 100644 --- a/worker/api/cpp/unittests/MockHttpClient.h +++ b/worker/api/cpp/unittests/MockHttpClient.h @@ -4,7 +4,7 @@ #include <gtest/gtest.h> #include <gmock/gmock.h> -#include "../src/http_client.h" +#include "http_client/http_client.h" #include "worker/data_broker.h" diff --git a/worker/api/cpp/unittests/test_server_broker.cpp b/worker/api/cpp/unittests/test_server_broker.cpp index 48296c46f..d20858b5e 100644 --- a/worker/api/cpp/unittests/test_server_broker.cpp +++ b/worker/api/cpp/unittests/test_server_broker.cpp @@ -5,10 +5,10 @@ #include "io/io.h" #include "../../../../common/cpp/src/system_io/system_io.h" #include "../src/server_data_broker.h" -#include "../src/curl_http_client.h" +#include "http_client/curl_http_client.h" #include "unittests/MockIO.h" #include "MockHttpClient.h" -#include "../src/http_error.h" +#include "http_client/http_error.h" using hidra2::DataBrokerFactory; using hidra2::DataBroker; -- GitLab