From 04a6da816e1aba2e136567d1e5000a47973f950f Mon Sep 17 00:00:00 2001 From: Alex Kremer Date: Thu, 26 Dec 2024 04:37:24 +0000 Subject: [PATCH] Apply new clang-tidy rules --- src/main/Main.cpp | 12 +- src/migration/MigratiorStatus.hpp | 2 +- src/migration/MigratorStatus.cpp | 6 +- .../cassandra/CassandraMigrationBackend.hpp | 12 +- .../impl/CassandraMigrationSchema.hpp | 4 +- .../cassandra/impl/FullTableScanner.hpp | 14 +- .../cassandra/impl/ObjectsAdapter.hpp | 4 +- src/migration/cassandra/impl/Spec.hpp | 4 +- .../cassandra/impl/TransactionsAdapter.hpp | 4 +- .../impl/MigrationManagerFactory.cpp | 6 +- src/migration/impl/MigratorsRegister.hpp | 6 +- src/migration/impl/Spec.hpp | 8 +- src/util/Concepts.hpp | 6 +- src/util/newconfig/ConfigDefinition.hpp | 2 +- tests/common/migration/TestMigrators.hpp | 8 +- .../util/MockMigrationBackendFixture.hpp | 10 +- .../CassandraMigrationManagerTests.cpp | 86 +++---- .../CassandraMigrationTestBackend.hpp | 28 +-- .../migration/cassandra/DBRawData.cpp | 6 +- .../migration/cassandra/DBRawData.hpp | 6 +- .../cassandra/ExampleDropTableMigrator.hpp | 4 +- .../cassandra/ExampleLedgerMigrator.hpp | 4 +- .../cassandra/ExampleObjectsMigrator.hpp | 4 +- .../cassandra/ExampleTransactionsMigrator.hpp | 4 +- tests/unit/app/WebHandlersTests.cpp | 104 ++++---- tests/unit/etl/LoadBalancerTests.cpp | 8 +- .../unit/migration/MigratorRegisterTests.cpp | 8 +- .../cassandra/FullTableScannerTests.cpp | 4 +- tests/unit/migration/cassandra/SpecTests.cpp | 4 +- tests/unit/rpc/handlers/BookOffersTests.cpp | 122 +++++----- .../rpc/handlers/GatewayBalancesTests.cpp | 44 ++-- tests/unit/rpc/handlers/LedgerEntryTests.cpp | 226 ++++++++--------- tests/unit/rpc/handlers/LedgerIndexTests.cpp | 12 +- tests/unit/rpc/handlers/LedgerTests.cpp | 12 +- tests/unit/rpc/handlers/MPTHoldersTests.cpp | 22 +- tests/unit/rpc/handlers/NFTBuyOffersTests.cpp | 10 +- tests/unit/rpc/handlers/NFTHistoryTests.cpp | 26 +- tests/unit/rpc/handlers/NFTInfoTests.cpp | 12 +- .../unit/rpc/handlers/NFTSellOffersTests.cpp | 10 +- tests/unit/rpc/handlers/NFTsByIssuerTest.cpp | 24 +- tests/unit/util/ConceptsTests.cpp | 6 +- tests/unit/web/RPCServerHandlerTests.cpp | 12 +- tests/unit/web/ng/RequestTests.cpp | 14 +- tests/unit/web/ng/ServerTests.cpp | 6 +- .../web/ng/impl/ConnectionHandlerTests.cpp | 230 +++++++++--------- tests/unit/web/ng/impl/ErrorHandlingTests.cpp | 4 +- .../unit/web/ng/impl/HttpConnectionTests.cpp | 2 +- 47 files changed, 589 insertions(+), 583 deletions(-) diff --git a/src/main/Main.cpp b/src/main/Main.cpp index 9664b9d58..6a817f0dc 100644 --- a/src/main/Main.cpp +++ b/src/main/Main.cpp @@ -46,14 +46,14 @@ try { std::cerr << json.error().error << std::endl; return EXIT_FAILURE; } - auto const errors = ClioConfig.parse(json.value()); + auto const errors = gClioConfig.parse(json.value()); if (errors.has_value()) { for (auto const& err : errors.value()) std::cerr << err.error << std::endl; return EXIT_FAILURE; } - util::LogService::init(ClioConfig); - app::ClioApplication clio{ClioConfig}; + util::LogService::init(gClioConfig); + app::ClioApplication clio{gClioConfig}; return clio.run(run.useNgWebServer); }, [](app::CliArgs::Action::Migrate const& migrate) { @@ -62,14 +62,14 @@ try { std::cerr << json.error().error << std::endl; return EXIT_FAILURE; } - auto const errors = ClioConfig.parse(json.value()); + auto const errors = gClioConfig.parse(json.value()); if (errors.has_value()) { for (auto const& err : errors.value()) std::cerr << err.error << std::endl; return EXIT_FAILURE; } - util::LogService::init(ClioConfig); - app::MigratorApplication migrator{ClioConfig, migrate.subCmd}; + util::LogService::init(gClioConfig); + app::MigratorApplication migrator{gClioConfig, migrate.subCmd}; return migrator.run(); } ); diff --git a/src/migration/MigratiorStatus.hpp b/src/migration/MigratiorStatus.hpp index 4c1a9ba2d..c01b0fabc 100644 --- a/src/migration/MigratiorStatus.hpp +++ b/src/migration/MigratiorStatus.hpp @@ -79,7 +79,7 @@ class MigratorStatus { fromString(std::string const& statusStr); private: - static constexpr std::array(NumStatuses)> statusStrMap = { + static constexpr std::array(NumStatuses)> kSTATUS_STR_MAP = { "Migrated", "NotMigrated", "NotKnown" diff --git a/src/migration/MigratorStatus.cpp b/src/migration/MigratorStatus.cpp index 03379c53c..75c66df95 100644 --- a/src/migration/MigratorStatus.cpp +++ b/src/migration/MigratorStatus.cpp @@ -39,14 +39,14 @@ MigratorStatus::operator==(Status const& other) const std::string MigratorStatus::toString() const { - return statusStrMap[static_cast(status_)]; + return kSTATUS_STR_MAP[static_cast(status_)]; } MigratorStatus MigratorStatus::fromString(std::string const& statusStr) { - for (std::size_t i = 0; i < statusStrMap.size(); ++i) { - if (statusStr == statusStrMap[i]) { + for (std::size_t i = 0; i < kSTATUS_STR_MAP.size(); ++i) { + if (statusStr == kSTATUS_STR_MAP[i]) { return MigratorStatus(static_cast(i)); } } diff --git a/src/migration/cassandra/CassandraMigrationBackend.hpp b/src/migration/cassandra/CassandraMigrationBackend.hpp index 1735a920f..f967d2f35 100644 --- a/src/migration/cassandra/CassandraMigrationBackend.hpp +++ b/src/migration/cassandra/CassandraMigrationBackend.hpp @@ -76,23 +76,23 @@ class CassandraMigrationBackend : public data::cassandra::CassandraBackend { ) { LOG(log_.debug()) << "Travsering token range: " << start << " - " << end - << " ; table: " << TableDesc::TABLE_NAME; + << " ; table: " << TableDesc::kTABLE_NAME; // for each table we only have one prepared statement - static auto statementPrepared = - migrationSchema_.getPreparedFullScanStatement(handle_, TableDesc::TABLE_NAME, TableDesc::PARTITION_KEY); + static auto kSTATEMENT_PREPARED = + migrationSchema_.getPreparedFullScanStatement(handle_, TableDesc::kTABLE_NAME, TableDesc::kPARTITION_KEY); - auto const statement = statementPrepared.bind(start, end); + auto const statement = kSTATEMENT_PREPARED.bind(start, end); auto const res = this->executor_.read(yield, statement); if (not res) { - LOG(log_.error()) << "Could not fetch data from table: " << TableDesc::TABLE_NAME << " range: " << start + LOG(log_.error()) << "Could not fetch data from table: " << TableDesc::kTABLE_NAME << " range: " << start << " - " << end << ";" << res.error(); return; } auto const& results = res.value(); if (not results.hasRows()) { - LOG(log_.debug()) << "No rows returned - table: " << TableDesc::TABLE_NAME << " range: " << start << " - " + LOG(log_.debug()) << "No rows returned - table: " << TableDesc::kTABLE_NAME << " range: " << start << " - " << end; return; } diff --git a/src/migration/cassandra/impl/CassandraMigrationSchema.hpp b/src/migration/cassandra/impl/CassandraMigrationSchema.hpp index 22c4fedfa..d998a6638 100644 --- a/src/migration/cassandra/impl/CassandraMigrationSchema.hpp +++ b/src/migration/cassandra/impl/CassandraMigrationSchema.hpp @@ -84,7 +84,7 @@ class CassandraMigrationSchema { data::cassandra::PreparedStatement const& getPreparedInsertMigratedMigrator(data::cassandra::Handle const& handler) { - static auto prepared = handler.prepare(fmt::format( + static auto kPREPARED = handler.prepare(fmt::format( R"( INSERT INTO {} (migrator_name, status) @@ -92,7 +92,7 @@ class CassandraMigrationSchema { )", data::cassandra::qualifiedTableName(settingsProvider_.get(), "migrator_status") )); - return prepared; + return kPREPARED; } }; } // namespace migration::cassandra::impl diff --git a/src/migration/cassandra/impl/FullTableScanner.hpp b/src/migration/cassandra/impl/FullTableScanner.hpp index dae94e704..34261893f 100644 --- a/src/migration/cassandra/impl/FullTableScanner.hpp +++ b/src/migration/cassandra/impl/FullTableScanner.hpp @@ -74,9 +74,9 @@ class FullTableScanner { * @brief The helper to generate the token ranges. */ struct TokenRangesProvider { - uint32_t numRanges_; + uint32_t numRanges; - TokenRangesProvider(uint32_t numRanges) : numRanges_{numRanges} + TokenRangesProvider(uint32_t numRanges) : numRanges{numRanges} { } @@ -85,18 +85,18 @@ class FullTableScanner { { auto const minValue = std::numeric_limits::min(); auto const maxValue = std::numeric_limits::max(); - if (numRanges_ == 1) + if (numRanges == 1) return {TokenRange{minValue, maxValue}}; // Safely calculate the range size using uint64_t to avoid overflow - uint64_t const rangeSize = (static_cast(maxValue) * 2) / numRanges_; + uint64_t const rangeSize = (static_cast(maxValue) * 2) / numRanges; std::vector ranges; - ranges.reserve(numRanges_); + ranges.reserve(numRanges); - for (std::int64_t i = 0; i < numRanges_; ++i) { + for (std::int64_t i = 0; i < numRanges; ++i) { int64_t const start = minValue + (i * rangeSize); - int64_t const end = (i == numRanges_ - 1) ? maxValue : start + static_cast(rangeSize) - 1; + int64_t const end = (i == numRanges - 1) ? maxValue : start + static_cast(rangeSize) - 1; ranges.emplace_back(start, end); } diff --git a/src/migration/cassandra/impl/ObjectsAdapter.hpp b/src/migration/cassandra/impl/ObjectsAdapter.hpp index 98bb932a6..91463e3be 100644 --- a/src/migration/cassandra/impl/ObjectsAdapter.hpp +++ b/src/migration/cassandra/impl/ObjectsAdapter.hpp @@ -42,8 +42,8 @@ namespace migration::cassandra::impl { */ struct TableObjectsDesc { using Row = std::tuple; - static constexpr char const* PARTITION_KEY = "key"; - static constexpr char const* TABLE_NAME = "objects"; + static constexpr char const* kPARTITION_KEY = "key"; + static constexpr char const* kTABLE_NAME = "objects"; }; /** diff --git a/src/migration/cassandra/impl/Spec.hpp b/src/migration/cassandra/impl/Spec.hpp index 2e21f42a3..c71956630 100644 --- a/src/migration/cassandra/impl/Spec.hpp +++ b/src/migration/cassandra/impl/Spec.hpp @@ -35,7 +35,7 @@ concept TableSpec = requires { requires std::tuple_size::value >= 0; // Ensures 'row' is a tuple // Check that static constexpr members 'partitionKey' and 'tableName' exist - { T::PARTITION_KEY } -> std::convertible_to; - { T::TABLE_NAME } -> std::convertible_to; + { T::kPARTITION_KEY } -> std::convertible_to; + { T::kTABLE_NAME } -> std::convertible_to; }; } // namespace migration::cassandra::impl diff --git a/src/migration/cassandra/impl/TransactionsAdapter.hpp b/src/migration/cassandra/impl/TransactionsAdapter.hpp index a5003944d..6bb27ee8a 100644 --- a/src/migration/cassandra/impl/TransactionsAdapter.hpp +++ b/src/migration/cassandra/impl/TransactionsAdapter.hpp @@ -42,8 +42,8 @@ namespace migration::cassandra::impl { struct TableTransactionsDesc { // hash, date, ledger_seq, metadata, transaction using Row = std::tuple; - static constexpr char const* PARTITION_KEY = "hash"; - static constexpr char const* TABLE_NAME = "transactions"; + static constexpr char const* kPARTITION_KEY = "hash"; + static constexpr char const* kTABLE_NAME = "transactions"; }; /** diff --git a/src/migration/impl/MigrationManagerFactory.cpp b/src/migration/impl/MigrationManagerFactory.cpp index 2ed705592..ca3b57565 100644 --- a/src/migration/impl/MigrationManagerFactory.cpp +++ b/src/migration/impl/MigrationManagerFactory.cpp @@ -37,13 +37,13 @@ namespace migration::impl { std::expected, std::string> makeMigrationManager(util::config::ClioConfigDefinition const& config) { - static util::Logger const log{"Migration"}; - LOG(log.info()) << "Constructing MigrationManager"; + static util::Logger const kLOG{"Migration"}; + LOG(kLOG.info()) << "Constructing MigrationManager"; auto const type = config.get("database.type"); if (not boost::iequals(type, "cassandra")) { - LOG(log.error()) << "Unknown database type to migrate: " << type; + LOG(kLOG.error()) << "Unknown database type to migrate: " << type; return std::unexpected(std::string("Invalid database type")); } diff --git a/src/migration/impl/MigratorsRegister.hpp b/src/migration/impl/MigratorsRegister.hpp index f361bcd04..e01c6e0e6 100644 --- a/src/migration/impl/MigratorsRegister.hpp +++ b/src/migration/impl/MigratorsRegister.hpp @@ -66,7 +66,7 @@ class MigratorsRegister { void callMigration(std::string const& name, util::config::ObjectView const& config) { - if (name == Migrator::name) { + if (name == Migrator::kNAME) { LOG(log_.info()) << "Running migration: " << name; Migrator::runMigration(backend_, config); backend_->writeMigratorStatus(name, MigratorStatus(MigratorStatus::Migrated).toString()); @@ -78,7 +78,7 @@ class MigratorsRegister { static constexpr std::string_view getDescriptionIfMatch(std::string_view targetName) { - return (T::name == targetName) ? T::description : ""; + return (T::kNAME == targetName) ? T::kDESCRIPTION : ""; } public: @@ -156,7 +156,7 @@ class MigratorsRegister { constexpr auto getMigratorNames() const { - return std::array{MigratorType::name...}; + return std::array{MigratorType::kNAME...}; } /** diff --git a/src/migration/impl/Spec.hpp b/src/migration/impl/Spec.hpp index 92d5e8c8e..5d6c15f72 100644 --- a/src/migration/impl/Spec.hpp +++ b/src/migration/impl/Spec.hpp @@ -34,11 +34,11 @@ namespace migration::impl { */ template concept MigratorSpec = requires(std::shared_ptr const& backend, util::config::ObjectView const& cfg) { - // Check that 'name' exists and is a string - { T::name } -> std::convertible_to; + // Check that 'kNAME' exists and is a string + { T::kNAME } -> std::convertible_to; - // Check that 'description' exists and is a string - { T::description } -> std::convertible_to; + // Check that 'kDESCRIPTION' exists and is a string + { T::kDESCRIPTION } -> std::convertible_to; // Check that the migrator specifies the backend type it supports typename T::Backend; diff --git a/src/util/Concepts.hpp b/src/util/Concepts.hpp index a6dd33b4b..1b7f25658 100644 --- a/src/util/Concepts.hpp +++ b/src/util/Concepts.hpp @@ -58,9 +58,9 @@ template constexpr bool hasNoDuplicateNames() { - constexpr std::array names = {Types::name...}; - return !std::ranges::any_of(names, [&](std::string_view const& name1) { - return std::ranges::any_of(names, [&](std::string_view const& name2) { + constexpr std::array kNAMES = {Types::kNAME...}; + return !std::ranges::any_of(kNAMES, [&](std::string_view const& name1) { + return std::ranges::any_of(kNAMES, [&](std::string_view const& name2) { return &name1 != &name2 && name1 == name2; // Ensure different elements are compared }); }); diff --git a/src/util/newconfig/ConfigDefinition.hpp b/src/util/newconfig/ConfigDefinition.hpp index e86f74f38..2766e767e 100644 --- a/src/util/newconfig/ConfigDefinition.hpp +++ b/src/util/newconfig/ConfigDefinition.hpp @@ -285,7 +285,7 @@ class ClioConfigDefinition { * Specifies which keys are valid in Clio Config and provides default values if user's do not specify one. Those * without default values must be present in the user's config file. */ -static ClioConfigDefinition ClioConfig = ClioConfigDefinition{ +static ClioConfigDefinition gClioConfig = ClioConfigDefinition{ {{"database.type", ConfigValue{ConfigType::String}.defaultValue("cassandra").withConstraint(gValidateCassandraName) }, {"database.cassandra.contact_points", ConfigValue{ConfigType::String}.defaultValue("localhost")}, diff --git a/tests/common/migration/TestMigrators.hpp b/tests/common/migration/TestMigrators.hpp index 1144b8db3..38131d50d 100644 --- a/tests/common/migration/TestMigrators.hpp +++ b/tests/common/migration/TestMigrators.hpp @@ -24,8 +24,8 @@ struct SimpleTestMigrator { using Backend = MockMigrationBackend; - static constexpr auto name = "SimpleTestMigrator"; - static constexpr auto description = "The migrator for version 0 -> 1"; + static constexpr auto kNAME = "SimpleTestMigrator"; + static constexpr auto kDESCRIPTION = "The migrator for version 0 -> 1"; static void runMigration(std::shared_ptr, util::config::ObjectView const&) { @@ -39,8 +39,8 @@ struct SimpleTestMigrator { struct SimpleTestMigrator2 { using Backend = MockMigrationBackend; - static constexpr auto name = "SimpleTestMigrator2"; - static constexpr auto description = "The migrator for version 1 -> 2"; + static constexpr auto kNAME = "SimpleTestMigrator2"; + static constexpr auto kDESCRIPTION = "The migrator for version 1 -> 2"; static void runMigration(std::shared_ptr, util::config::ObjectView const&) { diff --git a/tests/common/util/MockMigrationBackendFixture.hpp b/tests/common/util/MockMigrationBackendFixture.hpp index 952ba4441..f5370534b 100644 --- a/tests/common/util/MockMigrationBackendFixture.hpp +++ b/tests/common/util/MockMigrationBackendFixture.hpp @@ -30,30 +30,30 @@ template