1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef LIBRADOS_TEST_STUB_MOCK_TEST_MEM_IO_CTX_IMPL_H
5 #define LIBRADOS_TEST_STUB_MOCK_TEST_MEM_IO_CTX_IMPL_H
7 #include "test/librados_test_stub/TestMemIoCtxImpl.h"
8 #include "test/librados_test_stub/TestMemCluster.h"
9 #include "gmock/gmock.h"
13 class MockTestMemRadosClient
;
15 class MockTestMemIoCtxImpl
: public TestMemIoCtxImpl
{
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
) {
26 MockTestMemRadosClient
*get_mock_rados_client() {
30 MOCK_METHOD0(clone
, TestIoCtxImpl
*());
31 TestIoCtxImpl
*do_clone() {
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());
39 MOCK_METHOD5(aio_notify
, void(const std::string
& o
, AioCompletionImpl
*c
,
40 bufferlist
& bl
, uint64_t timeout_ms
,
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
);
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
);
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
);
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
);
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
);
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
);
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
);
82 MOCK_METHOD4(cmpext
, int(const std::string
&, uint64_t, bufferlist
&,
84 int do_cmpext(const std::string
& oid
, uint64_t off
, bufferlist
& cmp_bl
,
86 return TestMemIoCtxImpl::cmpext(oid
, off
, cmp_bl
, snap_id
);
89 MOCK_METHOD8(exec
, int(const std::string
& oid
,
90 TestClassHandler
*handler
,
96 const SnapContext
&snapc
));
97 int do_exec(const std::string
& oid
, TestClassHandler
*handler
,
98 const char *cls
, const char *method
, bufferlist
& inbl
,
99 bufferlist
* outbl
, uint64_t snap_id
, const SnapContext
&snapc
) {
100 return TestMemIoCtxImpl::exec(oid
, handler
, cls
, method
, inbl
, outbl
,
104 MOCK_CONST_METHOD0(get_instance_id
, uint64_t());
105 uint64_t do_get_instance_id() const {
106 return TestMemIoCtxImpl::get_instance_id();
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
);
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
);
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
);
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
);
132 MOCK_METHOD6(sparse_read
, int(const std::string
& oid
,
135 std::map
<uint64_t, uint64_t> *m
,
136 bufferlist
*bl
, uint64_t));
137 int do_sparse_read(const std::string
& oid
, uint64_t off
, size_t len
,
138 std::map
<uint64_t, uint64_t> *m
, bufferlist
*bl
,
140 return TestMemIoCtxImpl::sparse_read(oid
, off
, len
, m
, bl
, snap_id
);
143 MOCK_METHOD6(read
, int(const std::string
& oid
,
146 bufferlist
*bl
, uint64_t snap_id
, uint64_t* objver
));
147 int do_read(const std::string
& oid
, size_t len
, uint64_t off
,
148 bufferlist
*bl
, uint64_t snap_id
, uint64_t* objver
) {
149 return TestMemIoCtxImpl::read(oid
, len
, off
, bl
, snap_id
, objver
);
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
);
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
);
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
);
167 MOCK_METHOD2(selfmanaged_snap_rollback
, int(const std::string
& oid
,
169 int do_selfmanaged_snap_rollback(const std::string
& oid
, uint64_t snap_id
) {
170 return TestMemIoCtxImpl::selfmanaged_snap_rollback(oid
, snap_id
);
173 MOCK_METHOD3(truncate
, int(const std::string
& oid
,
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
);
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
);
188 MOCK_METHOD3(write_full
, int(const std::string
& oid
,
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
);
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
);
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
);
212 void default_to_parent() {
213 using namespace ::testing
;
215 ON_CALL(*this, clone()).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_clone
));
216 ON_CALL(*this, aio_notify(_
, _
, _
, _
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_aio_notify
));
217 ON_CALL(*this, aio_operate(_
, _
, _
, _
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_aio_operate
));
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
));
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
));
222 ON_CALL(*this, create(_
, _
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_create
));
223 ON_CALL(*this, cmpext(_
, _
, _
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_cmpext
));
224 ON_CALL(*this, exec(_
, _
, _
, _
, _
, _
, _
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_exec
));
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
));
229 ON_CALL(*this, read(_
, _
, _
, _
, _
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_read
));
230 ON_CALL(*this, set_snap_read(_
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_set_snap_read
));
231 ON_CALL(*this, sparse_read(_
, _
, _
, _
, _
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_sparse_read
));
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
));
239 ON_CALL(*this, writesame(_
, _
, _
, _
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_writesame
));
240 ON_CALL(*this, zero(_
,_
,_
,_
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_zero
));
244 MockTestMemRadosClient
*m_mock_client
;
245 TestMemRadosClient
*m_client
;
248 } // namespace librados
250 #endif // LIBRADOS_TEST_STUB_MOCK_TEST_MEM_IO_CTX_IMPL_H