From 6e611fb1cc455ced5f21ff39026cc06b11f05160 Mon Sep 17 00:00:00 2001 From: dev Date: Mon, 17 Jul 2023 14:44:10 -0400 Subject: [PATCH] Addressed sonar scanner code smells +Rule of 5 for Kafka consumer and producer + Remove virtual destructor for CARMAStreetsPlugin --- src/tmx/TmxUtils/src/kafka/kafka_consumer_worker.h | 7 ++++++- src/tmx/TmxUtils/src/kafka/kafka_producer_worker.h | 7 ++++++- src/tmx/TmxUtils/src/kafka/mock_kafka_consumer_worker.h | 1 - src/tmx/TmxUtils/src/kafka/mock_kafka_producer_worker.h | 1 - src/tmx/TmxUtils/test/KafkaTestEnvironment.cpp | 1 - src/v2i-hub/CARMAStreetsPlugin/src/CARMAStreetsPlugin.h | 1 - 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/tmx/TmxUtils/src/kafka/kafka_consumer_worker.h b/src/tmx/TmxUtils/src/kafka/kafka_consumer_worker.h index 691c6e7af..2ce2076eb 100644 --- a/src/tmx/TmxUtils/src/kafka/kafka_consumer_worker.h +++ b/src/tmx/TmxUtils/src/kafka/kafka_consumer_worker.h @@ -73,6 +73,11 @@ namespace tmx::utils { * */ ~kafka_consumer_worker(); + + kafka_consumer_worker(kafka_consumer_worker& other) = delete; + kafka_consumer_worker& operator=(const kafka_consumer_worker& other) = delete; + kafka_consumer_worker(kafka_consumer_worker &&consumer) = delete; + kafka_consumer_worker const & operator=(kafka_consumer_worker &&consumer) = delete; /** * @brief Initialize kafka_consumer_worker * @@ -94,7 +99,7 @@ namespace tmx::utils { /** * @brief Stop running kafka consumer. */ - virtual void stop(); + void stop(); /** * @brief Print current configurations. */ diff --git a/src/tmx/TmxUtils/src/kafka/kafka_producer_worker.h b/src/tmx/TmxUtils/src/kafka/kafka_producer_worker.h index 2ea7d4468..a8fc0a7fe 100644 --- a/src/tmx/TmxUtils/src/kafka/kafka_producer_worker.h +++ b/src/tmx/TmxUtils/src/kafka/kafka_producer_worker.h @@ -62,6 +62,11 @@ namespace tmx::utils explicit kafka_producer_worker(const std::string &brokers); virtual ~kafka_producer_worker(); + + kafka_producer_worker(kafka_producer_worker& other) = delete; + kafka_producer_worker& operator=(const kafka_producer_worker& other) = delete; + kafka_producer_worker(kafka_producer_worker &&producer) = delete; + kafka_producer_worker const & operator=(kafka_producer_worker &&producer) = delete; /** * @brief Initialize kafka_producer_worker. This method must be called before send! * @@ -102,7 +107,7 @@ namespace tmx::utils /** * @brief Stop running kafka producer. */ - virtual void stop(); + void stop(); /** * @brief Print current configurations. */ diff --git a/src/tmx/TmxUtils/src/kafka/mock_kafka_consumer_worker.h b/src/tmx/TmxUtils/src/kafka/mock_kafka_consumer_worker.h index a2bbb888b..fc927d84c 100644 --- a/src/tmx/TmxUtils/src/kafka/mock_kafka_consumer_worker.h +++ b/src/tmx/TmxUtils/src/kafka/mock_kafka_consumer_worker.h @@ -31,7 +31,6 @@ namespace tmx::utils { MOCK_METHOD(bool, init,(),(override)); MOCK_METHOD(const char*, consume, (int timeout_ms), (override)); MOCK_METHOD(void, subscribe, (), (override)); - MOCK_METHOD(void, stop, (), (override)); MOCK_METHOD(void, printCurrConf, (), (override)); MOCK_METHOD(bool, is_running, (), (const override)); }; diff --git a/src/tmx/TmxUtils/src/kafka/mock_kafka_producer_worker.h b/src/tmx/TmxUtils/src/kafka/mock_kafka_producer_worker.h index c587169b4..cb41d8de5 100644 --- a/src/tmx/TmxUtils/src/kafka/mock_kafka_producer_worker.h +++ b/src/tmx/TmxUtils/src/kafka/mock_kafka_producer_worker.h @@ -26,7 +26,6 @@ namespace tmx::utils { MOCK_METHOD(bool, init,(),(override)); MOCK_METHOD(void, send, (const std::string &msg), (override)); MOCK_METHOD(bool, is_running, (), (const, override)); - MOCK_METHOD(void, stop, (), (override)); MOCK_METHOD(void, printCurrConf, (), (override)); }; } \ No newline at end of file diff --git a/src/tmx/TmxUtils/test/KafkaTestEnvironment.cpp b/src/tmx/TmxUtils/test/KafkaTestEnvironment.cpp index 374a7ddaf..85fd6cdfa 100644 --- a/src/tmx/TmxUtils/test/KafkaTestEnvironment.cpp +++ b/src/tmx/TmxUtils/test/KafkaTestEnvironment.cpp @@ -23,6 +23,5 @@ class KafkaTestEnvironment : public ::testing::Environment { else { std::cout << "All Objects are destroyed!" << std::endl; } - } }; \ No newline at end of file diff --git a/src/v2i-hub/CARMAStreetsPlugin/src/CARMAStreetsPlugin.h b/src/v2i-hub/CARMAStreetsPlugin/src/CARMAStreetsPlugin.h index afb11cdc6..f7167f269 100755 --- a/src/v2i-hub/CARMAStreetsPlugin/src/CARMAStreetsPlugin.h +++ b/src/v2i-hub/CARMAStreetsPlugin/src/CARMAStreetsPlugin.h @@ -36,7 +36,6 @@ namespace CARMAStreetsPlugin { class CARMAStreetsPlugin: public PluginClientClockAware { public: CARMAStreetsPlugin(std::string); - virtual ~CARMAStreetsPlugin() = default ; int Main(); protected: