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