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 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());
38 MOCK_METHOD5(aio_notify
, void(const std::string
& o
, AioCompletionImpl
*c
,
39 bufferlist
& bl
, uint64_t timeout_ms
,
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
);
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
);
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
);
58 MOCK_METHOD1(assert_exists
, int(const std::string
&));
59 int do_assert_exists(const std::string
&oid
) {
60 return TestMemIoCtxImpl::assert_exists(oid
);
63 MOCK_METHOD3(cmpext
, int(const std::string
&, uint64_t, bufferlist
&));
64 int do_cmpext(const std::string
& oid
, uint64_t off
, bufferlist
& cmp_bl
) {
65 return TestMemIoCtxImpl::cmpext(oid
, off
, cmp_bl
);
68 MOCK_METHOD7(exec
, int(const std::string
& oid
,
69 TestClassHandler
*handler
,
74 const SnapContext
&snapc
));
75 int do_exec(const std::string
& oid
, TestClassHandler
*handler
,
76 const char *cls
, const char *method
, bufferlist
& inbl
,
77 bufferlist
* outbl
, const SnapContext
&snapc
) {
78 return TestMemIoCtxImpl::exec(oid
, handler
, cls
, method
, inbl
, outbl
,
82 MOCK_CONST_METHOD0(get_instance_id
, uint64_t());
83 uint64_t do_get_instance_id() const {
84 return TestMemIoCtxImpl::get_instance_id();
87 MOCK_METHOD2(list_snaps
, int(const std::string
& o
, snap_set_t
*out_snaps
));
88 int do_list_snaps(const std::string
& o
, snap_set_t
*out_snaps
) {
89 return TestMemIoCtxImpl::list_snaps(o
, out_snaps
);
92 MOCK_METHOD2(list_watchers
, int(const std::string
& o
,
93 std::list
<obj_watch_t
> *out_watchers
));
94 int do_list_watchers(const std::string
& o
,
95 std::list
<obj_watch_t
> *out_watchers
) {
96 return TestMemIoCtxImpl::list_watchers(o
, out_watchers
);
99 MOCK_METHOD4(notify
, int(const std::string
& o
, bufferlist
& bl
,
100 uint64_t timeout_ms
, bufferlist
*pbl
));
101 int do_notify(const std::string
& o
, bufferlist
& bl
,
102 uint64_t timeout_ms
, bufferlist
*pbl
) {
103 return TestMemIoCtxImpl::notify(o
, bl
, timeout_ms
, pbl
);
106 MOCK_METHOD1(set_snap_read
, void(snap_t
));
107 void do_set_snap_read(snap_t snap_id
) {
108 return TestMemIoCtxImpl::set_snap_read(snap_id
);
110 MOCK_METHOD5(sparse_read
, int(const std::string
& oid
,
113 std::map
<uint64_t, uint64_t> *m
,
115 int do_sparse_read(const std::string
& oid
, uint64_t off
, size_t len
,
116 std::map
<uint64_t, uint64_t> *m
, bufferlist
*bl
){
117 return TestMemIoCtxImpl::sparse_read(oid
, off
, len
, m
, bl
);
120 MOCK_METHOD4(read
, int(const std::string
& oid
,
124 int do_read(const std::string
& oid
, size_t len
, uint64_t off
,
126 return TestMemIoCtxImpl::read(oid
, len
, off
, bl
);
129 MOCK_METHOD2(remove
, int(const std::string
& oid
, const SnapContext
&snapc
));
130 int do_remove(const std::string
& oid
, const SnapContext
&snapc
) {
131 return TestMemIoCtxImpl::remove(oid
, snapc
);
134 MOCK_METHOD1(selfmanaged_snap_create
, int(uint64_t *snap_id
));
135 int do_selfmanaged_snap_create(uint64_t *snap_id
) {
136 return TestMemIoCtxImpl::selfmanaged_snap_create(snap_id
);
139 MOCK_METHOD1(selfmanaged_snap_remove
, int(uint64_t snap_id
));
140 int do_selfmanaged_snap_remove(uint64_t snap_id
) {
141 return TestMemIoCtxImpl::selfmanaged_snap_remove(snap_id
);
144 MOCK_METHOD2(selfmanaged_snap_rollback
, int(const std::string
& oid
,
146 int do_selfmanaged_snap_rollback(const std::string
& oid
, uint64_t snap_id
) {
147 return TestMemIoCtxImpl::selfmanaged_snap_rollback(oid
, snap_id
);
150 MOCK_METHOD3(truncate
, int(const std::string
& oid
,
152 const SnapContext
&snapc
));
153 int do_truncate(const std::string
& oid
, uint64_t size
,
154 const SnapContext
&snapc
) {
155 return TestMemIoCtxImpl::truncate(oid
, size
, snapc
);
158 MOCK_METHOD5(write
, int(const std::string
& oid
, bufferlist
& bl
, size_t len
,
159 uint64_t off
, const SnapContext
&snapc
));
160 int do_write(const std::string
& oid
, bufferlist
& bl
, size_t len
, uint64_t off
,
161 const SnapContext
&snapc
) {
162 return TestMemIoCtxImpl::write(oid
, bl
, len
, off
, snapc
);
165 MOCK_METHOD3(write_full
, int(const std::string
& oid
,
167 const SnapContext
&snapc
));
168 int do_write_full(const std::string
& oid
, bufferlist
& bl
,
169 const SnapContext
&snapc
) {
170 return TestMemIoCtxImpl::write_full(oid
, bl
, snapc
);
174 MOCK_METHOD5(writesame
, int(const std::string
& oid
, bufferlist
& bl
,
175 size_t len
, uint64_t off
,
176 const SnapContext
&snapc
));
177 int do_writesame(const std::string
& oid
, bufferlist
& bl
, size_t len
,
178 uint64_t off
, const SnapContext
&snapc
) {
179 return TestMemIoCtxImpl::writesame(oid
, bl
, len
, off
, snapc
);
182 MOCK_METHOD4(zero
, int(const std::string
& oid
, uint64_t offset
,
183 uint64_t length
, const SnapContext
&snapc
));
184 int do_zero(const std::string
& oid
, uint64_t offset
,
185 uint64_t length
, const SnapContext
&snapc
) {
186 return TestMemIoCtxImpl::zero(oid
, offset
, length
, snapc
);
189 void default_to_parent() {
190 using namespace ::testing
;
192 ON_CALL(*this, aio_notify(_
, _
, _
, _
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_aio_notify
));
193 ON_CALL(*this, aio_watch(_
, _
, _
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_aio_watch
));
194 ON_CALL(*this, aio_unwatch(_
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_aio_unwatch
));
195 ON_CALL(*this, assert_exists(_
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_assert_exists
));
196 ON_CALL(*this, cmpext(_
,_
,_
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_cmpext
));
197 ON_CALL(*this, exec(_
, _
, _
, _
, _
, _
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_exec
));
198 ON_CALL(*this, get_instance_id()).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_get_instance_id
));
199 ON_CALL(*this, list_snaps(_
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_list_snaps
));
200 ON_CALL(*this, list_watchers(_
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_list_watchers
));
201 ON_CALL(*this, notify(_
, _
, _
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_notify
));
202 ON_CALL(*this, read(_
, _
, _
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_read
));
203 ON_CALL(*this, set_snap_read(_
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_set_snap_read
));
204 ON_CALL(*this, sparse_read(_
, _
, _
, _
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_sparse_read
));
205 ON_CALL(*this, remove(_
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_remove
));
206 ON_CALL(*this, selfmanaged_snap_create(_
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_selfmanaged_snap_create
));
207 ON_CALL(*this, selfmanaged_snap_remove(_
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_selfmanaged_snap_remove
));
208 ON_CALL(*this, selfmanaged_snap_rollback(_
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_selfmanaged_snap_rollback
));
209 ON_CALL(*this, truncate(_
,_
,_
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_truncate
));
210 ON_CALL(*this, write(_
, _
, _
, _
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_write
));
211 ON_CALL(*this, write_full(_
, _
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_write_full
));
212 ON_CALL(*this, writesame(_
, _
, _
, _
, _
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_writesame
));
213 ON_CALL(*this, zero(_
,_
,_
,_
)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_zero
));
217 MockTestMemRadosClient
*m_mock_client
;
218 TestMemRadosClient
*m_client
;
221 } // namespace librados
223 #endif // LIBRADOS_TEST_STUB_MOCK_TEST_MEM_IO_CTX_IMPL_H