]>
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() { | |
26 | assert(s_instance != nullptr); | |
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() { | |
56 | assert(s_instance != nullptr); | |
57 | return *s_instance; | |
58 | } | |
59 | ||
60 | MockReplayEntry() { | |
61 | s_instance = this; | |
62 | } | |
63 | ||
64 | MOCK_CONST_METHOD0(get_commit_tid, uint64_t()); | |
65 | MOCK_METHOD0(get_data, bufferlist()); | |
66 | }; | |
67 | ||
68 | struct MockReplayEntryProxy { | |
69 | uint64_t get_commit_tid() const { | |
70 | return MockReplayEntry::get_instance().get_commit_tid(); | |
71 | } | |
72 | ||
73 | bufferlist get_data() { | |
74 | return MockReplayEntry::get_instance().get_data(); | |
75 | } | |
76 | }; | |
77 | ||
78 | struct MockJournaler { | |
79 | static MockJournaler *s_instance; | |
80 | static MockJournaler &get_instance() { | |
81 | assert(s_instance != nullptr); | |
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 | ||
123 | MOCK_METHOD3(start_append, void(int flush_interval, uint64_t flush_bytes, | |
124 | double flush_age)); | |
125 | MOCK_CONST_METHOD0(get_max_append_size, uint64_t()); | |
126 | MOCK_METHOD2(append, MockFutureProxy(uint64_t tag_id, | |
127 | const bufferlist &bl)); | |
128 | MOCK_METHOD1(flush, void(Context *on_safe)); | |
129 | MOCK_METHOD1(stop_append, void(Context *on_safe)); | |
130 | ||
131 | MOCK_METHOD1(committed, void(const MockReplayEntryProxy &)); | |
132 | MOCK_METHOD1(committed, void(const MockFutureProxy &future)); | |
133 | MOCK_METHOD1(flush_commit_position, void(Context*)); | |
134 | ||
135 | MOCK_METHOD1(add_listener, void(JournalMetadataListener *)); | |
136 | MOCK_METHOD1(remove_listener, void(JournalMetadataListener *)); | |
137 | ||
138 | }; | |
139 | ||
140 | struct MockJournalerProxy { | |
b32b8144 FG |
141 | MockJournalerProxy() { |
142 | MockJournaler::get_instance().construct(); | |
143 | } | |
144 | ||
7c673cae FG |
145 | template <typename IoCtxT> |
146 | MockJournalerProxy(IoCtxT &header_ioctx, const std::string &, | |
147 | const std::string &, const Settings&) { | |
148 | MockJournaler::get_instance().construct(); | |
149 | } | |
150 | ||
d2e6a577 FG |
151 | template <typename WorkQueue, typename Timer> |
152 | MockJournalerProxy(WorkQueue *work_queue, Timer *timer, Mutex *timer_lock, | |
153 | librados::IoCtx &header_ioctx, | |
154 | const std::string &journal_id, | |
7c673cae FG |
155 | const std::string &client_id, const Settings&) { |
156 | MockJournaler::get_instance().construct(); | |
157 | } | |
158 | ||
159 | void exists(Context *on_finish) const { | |
160 | on_finish->complete(-EINVAL); | |
161 | } | |
162 | void create(uint8_t order, uint8_t splay_width, int64_t pool_id, Context *on_finish) { | |
163 | on_finish->complete(-EINVAL); | |
164 | } | |
165 | void remove(bool force, Context *on_finish) { | |
166 | on_finish->complete(-EINVAL); | |
167 | } | |
168 | int register_client(const bufferlist &data) { | |
169 | return -EINVAL; | |
170 | } | |
171 | ||
172 | void allocate_tag(uint64_t tag_class, const bufferlist &tag_data, | |
173 | cls::journal::Tag* tag, Context *on_finish) { | |
174 | MockJournaler::get_instance().allocate_tag(tag_class, tag_data, tag, | |
175 | on_finish); | |
176 | } | |
177 | ||
178 | void init(Context *on_finish) { | |
179 | MockJournaler::get_instance().init(on_finish); | |
180 | } | |
181 | void shut_down() { | |
182 | MockJournaler::get_instance().shut_down(); | |
183 | } | |
184 | void shut_down(Context *on_finish) { | |
185 | MockJournaler::get_instance().shut_down(on_finish); | |
186 | } | |
187 | bool is_initialized() const { | |
188 | return MockJournaler::get_instance().is_initialized(); | |
189 | } | |
190 | ||
191 | void get_metadata(uint8_t *order, uint8_t *splay_width, int64_t *pool_id) { | |
192 | MockJournaler::get_instance().get_metadata(order, splay_width, pool_id); | |
193 | } | |
194 | ||
195 | void get_mutable_metadata(uint64_t *min, uint64_t *active, | |
196 | std::set<cls::journal::Client> *clients, | |
197 | Context *on_finish) { | |
198 | MockJournaler::get_instance().get_mutable_metadata(min, active, clients, | |
199 | on_finish); | |
200 | } | |
201 | ||
202 | void register_client(const bufferlist &data, Context *on_finish) { | |
203 | MockJournaler::get_instance().register_client(data, on_finish); | |
204 | } | |
205 | ||
206 | void unregister_client(Context *on_finish) { | |
207 | MockJournaler::get_instance().unregister_client(on_finish); | |
208 | } | |
209 | ||
210 | void get_client(const std::string &client_id, cls::journal::Client *client, | |
211 | Context *on_finish) { | |
212 | MockJournaler::get_instance().get_client(client_id, client, on_finish); | |
213 | } | |
214 | ||
215 | int get_cached_client(const std::string& client_id, | |
216 | cls::journal::Client* client) { | |
217 | return MockJournaler::get_instance().get_cached_client(client_id, client); | |
218 | } | |
219 | ||
220 | void update_client(const bufferlist &client_data, Context *on_finish) { | |
221 | MockJournaler::get_instance().update_client(client_data, on_finish); | |
222 | } | |
223 | ||
224 | void get_tag(uint64_t tag_tid, cls::journal::Tag *tag, Context *on_finish) { | |
225 | MockJournaler::get_instance().get_tag(tag_tid, tag, on_finish); | |
226 | } | |
227 | ||
228 | void get_tags(uint64_t tag_class, journal::Journaler::Tags *tags, | |
229 | Context *on_finish) { | |
230 | MockJournaler::get_instance().get_tags(tag_class, tags, on_finish); | |
231 | } | |
232 | void get_tags(uint64_t start_after_tag_tid, uint64_t tag_class, | |
233 | journal::Journaler::Tags *tags, Context *on_finish) { | |
234 | MockJournaler::get_instance().get_tags(start_after_tag_tid, tag_class, tags, | |
235 | on_finish); | |
236 | } | |
237 | ||
238 | void start_replay(::journal::ReplayHandler *replay_handler) { | |
239 | MockJournaler::get_instance().start_replay(replay_handler); | |
240 | } | |
241 | ||
242 | void start_live_replay(ReplayHandler *handler, double interval) { | |
243 | MockJournaler::get_instance().start_live_replay(handler, interval); | |
244 | } | |
245 | ||
246 | bool try_pop_front(MockReplayEntryProxy *replay_entry) { | |
247 | return MockJournaler::get_instance().try_pop_front(replay_entry); | |
248 | } | |
249 | ||
250 | bool try_pop_front(MockReplayEntryProxy *entry, uint64_t *tag_tid) { | |
251 | return MockJournaler::get_instance().try_pop_front(entry, tag_tid); | |
252 | } | |
253 | ||
254 | void stop_replay() { | |
255 | MockJournaler::get_instance().stop_replay(); | |
256 | } | |
257 | void stop_replay(Context *on_finish) { | |
258 | MockJournaler::get_instance().stop_replay(on_finish); | |
259 | } | |
260 | ||
261 | void start_append(int flush_interval, uint64_t flush_bytes, double flush_age) { | |
262 | MockJournaler::get_instance().start_append(flush_interval, flush_bytes, | |
263 | flush_age); | |
264 | } | |
265 | ||
266 | uint64_t get_max_append_size() const { | |
267 | return MockJournaler::get_instance().get_max_append_size(); | |
268 | } | |
269 | ||
270 | MockFutureProxy append(uint64_t tag_id, const bufferlist &bl) { | |
271 | return MockJournaler::get_instance().append(tag_id, bl); | |
272 | } | |
273 | ||
274 | void flush(Context *on_safe) { | |
275 | MockJournaler::get_instance().flush(on_safe); | |
276 | } | |
277 | ||
278 | void stop_append(Context *on_safe) { | |
279 | MockJournaler::get_instance().stop_append(on_safe); | |
280 | } | |
281 | ||
282 | void committed(const MockReplayEntryProxy &entry) { | |
283 | MockJournaler::get_instance().committed(entry); | |
284 | } | |
285 | ||
286 | void committed(const MockFutureProxy &future) { | |
287 | MockJournaler::get_instance().committed(future); | |
288 | } | |
289 | ||
290 | void flush_commit_position(Context *on_finish) { | |
291 | MockJournaler::get_instance().flush_commit_position(on_finish); | |
292 | } | |
293 | ||
294 | void add_listener(JournalMetadataListener *listener) { | |
295 | MockJournaler::get_instance().add_listener(listener); | |
296 | } | |
297 | ||
298 | void remove_listener(JournalMetadataListener *listener) { | |
299 | MockJournaler::get_instance().remove_listener(listener); | |
300 | } | |
301 | }; | |
302 | ||
303 | std::ostream &operator<<(std::ostream &os, const MockJournalerProxy &); | |
304 | ||
305 | } // namespace journal | |
306 | ||
307 | #endif // TEST_RBD_MIRROR_MOCK_JOURNALER_H |