From 649b90e529a5f16988818f81a7bc02c62f8f5b86 Mon Sep 17 00:00:00 2001 From: Sergey Yakubov <sergey.yakubov@desy.de> Date: Thu, 28 Oct 2021 01:06:06 +0200 Subject: [PATCH] cleanup code --- common/cpp/include/asapo/common/common_c.h | 2 +- .../cpp/include/asapo/request/request_pool.h | 2 +- common/cpp/src/database/mongodb_client.cpp | 2 +- producer/api/cpp/unittests/mocking.h | 6 +- .../api/cpp/unittests/test_producer_impl.cpp | 2 +- receiver/src/data_cache.cpp | 1 - receiver/src/receiver.cpp | 1 - receiver/src/request.cpp | 1 - .../request_handler_db_check_request.cpp | 1 - .../request_handler_receive_data.cpp | 2 - .../request_handler_receive_metadata.cpp | 2 - .../request_handler/requests_dispatcher.cpp | 1 - tests/automatic/mongo_db/auto_id/auto_id.cpp | 3 - .../insert_retrieve_mongodb.cpp | 10 +- .../insert_retrieve_dataset_mongodb.cpp | 2 +- .../automatic/mongo_db/meta/meta_mongodb.cpp | 4 +- tests/automatic/producer/c_api/producer_api.c | 4 +- .../client_serv/ip_tcp_network.cpp | 12 +- .../getlast_broker.cpp | 4 +- tests/manual/producer_cpp/CMakeLists.txt | 11 -- tests/manual/producer_cpp/producer.cpp | 107 ------------------ 21 files changed, 25 insertions(+), 155 deletions(-) delete mode 100644 tests/manual/producer_cpp/CMakeLists.txt delete mode 100644 tests/manual/producer_cpp/producer.cpp diff --git a/common/cpp/include/asapo/common/common_c.h b/common/cpp/include/asapo/common/common_c.h index 08cff2ad6..d851b87ef 100644 --- a/common/cpp/include/asapo/common/common_c.h +++ b/common/cpp/include/asapo/common/common_c.h @@ -33,7 +33,7 @@ enum AsapoSourceType { kRaw }; -#define asapo_free_handle(handle) asapo_free_handle__((void**)handle); +#define asapo_free_handle(handle) asapo_free_handle__((void**)handle) void asapo_free_handle__(void** handle); void* asapo_new_handle(); diff --git a/common/cpp/include/asapo/request/request_pool.h b/common/cpp/include/asapo/request/request_pool.h index 2af119d68..32be614b0 100644 --- a/common/cpp/include/asapo/request/request_pool.h +++ b/common/cpp/include/asapo/request/request_pool.h @@ -34,7 +34,7 @@ class RequestPool { VIRTUAL uint64_t NRequestsInPool(); VIRTUAL uint64_t UsedMemoryInPool(); VIRTUAL Error WaitRequestsFinished(uint64_t timeout_ms); - VIRTUAL void StopThreads(); + void StopThreads(); private: const AbstractLogger* log__; RequestHandlerFactory* request_handler_factory__; diff --git a/common/cpp/src/database/mongodb_client.cpp b/common/cpp/src/database/mongodb_client.cpp index d57c3a275..f5e68433c 100644 --- a/common/cpp/src/database/mongodb_client.cpp +++ b/common/cpp/src/database/mongodb_client.cpp @@ -308,7 +308,7 @@ Error MongoDBClient::GetNextId(const std::string& stream, uint64_t* id) const { } } mongoc_find_and_modify_opts_set_flags(opts, - mongoc_find_and_modify_flags_t(MONGOC_FIND_AND_MODIFY_UPSERT | MONGOC_FIND_AND_MODIFY_RETURN_NEW)); + MONGOC_FIND_AND_MODIFY_UPSERT | MONGOC_FIND_AND_MODIFY_RETURN_NEW); success = mongoc_collection_find_and_modify_with_opts ( collection, &query, opts, &reply, &error); Error err; diff --git a/producer/api/cpp/unittests/mocking.h b/producer/api/cpp/unittests/mocking.h index e2d182f16..32aab9047 100644 --- a/producer/api/cpp/unittests/mocking.h +++ b/producer/api/cpp/unittests/mocking.h @@ -22,9 +22,9 @@ class MockDiscoveryService : public asapo::ReceiverDiscoveryService { } }; -class MockRequestPull : public RequestPool { +class MockRequestPool : public RequestPool { public: - MockRequestPull(RequestHandlerFactory* request_handler_factory, AbstractLogger* log) : + MockRequestPool(RequestHandlerFactory* request_handler_factory, AbstractLogger* log) : RequestPool{1, request_handler_factory, log} {}; asapo::Error AddRequest(std::unique_ptr<asapo::GenericRequest> request, bool top_priority = false) override { if (request == nullptr) { @@ -52,6 +52,6 @@ class MockRequestPull : public RequestPool { } using asapo::MockDiscoveryService; -using asapo::MockRequestPull; +using asapo::MockRequestPool; #endif //ASAPO_MOCKING_H diff --git a/producer/api/cpp/unittests/test_producer_impl.cpp b/producer/api/cpp/unittests/test_producer_impl.cpp index e62c21735..1929bba56 100644 --- a/producer/api/cpp/unittests/test_producer_impl.cpp +++ b/producer/api/cpp/unittests/test_producer_impl.cpp @@ -73,7 +73,7 @@ class ProducerImplTests : public testing::Test { testing::NiceMock<MockDiscoveryService> service; asapo::ProducerRequestHandlerFactory factory{&service}; testing::NiceMock<asapo::MockLogger> mock_logger; - testing::NiceMock<MockRequestPull> mock_pull{&factory, &mock_logger}; + testing::NiceMock<MockRequestPool> mock_pull{&factory, &mock_logger}; std::string expected_server_uri = "127.0.0.1:9400"; asapo::ProducerImpl producer{expected_server_uri, 1, 3600000, asapo::RequestHandlerType::kTcp}; uint64_t expected_size = 100; diff --git a/receiver/src/data_cache.cpp b/receiver/src/data_cache.cpp index f2fa93256..3a8434346 100644 --- a/receiver/src/data_cache.cpp +++ b/receiver/src/data_cache.cpp @@ -1,5 +1,4 @@ #include "data_cache.h" -#include "data_cache.h" #include <iostream> #include <chrono> diff --git a/receiver/src/receiver.cpp b/receiver/src/receiver.cpp index 4e6f2352e..7038deceb 100644 --- a/receiver/src/receiver.cpp +++ b/receiver/src/receiver.cpp @@ -1,4 +1,3 @@ -#include <cstring> #include <iostream> #include "receiver.h" #include "receiver_error.h" diff --git a/receiver/src/request.cpp b/receiver/src/request.cpp index cc660fc19..6eb78f82c 100644 --- a/receiver/src/request.cpp +++ b/receiver/src/request.cpp @@ -1,6 +1,5 @@ #include "request.h" #include "asapo/io/io_factory.h" -#include "receiver_config.h" #include "request_handler/request_handler_db_check_request.h" namespace asapo { diff --git a/receiver/src/request_handler/request_handler_db_check_request.cpp b/receiver/src/request_handler/request_handler_db_check_request.cpp index 3d33e1441..eb6f3e0ea 100644 --- a/receiver/src/request_handler/request_handler_db_check_request.cpp +++ b/receiver/src/request_handler/request_handler_db_check_request.cpp @@ -5,7 +5,6 @@ #include "asapo/logger/logger.h" #include "request_handler_db.h" #include "../receiver_config.h" -#include "asapo/io/io.h" #include "../request.h" namespace asapo { diff --git a/receiver/src/request_handler/request_handler_receive_data.cpp b/receiver/src/request_handler/request_handler_receive_data.cpp index 4fa314171..8c840c026 100644 --- a/receiver/src/request_handler/request_handler_receive_data.cpp +++ b/receiver/src/request_handler/request_handler_receive_data.cpp @@ -2,8 +2,6 @@ #include "asapo/io/io_factory.h" #include "../request.h" #include "../receiver_logger.h" -#include "../receiver_config.h" -#include "asapo/preprocessor/definitions.h" namespace asapo { diff --git a/receiver/src/request_handler/request_handler_receive_metadata.cpp b/receiver/src/request_handler/request_handler_receive_metadata.cpp index 36b723e0b..71aab0b74 100644 --- a/receiver/src/request_handler/request_handler_receive_metadata.cpp +++ b/receiver/src/request_handler/request_handler_receive_metadata.cpp @@ -2,8 +2,6 @@ #include "asapo/io/io_factory.h" #include "../request.h" #include "../receiver_logger.h" -#include "../receiver_config.h" -#include "asapo/preprocessor/definitions.h" namespace asapo { diff --git a/receiver/src/request_handler/requests_dispatcher.cpp b/receiver/src/request_handler/requests_dispatcher.cpp index d9bb0642c..e015ca9eb 100644 --- a/receiver/src/request_handler/requests_dispatcher.cpp +++ b/receiver/src/request_handler/requests_dispatcher.cpp @@ -1,5 +1,4 @@ #include "requests_dispatcher.h" -#include "../request.h" #include "asapo/io/io_factory.h" #include "../receiver_logger.h" #include "asapo/database/db_error.h" diff --git a/tests/automatic/mongo_db/auto_id/auto_id.cpp b/tests/automatic/mongo_db/auto_id/auto_id.cpp index 019017e3e..1aec1cfd0 100644 --- a/tests/automatic/mongo_db/auto_id/auto_id.cpp +++ b/tests/automatic/mongo_db/auto_id/auto_id.cpp @@ -61,14 +61,11 @@ void insert(const asapo::MongoDBClient& db, const std::string& name, asapo::Mess case Mode::kUpdateCounterThenIngest: fi.id = start + static_cast<uint64_t>(i) + 1; break; - default: - abort(); } uint64_t inserted_id{0}; Error err = db.Insert(std::string("data_") + name, fi, false, &inserted_id); if (err != nullptr) { printf("%s\n", err->Explain().c_str()); -// break; } else { if (inserted_id == 0) { M_AssertTrue(false); 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 2e51f8eac..411148140 100644 --- a/tests/automatic/mongo_db/insert_retrieve/insert_retrieve_mongodb.cpp +++ b/tests/automatic/mongo_db/insert_retrieve/insert_retrieve_mongodb.cpp @@ -117,15 +117,15 @@ int main(int argc, char* argv[]) { db.Insert(std::string("acks_") + stream_name + "_blabla", fi, false, nullptr); db.Insert(std::string("acks_") + stream_name + "_blabla1", fi, false, nullptr); db.DeleteStream(stream_name); - err = db.GetStreamInfo(std::string("data_") + stream_name, &info); + db.GetStreamInfo(std::string("data_") + stream_name, &info); M_AssertTrue(info.last_id == 0); - err = db.GetStreamInfo(std::string("inprocess_") + stream_name + "_blabla", &info); + db.GetStreamInfo(std::string("inprocess_") + stream_name + "_blabla", &info); M_AssertTrue(info.last_id == 0); - err = db.GetStreamInfo(std::string("inprocess_") + stream_name + "_blabla1", &info); + db.GetStreamInfo(std::string("inprocess_") + stream_name + "_blabla1", &info); M_AssertTrue(info.last_id == 0); - err = db.GetStreamInfo(std::string("acks_") + stream_name + "_blabla", &info); + db.GetStreamInfo(std::string("acks_") + stream_name + "_blabla", &info); M_AssertTrue(info.last_id == 0); - err = db.GetStreamInfo(std::string("acks_") + stream_name + "_blabla1", &info); + db.GetStreamInfo(std::string("acks_") + stream_name + "_blabla1", &info); M_AssertTrue(info.last_id == 0); err = db.DeleteStream("test1"); M_AssertTrue(err == nullptr); 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 4217c48e6..3c5854147 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 @@ -54,7 +54,7 @@ int main(int argc, char* argv[]) { if (args.keyword == "DuplicateID") { Assert(err, "OK"); - err = db.InsertAsDatasetMessage("data_test", fi, dataset_size, true); + db.InsertAsDatasetMessage("data_test", fi, dataset_size, true); err = db.InsertAsDatasetMessage("data_test", fi, dataset_size, false); } diff --git a/tests/automatic/mongo_db/meta/meta_mongodb.cpp b/tests/automatic/mongo_db/meta/meta_mongodb.cpp index 6a9f07b0c..8c61b4e17 100644 --- a/tests/automatic/mongo_db/meta/meta_mongodb.cpp +++ b/tests/automatic/mongo_db/meta/meta_mongodb.cpp @@ -62,7 +62,7 @@ int main(int argc, char* argv[]) { Assert(err, args.keyword); if (args.keyword == "OK") { - asapo::MetaIngestMode mode{asapo::MetaIngestOp::kInsert, false}; + mode = {asapo::MetaIngestOp::kInsert, false}; std::string meta = R"({"data":"test","data1":"test1","embedded":{"edata":1}})"; err = db.InsertMeta("meta", stream_name, reinterpret_cast<const uint8_t*>(meta.c_str()), meta.size(), mode); @@ -78,7 +78,7 @@ int main(int argc, char* argv[]) { M_AssertTrue(err == asapo::DBErrorTemplates::kWrongInput); std::string meta_res; - err = db.GetMetaFromDb("meta", "0", &meta_res); + db.GetMetaFromDb("meta", "0", &meta_res); M_AssertEq(meta_res, json); diff --git a/tests/automatic/producer/c_api/producer_api.c b/tests/automatic/producer/c_api/producer_api.c index 2aee99a91..5953414d0 100644 --- a/tests/automatic/producer/c_api/producer_api.c +++ b/tests/automatic/producer/c_api/producer_api.c @@ -52,13 +52,13 @@ void test_meta(AsapoProducerHandle producer) { asapo_producer_wait_requests_finished(producer,5000,NULL); AsapoStringHandle meta_received = asapo_producer_get_beamtime_meta(producer,5000, &err); EXIT_IF_ERROR("asapo_producer_get_beamtime_meta", err); - ASSERT_EQ_STRING(meta,(const char*)asapo_string_c_str(meta_received),"returned same meta as was ingested"); + ASSERT_EQ_STRING(meta,asapo_string_c_str(meta_received),"returned same meta as was ingested"); asapo_producer_send_stream_metadata(producer,meta,kInsert,1,"default", NULL,&err); asapo_producer_wait_requests_finished(producer,5000,NULL); AsapoStringHandle stream_meta_received = asapo_producer_get_stream_meta(producer,"default",5000, &err); EXIT_IF_ERROR("asapo_producer_send_stream_metadata", err); - ASSERT_EQ_STRING(meta,(const char*)asapo_string_c_str(stream_meta_received),"stream meta returned same meta as was ingested"); + ASSERT_EQ_STRING(meta,asapo_string_c_str(stream_meta_received),"stream meta returned same meta as was ingested"); asapo_free_handle(&err); asapo_free_handle(&meta_received); asapo_free_handle(&stream_meta_received); 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 c551e5f80..0a6354c36 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 @@ -108,8 +108,8 @@ void CheckNormal(int times, size_t size) { for (int i = 0; i < times; i++) { std::cout << "[CLIENT] Allocate and create random numbers" << std::endl; std::unique_ptr<uint8_t[]> buffer(new uint8_t[size]); - for (size_t i = 0; i < size; i++) { - buffer[i] = static_cast<uint8_t>(256 * rand() / RAND_MAX); + for (size_t ii = 0; ii < size; ii++) { + buffer[ii] = static_cast<uint8_t>(256 * rand() / RAND_MAX); } FILE* out = fopen("sent", "wb"); @@ -139,8 +139,8 @@ void CheckNormal(int times, size_t size) { } std::cout << "[CLIENT] buffer check" << std::endl; - for (size_t i = 0; i < size; i++) { - if (buffer[i] != buffer2[i]) { + for (size_t ii = 0; ii < size; ii++) { + if (buffer[ii] != buffer2[i]) { Exit(207); } } @@ -155,8 +155,8 @@ void CheckNormal(int times, size_t size) { Exit(210); } std::cout << "[CLIENT] buffer check after receive file" << std::endl; - for (size_t i = 0; i < size; i++) { - if (buffer[i] != buffer2[i]) { + for (size_t ii = 0; ii < size; ii++) { + if (buffer[ii] != buffer2[i]) { Exit(211); } } diff --git a/tests/manual/performance_broker_receiver/getlast_broker.cpp b/tests/manual/performance_broker_receiver/getlast_broker.cpp index ff58c1f5b..0305ce0a6 100644 --- a/tests/manual/performance_broker_receiver/getlast_broker.cpp +++ b/tests/manual/performance_broker_receiver/getlast_broker.cpp @@ -85,8 +85,8 @@ std::vector<std::thread> StartThreads(const Args& params, if (params.datasets) { auto dataset = consumer->GetLastDataset(0, "default", &err); if (err == nullptr) { - for (auto& fi : dataset.content) { - (*nbuf)[i] += fi.buf_id == 0 ? 0 : 1; + for (auto& info : dataset.content) { + (*nbuf)[i] += info.buf_id == 0 ? 0 : 1; (*nfiles_total)[i]++; } } diff --git a/tests/manual/producer_cpp/CMakeLists.txt b/tests/manual/producer_cpp/CMakeLists.txt deleted file mode 100644 index 07d230c4b..000000000 --- a/tests/manual/producer_cpp/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -set(TARGET_NAME producer) -set(SOURCE_FILES - producer.cpp - ) - -add_executable(${TARGET_NAME} ${SOURCE_FILES}) -target_include_directories(${TARGET_NAME} PUBLIC include ${CMAKE_SOURCE_DIR}/common/cpp/include) - -#Add all necessary common libraries -GET_PROPERTY(ASAPO_COMMON_IO_LIBRARIES GLOBAL PROPERTY ASAPO_COMMON_IO_LIBRARIES) -target_link_libraries(${TARGET_NAME} ${ASAPO_COMMON_IO_LIBRARIES} asapo-producer) diff --git a/tests/manual/producer_cpp/producer.cpp b/tests/manual/producer_cpp/producer.cpp deleted file mode 100644 index 78aa3c0da..000000000 --- a/tests/manual/producer_cpp/producer.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include <thread> -#include <chrono> -#include "asapo/asapo_producer.h" -#include <iostream> - -void ProcessAfterSend(asapo::RequestCallbackPayload payload, asapo::Error err) { - if (err) { - std::cerr << "error/warning during send: " << err << std::endl; - return; - } else { - std::cout << "successfuly send " << payload.original_header.Json() << std::endl; - return; - } -} - -void exit_if_error(std::string error_string, const asapo::Error& err) { - if (err) { - std::cerr << error_string << err << std::endl; - //exit(EXIT_FAILURE); - } -} - -std::string format_string(uint32_t in, std::string format = "%05d") { - if(in > 99999) - in = 0; - - char buf[6]; - snprintf(buf, sizeof(buf), format.c_str(), in); - return std::string(buf); - -} - - -int main(int argc, char* argv[]) { - - uint32_t submodule = 1; - uint32_t sleeptime = 1; - - - if(argc >= 2) - submodule = static_cast<uint32_t>(atoi(argv[1])); - - if(argc >= 3) - sleeptime = static_cast<uint32_t>(atoi(argv[2])); - - - asapo::Error err; - - auto endpoint = "localhost:8400"; // or your endpoint - auto beamtime = "asapo_test"; - - auto producer = asapo::Producer::Create(endpoint, 1, asapo::RequestHandlerType::kTcp, - asapo::SourceCredentials{asapo::SourceType::kProcessed, beamtime, "", "", ""}, 60000, &err); - exit_if_error("Cannot start producer", err); - - uint32_t start_number = 1; - - // number of files per acquistion per module - const uint32_t number_of_splitted_files = 5; - - // number of modules - const uint32_t modules = 3; - - while(true) { - for(uint32_t part = 1; part <= number_of_splitted_files; ++part) { - std::string to_send = "processed/lambdatest_" - + format_string(start_number) // file start number (acquistion id) - + "_part" + format_string(part) // file part id (chunk id) - + "_m" + format_string(submodule, std::string("%02d")); - auto send_size = to_send.size() + 1; - auto buffer = asapo::MessageData(new uint8_t[send_size]); - memcpy(buffer.get(), to_send.c_str(), send_size); - std::string stream = std::to_string(start_number); - // std::cout<<"submodule:"<<submodule - // <<"- stream:"<<stream - // <<"- filename:"<<to_send<<std::endl; - - asapo::MessageHeader message_header{submodule, send_size, to_send, "", part, modules}; - // err = producer->Send(message_header,stream, std::move(buffer), - // asapo::kTransferMetaDataOnly, &ProcessAfterSend); - - err = producer->Send(message_header, std::move(buffer), - asapo::kDefaultIngestMode, stream, &ProcessAfterSend); - exit_if_error("Cannot send file", err); - - err = producer->WaitRequestsFinished(1000); - exit_if_error("Producer exit on timeout", err); - std::this_thread::sleep_for (std::chrono::seconds(sleeptime)); - - // if(part == number_of_splitted_files) - // { - - // err = producer->SendStreamFinishedFlag(stream, - // part, - // std::to_string(start_number+1), - // &ProcessAfterSend); - // exit_if_error("Cannot send file", err); - // } - - } - start_number++; - - } - - - return EXIT_SUCCESS; -} -- GitLab