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