]>
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 LIBRADOS_TEST_STUB_MOCK_TEST_MEM_IO_CTX_IMPL_H | |
5 | #define LIBRADOS_TEST_STUB_MOCK_TEST_MEM_IO_CTX_IMPL_H | |
6 | ||
7 | #include "test/librados_test_stub/TestMemIoCtxImpl.h" | |
8 | #include "test/librados_test_stub/TestMemCluster.h" | |
9 | #include "gmock/gmock.h" | |
10 | ||
11 | namespace librados { | |
12 | ||
13 | class MockTestMemRadosClient; | |
14 | ||
15 | class MockTestMemIoCtxImpl : public TestMemIoCtxImpl { | |
16 | public: | |
17 | MockTestMemIoCtxImpl(MockTestMemRadosClient *mock_client, | |
18 | TestMemRadosClient *client, int64_t pool_id, | |
19 | const std::string& pool_name, | |
20 | TestMemCluster::Pool *pool) | |
21 | : TestMemIoCtxImpl(client, pool_id, pool_name, pool), | |
22 | m_mock_client(mock_client), m_client(client) { | |
23 | default_to_parent(); | |
24 | } | |
25 | ||
26 | MockTestMemRadosClient *get_mock_rados_client() { | |
27 | return m_mock_client; | |
28 | } | |
29 | ||
30 | TestIoCtxImpl *clone() override { | |
31 | TestIoCtxImpl *io_ctx_impl = new ::testing::NiceMock<MockTestMemIoCtxImpl>( | |
32 | m_mock_client, m_client, get_pool_id(), get_pool_name(), get_pool()); | |
33 | io_ctx_impl->set_snap_read(get_snap_read()); | |
34 | io_ctx_impl->set_snap_context(get_snap_context()); | |
35 | return io_ctx_impl; | |
36 | } | |
37 | ||
38 | MOCK_METHOD5(aio_notify, void(const std::string& o, AioCompletionImpl *c, | |
39 | bufferlist& bl, uint64_t timeout_ms, | |
40 | bufferlist *pbl)); | |
41 | void do_aio_notify(const std::string& o, AioCompletionImpl *c, bufferlist& bl, | |
42 | uint64_t timeout_ms, bufferlist *pbl) { | |
43 | return TestMemIoCtxImpl::aio_notify(o, c, bl, timeout_ms, pbl); | |
44 | } | |
45 | ||
46 | MOCK_METHOD4(aio_watch, int(const std::string& o, AioCompletionImpl *c, | |
47 | uint64_t *handle, librados::WatchCtx2 *ctx)); | |
48 | int do_aio_watch(const std::string& o, AioCompletionImpl *c, | |
49 | uint64_t *handle, librados::WatchCtx2 *ctx) { | |
50 | return TestMemIoCtxImpl::aio_watch(o, c, handle, ctx); | |
51 | } | |
52 | ||
53 | MOCK_METHOD2(aio_unwatch, int(uint64_t handle, AioCompletionImpl *c)); | |
54 | int do_aio_unwatch(uint64_t handle, AioCompletionImpl *c) { | |
55 | return TestMemIoCtxImpl::aio_unwatch(handle, c); | |
56 | } | |
57 | ||
58 | MOCK_METHOD7(exec, int(const std::string& oid, | |
59 | TestClassHandler *handler, | |
60 | const char *cls, | |
61 | const char *method, | |
62 | bufferlist& inbl, | |
63 | bufferlist* outbl, | |
64 | const SnapContext &snapc)); | |
65 | int do_exec(const std::string& oid, TestClassHandler *handler, | |
66 | const char *cls, const char *method, bufferlist& inbl, | |
67 | bufferlist* outbl, const SnapContext &snapc) { | |
68 | return TestMemIoCtxImpl::exec(oid, handler, cls, method, inbl, outbl, | |
69 | snapc); | |
70 | } | |
71 | ||
72 | MOCK_CONST_METHOD0(get_instance_id, uint64_t()); | |
73 | uint64_t do_get_instance_id() const { | |
74 | return TestMemIoCtxImpl::get_instance_id(); | |
75 | } | |
76 | ||
77 | MOCK_METHOD2(list_snaps, int(const std::string& o, snap_set_t *out_snaps)); | |
78 | int do_list_snaps(const std::string& o, snap_set_t *out_snaps) { | |
79 | return TestMemIoCtxImpl::list_snaps(o, out_snaps); | |
80 | } | |
81 | ||
82 | MOCK_METHOD2(list_watchers, int(const std::string& o, | |
83 | std::list<obj_watch_t> *out_watchers)); | |
84 | int do_list_watchers(const std::string& o, | |
85 | std::list<obj_watch_t> *out_watchers) { | |
86 | return TestMemIoCtxImpl::list_watchers(o, out_watchers); | |
87 | } | |
88 | ||
89 | MOCK_METHOD4(notify, int(const std::string& o, bufferlist& bl, | |
90 | uint64_t timeout_ms, bufferlist *pbl)); | |
91 | int do_notify(const std::string& o, bufferlist& bl, | |
92 | uint64_t timeout_ms, bufferlist *pbl) { | |
93 | return TestMemIoCtxImpl::notify(o, bl, timeout_ms, pbl); | |
94 | } | |
95 | ||
96 | MOCK_METHOD1(set_snap_read, void(snap_t)); | |
97 | void do_set_snap_read(snap_t snap_id) { | |
98 | return TestMemIoCtxImpl::set_snap_read(snap_id); | |
99 | } | |
100 | MOCK_METHOD5(sparse_read, int(const std::string& oid, | |
101 | uint64_t off, | |
102 | uint64_t len, | |
103 | std::map<uint64_t, uint64_t> *m, | |
104 | bufferlist *bl)); | |
105 | int do_sparse_read(const std::string& oid, uint64_t off, size_t len, | |
106 | std::map<uint64_t, uint64_t> *m, bufferlist *bl){ | |
107 | return TestMemIoCtxImpl::sparse_read(oid, off, len, m, bl); | |
108 | } | |
109 | ||
110 | MOCK_METHOD4(read, int(const std::string& oid, | |
111 | size_t len, | |
112 | uint64_t off, | |
113 | bufferlist *bl)); | |
114 | int do_read(const std::string& oid, size_t len, uint64_t off, | |
115 | bufferlist *bl) { | |
116 | return TestMemIoCtxImpl::read(oid, len, off, bl); | |
117 | } | |
118 | ||
119 | MOCK_METHOD2(remove, int(const std::string& oid, const SnapContext &snapc)); | |
120 | int do_remove(const std::string& oid, const SnapContext &snapc) { | |
121 | return TestMemIoCtxImpl::remove(oid, snapc); | |
122 | } | |
123 | ||
124 | MOCK_METHOD1(selfmanaged_snap_create, int(uint64_t *snap_id)); | |
125 | int do_selfmanaged_snap_create(uint64_t *snap_id) { | |
126 | return TestMemIoCtxImpl::selfmanaged_snap_create(snap_id); | |
127 | } | |
128 | ||
129 | MOCK_METHOD1(selfmanaged_snap_remove, int(uint64_t snap_id)); | |
130 | int do_selfmanaged_snap_remove(uint64_t snap_id) { | |
131 | return TestMemIoCtxImpl::selfmanaged_snap_remove(snap_id); | |
132 | } | |
133 | ||
134 | MOCK_METHOD2(selfmanaged_snap_rollback, int(const std::string& oid, | |
135 | uint64_t snap_id)); | |
136 | int do_selfmanaged_snap_rollback(const std::string& oid, uint64_t snap_id) { | |
137 | return TestMemIoCtxImpl::selfmanaged_snap_rollback(oid, snap_id); | |
138 | } | |
139 | ||
140 | MOCK_METHOD3(truncate, int(const std::string& oid, | |
141 | uint64_t size, | |
142 | const SnapContext &snapc)); | |
143 | int do_truncate(const std::string& oid, uint64_t size, | |
144 | const SnapContext &snapc) { | |
145 | return TestMemIoCtxImpl::truncate(oid, size, snapc); | |
146 | } | |
147 | ||
148 | MOCK_METHOD5(write, int(const std::string& oid, bufferlist& bl, size_t len, | |
149 | uint64_t off, const SnapContext &snapc)); | |
150 | int do_write(const std::string& oid, bufferlist& bl, size_t len, uint64_t off, | |
151 | const SnapContext &snapc) { | |
152 | return TestMemIoCtxImpl::write(oid, bl, len, off, snapc); | |
153 | } | |
154 | ||
155 | MOCK_METHOD3(write_full, int(const std::string& oid, | |
156 | bufferlist& bl, | |
157 | const SnapContext &snapc)); | |
158 | int do_write_full(const std::string& oid, bufferlist& bl, | |
159 | const SnapContext &snapc) { | |
160 | return TestMemIoCtxImpl::write_full(oid, bl, snapc); | |
161 | } | |
162 | ||
163 | void default_to_parent() { | |
164 | using namespace ::testing; | |
165 | ||
166 | ON_CALL(*this, aio_notify(_, _, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_aio_notify)); | |
167 | ON_CALL(*this, aio_watch(_, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_aio_watch)); | |
168 | ON_CALL(*this, aio_unwatch(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_aio_unwatch)); | |
169 | ON_CALL(*this, exec(_, _, _, _, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_exec)); | |
170 | ON_CALL(*this, get_instance_id()).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_get_instance_id)); | |
171 | ON_CALL(*this, list_snaps(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_list_snaps)); | |
172 | ON_CALL(*this, list_watchers(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_list_watchers)); | |
173 | ON_CALL(*this, notify(_, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_notify)); | |
174 | ON_CALL(*this, read(_, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_read)); | |
175 | ON_CALL(*this, set_snap_read(_)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_set_snap_read)); | |
176 | ON_CALL(*this, sparse_read(_, _, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_sparse_read)); | |
177 | ON_CALL(*this, remove(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_remove)); | |
178 | ON_CALL(*this, selfmanaged_snap_create(_)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_selfmanaged_snap_create)); | |
179 | ON_CALL(*this, selfmanaged_snap_remove(_)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_selfmanaged_snap_remove)); | |
180 | ON_CALL(*this, selfmanaged_snap_rollback(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_selfmanaged_snap_rollback)); | |
181 | ON_CALL(*this, truncate(_,_,_)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_truncate)); | |
182 | ON_CALL(*this, write(_, _, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_write)); | |
183 | ON_CALL(*this, write_full(_, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_write_full)); | |
184 | } | |
185 | ||
186 | private: | |
187 | MockTestMemRadosClient *m_mock_client; | |
188 | TestMemRadosClient *m_client; | |
189 | }; | |
190 | ||
191 | } // namespace librados | |
192 | ||
193 | #endif // LIBRADOS_TEST_STUB_MOCK_TEST_MEM_IO_CTX_IMPL_H |