From bbed6f72373e3889f99fecd7da2b23f5136d0077 Mon Sep 17 00:00:00 2001 From: Ruben Perez Date: Wed, 12 Oct 2022 16:26:59 +0200 Subject: [PATCH] connection tests --- include/boost/mysql/conn_init_params.hpp | 35 +++++++++++++++++ include/boost/mysql/connection.hpp | 29 ++++++++------ include/boost/mysql/errc.hpp | 10 +++++ .../boost/mysql/impl/error_descriptions.hpp | 10 +++++ test/CMakeLists.txt | 2 +- test/unit/connection.cpp | 38 ++++++------------- 6 files changed, 85 insertions(+), 39 deletions(-) create mode 100644 include/boost/mysql/conn_init_params.hpp diff --git a/include/boost/mysql/conn_init_params.hpp b/include/boost/mysql/conn_init_params.hpp new file mode 100644 index 00000000..9c414115 --- /dev/null +++ b/include/boost/mysql/conn_init_params.hpp @@ -0,0 +1,35 @@ +// +// Copyright (c) 2019-2022 Ruben Perez Hidalgo (rubenperez038 at gmail dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef BOOST_MYSQL_CONN_INIT_PARAMS_HPP +#define BOOST_MYSQL_CONN_INIT_PARAMS_HPP + +#include + +namespace boost { +namespace mysql { + +class conn_init_params +{ + std::size_t initial_read_buffer_size_; + +public: + constexpr conn_init_params(std::size_t init_read_buffer_size = 0) noexcept + : initial_read_buffer_size_(init_read_buffer_size) + { + } + + constexpr std::size_t initial_read_buffer_size() const noexcept + { + return initial_read_buffer_size_; + } +}; + +} // namespace mysql +} // namespace boost + +#endif diff --git a/include/boost/mysql/connection.hpp b/include/boost/mysql/connection.hpp index 206253af..b1be1295 100644 --- a/include/boost/mysql/connection.hpp +++ b/include/boost/mysql/connection.hpp @@ -8,11 +8,7 @@ #ifndef BOOST_MYSQL_CONNECTION_HPP #define BOOST_MYSQL_CONNECTION_HPP -#include - -#ifndef BOOST_MYSQL_DOXYGEN // For some arcane reason, Doxygen fails to expand Asio macros without - // this - +#include #include #include #include @@ -21,8 +17,7 @@ #include #include - -#endif +#include /// The Boost libraries namespace. namespace boost { @@ -87,7 +82,19 @@ public: class... Args, class EnableIf = typename std::enable_if::value>::type> - connection(Args&&... args) : channel_(new detail::channel(std::forward(args)...)) + connection(Args&&... args) : connection(conn_init_params(), std::forward(args)...) + { + } + + template < + class... Args, + class EnableIf = + typename std::enable_if::value>::type> + connection(const conn_init_params& params, Args&&... args) + : channel_(new detail::channel( + params.initial_read_buffer_size(), + std::forward(args)... + )) { } @@ -331,8 +338,7 @@ public: * before calling any function that involves communication with the server over this * connection. Otherwise, the results are undefined. */ - void - query(boost::string_view query_string, resultset& result, error_code&, error_info&); + void query(boost::string_view query_string, resultset& result, error_code&, error_info&); /** * \brief Executes a SQL text query (sync with exceptions version). @@ -399,8 +405,7 @@ public: * Prepared statements are only valid while the connection object on which * this function was called is alive and open. */ - void - prepare_statement(boost::string_view stmt, statement& result, error_code&, error_info&); + void prepare_statement(boost::string_view stmt, statement& result, error_code&, error_info&); /** * \brief Prepares a statement (sync with exceptions version). diff --git a/include/boost/mysql/errc.hpp b/include/boost/mysql/errc.hpp index 078cdf49..91e1858a 100644 --- a/include/boost/mysql/errc.hpp +++ b/include/boost/mysql/errc.hpp @@ -1601,6 +1601,16 @@ enum class errc : int drop_pk_column_to_drop_gipk = 4111, ///< Server error. Error number: 4111, symbol: [mysqlerrlink2 error_er_drop_pk_column_to_drop_gipk ER_DROP_PK_COLUMN_TO_DROP_GIPK]. create_select_with_gipk_disallowed_in_sbr = 4112, ///< Server error. Error number: 4112, symbol: [mysqlerrlink2 error_er_create_select_with_gipk_disallowed_in_sbr ER_CREATE_SELECT_WITH_GIPK_DISALLOWED_IN_SBR]. da_expire_logs_days_ignored = 4113, ///< Server error. Error number: 4113, symbol: [mysqlerrlink2 error_er_da_expire_logs_days_ignored ER_DA_EXPIRE_LOGS_DAYS_IGNORED]. + cte_recursive_not_union = 4114, ///< Server error. Error number: 4114, symbol: [mysqlerrlink2 error_er_cte_recursive_not_union ER_CTE_RECURSIVE_NOT_UNION]. + command_backend_failed_to_fetch_security_ctx = 4115, ///< Server error. Error number: 4115, symbol: [mysqlerrlink2 error_er_command_backend_failed_to_fetch_security_ctx ER_COMMAND_BACKEND_FAILED_TO_FETCH_SECURITY_CTX]. + command_service_backend_failed = 4116, ///< Server error. Error number: 4116, symbol: [mysqlerrlink2 error_er_command_service_backend_failed ER_COMMAND_SERVICE_BACKEND_FAILED]. + client_file_privilege_for_replication_checks = 4117, ///< Server error. Error number: 4117, symbol: [mysqlerrlink2 error_er_client_file_privilege_for_replication_checks ER_CLIENT_FILE_PRIVILEGE_FOR_REPLICATION_CHECKS]. + group_replication_force_members_command_failure = 4118, ///< Server error. Error number: 4118, symbol: [mysqlerrlink2 error_er_group_replication_force_members_command_failure ER_GROUP_REPLICATION_FORCE_MEMBERS_COMMAND_FAILURE]. + warn_deprecated_ident = 4119, ///< Server error. Error number: 4119, symbol: [mysqlerrlink2 error_er_warn_deprecated_ident ER_WARN_DEPRECATED_IDENT]. + intersect_all_max_duplicates_exceeded = 4120, ///< Server error. Error number: 4120, symbol: [mysqlerrlink2 error_er_intersect_all_max_duplicates_exceeded ER_INTERSECT_ALL_MAX_DUPLICATES_EXCEEDED]. + tp_query_thrs_per_grp_exceeds_txn_thr_limit = 4121, ///< Server error. Error number: 4121, symbol: [mysqlerrlink2 error_er_tp_query_thrs_per_grp_exceeds_txn_thr_limit ER_TP_QUERY_THRS_PER_GRP_EXCEEDS_TXN_THR_LIMIT]. + bad_timestamp_format = 4122, ///< Server error. Error number: 4122, symbol: [mysqlerrlink2 error_er_bad_timestamp_format ER_BAD_TIMESTAMP_FORMAT]. + shape_pridiction_udf = 4123, ///< Server error. Error number: 4123, symbol: [mysqlerrlink2 error_er_shape_pridiction_udf ER_SHAPE_PRIDICTION_UDF]. incomplete_message = 65536, ///< Client error. An incomplete message was received from the server extra_bytes = 65537, ///< Client error. Unexpected extra bytes at the end of a message were received sequence_number_mismatch = 65538, ///< Client error. Mismatched sequence numbers diff --git a/include/boost/mysql/impl/error_descriptions.hpp b/include/boost/mysql/impl/error_descriptions.hpp index 25d999ac..a411fb4d 100644 --- a/include/boost/mysql/impl/error_descriptions.hpp +++ b/include/boost/mysql/impl/error_descriptions.hpp @@ -1599,6 +1599,16 @@ constexpr error_entry all_errors [] = { { errc::drop_pk_column_to_drop_gipk, "drop_pk_column_to_drop_gipk" }, { errc::create_select_with_gipk_disallowed_in_sbr, "create_select_with_gipk_disallowed_in_sbr" }, { errc::da_expire_logs_days_ignored, "da_expire_logs_days_ignored" }, + { errc::cte_recursive_not_union, "cte_recursive_not_union" }, + { errc::command_backend_failed_to_fetch_security_ctx, "command_backend_failed_to_fetch_security_ctx" }, + { errc::command_service_backend_failed, "command_service_backend_failed" }, + { errc::client_file_privilege_for_replication_checks, "client_file_privilege_for_replication_checks" }, + { errc::group_replication_force_members_command_failure, "group_replication_force_members_command_failure" }, + { errc::warn_deprecated_ident, "warn_deprecated_ident" }, + { errc::intersect_all_max_duplicates_exceeded, "intersect_all_max_duplicates_exceeded" }, + { errc::tp_query_thrs_per_grp_exceeds_txn_thr_limit, "tp_query_thrs_per_grp_exceeds_txn_thr_limit" }, + { errc::bad_timestamp_format, "bad_timestamp_format" }, + { errc::shape_pridiction_udf, "shape_pridiction_udf" }, { errc::incomplete_message, "An incomplete message was received from the server" }, { errc::extra_bytes, "Unexpected extra bytes at the end of a message were received" }, { errc::sequence_number_mismatch, "Mismatched sequence numbers" }, diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b3af0524..1f1b20fc 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -60,7 +60,7 @@ add_executable( unit/execute_params.cpp unit/statement.cpp unit/resultset.cpp - # unit/connection.cpp + unit/connection.cpp unit/entry_point.cpp ) target_link_libraries( diff --git a/test/unit/connection.cpp b/test/unit/connection.cpp index fae571b4..f4fb9565 100644 --- a/test/unit/connection.cpp +++ b/test/unit/connection.cpp @@ -6,13 +6,14 @@ // #include + #include + #include "test_stream.hpp" using conn_t = boost::mysql::connection; -namespace -{ +namespace { BOOST_AUTO_TEST_SUITE(test_connection) @@ -27,8 +28,8 @@ BOOST_AUTO_TEST_CASE(init_ctor) BOOST_AUTO_TEST_CASE(move_ctor_from_invalid) { conn_t c1; - conn_t c2 {std::move(c1)}; - conn_t c3 {std::move(c1)}; + conn_t c2{std::move(c1)}; + conn_t c3{std::move(c1)}; BOOST_TEST(!c1.valid()); BOOST_TEST(!c3.valid()); } @@ -36,7 +37,7 @@ BOOST_AUTO_TEST_CASE(move_ctor_from_invalid) BOOST_AUTO_TEST_CASE(move_ctor_from_valid) { conn_t c1; - conn_t c2 {std::move(c1)}; + conn_t c2{std::move(c1)}; BOOST_TEST(!c1.valid()); BOOST_TEST(c2.valid()); } @@ -45,9 +46,9 @@ BOOST_AUTO_TEST_CASE(move_ctor_from_valid) BOOST_AUTO_TEST_CASE(move_assign_invalid_to_invalid) { conn_t c1; - conn_t c2 {std::move(c1)}; + conn_t c2{std::move(c1)}; conn_t c3; - conn_t c4 {std::move(c2)}; + conn_t c4{std::move(c2)}; c3 = std::move(c1); BOOST_TEST(!c1.valid()); BOOST_TEST(!c3.valid()); @@ -56,7 +57,7 @@ BOOST_AUTO_TEST_CASE(move_assign_invalid_to_invalid) BOOST_AUTO_TEST_CASE(move_assign_invalid_to_valid) { conn_t c1; - conn_t c2 {std::move(c1)}; + conn_t c2{std::move(c1)}; conn_t c3; c1 = std::move(c3); BOOST_TEST(c1.valid()); @@ -66,7 +67,7 @@ BOOST_AUTO_TEST_CASE(move_assign_invalid_to_valid) BOOST_AUTO_TEST_CASE(move_assign_valid_to_invalid) { conn_t c1; - conn_t c2 {std::move(c1)}; + conn_t c2{std::move(c1)}; conn_t c3; c3 = std::move(c1); BOOST_TEST(!c1.valid()); @@ -82,21 +83,6 @@ BOOST_AUTO_TEST_CASE(move_assign_valid_to_valid) BOOST_TEST(!c2.valid()); } -using other_executor = boost::asio::strand; +BOOST_AUTO_TEST_SUITE_END() // test_connection -BOOST_AUTO_TEST_CASE(connection_rebind_executor) -{ - using original_type = boost::mysql::connection; - using rebound_type = original_type::rebind_executor::other; - using expected_type = boost::mysql::connection< - boost::asio::basic_stream_socket< - boost::asio::ip::tcp, - other_executor - > - >; - BOOST_TEST((std::is_same::value)); -} - -BOOST_AUTO_TEST_SUITE_END() // test_connection - -} +} // namespace