MySQL 9.2.0
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
31#include "mock_session.h"
32#include "mysql.h" // mysql_ssl_mode
35#include "mysql/harness/plugin.h"
38
39namespace server_mock {
40
41/** @class MySQLServerMock
42 *
43 * @brief Main class. Responsible for accepting and handling client's
44 *connections.
45 *
46 **/
48 public:
49 /** @brief Constructor.
50 *
51 * @param io_ctx IO context for network operations
52 * @param expected_queries_file Path to the json file with definitins
53 * of the expected SQL statements and responses
54 * @param module_prefixes prefixes of javascript modules used by the nodejs
55 * compatible module-loader
56 * @param bind_destination endpoint on which the server accepts client
57 * connections
58 * @param protocol the protocol this mock instance speaks: "x" or "classic"
59 * @param debug_mode Flag indicating if the handled queries should be printed
60 * to the standard output
61 * @param tls_server_ctx TLS Server Context
62 * @param ssl_mode SSL mode
63 */
64 MySQLServerMock(net::io_context &io_ctx, std::string expected_queries_file,
65 std::vector<std::string> module_prefixes,
66 mysql_harness::Destination bind_destination,
67 std::string protocol, bool debug_mode,
68 TlsServerContext &&tls_server_ctx, mysql_ssl_mode ssl_mode);
69
70 /** @brief Starts handling the clients connections in infinite loop.
71 * Will return only in case of an exception (error).
72 */
74
75 /**
76 * close all open connections.
77 *
78 * can be called from other threads.
79 */
81
82 private:
87 std::vector<std::string> module_prefixes_;
88 std::string protocol_name_;
89
91
93
96};
97
98} // namespace server_mock
99
100#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
Definition: destination.h:95
PluginFuncEnv object.
Definition: loader.h:673
Definition: io_context.h:61
Main class.
Definition: mysql_server_mock.h:47
std::string expected_queries_file_
Definition: mysql_server_mock.h:86
bool debug_mode_
Definition: mysql_server_mock.h:84
void run(mysql_harness::PluginFuncEnv *env)
Starts handling the clients connections in infinite loop.
Definition: mysql_server_mock.cc:313
std::string protocol_name_
Definition: mysql_server_mock.h:88
mysql_ssl_mode ssl_mode_
Definition: mysql_server_mock.h:92
WaitableMonitor< std::list< std::unique_ptr< MySQLServerMockSession > > > client_sessions_
Definition: mysql_server_mock.h:95
std::vector< std::string > module_prefixes_
Definition: mysql_server_mock.h:87
net::io_context & io_ctx_
Definition: mysql_server_mock.h:85
void close_all_connections()
close all open connections.
Definition: mysql_server_mock.cc:85
TlsServerContext tls_server_ctx_
Definition: mysql_server_mock.h:90
MySQLServerMock(net::io_context &io_ctx, std::string expected_queries_file, std::vector< std::string > module_prefixes, mysql_harness::Destination bind_destination, std::string protocol, bool debug_mode, TlsServerContext &&tls_server_ctx, mysql_ssl_mode ssl_mode)
Constructor.
Definition: mysql_server_mock.cc:64
mysql_harness::Destination bind_destination_
Definition: mysql_server_mock.h:83
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