diff --git a/common/cpp/include/http_client/curl_http_client.h b/common/cpp/include/http_client/curl_http_client.h index 135a6cd5c5b38af9e3d54421538a2197ee9b0889..9b65491aac43110c1e4de6bed792c9bf77ba7ab6 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 ff4c1395b3db5c5b9edc070a0edf8c5e4b9c47f2..92a9299617bc6bea7b2979bc5d04865a44fc35bc 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 0000000000000000000000000000000000000000..a497c396e4a03ab2b52f26a39f701dce2c14c9fd --- /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 fc9904e491b61b4c9f6a36e1ebb197fcf7db7f78..c9f91a215947f8e16e6b840cedaecc6da202b30f 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 70c4a93ddfbbe4fd6c6872491370d2539e651ff5..1315a8eb613e98f34a5a7e1ff27acabe33474327 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 e0faf78b744ddc6becc4e556d2d575ec9e6fdcf6..c84e2f1e93e49dbc45fa632cef0c86216b90cbce 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 c1d4f0a979ad74778244d47b760425a6760e92b6..c247ba8874a9c70c8f53b636f254fba0dc199c98 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 ddb8c6b4e6fc6b6a2ddf97987577d10d4b79e228..49a032cf68744d6fdb7d0b7d5744aa734aa471e7 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 0ac7e8b41d7d4bfdfd9dbe4d628cf323d2010c66..beed7f232d5340ae56c2dd5992c8688f01062936 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 e59954f463829f263c171b8664ed72763c911bdb..aeff173333ec802cea81ae732e28d3dfa703832c 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 085e246023e2c4f0768777c8b3ec8dbcfe5b3864..1ac9307bd7b0b1d32350d8ac2b321b06c9cea427 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 5302896967a5574b4e4d02fbf129e44569603935..4ba29133e28e21aab9e7d3a5b52a6a1c2ff7dc9f 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 6690e981e8be35939e59667dce076f731c7761b0..7c2b5a5f4eb24166f2553d99ceb5c45e6dcb4527 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 c375a144de531be429b0e85e3e3689115a826c33..c704851020a6b314c6172cedde15c2e58cbe489c 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 0000000000000000000000000000000000000000..503b9e91b51343704ccd80b856da664d5c99aab7 --- /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 478839271d364ce2bcfa98cc00de5ac4f602707d..f049bc15573a7e502e53719fa4128944c3848a87 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 e233d8a7893f9126dfd81a27a739936d11be1f6b..0000000000000000000000000000000000000000 --- 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 ba445416229fcbc863dbb3f3041043926dbf7808..0000000000000000000000000000000000000000 --- 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 d20858b5ea9de38112afd4ba7ae5794500b07d32..7987769fdd31e72e715f1959375ec806525e94aa 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;