2
0
mirror of https://github.com/boostorg/mysql.git synced 2026-02-14 00:42:53 +00:00

connection tests

This commit is contained in:
Ruben Perez
2022-10-12 16:26:59 +02:00
parent 7d96034766
commit bbed6f7237
6 changed files with 85 additions and 39 deletions

View File

@@ -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 <cstddef>
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

View File

@@ -8,11 +8,7 @@
#ifndef BOOST_MYSQL_CONNECTION_HPP
#define BOOST_MYSQL_CONNECTION_HPP
#include <boost/asio/ssl/context.hpp>
#ifndef BOOST_MYSQL_DOXYGEN // For some arcane reason, Doxygen fails to expand Asio macros without
// this
#include <boost/mysql/conn_init_params.hpp>
#include <boost/mysql/detail/channel/channel.hpp>
#include <boost/mysql/detail/protocol/protocol_types.hpp>
#include <boost/mysql/error.hpp>
@@ -21,8 +17,7 @@
#include <boost/mysql/statement.hpp>
#include <type_traits>
#endif
#include <utility>
/// The Boost libraries namespace.
namespace boost {
@@ -87,7 +82,19 @@ public:
class... Args,
class EnableIf =
typename std::enable_if<std::is_constructible<Stream, Args...>::value>::type>
connection(Args&&... args) : channel_(new detail::channel<Stream>(std::forward<Args>(args)...))
connection(Args&&... args) : connection(conn_init_params(), std::forward<Args>(args)...)
{
}
template <
class... Args,
class EnableIf =
typename std::enable_if<std::is_constructible<Stream, Args...>::value>::type>
connection(const conn_init_params& params, Args&&... args)
: channel_(new detail::channel<Stream>(
params.initial_read_buffer_size(),
std::forward<Args>(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<Stream>& result, error_code&, error_info&);
void query(boost::string_view query_string, resultset<Stream>& 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<Stream>& result, error_code&, error_info&);
void prepare_statement(boost::string_view stmt, statement<Stream>& result, error_code&, error_info&);
/**
* \brief Prepares a statement (sync with exceptions version).

View File

@@ -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

View File

@@ -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" },

View File

@@ -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(

View File

@@ -6,13 +6,14 @@
//
#include <boost/mysql/connection.hpp>
#include <boost/test/unit_test.hpp>
#include "test_stream.hpp"
using conn_t = boost::mysql::connection<boost::mysql::test::test_stream>;
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::asio::io_context::executor_type>;
BOOST_AUTO_TEST_SUITE_END() // test_connection
BOOST_AUTO_TEST_CASE(connection_rebind_executor)
{
using original_type = boost::mysql::connection<boost::asio::ip::tcp::socket>;
using rebound_type = original_type::rebind_executor<other_executor>::other;
using expected_type = boost::mysql::connection<
boost::asio::basic_stream_socket<
boost::asio::ip::tcp,
other_executor
>
>;
BOOST_TEST((std::is_same<rebound_type, expected_type>::value));
}
BOOST_AUTO_TEST_SUITE_END() // test_connection
}
} // namespace