]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/librbd/mock/MockJournal.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / test / librbd / mock / MockJournal.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_TEST_LIBRBD_MOCK_JOURNAL_H
5 #define CEPH_TEST_LIBRBD_MOCK_JOURNAL_H
6
7 #include "gmock/gmock.h"
8 #include "librbd/Journal.h"
9 #include "librbd/journal/Types.h"
10 #include <list>
11
12 struct Context;
13 struct ContextWQ;
14 namespace librados { class IoCtx; }
15
16 namespace librbd {
17
18 struct ImageCtx;
19 namespace io { struct ObjectRequestHandle; }
20
21 struct MockJournal {
22 typedef std::list<io::ObjectRequestHandle *> ObjectRequests;
23
24 static MockJournal *s_instance;
25 static MockJournal *get_instance() {
26 assert(s_instance != nullptr);
27 return s_instance;
28 }
29
30 template <typename ImageCtxT>
31 static int is_tag_owner(ImageCtxT *image_ctx, bool *is_tag_owner) {
32 return get_instance()->is_tag_owner(is_tag_owner);
33 }
34
35 static void get_tag_owner(librados::IoCtx &,
36 const std::string &global_image_id,
37 std::string *tag_owner, ContextWQ *work_queue,
38 Context *on_finish) {
39 get_instance()->get_tag_owner(global_image_id, tag_owner,
40 work_queue, on_finish);
41 }
42
43 MockJournal() {
44 s_instance = this;
45 }
46
47 MOCK_CONST_METHOD0(is_journal_ready, bool());
48 MOCK_CONST_METHOD0(is_journal_replaying, bool());
49 MOCK_CONST_METHOD0(is_journal_appending, bool());
50
51 MOCK_METHOD1(wait_for_journal_ready, void(Context *));
52
53 MOCK_METHOD4(get_tag_owner, void(const std::string &,
54 std::string *, ContextWQ *,
55 Context *));
56
57 MOCK_CONST_METHOD0(is_tag_owner, bool());
58 MOCK_CONST_METHOD1(is_tag_owner, int(bool *));
59 MOCK_METHOD3(allocate_tag, void(const std::string &mirror_uuid,
60 const journal::TagPredecessor &predecessor,
61 Context *on_finish));
62
63 MOCK_METHOD1(open, void(Context *));
64 MOCK_METHOD1(close, void(Context *));
65
66 MOCK_CONST_METHOD0(get_tag_tid, uint64_t());
67 MOCK_CONST_METHOD0(get_tag_data, journal::TagData());
68
69 MOCK_METHOD0(allocate_op_tid, uint64_t());
70
71 MOCK_METHOD5(append_write_event, uint64_t(uint64_t, size_t,
72 const bufferlist &,
73 const ObjectRequests &, bool));
74 MOCK_METHOD5(append_io_event_mock, uint64_t(const journal::EventEntry&,
75 const ObjectRequests &,
76 uint64_t, size_t, bool));
77 uint64_t append_io_event(journal::EventEntry &&event_entry,
78 const ObjectRequests &requests,
79 uint64_t offset, size_t length,
80 bool flush_entry) {
81 // googlemock doesn't support move semantics
82 return append_io_event_mock(event_entry, requests, offset, length,
83 flush_entry);
84 }
85
86 MOCK_METHOD3(append_op_event_mock, void(uint64_t, const journal::EventEntry&,
87 Context *));
88 void append_op_event(uint64_t op_tid, journal::EventEntry &&event_entry,
89 Context *on_safe) {
90 // googlemock doesn't support move semantics
91 append_op_event_mock(op_tid, event_entry, on_safe);
92 }
93
94 MOCK_METHOD2(flush_event, void(uint64_t, Context *));
95 MOCK_METHOD2(wait_event, void(uint64_t, Context *));
96
97 MOCK_METHOD3(commit_op_event, void(uint64_t, int, Context *));
98 MOCK_METHOD2(replay_op_ready, void(uint64_t, Context *));
99
100 MOCK_METHOD1(add_listener, void(journal::Listener *));
101 MOCK_METHOD1(remove_listener, void(journal::Listener *));
102
103 MOCK_METHOD1(is_resync_requested, int(bool *));
104 };
105
106 } // namespace librbd
107
108 #endif // CEPH_TEST_LIBRBD_MOCK_JOURNAL_H