From d1c11a67a5b986a545e35513b1984865d6dd8108 Mon Sep 17 00:00:00 2001 From: Sergey Yakubov <sergey.yakubov@desy.de> Date: Tue, 10 Apr 2018 17:24:12 +0200 Subject: [PATCH] send statistics to influxdb --- .../include/http_client/curl_http_client.h | 4 ++ common/cpp/include/http_client/http_client.h | 2 + common/cpp/include/unittests/MockHttpClient.h | 35 +++++++++++++++++ .../cpp/src/http_client/curl_http_client.cpp | 24 ++++++++++-- common/cpp/src/system_io/system_io.cpp | 2 +- common/cpp/src/system_io/system_io_linux.cpp | 1 - receiver/src/request.cpp | 2 + receiver/src/statistics.cpp | 2 +- receiver/src/statistics_sender_influx_db.cpp | 38 ++++++++++++++++++- receiver/src/statistics_sender_influx_db.h | 3 ++ receiver/unittests/test_request.cpp | 34 +++++++++++++---- receiver/unittests/test_statistics.cpp | 27 ++++++++++++- .../test_statistics_sender_influx_db.cpp | 36 ++++++++++++++++++ .../automatic/curl_http_client/CMakeLists.txt | 2 +- .../curl_http_client_command/CMakeLists.txt | 27 +++++++++++++ .../curl_httpclient_command.cpp} | 19 +++++++--- .../curl_http_client_get/CMakeLists.txt | 25 ------------ worker/api/cpp/unittests/MockHttpClient.h | 25 ------------ .../api/cpp/unittests/test_server_broker.cpp | 2 +- 19 files changed, 237 insertions(+), 73 deletions(-) create mode 100644 common/cpp/include/unittests/MockHttpClient.h create mode 100644 tests/automatic/curl_http_client/curl_http_client_command/CMakeLists.txt rename tests/automatic/curl_http_client/{curl_http_client_get/curl_httpclient_get.cpp => curl_http_client_command/curl_httpclient_command.cpp} (66%) delete mode 100644 tests/automatic/curl_http_client/curl_http_client_get/CMakeLists.txt delete mode 100644 worker/api/cpp/unittests/MockHttpClient.h diff --git a/common/cpp/include/http_client/curl_http_client.h b/common/cpp/include/http_client/curl_http_client.h index 135a6cd5c..9b65491aa 100644 --- a/common/cpp/include/http_client/curl_http_client.h +++ b/common/cpp/include/http_client/curl_http_client.h @@ -13,8 +13,12 @@ class CurlHttpClient final : public HttpClient { public: CurlHttpClient(); std::string Get(const std::string& uri, HttpCode* response_code, Error* err) const noexcept override; + std::string Post(const std::string& uri, const std::string& data, HttpCode* response_code, + Error* err) const noexcept override; virtual ~CurlHttpClient(); private: + std::string Command(bool post, const std::string& uri, const std::string& data, HttpCode* response_code, + Error* err) const noexcept; mutable std::mutex mutex_; CURL* curl_ = 0; }; diff --git a/common/cpp/include/http_client/http_client.h b/common/cpp/include/http_client/http_client.h index ff4c1395b..92a929961 100644 --- a/common/cpp/include/http_client/http_client.h +++ b/common/cpp/include/http_client/http_client.h @@ -10,6 +10,8 @@ enum class HttpCode; class HttpClient { public: virtual std::string Get(const std::string& uri, HttpCode* response_code, Error* err) const noexcept = 0; + virtual std::string Post(const std::string& uri, const std::string& data, HttpCode* response_code, + Error* err) const noexcept = 0; virtual ~HttpClient() = default; }; diff --git a/common/cpp/include/unittests/MockHttpClient.h b/common/cpp/include/unittests/MockHttpClient.h new file mode 100644 index 000000000..a497c396e --- /dev/null +++ b/common/cpp/include/unittests/MockHttpClient.h @@ -0,0 +1,35 @@ +#ifndef HIDRA2_MOCKHTTPCLIENT_H +#define HIDRA2_MOCKHTTPCLIENT_H + +#include <gtest/gtest.h> +#include <gmock/gmock.h> + +#include "http_client/http_client.h" + +namespace hidra2 { + +class MockHttpClient : public HttpClient { + public: + std::string Get(const std::string& uri, HttpCode* code, Error* err) const noexcept override { + ErrorInterface* error = nullptr; + auto responce = Get_t(uri, code, &error); + err->reset(error); + return responce; + } + std::string Post(const std::string& uri, const std::string& data, HttpCode* code, Error* err) const noexcept override { + ErrorInterface* error = nullptr; + auto responce = Post_t(uri, data, code, &error); + err->reset(error); + return responce; + } + MOCK_CONST_METHOD3(Get_t, + std::string(const std::string& uri, HttpCode* code, ErrorInterface** err)); + MOCK_CONST_METHOD4(Post_t, + std::string(const std::string& uri, const std::string& data, HttpCode* code, ErrorInterface** err)); + +}; + + +} + +#endif //HIDRA2_MOCKHTTPCLIENT_H diff --git a/common/cpp/src/http_client/curl_http_client.cpp b/common/cpp/src/http_client/curl_http_client.cpp index fc9904e49..c9f91a215 100644 --- a/common/cpp/src/http_client/curl_http_client.cpp +++ b/common/cpp/src/http_client/curl_http_client.cpp @@ -25,13 +25,17 @@ size_t curl_write( void* ptr, size_t size, size_t nmemb, void* buffer) { return size * nmemb; } -void SetCurlOptions(CURL* curl, const std::string& uri, char* errbuf, std::string* buffer) { +void SetCurlOptions(CURL* curl, bool post, const std::string& data, const std::string& uri, char* errbuf, + std::string* buffer) { errbuf[0] = 0; curl_easy_setopt(curl, CURLOPT_URL, uri.c_str()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write); curl_easy_setopt(curl, CURLOPT_WRITEDATA, buffer); curl_easy_setopt(curl, CURLOPT_FAILONERROR, 0L); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); + if (post) { + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str()); + } } @@ -60,20 +64,34 @@ Error ProcessCurlResponse(CURL* curl, CURLcode res, const char* errbuf, } } -std::string CurlHttpClient::Get(const std::string& uri, HttpCode* response_code, Error* err) const noexcept { +std::string CurlHttpClient::Command(bool post, const std::string& uri, const std::string& data, HttpCode* response_code, + Error* err) const noexcept { std::lock_guard<std::mutex> lock{mutex_}; std::string buffer; char errbuf[CURL_ERROR_SIZE]; - SetCurlOptions(curl_, uri, errbuf, &buffer); + + SetCurlOptions(curl_, post, data, uri, errbuf, &buffer); auto res = curl_easy_perform(curl_); *err = ProcessCurlResponse(curl_, res, errbuf, &buffer, response_code); return buffer; + } + +std::string CurlHttpClient::Get(const std::string& uri, HttpCode* response_code, Error* err) const noexcept { + return Command(false, uri, "", response_code, err); +} + +std::string CurlHttpClient::Post(const std::string& uri, const std::string& data, HttpCode* response_code, + Error* err) const noexcept { + return Command(true, uri, data, response_code, err); +} + + CurlHttpClient::CurlHttpClient() { curl_ = curl_easy_init(); if (!curl_) { diff --git a/common/cpp/src/system_io/system_io.cpp b/common/cpp/src/system_io/system_io.cpp index 70c4a93dd..1315a8eb6 100644 --- a/common/cpp/src/system_io/system_io.cpp +++ b/common/cpp/src/system_io/system_io.cpp @@ -23,7 +23,7 @@ namespace hidra2 { -const int SystemIO::kNetBufferSize = 1024 * 1024 ; //MiByte +const int SystemIO::kNetBufferSize = 1024 * 1024; //* 1024 ; //MiByte /******************************************************************************* * system_io.cpp * diff --git a/common/cpp/src/system_io/system_io_linux.cpp b/common/cpp/src/system_io/system_io_linux.cpp index e0faf78b7..c84e2f1e9 100644 --- a/common/cpp/src/system_io/system_io_linux.cpp +++ b/common/cpp/src/system_io/system_io_linux.cpp @@ -176,7 +176,6 @@ void SystemIO::CollectFileInformationRecursively(const std::string& path, void SystemIO::ApplyNetworkOptions(SocketDescriptor socket_fd, Error* err) const { //TODO: Need to change network layer code, so everything can be NonBlocking - // in use and one have to wait for some time until the system cleans up the stuff int flag; if ( /*(flags = fcntl(socket_fd, F_GETFL, 0)) == -1 diff --git a/receiver/src/request.cpp b/receiver/src/request.cpp index c1d4f0a97..c247ba887 100644 --- a/receiver/src/request.cpp +++ b/receiver/src/request.cpp @@ -31,10 +31,12 @@ Error Request::ReceiveData() { Error Request::Handle(std::unique_ptr<Statistics>* statistics) { Error err; if (request_header_.data_size != 0) { + (*statistics)->StartTimer(StatisticEntity::kNetwork); auto err = ReceiveData(); if (err) { return err; } + (*statistics)->StopTimer(); } for (auto handler : handlers_) { (*statistics)->StartTimer(handler->GetStatisticEntity()); diff --git a/receiver/src/statistics.cpp b/receiver/src/statistics.cpp index ddb8c6b4e..49a032cf6 100644 --- a/receiver/src/statistics.cpp +++ b/receiver/src/statistics.cpp @@ -30,7 +30,7 @@ uint64_t Statistics::GetTotalElapsedMs() const noexcept { } uint64_t Statistics::GetElapsedMs(StatisticEntity entity) const noexcept { - return std::chrono::duration_cast<std::chrono::milliseconds>(time_counters_[current_statistic_entity_]).count(); + return std::chrono::duration_cast<std::chrono::milliseconds>(time_counters_[entity]).count(); } void Statistics::SetWriteInterval(uint64_t interval_ms) { diff --git a/receiver/src/statistics_sender_influx_db.cpp b/receiver/src/statistics_sender_influx_db.cpp index 0ac7e8b41..beed7f232 100644 --- a/receiver/src/statistics_sender_influx_db.cpp +++ b/receiver/src/statistics_sender_influx_db.cpp @@ -1,15 +1,51 @@ #include "statistics_sender_influx_db.h" + +#include <iostream> + #include "statistics.h" #include "http_client/curl_http_client.h" namespace hidra2 { +template<typename ... Args> +std::string string_format( const std::string& format, Args ... args ) { + size_t size = snprintf( nullptr, 0, format.c_str(), args ... ) + 1; + std::unique_ptr<char[]> buf( new char[ size ] ); + snprintf( buf.get(), size, format.c_str(), args ... ); + return std::string( buf.get(), buf.get() + size - 1 ); +} + + void StatisticsSenderInfluxDb::SendStatistics(const StatisticsToSend& statistic) const noexcept { + HttpCode code; + Error err; + //TODO influxdb uri from config + auto responce = httpclient__->Post("http://zitpcx27016.desy.de:8086/write?db=db_test", StatisticsToString(statistic), + &code, + &err); + if (err) { + std::cerr << "Error sending statistics: " << err << std::endl; + return; + } + if (code != HttpCode::OK && code != HttpCode::NoContent) { + std::cerr << "Error sending statistics: " << responce << std::endl; + } } -StatisticsSenderInfluxDb::StatisticsSenderInfluxDb(): httpclient__{new CurlHttpClient} { +std::string StatisticsSenderInfluxDb::StatisticsToString(const StatisticsToSend& statistic) const noexcept { + std::string str; + std::string tags = "receiver=1,connection=1"; + str = "statistics," + tags + " elapsed_ms=" + string_format("%ld", statistic.elapsed_ms); + str += ",data_volume=" + string_format("%ld", statistic.data_volume); + str += ",n_requests=" + string_format("%ld", statistic.n_requests); + str += ",db_share=" + string_format("%.4f", statistic.entity_shares[StatisticEntity::kDatabase]); + str += ",network_share=" + string_format("%.4f", statistic.entity_shares[StatisticEntity::kNetwork]); + str += ",disk_share=" + string_format("%.4f", statistic.entity_shares[StatisticEntity::kDisk]); + return str; +} +StatisticsSenderInfluxDb::StatisticsSenderInfluxDb(): httpclient__{new CurlHttpClient} { }; diff --git a/receiver/src/statistics_sender_influx_db.h b/receiver/src/statistics_sender_influx_db.h index e59954f46..aeff17333 100644 --- a/receiver/src/statistics_sender_influx_db.h +++ b/receiver/src/statistics_sender_influx_db.h @@ -12,6 +12,9 @@ class StatisticsSenderInfluxDb : public StatisticsSender { StatisticsSenderInfluxDb(); virtual void SendStatistics(const StatisticsToSend& statistic) const noexcept override; std::unique_ptr<HttpClient> httpclient__; + private: + std::string StatisticsToString(const StatisticsToSend& statistic) const noexcept; + }; } diff --git a/receiver/unittests/test_request.cpp b/receiver/unittests/test_request.cpp index 085e24602..1ac9307bd 100644 --- a/receiver/unittests/test_request.cpp +++ b/receiver/unittests/test_request.cpp @@ -90,7 +90,10 @@ class RequestTests : public Test { uint64_t data_id_{15}; std::unique_ptr<Request> request; NiceMock<MockIO> mock_io; + MockStatistics mock_statistics; + std::unique_ptr<hidra2::Statistics> stat; void SetUp() override { + stat = std::unique_ptr<hidra2::Statistics> {&mock_statistics}; generic_request_header.data_size = data_size_; generic_request_header.data_id = data_id_; request.reset(new Request{generic_request_header, socket_fd_}); @@ -102,6 +105,7 @@ class RequestTests : public Test { } void TearDown() override { request->io__.release(); + stat.release(); } }; @@ -114,7 +118,7 @@ TEST_F(RequestTests, HandleDoesNotReceiveEmptyData) { EXPECT_CALL(mock_io, Receive_t(_, _, _, _)).Times(0); - auto err = request->Handle(nullptr); + auto err = request->Handle(&stat); ASSERT_THAT(err, Eq(nullptr)); } @@ -125,17 +129,34 @@ TEST_F(RequestTests, HandleReturnsErrorOnDataReceive) { Return(0) )); - auto err = request->Handle(nullptr); + auto err = request->Handle(&stat); ASSERT_THAT(err, Eq(hidra2::IOErrorTemplates::kReadError)); } + +TEST_F(RequestTests, HandleMeasuresTimeOnDataReceive) { + + EXPECT_CALL(mock_statistics, StartTimer_t(hidra2::StatisticEntity::kNetwork)); + + EXPECT_CALL(mock_io, Receive_t(socket_fd_, _, data_size_, _)).WillOnce( + DoAll(SetArgPointee<3>(nullptr), + Return(0) + )); + + EXPECT_CALL(mock_statistics, StopTimer_t()); + + request->Handle(&stat); +} + + + + TEST_F(RequestTests, HandleProcessesRequests) { MockReqestHandler mock_request_handler; - MockStatistics mock_statistics; - auto stat = std::unique_ptr<hidra2::Statistics> {&mock_statistics}; + EXPECT_CALL(mock_statistics, StartTimer_t(hidra2::StatisticEntity::kNetwork)); EXPECT_CALL(mock_request_handler, ProcessRequest_t(_)).WillOnce( Return(nullptr) @@ -148,13 +169,12 @@ TEST_F(RequestTests, HandleProcessesRequests) { EXPECT_CALL(mock_statistics, StartTimer_t(hidra2::StatisticEntity::kDisk)).Times(2); - EXPECT_CALL(mock_statistics, StopTimer_t()); + EXPECT_CALL(mock_statistics, StopTimer_t()).Times(2); auto err = request->Handle(&stat); ASSERT_THAT(err, Eq(hidra2::IOErrorTemplates::kUnknownIOError)); - stat.release(); } TEST_F(RequestTests, DataIsNullAtInit) { @@ -165,7 +185,7 @@ TEST_F(RequestTests, DataIsNullAtInit) { TEST_F(RequestTests, GetDataIsNotNullptr) { - request->Handle(nullptr); + request->Handle(&stat); auto& data = request->GetData(); diff --git a/receiver/unittests/test_statistics.cpp b/receiver/unittests/test_statistics.cpp index 530289696..4ba29133e 100644 --- a/receiver/unittests/test_statistics.cpp +++ b/receiver/unittests/test_statistics.cpp @@ -9,6 +9,7 @@ using ::testing::Test; using ::testing::Gt; using ::testing::Ge; +using ::testing::Le; using ::testing::Eq; using ::testing::Ne; using ::testing::Ref; @@ -138,7 +139,7 @@ void StatisticTests::TestTimer(const StatisticEntity& entity) { auto stat = ExtractStat(); - ASSERT_THAT(stat.entity_shares[entity], Ge(0.25)); + ASSERT_THAT(stat.entity_shares[entity], Ge(0.4)); } @@ -154,6 +155,30 @@ TEST_F(StatisticTests, TimerForDisk) { TestTimer(StatisticEntity::kDisk); } +TEST_F(StatisticTests, TimerForAll) { + statistics.StartTimer(StatisticEntity::kDatabase); + std::this_thread::sleep_for(std::chrono::milliseconds(20)); + statistics.StopTimer(); + statistics.StartTimer(StatisticEntity::kNetwork); + std::this_thread::sleep_for(std::chrono::milliseconds(30)); + statistics.StopTimer(); + + statistics.StartTimer(StatisticEntity::kDisk); + std::this_thread::sleep_for(std::chrono::milliseconds(40)); + statistics.StopTimer(); + + auto stat = ExtractStat(); + + ASSERT_THAT(stat.entity_shares[StatisticEntity::kDatabase], Ge(0.15)); + ASSERT_THAT(stat.entity_shares[StatisticEntity::kDatabase], Le(0.25)); + + ASSERT_THAT(stat.entity_shares[StatisticEntity::kNetwork], Ge(0.25)); + ASSERT_THAT(stat.entity_shares[StatisticEntity::kNetwork], Le(0.35)); + + ASSERT_THAT(stat.entity_shares[StatisticEntity::kDisk], Ge(0.35)); + ASSERT_THAT(stat.entity_shares[StatisticEntity::kDisk], Le(0.45)); +} + TEST_F(StatisticTests, SendStaticsDoesCallsSender) { statistics.SetWriteInterval(1000); diff --git a/receiver/unittests/test_statistics_sender_influx_db.cpp b/receiver/unittests/test_statistics_sender_influx_db.cpp index 6690e981e..7c2b5a5f4 100644 --- a/receiver/unittests/test_statistics_sender_influx_db.cpp +++ b/receiver/unittests/test_statistics_sender_influx_db.cpp @@ -5,6 +5,8 @@ #include "../src/statistics_sender_influx_db.h" #include "../src/statistics_sender.h" #include "http_client/curl_http_client.h" +#include "unittests/MockHttpClient.h" +#include "../src/statistics.h" using ::testing::Test; using ::testing::Return; @@ -22,6 +24,8 @@ using ::testing::InSequence; using ::testing::SetArgPointee; using hidra2::StatisticsSenderInfluxDb; +using hidra2::MockHttpClient; +using hidra2::StatisticsToSend; namespace { @@ -32,5 +36,37 @@ TEST(SenderInfluxDb, Constructor) { } +class SenderInfluxDbTests : public Test { + public: + StatisticsSenderInfluxDb sender; + MockHttpClient mock_http_client; + void SetUp() override { + sender.httpclient__.reset(&mock_http_client); + } + void TearDown() override { + sender.httpclient__.release(); + } +}; + + +TEST_F(SenderInfluxDbTests, SendStatisticsCallsPost) { + StatisticsToSend statistics; + statistics.n_requests = 4; + statistics.entity_shares[hidra2::StatisticEntity::kDisk] = 0.6; + statistics.entity_shares[hidra2::StatisticEntity::kNetwork] = 0.3; + statistics.entity_shares[hidra2::StatisticEntity::kDatabase] = 0.1; + statistics.elapsed_ms = 100; + statistics.data_volume = 1000; + std::string expect_string = "statistics,receiver=1,connection=1 elapsed_ms=100,data_volume=1000," + "n_requests=4,db_share=0.1000,network_share=0.3000,disk_share=0.6000"; + EXPECT_CALL(mock_http_client, Post_t("http://zitpcx27016.desy.de:8086/write?db=db_test", expect_string, _, _)). + WillOnce( + DoAll(SetArgPointee<3>(new hidra2::IOError("Test Read Error", hidra2::IOErrorType::kReadError)), + Return("") + )); + + sender.SendStatistics(statistics); +} + } diff --git a/tests/automatic/curl_http_client/CMakeLists.txt b/tests/automatic/curl_http_client/CMakeLists.txt index c375a144d..c70485102 100644 --- a/tests/automatic/curl_http_client/CMakeLists.txt +++ b/tests/automatic/curl_http_client/CMakeLists.txt @@ -1 +1 @@ -add_subdirectory(curl_http_client_get) +add_subdirectory(curl_http_client_command) diff --git a/tests/automatic/curl_http_client/curl_http_client_command/CMakeLists.txt b/tests/automatic/curl_http_client/curl_http_client_command/CMakeLists.txt new file mode 100644 index 000000000..503b9e91b --- /dev/null +++ b/tests/automatic/curl_http_client/curl_http_client_command/CMakeLists.txt @@ -0,0 +1,27 @@ +set(TARGET_NAME curl_httpclient_command) +set(SOURCE_FILES curl_httpclient_command.cpp) + + +################################ +# Executable and link +################################ +add_executable(${TARGET_NAME} ${SOURCE_FILES}) +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() + + +################################ +# Testing +################################ + +#add_test_setup_cleanup(${TARGET_NAME}) +add_integration_test(${TARGET_NAME} get_google "GET google.com moved 302") +add_integration_test(${TARGET_NAME} get_badaddress "GET google.com/badaddress found 404") +add_integration_test(${TARGET_NAME} get_badaddress2 "GET 111 clienterror 404") +add_integration_test(${TARGET_NAME} post "POST httpbin.org/post testdata 200") +add_integration_test(${TARGET_NAME} post_badaddress "POST google.com/badaddress found 404") +add_integration_test(${TARGET_NAME} post_badaddress2 "POST 111 clienterror 404") \ No newline at end of file diff --git a/tests/automatic/curl_http_client/curl_http_client_get/curl_httpclient_get.cpp b/tests/automatic/curl_http_client/curl_http_client_command/curl_httpclient_command.cpp similarity index 66% rename from tests/automatic/curl_http_client/curl_http_client_get/curl_httpclient_get.cpp rename to tests/automatic/curl_http_client/curl_http_client_command/curl_httpclient_command.cpp index 478839271..f049bc155 100644 --- a/tests/automatic/curl_http_client/curl_http_client_get/curl_httpclient_get.cpp +++ b/tests/automatic/curl_http_client/curl_http_client_command/curl_httpclient_command.cpp @@ -8,20 +8,22 @@ using hidra2::M_AssertEq; using hidra2::M_AssertContains; struct Args { + std::string command; std::string uri; int code; std::string answer; }; Args GetArgs(int argc, char* argv[]) { - if (argc != 4) { + if (argc != 5) { std::cout << "Wrong number of arguments" << std::endl; exit(EXIT_FAILURE); } - std::string uri{argv[1]}; - std::string answer {argv[2]}; - int code = std::stoi(argv[3]); - return Args{uri, code, answer}; + std::string command{argv[1]}; + std::string uri{argv[2]}; + std::string answer {argv[3]}; + int code = std::stoi(argv[4]); + return Args{command, uri, code, answer}; } @@ -34,7 +36,12 @@ int main(int argc, char* argv[]) { auto server_broker = static_cast<hidra2::ServerDataBroker*>(broker.get()); hidra2::HttpCode code; - auto response = server_broker->httpclient__->Get(args.uri, &code, &err); + std::string response; + if (args.command == "GET") { + response = server_broker->httpclient__->Get(args.uri, &code, &err); + } else if (args.command == "POST") { + response = server_broker->httpclient__->Post(args.uri, "testdata", &code, &err); + } if (err != nullptr) { M_AssertEq("clienterror", args.answer); diff --git a/tests/automatic/curl_http_client/curl_http_client_get/CMakeLists.txt b/tests/automatic/curl_http_client/curl_http_client_get/CMakeLists.txt deleted file mode 100644 index e233d8a78..000000000 --- a/tests/automatic/curl_http_client/curl_http_client_get/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -set(TARGET_NAME curl_httpclient_get) -set(SOURCE_FILES curl_httpclient_get.cpp) - - -################################ -# Executable and link -################################ -add_executable(${TARGET_NAME} ${SOURCE_FILES}) -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() - - -################################ -# Testing -################################ - -#add_test_setup_cleanup(${TARGET_NAME}) -add_integration_test(${TARGET_NAME} get_google "google.com moved 302") -add_integration_test(${TARGET_NAME} get_badaddress "google.com/badaddress found 404") -add_integration_test(${TARGET_NAME} get_badaddress2 "111 clienterror 404") - diff --git a/worker/api/cpp/unittests/MockHttpClient.h b/worker/api/cpp/unittests/MockHttpClient.h deleted file mode 100644 index ba4454162..000000000 --- a/worker/api/cpp/unittests/MockHttpClient.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef HIDRA2_MOCKHTTPCLIENT_H -#define HIDRA2_MOCKHTTPCLIENT_H - -#include <gtest/gtest.h> -#include <gmock/gmock.h> - -#include "http_client/http_client.h" -#include "worker/data_broker.h" - - -namespace hidra2 { - -class MockHttpClient : public HttpClient { - public: - std::string Get(const std::string& uri, HttpCode* code, Error* err) const noexcept override { - return Get_t(uri, code, err); - } - MOCK_CONST_METHOD3(Get_t, - std::string(const std::string& uri, HttpCode* code, Error* err)); -}; - - -} - -#endif //HIDRA2_MOCKHTTPCLIENT_H diff --git a/worker/api/cpp/unittests/test_server_broker.cpp b/worker/api/cpp/unittests/test_server_broker.cpp index d20858b5e..7987769fd 100644 --- a/worker/api/cpp/unittests/test_server_broker.cpp +++ b/worker/api/cpp/unittests/test_server_broker.cpp @@ -7,7 +7,7 @@ #include "../src/server_data_broker.h" #include "http_client/curl_http_client.h" #include "unittests/MockIO.h" -#include "MockHttpClient.h" +#include "unittests/MockHttpClient.h" #include "http_client/http_error.h" using hidra2::DataBrokerFactory; -- GitLab