Line data Source code
1 : /*
2 : ___________________________________________
3 : | _ ___ _ |
4 : | | | |__ \ | | |
5 : | | |__ ) |__ _ __ _ ___ _ __ | |_ |
6 : | | '_ \ / // _` |/ _` |/ _ \ '_ \| __| | HTTP/2 AGENT FOR MOCK TESTING
7 : | | | | |/ /| (_| | (_| | __/ | | | |_ | Version 0.0.z
8 : | |_| |_|____\__,_|\__, |\___|_| |_|\__| | https://github.com/testillano/h2agent
9 : | __/ | |
10 : | |___/ |
11 : |___________________________________________|
12 :
13 : Licensed under the MIT License <http://opensource.org/licenses/MIT>.
14 : SPDX-License-Identifier: MIT
15 : Copyright (c) 2021 Eduardo Ramos
16 :
17 : Permission is hereby granted, free of charge, to any person obtaining a copy
18 : of this software and associated documentation files (the "Software"), to deal
19 : in the Software without restriction, including without limitation the rights
20 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21 : copies of the Software, and to permit persons to whom the Software is
22 : furnished to do so, subject to the following conditions:
23 :
24 : The above copyright notice and this permission notice shall be included in all
25 : copies or substantial portions of the Software.
26 :
27 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 : SOFTWARE.
34 : */
35 :
36 : #pragma once
37 :
38 : #include <vector>
39 : #include <string>
40 : #include <memory>
41 : #include <cstdint>
42 : #include <atomic>
43 : #include <chrono>
44 :
45 : #include <boost/asio.hpp>
46 :
47 : #include <JsonSchema.hpp>
48 :
49 : #include <ert/metrics/Metrics.hpp>
50 : #include <ert/http2comm/Http2Client.hpp>
51 : #include <MockClientData.hpp>
52 :
53 : namespace h2agent
54 : {
55 : namespace model
56 : {
57 : class Configuration;
58 : class GlobalVariable;
59 : class FileManager;
60 : class SocketManager;
61 : class AdminData;
62 : }
63 :
64 : namespace http2
65 : {
66 :
67 : class MyTrafficHttp2Client : public ert::http2comm::Http2Client
68 : {
69 : std::uint64_t general_unique_client_sequence_{};
70 :
71 : model::AdminData *admin_data_{};
72 : model::MockClientData *mock_client_events_data_{};
73 :
74 : // metrics:
75 : ert::metrics::Metrics *metrics_{};
76 :
77 : ert::metrics::counter_t *provisioned_requests_successful_counter_{};
78 : ert::metrics::counter_t *provisioned_requests_failed_counter_{};
79 : ert::metrics::counter_t *purged_contexts_successful_counter_{};
80 : ert::metrics::counter_t *purged_contexts_failed_counter_{};
81 : ert::metrics::counter_t *response_validation_failures_counter_{};
82 :
83 : public:
84 :
85 23 : MyTrafficHttp2Client(const std::string &name, const std::string& host, const std::string& port, bool secure = false, boost::asio::io_context *timersIoContext = nullptr /*temporary */):
86 : ert::http2comm::Http2Client(name, host, port, secure),
87 23 : admin_data_(nullptr) {
88 :
89 23 : mock_client_events_data_ = new model::MockClientData();
90 :
91 : //general_unique_client_sequence_ = 1;
92 23 : }
93 :
94 39 : ~MyTrafficHttp2Client() {
95 23 : delete (mock_client_events_data_);
96 39 : }
97 :
98 : /**
99 : * Enable metrics
100 : *
101 : * @param metrics Optional metrics object to compute counters
102 : */
103 : void enableMyMetrics(ert::metrics::Metrics *metrics, const std::string &source = "");
104 :
105 2 : void incrementProvisionedRequestsSuccessful() { if (provisioned_requests_successful_counter_) provisioned_requests_successful_counter_->Increment(); }
106 2 : void incrementProvisionedRequestsFailed() { if (provisioned_requests_failed_counter_) provisioned_requests_failed_counter_->Increment(); }
107 2 : void incrementPurgedContextsSuccessful() { if (purged_contexts_successful_counter_) purged_contexts_successful_counter_->Increment(); }
108 2 : void incrementPurgedContextsFailed() { if (purged_contexts_failed_counter_) purged_contexts_failed_counter_->Increment(); }
109 0 : void incrementResponseValidationFailures() { if (response_validation_failures_counter_) response_validation_failures_counter_->Increment(); }
110 :
111 : //void responseTimeout();
112 :
113 3 : void setAdminData(model::AdminData *p) {
114 3 : admin_data_ = p;
115 3 : }
116 4 : model::AdminData *getAdminData() const {
117 4 : return admin_data_;
118 : }
119 :
120 1 : void setMockClientData(model::MockClientData *p) {
121 1 : mock_client_events_data_ = p;
122 1 : }
123 6 : model::MockClientData *getMockClientData() const {
124 6 : return mock_client_events_data_;
125 : }
126 :
127 6 : const std::uint64_t &getGeneralUniqueClientSequence() const {
128 6 : return general_unique_client_sequence_;
129 : }
130 :
131 103 : void incrementGeneralUniqueClientSequence() {
132 103 : general_unique_client_sequence_++;
133 103 : }
134 : };
135 :
136 : }
137 : }
138 :
|