]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/librados_test_stub/MockTestMemIoCtxImpl.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / test / librados_test_stub / MockTestMemIoCtxImpl.h
CommitLineData
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
11namespace librados {
12
13class MockTestMemRadosClient;
14
15class MockTestMemIoCtxImpl : public TestMemIoCtxImpl {
16public:
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
11fdf7f2
TL
30 MOCK_METHOD0(clone, TestIoCtxImpl*());
31 TestIoCtxImpl *do_clone() {
7c673cae
FG
32 TestIoCtxImpl *io_ctx_impl = new ::testing::NiceMock<MockTestMemIoCtxImpl>(
33 m_mock_client, m_client, get_pool_id(), get_pool_name(), get_pool());
34 io_ctx_impl->set_snap_read(get_snap_read());
35 io_ctx_impl->set_snap_context(get_snap_context());
36 return io_ctx_impl;
37 }
38
39 MOCK_METHOD5(aio_notify, void(const std::string& o, AioCompletionImpl *c,
40 bufferlist& bl, uint64_t timeout_ms,
41 bufferlist *pbl));
42 void do_aio_notify(const std::string& o, AioCompletionImpl *c, bufferlist& bl,
43 uint64_t timeout_ms, bufferlist *pbl) {
44 return TestMemIoCtxImpl::aio_notify(o, c, bl, timeout_ms, pbl);
45 }
46
9f95a23c
TL
47 MOCK_METHOD5(aio_operate, int(const std::string&, TestObjectOperationImpl&,
48 AioCompletionImpl*, SnapContext*, int));
49 int do_aio_operate(const std::string& o, TestObjectOperationImpl& ops,
50 AioCompletionImpl* c, SnapContext* snapc, int flags) {
51 return TestMemIoCtxImpl::aio_operate(o, ops, c, snapc, flags);
52 }
53
7c673cae
FG
54 MOCK_METHOD4(aio_watch, int(const std::string& o, AioCompletionImpl *c,
55 uint64_t *handle, librados::WatchCtx2 *ctx));
56 int do_aio_watch(const std::string& o, AioCompletionImpl *c,
57 uint64_t *handle, librados::WatchCtx2 *ctx) {
58 return TestMemIoCtxImpl::aio_watch(o, c, handle, ctx);
59 }
60
61 MOCK_METHOD2(aio_unwatch, int(uint64_t handle, AioCompletionImpl *c));
62 int do_aio_unwatch(uint64_t handle, AioCompletionImpl *c) {
63 return TestMemIoCtxImpl::aio_unwatch(handle, c);
64 }
65
f67539c2
TL
66 MOCK_METHOD2(assert_exists, int(const std::string &, uint64_t));
67 int do_assert_exists(const std::string &oid, uint64_t snap_id) {
68 return TestMemIoCtxImpl::assert_exists(oid, snap_id);
69 }
70
71 MOCK_METHOD2(assert_version, int(const std::string &, uint64_t));
72 int do_assert_version(const std::string &oid, uint64_t ver) {
73 return TestMemIoCtxImpl::assert_version(oid, ver);
b32b8144
FG
74 }
75
9f95a23c
TL
76 MOCK_METHOD3(create, int(const std::string&, bool, const SnapContext &));
77 int do_create(const std::string& oid, bool exclusive,
78 const SnapContext &snapc) {
79 return TestMemIoCtxImpl::create(oid, exclusive, snapc);
94b18763
FG
80 }
81
f67539c2
TL
82 MOCK_METHOD4(cmpext, int(const std::string&, uint64_t, bufferlist&,
83 uint64_t snap_id));
84 int do_cmpext(const std::string& oid, uint64_t off, bufferlist& cmp_bl,
85 uint64_t snap_id) {
86 return TestMemIoCtxImpl::cmpext(oid, off, cmp_bl, snap_id);
b32b8144
FG
87 }
88
f67539c2 89 MOCK_METHOD8(exec, int(const std::string& oid,
7c673cae
FG
90 TestClassHandler *handler,
91 const char *cls,
92 const char *method,
93 bufferlist& inbl,
94 bufferlist* outbl,
f67539c2 95 uint64_t snap_id,
7c673cae
FG
96 const SnapContext &snapc));
97 int do_exec(const std::string& oid, TestClassHandler *handler,
98 const char *cls, const char *method, bufferlist& inbl,
f67539c2 99 bufferlist* outbl, uint64_t snap_id, const SnapContext &snapc) {
7c673cae 100 return TestMemIoCtxImpl::exec(oid, handler, cls, method, inbl, outbl,
f67539c2 101 snap_id, snapc);
7c673cae
FG
102 }
103
104 MOCK_CONST_METHOD0(get_instance_id, uint64_t());
105 uint64_t do_get_instance_id() const {
106 return TestMemIoCtxImpl::get_instance_id();
107 }
108
109 MOCK_METHOD2(list_snaps, int(const std::string& o, snap_set_t *out_snaps));
110 int do_list_snaps(const std::string& o, snap_set_t *out_snaps) {
111 return TestMemIoCtxImpl::list_snaps(o, out_snaps);
112 }
113
114 MOCK_METHOD2(list_watchers, int(const std::string& o,
115 std::list<obj_watch_t> *out_watchers));
116 int do_list_watchers(const std::string& o,
117 std::list<obj_watch_t> *out_watchers) {
118 return TestMemIoCtxImpl::list_watchers(o, out_watchers);
119 }
120
121 MOCK_METHOD4(notify, int(const std::string& o, bufferlist& bl,
122 uint64_t timeout_ms, bufferlist *pbl));
123 int do_notify(const std::string& o, bufferlist& bl,
124 uint64_t timeout_ms, bufferlist *pbl) {
125 return TestMemIoCtxImpl::notify(o, bl, timeout_ms, pbl);
126 }
127
128 MOCK_METHOD1(set_snap_read, void(snap_t));
129 void do_set_snap_read(snap_t snap_id) {
130 return TestMemIoCtxImpl::set_snap_read(snap_id);
131 }
f67539c2 132 MOCK_METHOD6(sparse_read, int(const std::string& oid,
7c673cae
FG
133 uint64_t off,
134 uint64_t len,
135 std::map<uint64_t, uint64_t> *m,
f67539c2 136 bufferlist *bl, uint64_t));
7c673cae 137 int do_sparse_read(const std::string& oid, uint64_t off, size_t len,
f67539c2
TL
138 std::map<uint64_t, uint64_t> *m, bufferlist *bl,
139 uint64_t snap_id) {
140 return TestMemIoCtxImpl::sparse_read(oid, off, len, m, bl, snap_id);
7c673cae
FG
141 }
142
f67539c2 143 MOCK_METHOD6(read, int(const std::string& oid,
7c673cae
FG
144 size_t len,
145 uint64_t off,
f67539c2 146 bufferlist *bl, uint64_t snap_id, uint64_t* objver));
7c673cae 147 int do_read(const std::string& oid, size_t len, uint64_t off,
f67539c2
TL
148 bufferlist *bl, uint64_t snap_id, uint64_t* objver) {
149 return TestMemIoCtxImpl::read(oid, len, off, bl, snap_id, objver);
7c673cae
FG
150 }
151
152 MOCK_METHOD2(remove, int(const std::string& oid, const SnapContext &snapc));
153 int do_remove(const std::string& oid, const SnapContext &snapc) {
154 return TestMemIoCtxImpl::remove(oid, snapc);
155 }
156
157 MOCK_METHOD1(selfmanaged_snap_create, int(uint64_t *snap_id));
158 int do_selfmanaged_snap_create(uint64_t *snap_id) {
159 return TestMemIoCtxImpl::selfmanaged_snap_create(snap_id);
160 }
161
162 MOCK_METHOD1(selfmanaged_snap_remove, int(uint64_t snap_id));
163 int do_selfmanaged_snap_remove(uint64_t snap_id) {
164 return TestMemIoCtxImpl::selfmanaged_snap_remove(snap_id);
165 }
166
167 MOCK_METHOD2(selfmanaged_snap_rollback, int(const std::string& oid,
168 uint64_t snap_id));
169 int do_selfmanaged_snap_rollback(const std::string& oid, uint64_t snap_id) {
170 return TestMemIoCtxImpl::selfmanaged_snap_rollback(oid, snap_id);
171 }
172
173 MOCK_METHOD3(truncate, int(const std::string& oid,
174 uint64_t size,
175 const SnapContext &snapc));
176 int do_truncate(const std::string& oid, uint64_t size,
177 const SnapContext &snapc) {
178 return TestMemIoCtxImpl::truncate(oid, size, snapc);
179 }
180
181 MOCK_METHOD5(write, int(const std::string& oid, bufferlist& bl, size_t len,
182 uint64_t off, const SnapContext &snapc));
183 int do_write(const std::string& oid, bufferlist& bl, size_t len, uint64_t off,
184 const SnapContext &snapc) {
185 return TestMemIoCtxImpl::write(oid, bl, len, off, snapc);
186 }
187
188 MOCK_METHOD3(write_full, int(const std::string& oid,
189 bufferlist& bl,
190 const SnapContext &snapc));
191 int do_write_full(const std::string& oid, bufferlist& bl,
192 const SnapContext &snapc) {
193 return TestMemIoCtxImpl::write_full(oid, bl, snapc);
194 }
195
b32b8144
FG
196
197 MOCK_METHOD5(writesame, int(const std::string& oid, bufferlist& bl,
198 size_t len, uint64_t off,
199 const SnapContext &snapc));
200 int do_writesame(const std::string& oid, bufferlist& bl, size_t len,
201 uint64_t off, const SnapContext &snapc) {
202 return TestMemIoCtxImpl::writesame(oid, bl, len, off, snapc);
203 }
204
205 MOCK_METHOD4(zero, int(const std::string& oid, uint64_t offset,
206 uint64_t length, const SnapContext &snapc));
207 int do_zero(const std::string& oid, uint64_t offset,
208 uint64_t length, const SnapContext &snapc) {
209 return TestMemIoCtxImpl::zero(oid, offset, length, snapc);
210 }
211
7c673cae
FG
212 void default_to_parent() {
213 using namespace ::testing;
214
11fdf7f2 215 ON_CALL(*this, clone()).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_clone));
7c673cae 216 ON_CALL(*this, aio_notify(_, _, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_aio_notify));
9f95a23c 217 ON_CALL(*this, aio_operate(_, _, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_aio_operate));
7c673cae
FG
218 ON_CALL(*this, aio_watch(_, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_aio_watch));
219 ON_CALL(*this, aio_unwatch(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_aio_unwatch));
f67539c2
TL
220 ON_CALL(*this, assert_exists(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_assert_exists));
221 ON_CALL(*this, assert_version(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_assert_version));
9f95a23c 222 ON_CALL(*this, create(_, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_create));
f67539c2
TL
223 ON_CALL(*this, cmpext(_, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_cmpext));
224 ON_CALL(*this, exec(_, _, _, _, _, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_exec));
7c673cae
FG
225 ON_CALL(*this, get_instance_id()).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_get_instance_id));
226 ON_CALL(*this, list_snaps(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_list_snaps));
227 ON_CALL(*this, list_watchers(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_list_watchers));
228 ON_CALL(*this, notify(_, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_notify));
f67539c2 229 ON_CALL(*this, read(_, _, _, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_read));
7c673cae 230 ON_CALL(*this, set_snap_read(_)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_set_snap_read));
f67539c2 231 ON_CALL(*this, sparse_read(_, _, _, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_sparse_read));
7c673cae
FG
232 ON_CALL(*this, remove(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_remove));
233 ON_CALL(*this, selfmanaged_snap_create(_)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_selfmanaged_snap_create));
234 ON_CALL(*this, selfmanaged_snap_remove(_)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_selfmanaged_snap_remove));
235 ON_CALL(*this, selfmanaged_snap_rollback(_, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_selfmanaged_snap_rollback));
236 ON_CALL(*this, truncate(_,_,_)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_truncate));
237 ON_CALL(*this, write(_, _, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_write));
238 ON_CALL(*this, write_full(_, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_write_full));
b32b8144
FG
239 ON_CALL(*this, writesame(_, _, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_writesame));
240 ON_CALL(*this, zero(_,_,_,_)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_zero));
7c673cae
FG
241 }
242
243private:
244 MockTestMemRadosClient *m_mock_client;
245 TestMemRadosClient *m_client;
246};
247
248} // namespace librados
249
250#endif // LIBRADOS_TEST_STUB_MOCK_TEST_MEM_IO_CTX_IMPL_H