diff --git a/common/cpp/src/http_client/curl_http_client.cpp b/common/cpp/src/http_client/curl_http_client.cpp index c9f91a215947f8e16e6b840cedaecc6da202b30f..a6c98fa136c99d1d530c54f2cb7ece2b0e79bce6 100644 --- a/common/cpp/src/http_client/curl_http_client.cpp +++ b/common/cpp/src/http_client/curl_http_client.cpp @@ -33,6 +33,9 @@ void SetCurlOptions(CURL* curl, bool post, const std::string& data, const std::s curl_easy_setopt(curl, CURLOPT_WRITEDATA, buffer); curl_easy_setopt(curl, CURLOPT_FAILONERROR, 0L); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); + //todo use a config parameter for this + curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, 5000L); + if (post) { curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str()); } diff --git a/receiver/CMakeLists.txt b/receiver/CMakeLists.txt index 371b917b0d85e82476392a4ca6ebfc4c79c4a131..83f928fd4aab2de74774407b73ffc5d9eb006281 100644 --- a/receiver/CMakeLists.txt +++ b/receiver/CMakeLists.txt @@ -7,7 +7,7 @@ set(SOURCE_FILES src/request_handler_file_write.cpp src/statistics.cpp src/statistics_sender_influx_db.cpp - ) + src/receiver_config.cpp src/receiver_config.h) ################################ @@ -35,6 +35,7 @@ set(TEST_SOURCE_FILES unittests/test_receiver.cpp unittests/test_connection.cpp unittests/test_statistics.cpp + unittests/test_config.cpp unittests/test_request.cpp unittests/test_request_handler_file_write.cpp unittests/test_statistics_sender_influx_db.cpp diff --git a/receiver/src/main.cpp b/receiver/src/main.cpp index 3b871296c3a2838b2fc4561e5e01579380ae74cb..61a1d2b71679def78e808a6722e7f9a14c05f0f8 100644 --- a/receiver/src/main.cpp +++ b/receiver/src/main.cpp @@ -1,13 +1,33 @@ #include <iostream> #include "receiver.h" +#include "receiver_config_factory.h" +#include "receiver_config.h" + + +hidra2::Error ReadConfigFile(int argc, char* argv[]) { + if (argc != 2) { + std::cerr << "Usage: " << argv[0] << " <config file>" << std::endl; + exit(EXIT_FAILURE); + } + hidra2::ReceiverConfigFactory factory; + return factory.SetConfigFromFile("fname"); +} + int main (int argc, char* argv[]) { + + auto err = ReadConfigFile(argc, argv); + if (err) { + std::cerr << "Cannot read config file: " << err << std::endl; + return 1; + } + + auto config = hidra2::GetReceiverConfig(); + static const std::string address = "0.0.0.0:4200"; auto* receiver = new hidra2::Receiver(); - hidra2::Error err; - std::cout << "Listening on " << address << std::endl; receiver->Listen(address, &err); if(err) { diff --git a/receiver/src/receiver_config.cpp b/receiver/src/receiver_config.cpp new file mode 100644 index 0000000000000000000000000000000000000000..be8d221a2a304cb488929ba1f4918402373c95e8 --- /dev/null +++ b/receiver/src/receiver_config.cpp @@ -0,0 +1,23 @@ +#include "receiver_config.h" +#include "receiver_config_factory.h" +#include "io/io_factory.h" + +namespace hidra2 { + +ReceiverConfig config; + +ReceiverConfigFactory::ReceiverConfigFactory() : io__{GenerateDefaultIO()} { + +} + +Error ReceiverConfigFactory::SetConfigFromFile(std::string file_name) { + config.influxdb_uri = "localhost"; + return {}; +} + +const ReceiverConfig* GetReceiverConfig() { + return &config; +} + + +} \ No newline at end of file diff --git a/receiver/src/receiver_config.h b/receiver/src/receiver_config.h new file mode 100644 index 0000000000000000000000000000000000000000..38e5648b17d4c974aa1ae367737652bb08688fa2 --- /dev/null +++ b/receiver/src/receiver_config.h @@ -0,0 +1,18 @@ +#ifndef HIDRA2_RECEIVER_CONFIG_H +#define HIDRA2_RECEIVER_CONFIG_H + +#include "io/io.h" +#include "common/error.h" + +namespace hidra2 { + +struct ReceiverConfig { + std::string influxdb_uri; +}; + +const ReceiverConfig* GetReceiverConfig(); + +} + + +#endif //HIDRA2_RECEIVER_CONFIG_H diff --git a/receiver/src/receiver_config_factory.h b/receiver/src/receiver_config_factory.h new file mode 100644 index 0000000000000000000000000000000000000000..ea4087e85c6d906d75244f6b76ee9dc4cd77c738 --- /dev/null +++ b/receiver/src/receiver_config_factory.h @@ -0,0 +1,20 @@ +#ifndef HIDRA2_RECEIVER_CONFIG_FACTORY__H +#define HIDRA2_RECEIVER_CONFIG_FACTORY__H + +#include "io/io.h" +#include "common/error.h" + +namespace hidra2 { + +class ReceiverConfigFactory { + public: + ReceiverConfigFactory(); + Error SetConfigFromFile(std::string file_name); + public: + std::unique_ptr<IO> io__; +}; + +} + + +#endif //HIDRA2_RECEIVER_CONFIG_FACTORY__H diff --git a/receiver/unittests/test_config.cpp b/receiver/unittests/test_config.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fef17aa1faf67ab056da4579077585974c439e7b --- /dev/null +++ b/receiver/unittests/test_config.cpp @@ -0,0 +1,52 @@ +#include <gtest/gtest.h> +#include <gmock/gmock.h> +#include <unittests/MockIO.h> + +#include "../src/receiver_config.h" +#include "../src/receiver_config_factory.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::Error; +using ::hidra2::ErrorInterface; +using ::hidra2::FileDescriptor; +using ::hidra2::SocketDescriptor; +using ::hidra2::MockIO; + +using ::hidra2::ReceiverConfigFactory; + + +namespace { + + +class ConfigTests : public Test { + public: + MockIO mock_io; + ReceiverConfigFactory config_factory; + void SetUp() override { + config_factory.io__ = std::unique_ptr<hidra2::IO> {&mock_io}; + } + void TearDown() override { + config_factory.io__.release(); + } + +}; + + +TEST_F(ConfigTests, ErrorWaitForNewRequest) { + +} + +} diff --git a/tests/automatic/producer_receiver/check_monitoring/check_linux.sh b/tests/automatic/producer_receiver/check_monitoring/check_linux.sh index 7f7dbb65dc12d17f74aac4856bf2ab4f4a534f44..3b4b82ec54b48718f5b00412ca0e9a83ddbbdd0e 100644 --- a/tests/automatic/producer_receiver/check_monitoring/check_linux.sh +++ b/tests/automatic/producer_receiver/check_monitoring/check_linux.sh @@ -16,7 +16,7 @@ Cleanup() { influx -execute "create database ${database_name}" -nohup $2 &>/dev/null & +nohup $2 receiver.json &>/dev/null & sleep 0.3 receiverid=`echo $!` diff --git a/tests/automatic/producer_receiver/transfer_single_file/check_linux.sh b/tests/automatic/producer_receiver/transfer_single_file/check_linux.sh index f03eaad1067fb4a3056f9ac1504d07139c1aa8df..96b43f006d3e4c0424fd93dd30c1d664264a31c5 100644 --- a/tests/automatic/producer_receiver/transfer_single_file/check_linux.sh +++ b/tests/automatic/producer_receiver/transfer_single_file/check_linux.sh @@ -10,7 +10,7 @@ Cleanup() { rm -rf files } -nohup $2 &>/dev/null & +nohup $2 receiver.json &>/dev/null & sleep 0.3 receiverid=`echo $!` diff --git a/tests/automatic/producer_receiver/transfer_single_file/check_windows.bat b/tests/automatic/producer_receiver/transfer_single_file/check_windows.bat index c1f3a66fda640e07332fa0b755f54c0b34d23b4a..ee15242cd4354e178f16d6e4059b635cf01b3db4 100644 --- a/tests/automatic/producer_receiver/transfer_single_file/check_windows.bat +++ b/tests/automatic/producer_receiver/transfer_single_file/check_windows.bat @@ -1,7 +1,7 @@ set full_recv_name="%2" set short_recv_name="%~nx2" -start /B "" "%full_recv_name%" +start /B "" "%full_recv_name%" receiver.json ping 1.0.0.0 -n 1 -w 100 > nul