]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #ifndef TEST_RBD_MIRROR_MOCK_JOURNALER_H | |
5 | #define TEST_RBD_MIRROR_MOCK_JOURNALER_H | |
6 | ||
7 | #include <gmock/gmock.h> | |
8 | #include "include/int_types.h" | |
9 | #include "include/rados/librados.hpp" | |
10 | #include "cls/journal/cls_journal_types.h" | |
11 | #include "journal/Journaler.h" | |
12 | #include <iosfwd> | |
13 | #include <string> | |
14 | ||
15 | class Context; | |
7c673cae | 16 | class Mutex; |
7c673cae FG |
17 | |
18 | namespace journal { | |
19 | ||
20 | struct ReplayHandler; | |
21 | struct Settings; | |
22 | ||
23 | struct MockFuture { | |
24 | static MockFuture *s_instance; | |
25 | static MockFuture &get_instance() { | |
11fdf7f2 | 26 | ceph_assert(s_instance != nullptr); |
7c673cae FG |
27 | return *s_instance; |
28 | } | |
29 | ||
30 | MockFuture() { | |
31 | s_instance = this; | |
32 | } | |
33 | ||
34 | MOCK_CONST_METHOD0(is_valid, bool()); | |
35 | MOCK_METHOD1(flush, void(Context *)); | |
36 | MOCK_METHOD1(wait, void(Context *)); | |
37 | }; | |
38 | ||
39 | struct MockFutureProxy { | |
40 | bool is_valid() const { | |
41 | return MockFuture::get_instance().is_valid(); | |
42 | } | |
43 | ||
44 | void flush(Context *on_safe) { | |
45 | MockFuture::get_instance().flush(on_safe); | |
46 | } | |
47 | ||
48 | void wait(Context *on_safe) { | |
49 | MockFuture::get_instance().wait(on_safe); | |
50 | } | |
51 | }; | |
52 | ||
53 | struct MockReplayEntry { | |
54 | static MockReplayEntry *s_instance; | |
55 | static MockReplayEntry &get_instance() { | |
11fdf7f2 | 56 | ceph_assert(s_instance != nullptr); |
7c673cae FG |
57 | return *s_instance; |
58 | } | |
59 | ||
60 | MockReplayEntry() { | |
61 | s_instance = this; | |
62 | } | |
63 | ||
64 | MOCK_CONST_METHOD0(get_commit_tid, uint64_t()); | |
11fdf7f2 | 65 | MOCK_CONST_METHOD0(get_data, bufferlist()); |
7c673cae FG |
66 | }; |
67 | ||
68 | struct MockReplayEntryProxy { | |
69 | uint64_t get_commit_tid() const { | |
70 | return MockReplayEntry::get_instance().get_commit_tid(); | |
71 | } | |
72 | ||
11fdf7f2 | 73 | bufferlist get_data() const { |
7c673cae FG |
74 | return MockReplayEntry::get_instance().get_data(); |
75 | } | |
76 | }; | |
77 | ||
78 | struct MockJournaler { | |
79 | static MockJournaler *s_instance; | |
80 | static MockJournaler &get_instance() { | |
11fdf7f2 | 81 | ceph_assert(s_instance != nullptr); |
7c673cae FG |
82 | return *s_instance; |
83 | } | |
84 | ||
85 | MockJournaler() { | |
86 | s_instance = this; | |
87 | } | |
88 | ||
89 | MOCK_METHOD0(construct, void()); | |
90 | ||
91 | MOCK_METHOD1(init, void(Context *)); | |
92 | MOCK_METHOD0(shut_down, void()); | |
93 | MOCK_METHOD1(shut_down, void(Context *)); | |
94 | MOCK_CONST_METHOD0(is_initialized, bool()); | |
95 | ||
96 | MOCK_METHOD3(get_metadata, void(uint8_t *order, uint8_t *splay_width, | |
97 | int64_t *pool_id)); | |
98 | MOCK_METHOD4(get_mutable_metadata, void(uint64_t*, uint64_t*, | |
99 | std::set<cls::journal::Client> *, | |
100 | Context*)); | |
101 | ||
102 | MOCK_METHOD2(register_client, void(const bufferlist &, Context *)); | |
103 | MOCK_METHOD1(unregister_client, void(Context *)); | |
104 | MOCK_METHOD3(get_client, void(const std::string &, cls::journal::Client *, | |
105 | Context *)); | |
106 | MOCK_METHOD2(get_cached_client, int(const std::string&, cls::journal::Client*)); | |
107 | MOCK_METHOD2(update_client, void(const bufferlist &, Context *)); | |
108 | ||
109 | MOCK_METHOD4(allocate_tag, void(uint64_t, const bufferlist &, | |
110 | cls::journal::Tag*, Context *)); | |
111 | MOCK_METHOD3(get_tag, void(uint64_t, cls::journal::Tag *, Context *)); | |
112 | MOCK_METHOD3(get_tags, void(uint64_t, journal::Journaler::Tags*, Context*)); | |
113 | MOCK_METHOD4(get_tags, void(uint64_t, uint64_t, journal::Journaler::Tags*, | |
114 | Context*)); | |
115 | ||
116 | MOCK_METHOD1(start_replay, void(::journal::ReplayHandler *replay_handler)); | |
117 | MOCK_METHOD2(start_live_replay, void(ReplayHandler *, double)); | |
118 | MOCK_METHOD1(try_pop_front, bool(MockReplayEntryProxy *)); | |
119 | MOCK_METHOD2(try_pop_front, bool(MockReplayEntryProxy *, uint64_t *)); | |
120 | MOCK_METHOD0(stop_replay, void()); | |
121 | MOCK_METHOD1(stop_replay, void(Context *on_finish)); | |
122 | ||
11fdf7f2 | 123 | MOCK_METHOD4(start_append, void(int, uint64_t, double, uint64_t)); |
7c673cae FG |
124 | MOCK_CONST_METHOD0(get_max_append_size, uint64_t()); |
125 | MOCK_METHOD2(append, MockFutureProxy(uint64_t tag_id, | |
126 | const bufferlist &bl)); | |
127 | MOCK_METHOD1(flush, void(Context *on_safe)); | |
128 | MOCK_METHOD1(stop_append, void(Context *on_safe)); | |
129 | ||
130 | MOCK_METHOD1(committed, void(const MockReplayEntryProxy &)); | |
131 | MOCK_METHOD1(committed, void(const MockFutureProxy &future)); | |
132 | MOCK_METHOD1(flush_commit_position, void(Context*)); | |
133 | ||
134 | MOCK_METHOD1(add_listener, void(JournalMetadataListener *)); | |
135 | MOCK_METHOD1(remove_listener, void(JournalMetadataListener *)); | |
136 | ||
137 | }; | |
138 | ||
139 | struct MockJournalerProxy { | |
b32b8144 FG |
140 | MockJournalerProxy() { |
141 | MockJournaler::get_instance().construct(); | |
142 | } | |
143 | ||
7c673cae FG |
144 | template <typename IoCtxT> |
145 | MockJournalerProxy(IoCtxT &header_ioctx, const std::string &, | |
146 | const std::string &, const Settings&) { | |
147 | MockJournaler::get_instance().construct(); | |
148 | } | |
149 | ||
d2e6a577 FG |
150 | template <typename WorkQueue, typename Timer> |
151 | MockJournalerProxy(WorkQueue *work_queue, Timer *timer, Mutex *timer_lock, | |
152 | librados::IoCtx &header_ioctx, | |
153 | const std::string &journal_id, | |
7c673cae FG |
154 | const std::string &client_id, const Settings&) { |
155 | MockJournaler::get_instance().construct(); | |
156 | } | |
157 | ||
158 | void exists(Context *on_finish) const { | |
159 | on_finish->complete(-EINVAL); | |
160 | } | |
161 | void create(uint8_t order, uint8_t splay_width, int64_t pool_id, Context *on_finish) { | |
162 | on_finish->complete(-EINVAL); | |
163 | } | |
164 | void remove(bool force, Context *on_finish) { | |
165 | on_finish->complete(-EINVAL); | |
166 | } | |
167 | int register_client(const bufferlist &data) { | |
168 | return -EINVAL; | |
169 | } | |
170 | ||
171 | void allocate_tag(uint64_t tag_class, const bufferlist &tag_data, | |
172 | cls::journal::Tag* tag, Context *on_finish) { | |
173 | MockJournaler::get_instance().allocate_tag(tag_class, tag_data, tag, | |
174 | on_finish); | |
175 | } | |
176 | ||
177 | void init(Context *on_finish) { | |
178 | MockJournaler::get_instance().init(on_finish); | |
179 | } | |
180 | void shut_down() { | |
181 | MockJournaler::get_instance().shut_down(); | |
182 | } | |
183 | void shut_down(Context *on_finish) { | |
184 | MockJournaler::get_instance().shut_down(on_finish); | |
185 | } | |
186 | bool is_initialized() const { | |
187 | return MockJournaler::get_instance().is_initialized(); | |
188 | } | |
189 | ||
190 | void get_metadata(uint8_t *order, uint8_t *splay_width, int64_t *pool_id) { | |
191 | MockJournaler::get_instance().get_metadata(order, splay_width, pool_id); | |
192 | } | |
193 | ||
194 | void get_mutable_metadata(uint64_t *min, uint64_t *active, | |
195 | std::set<cls::journal::Client> *clients, | |
196 | Context *on_finish) { | |
197 | MockJournaler::get_instance().get_mutable_metadata(min, active, clients, | |
198 | on_finish); | |
199 | } | |
200 | ||
201 | void register_client(const bufferlist &data, Context *on_finish) { | |
202 | MockJournaler::get_instance().register_client(data, on_finish); | |
203 | } | |
204 | ||
205 | void unregister_client(Context *on_finish) { | |
206 | MockJournaler::get_instance().unregister_client(on_finish); | |
207 | } | |
208 | ||
209 | void get_client(const std::string &client_id, cls::journal::Client *client, | |
210 | Context *on_finish) { | |
211 | MockJournaler::get_instance().get_client(client_id, client, on_finish); | |
212 | } | |
213 | ||
214 | int get_cached_client(const std::string& client_id, | |
215 | cls::journal::Client* client) { | |
216 | return MockJournaler::get_instance().get_cached_client(client_id, client); | |
217 | } | |
218 | ||
219 | void update_client(const bufferlist &client_data, Context *on_finish) { | |
220 | MockJournaler::get_instance().update_client(client_data, on_finish); | |
221 | } | |
222 | ||
223 | void get_tag(uint64_t tag_tid, cls::journal::Tag *tag, Context *on_finish) { | |
224 | MockJournaler::get_instance().get_tag(tag_tid, tag, on_finish); | |
225 | } | |
226 | ||
227 | void get_tags(uint64_t tag_class, journal::Journaler::Tags *tags, | |
228 | Context *on_finish) { | |
229 | MockJournaler::get_instance().get_tags(tag_class, tags, on_finish); | |
230 | } | |
231 | void get_tags(uint64_t start_after_tag_tid, uint64_t tag_class, | |
232 | journal::Journaler::Tags *tags, Context *on_finish) { | |
233 | MockJournaler::get_instance().get_tags(start_after_tag_tid, tag_class, tags, | |
234 | on_finish); | |
235 | } | |
236 | ||
237 | void start_replay(::journal::ReplayHandler *replay_handler) { | |
238 | MockJournaler::get_instance().start_replay(replay_handler); | |
239 | } | |
240 | ||
241 | void start_live_replay(ReplayHandler *handler, double interval) { | |
242 | MockJournaler::get_instance().start_live_replay(handler, interval); | |
243 | } | |
244 | ||
245 | bool try_pop_front(MockReplayEntryProxy *replay_entry) { | |
246 | return MockJournaler::get_instance().try_pop_front(replay_entry); | |
247 | } | |
248 | ||
249 | bool try_pop_front(MockReplayEntryProxy *entry, uint64_t *tag_tid) { | |
250 | return MockJournaler::get_instance().try_pop_front(entry, tag_tid); | |
251 | } | |
252 | ||
253 | void stop_replay() { | |
254 | MockJournaler::get_instance().stop_replay(); | |
255 | } | |
256 | void stop_replay(Context *on_finish) { | |
257 | MockJournaler::get_instance().stop_replay(on_finish); | |
258 | } | |
259 | ||
11fdf7f2 TL |
260 | void start_append(int flush_interval, uint64_t flush_bytes, double flush_age, |
261 | uint64_t max_in_flight_appends) { | |
7c673cae | 262 | MockJournaler::get_instance().start_append(flush_interval, flush_bytes, |
11fdf7f2 TL |
263 | flush_age, |
264 | max_in_flight_appends); | |
7c673cae FG |
265 | } |
266 | ||
267 | uint64_t get_max_append_size() const { | |
268 | return MockJournaler::get_instance().get_max_append_size(); | |
269 | } | |
270 | ||
271 | MockFutureProxy append(uint64_t tag_id, const bufferlist &bl) { | |
272 | return MockJournaler::get_instance().append(tag_id, bl); | |
273 | } | |
274 | ||
275 | void flush(Context *on_safe) { | |
276 | MockJournaler::get_instance().flush(on_safe); | |
277 | } | |
278 | ||
279 | void stop_append(Context *on_safe) { | |
280 | MockJournaler::get_instance().stop_append(on_safe); | |
281 | } | |
282 | ||
283 | void committed(const MockReplayEntryProxy &entry) { | |
284 | MockJournaler::get_instance().committed(entry); | |
285 | } | |
286 | ||
287 | void committed(const MockFutureProxy &future) { | |
288 | MockJournaler::get_instance().committed(future); | |
289 | } | |
290 | ||
291 | void flush_commit_position(Context *on_finish) { | |
292 | MockJournaler::get_instance().flush_commit_position(on_finish); | |
293 | } | |
294 | ||
295 | void add_listener(JournalMetadataListener *listener) { | |
296 | MockJournaler::get_instance().add_listener(listener); | |
297 | } | |
298 | ||
299 | void remove_listener(JournalMetadataListener *listener) { | |
300 | MockJournaler::get_instance().remove_listener(listener); | |
301 | } | |
302 | }; | |
303 | ||
304 | std::ostream &operator<<(std::ostream &os, const MockJournalerProxy &); | |
305 | ||
306 | } // namespace journal | |
307 | ||
308 | #endif // TEST_RBD_MIRROR_MOCK_JOURNALER_H |