MySQL 8.4.2
Source Code Documentation
mysql_server_mock.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2017, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQLD_MOCK_MYSQL_SERVER_MOCK_INCLUDED
27#define MYSQLD_MOCK_MYSQL_SERVER_MOCK_INCLUDED
28
29#include <memory>
30#include <mutex>
31#include <set>
32
33#include "mock_session.h"
34#include "mysql.h" // mysql_ssl_mode
38#include "mysql/harness/plugin.h"
42#include "statement_reader.h"
43
44namespace server_mock {
45
46/** @class MySQLServerMock
47 *
48 * @brief Main class. Responsible for accepting and handling client's
49 *connections.
50 *
51 **/
53 public:
54 /** @brief Constructor.
55 *
56 * @param io_ctx IO context for network operations
57 * @param expected_queries_file Path to the json file with definitins
58 * of the expected SQL statements and responses
59 * @param module_prefixes prefixes of javascript modules used by the nodejs
60 * compatible module-loader
61 * @param bind_address Address on which the server accepts client connections
62 * @param bind_port Number of the port on which the server accepts clients
63 * connections
64 * @param protocol the protocol this mock instance speaks: "x" or "classic"
65 * @param debug_mode Flag indicating if the handled queries should be printed
66 * to the standard output
67 * @param tls_server_ctx TLS Server Context
68 * @param ssl_mode SSL mode
69 */
70 MySQLServerMock(net::io_context &io_ctx, std::string expected_queries_file,
71 std::vector<std::string> module_prefixes,
72 std::string bind_address, unsigned bind_port,
73 std::string protocol, bool debug_mode,
74 TlsServerContext &&tls_server_ctx, mysql_ssl_mode ssl_mode);
75
76 /** @brief Starts handling the clients connections in infinite loop.
77 * Will return only in case of an exception (error).
78 */
80
81 /**
82 * close all open connections.
83 *
84 * can be called from other threads.
85 */
87
88 private:
89 std::string bind_address_;
90 unsigned bind_port_;
94 std::vector<std::string> module_prefixes_;
95 std::string protocol_name_;
96
98
100
103};
104
105} // namespace server_mock
106
107#endif // MYSQLD_MOCK_MYSQL_SERVER_MOCK_INCLUDED
TLS Context for the server side.
Definition: tls_server_context.h:51
Monitor can be waited for.
Definition: monitor.h:62
PluginFuncEnv object.
Definition: loader.h:673
Definition: io_context.h:61
Main class.
Definition: mysql_server_mock.h:52
std::string expected_queries_file_
Definition: mysql_server_mock.h:93
bool debug_mode_
Definition: mysql_server_mock.h:91
void run(mysql_harness::PluginFuncEnv *env)
Starts handling the clients connections in infinite loop.
Definition: mysql_server_mock.cc:275
MySQLServerMock(net::io_context &io_ctx, std::string expected_queries_file, std::vector< std::string > module_prefixes, std::string bind_address, unsigned bind_port, std::string protocol, bool debug_mode, TlsServerContext &&tls_server_ctx, mysql_ssl_mode ssl_mode)
Constructor.
Definition: mysql_server_mock.cc:63
std::string protocol_name_
Definition: mysql_server_mock.h:95
unsigned bind_port_
Definition: mysql_server_mock.h:90
mysql_ssl_mode ssl_mode_
Definition: mysql_server_mock.h:99
WaitableMonitor< std::list< std::unique_ptr< MySQLServerMockSession > > > client_sessions_
Definition: mysql_server_mock.h:102
std::vector< std::string > module_prefixes_
Definition: mysql_server_mock.h:94
net::io_context & io_ctx_
Definition: mysql_server_mock.h:92
std::string bind_address_
Definition: mysql_server_mock.h:89
void close_all_connections()
close all open connections.
Definition: mysql_server_mock.cc:85
TlsServerContext tls_server_ctx_
Definition: mysql_server_mock.h:97
This file defines the client API to MySQL and also the ABI of the dynamically linked libmysqlclient.
mysql_ssl_mode
Definition: mysql.h:272
Definition: mock_server_component.h:36