MySQL 9.2.0
Source Code Documentation
x_mock_session.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_X_MOCK_SESSION_INCLUDED
27#define MYSQLD_MOCK_X_MOCK_SESSION_INCLUDED
28
29#include <memory>
30
36#include "mysql_server_mock.h"
39#include "x_protocol_decoder.h"
40#include "x_protocol_encoder.h"
41
42namespace server_mock {
43
45 public:
47
49 std::vector<uint8_t> &payload);
50
52 const net::const_buffer &buf);
53
54 stdx::expected<std::pair<xcl::XProtocol::Client_message_type_id,
55 std::unique_ptr<xcl::XProtocol::Message>>,
56 std::error_code>
57 decode_single_message(const std::vector<uint8_t> &payload);
58
59 // throws std::system_error
60 void encode_error(const ErrorResponse &msg) override;
61
62 // throws std::system_error
63 void encode_ok(const OkResponse &msg) override;
64
65 // throws std::system_error
66 void encode_resultset(const ResultsetResponse &response) override;
67
68 void encode_message(const xcl::XProtocol::Server_message_type_id msg_id,
69 const xcl::XProtocol::Message &msg);
70
71 void encode_async_notice(const AsyncNotice &async_notice);
72
75 gr_state_changed_from_json(const std::string &json_string);
76
78 get_notice_message(const unsigned id, const std::string &payload);
79
80 private:
83};
84
86 public:
87 using clock_type = std::chrono::steady_clock;
88
92 std::unique_ptr<StatementReaderBase> statement_processor,
93 const bool debug_mode, bool with_tls);
94
95 void run() override;
96
97 void cancel() override { protocol_.cancel(); }
98
99 void terminate() override { protocol_.terminate(); }
100
101 /**
102 * encode all async notices.
103 *
104 * @param start_time start time
105 *
106 * @retval true one or more notice was added
107 * @retval false no notice encoded.
108 */
109 bool encode_due_async_notices(const clock_type::time_point &start_time);
110
111 /**
112 * expiry of the notice.
113 *
114 * @return when the next notice needs to be sent.
115 * @retval {} if no expiry
116 */
117 clock_type::time_point notice_expiry() const;
118
119 private:
120 void greeting();
121 void handshake();
122 void idle();
123 void finish();
124 void notices();
125
131
132 std::vector<AsyncNotice> async_notices_;
134
135 bool with_tls_{false};
136
137 clock_type::time_point start_time_{};
138
140
142};
143
144} // namespace server_mock
145
146#endif // MYSQLD_MOCK_X_MOCK_SESSION_INCLUDED
TLS Context for the server side.
Definition: tls_server_context.h:51
Definition: destination_endpoint.h:38
Definition: destination_socket.h:40
Definition: timer.h:57
Definition: buffer.h:135
Definition: x_mock_session.h:85
clock_type::time_point start_time_
Definition: x_mock_session.h:137
MySQLServerMockSessionX(mysql_harness::DestinationSocket sock, mysql_harness::DestinationEndpoint ep, TlsServerContext &tls_ctx, std::unique_ptr< StatementReaderBase > statement_processor, const bool debug_mode, bool with_tls)
Definition: x_mock_session.cc:261
MySQLXProtocol protocol_
Definition: x_mock_session.h:133
std::vector< AsyncNotice > async_notices_
Definition: x_mock_session.h:132
clock_type::time_point notice_expiry() const
expiry of the notice.
Definition: x_mock_session.cc:149
net::steady_timer notice_timer_
Definition: x_mock_session.h:139
void greeting()
Definition: x_mock_session.cc:287
std::chrono::steady_clock clock_type
Definition: x_mock_session.h:87
void handshake()
Definition: x_mock_session.cc:297
void send_notice_then_notices()
Definition: x_mock_session.cc:553
void idle()
Definition: x_mock_session.cc:597
void send_response_then_handshake()
Definition: x_mock_session.cc:271
void notices()
Definition: x_mock_session.cc:574
void send_response_then_first_idle()
Definition: x_mock_session.cc:504
void terminate() override
Definition: x_mock_session.h:99
void cancel() override
Definition: x_mock_session.h:97
bool with_tls_
Definition: x_mock_session.h:135
bool encode_due_async_notices(const clock_type::time_point &start_time)
encode all async notices.
Definition: x_mock_session.cc:163
void send_response_then_disconnect()
Definition: x_mock_session.cc:483
void run() override
Definition: x_mock_session.cc:710
void send_response_then_idle()
Definition: x_mock_session.cc:530
mysql_harness::logging::DomainLogger logger_
Definition: x_mock_session.h:141
Definition: mock_session.h:35
bool debug_mode() const
Definition: mock_session.h:50
Definition: x_mock_session.h:44
stdx::expected< std::unique_ptr< xcl::XProtocol::Message >, std::string > gr_state_changed_from_json(const std::string &json_string)
Definition: x_mock_session.cc:187
void encode_ok(const OkResponse &msg) override
Definition: x_mock_session.cc:720
void encode_resultset(const ResultsetResponse &response) override
Definition: x_mock_session.cc:725
void encode_message(const xcl::XProtocol::Server_message_type_id msg_id, const xcl::XProtocol::Message &msg)
Definition: x_mock_session.cc:119
XProtocolEncoder protocol_encoder_
Definition: x_mock_session.h:81
Mysqlx::Notice::Frame notice_frame
Definition: x_mock_session.h:73
XProtocolDecoder protocol_decoder_
Definition: x_mock_session.h:82
stdx::expected< size_t, std::error_code > decode_frame(std::vector< uint8_t > &payload)
Definition: x_mock_session.cc:64
void encode_async_notice(const AsyncNotice &async_notice)
Definition: x_mock_session.cc:241
stdx::expected< std::unique_ptr< xcl::XProtocol::Message >, std::string > get_notice_message(const unsigned id, const std::string &payload)
Definition: x_mock_session.cc:222
stdx::expected< std::tuple< uint8_t, size_t >, std::error_code > recv_header(const net::const_buffer &buf)
stdx::expected< std::pair< xcl::XProtocol::Client_message_type_id, std::unique_ptr< xcl::XProtocol::Message > >, std::error_code > decode_single_message(const std::vector< uint8_t > &payload)
Definition: x_mock_session.cc:94
void encode_error(const ErrorResponse &msg) override
Definition: x_mock_session.cc:712
Definition: statement_reader.h:331
void terminate()
terminate the current connection.
Definition: statement_reader.h:430
void cancel()
Definition: protocol_base.cc:120
ProtocolBase(mysql_harness::DestinationSocket sock, mysql_harness::DestinationEndpoint ep, TlsServerContext &tls_ctx)
Definition: statement_reader.h:333
net::io_context & io_context()
Definition: statement_reader.h:432
Definition: x_protocol_decoder.h:37
Definition: x_protocol_encoder.h:38
static MYSQL * sock
Definition: mysqlcheck.cc:57
Definition: buf0block_hint.cc:30
Message
Definition: histogram.h:84
Definition: mock_server_component.h:36
classic_protocol::message::server::Ok OkResponse
Definition: statement_reader.h:83
classic_protocol::message::server::Error ErrorResponse
Definition: statement_reader.h:84
Common frame for all notices.
Definition: mysqlx_notice.proto:71
Definition: statement_reader.h:86
Keeps result data for single SQL statement that returns resultset.
Definition: statement_reader.h:76