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_METHOD7(exec
, int(const std::string
& oid
,
59 TestClassHandler
*handler
,
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
,
72 MOCK_CONST_METHOD0(get_instance_id
, uint64_t());
73 uint64_t do_get_instance_id() const {
74 return TestMemIoCtxImpl::get_instance_id();
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
);
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
);
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
);
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
);
100 MOCK_METHOD5(sparse_read
, int(const std::string
& oid
,
103 std::map
<uint64_t, uint64_t> *m
,
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
);
110 MOCK_METHOD4(read
, int(const std::string
& oid
,
114 int do_read(const std::string
& oid
, size_t len
, uint64_t off
,
116 return TestMemIoCtxImpl::read(oid
, len
, off
, bl
);
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
);
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
);
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
);
134 MOCK_METHOD2(selfmanaged_snap_rollback
, int(const std::string
& oid
,
136 int do_selfmanaged_snap_rollback(const std::string
& oid
, uint64_t snap_id
) {
137 return TestMemIoCtxImpl::selfmanaged_snap_rollback(oid
, snap_id
);
140 MOCK_METHOD3(truncate
, int(const std::string
& oid
,
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
);
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
);
155 MOCK_METHOD3(write_full
, int(const std::string
& oid
,
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
);
163 void default_to_parent() {
164 using namespace ::testing
;
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
));
187 MockTestMemRadosClient
*m_mock_client
;
188 TestMemRadosClient
*m_client
;
191 } // namespace librados
193 #endif // LIBRADOS_TEST_STUB_MOCK_TEST_MEM_IO_CTX_IMPL_H