MySQL 8.0.33
Source Code Documentation
x_mock_session.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_X_MOCK_SESSION_INCLUDED
26#define MYSQLD_MOCK_X_MOCK_SESSION_INCLUDED
27
28#include <memory>
29#include <mutex>
30#include <set>
31
33#include "mysql_server_mock.h"
36#include "x_protocol_decoder.h"
37#include "x_protocol_encoder.h"
38
39namespace server_mock {
40
42 public:
44
46 std::vector<uint8_t> &payload);
47
49 const net::const_buffer &buf);
50
51 stdx::expected<std::pair<xcl::XProtocol::Client_message_type_id,
52 std::unique_ptr<xcl::XProtocol::Message>>,
53 std::error_code>
54 decode_single_message(const std::vector<uint8_t> &payload);
55
56 // throws std::system_error
57 void encode_error(const ErrorResponse &msg) override;
58
59 // throws std::system_error
60 void encode_ok(const uint64_t affected_rows = 0,
61 const uint64_t last_insert_id = 0,
62 const uint16_t server_status = 0,
63 const uint16_t warning_count = 0) 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
90 MySQLXProtocol protocol,
91 std::unique_ptr<StatementReaderBase> statement_processor,
92 const bool debug_mode, bool with_tls);
93
94 void run() override;
95
96 void cancel() override { protocol_.cancel(); }
97
98 /**
99 * encode all async notices.
100 *
101 * @param start_time start time
102 *
103 * @retval true one or more notice was added
104 * @retval false no notice encoded.
105 */
106 bool encode_due_async_notices(const clock_type::time_point &start_time);
107
108 /**
109 * expiry of the notice.
110 *
111 * @return when the next notice needs to be sent.
112 * @retval {} if no expiry
113 */
114 clock_type::time_point notice_expiry() const;
115
116 private:
117 void greeting();
118 void handshake();
119 void idle();
120 void finish();
121 void notices();
122
128
129 std::vector<AsyncNotice> async_notices_;
131
132 bool with_tls_{false};
133
134 clock_type::time_point start_time_{};
135
137};
138
139} // namespace server_mock
140
141#endif // MYSQLD_MOCK_X_MOCK_SESSION_INCLUDED
Definition: timer.h:56
Definition: buffer.h:134
Definition: x_mock_session.h:85
clock_type::time_point start_time_
Definition: x_mock_session.h:134
MySQLServerMockSessionX(MySQLXProtocol protocol, std::unique_ptr< StatementReaderBase > statement_processor, const bool debug_mode, bool with_tls)
Definition: x_mock_session.cc:260
MySQLXProtocol protocol_
Definition: x_mock_session.h:130
std::vector< AsyncNotice > async_notices_
Definition: x_mock_session.h:129
clock_type::time_point notice_expiry() const
expiry of the notice.
Definition: x_mock_session.cc:147
net::steady_timer notice_timer_
Definition: x_mock_session.h:136
void greeting()
Definition: x_mock_session.cc:285
std::chrono::steady_clock clock_type
Definition: x_mock_session.h:87
void handshake()
Definition: x_mock_session.cc:295
void send_notice_then_notices()
Definition: x_mock_session.cc:554
void idle()
Definition: x_mock_session.cc:599
void send_response_then_handshake()
Definition: x_mock_session.cc:269
void notices()
Definition: x_mock_session.cc:575
void send_response_then_first_idle()
Definition: x_mock_session.cc:505
void cancel() override
Definition: x_mock_session.h:96
bool with_tls_
Definition: x_mock_session.h:132
bool encode_due_async_notices(const clock_type::time_point &start_time)
encode all async notices.
Definition: x_mock_session.cc:161
void send_response_then_disconnect()
Definition: x_mock_session.cc:484
void run() override
Definition: x_mock_session.cc:711
void send_response_then_idle()
Definition: x_mock_session.cc:531
Definition: mock_session.h:34
bool debug_mode() const
Definition: mock_session.h:47
Definition: x_mock_session.h:41
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:185
void encode_resultset(const ResultsetResponse &response) override
Definition: x_mock_session.cc:729
void encode_message(const xcl::XProtocol::Server_message_type_id msg_id, const xcl::XProtocol::Message &msg)
Definition: x_mock_session.cc:117
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:65
void encode_async_notice(const AsyncNotice &async_notice)
Definition: x_mock_session.cc:240
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:220
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:96
void encode_ok(const uint64_t affected_rows=0, const uint64_t last_insert_id=0, const uint16_t server_status=0, const uint16_t warning_count=0) override
Definition: x_mock_session.cc:721
void encode_error(const ErrorResponse &msg) override
Definition: x_mock_session.cc:713
Definition: statement_reader.h:79
ProtocolBase(socket_type client_sock, endpoint_type client_ep, TlsServerContext &tls_ctx)
Definition: protocol_base.cc:35
void cancel()
Definition: protocol_base.cc:132
net::io_context & io_context()
Definition: statement_reader.h:321
Definition: x_protocol_decoder.h:36
Definition: x_protocol_encoder.h:37
Definition: buf0block_hint.cc:29
Message
Definition: histogram.h:82
Definition: mock_server_component.h:35
classic_protocol::message::server::Error ErrorResponse
Definition: statement_reader.h:68
Common frame for all notices.
Definition: mysqlx_notice.proto:70
Definition: statement_reader.h:70
Keeps result data for single SQL statement that returns resultset.
Definition: statement_reader.h:62