Skip to content

Commit

Permalink
tests: unit test case for librbd::operation::ResizeRequest
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dillaman <[email protected]>
  • Loading branch information
Jason Dillaman committed Jan 15, 2016
1 parent bf7a1f6 commit ce8fa3d
Show file tree
Hide file tree
Showing 6 changed files with 414 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/test/Makefile-client.am
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ unittest_librbd_SOURCES = \
test/librbd/object_map/test_mock_SnapshotRollbackRequest.cc \
test/librbd/object_map/test_mock_UnlockRequest.cc \
test/librbd/object_map/test_mock_UpdateRequest.cc \
test/librbd/operation/test_mock_ResizeRequest.cc \
test/librbd/operation/test_mock_SnapshotCreateRequest.cc \
test/librbd/operation/test_mock_SnapshotProtectRequest.cc \
test/librbd/operation/test_mock_SnapshotRemoveRequest.cc \
Expand Down
8 changes: 8 additions & 0 deletions src/test/librados_test_stub/MockTestMemIoCtxImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ class MockTestMemIoCtxImpl : public TestMemIoCtxImpl {
return TestMemIoCtxImpl::truncate(oid, size, snapc);
}

MOCK_METHOD5(write, int(const std::string& oid, bufferlist& bl, size_t len,
uint64_t off, const SnapContext &snapc));
int do_write(const std::string& oid, bufferlist& bl, size_t len, uint64_t off,
const SnapContext &snapc) {
return TestMemIoCtxImpl::write(oid, bl, len, off, snapc);
}

MOCK_METHOD3(write_full, int(const std::string& oid,
bufferlist& bl,
const SnapContext &snapc));
Expand All @@ -105,6 +112,7 @@ class MockTestMemIoCtxImpl : public TestMemIoCtxImpl {
ON_CALL(*this, selfmanaged_snap_create(_)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_selfmanaged_snap_create));
ON_CALL(*this, selfmanaged_snap_remove(_)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_selfmanaged_snap_remove));
ON_CALL(*this, truncate(_,_,_)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_truncate));
ON_CALL(*this, write(_, _, _, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_write));
ON_CALL(*this, write_full(_, _, _)).WillByDefault(Invoke(this, &MockTestMemIoCtxImpl::do_write_full));
}

Expand Down
6 changes: 6 additions & 0 deletions src/test/librbd/mock/MockImageCtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

namespace librbd {

namespace operation {
template <typename> class ResizeRequest;
}

struct MockImageCtx {
MockImageCtx(librbd::ImageCtx &image_ctx)
: image_ctx(&image_ctx),
Expand Down Expand Up @@ -106,6 +110,7 @@ struct MockImageCtx {
MOCK_METHOD1(flush, void(Context *));
MOCK_METHOD1(flush_copyup, void(Context *));

MOCK_METHOD1(invalidate_cache, void(Context *));
MOCK_METHOD1(shut_down_cache, void(Context *));

MOCK_CONST_METHOD1(test_features, bool(uint64_t test_features));
Expand Down Expand Up @@ -145,6 +150,7 @@ struct MockImageCtx {

ceph_file_layout layout;

xlist<operation::ResizeRequest<MockImageCtx>*> resize_reqs;
xlist<AsyncRequest<MockImageCtx>*> async_requests;
std::list<Context*> async_requests_waiters;

Expand Down
10 changes: 9 additions & 1 deletion src/test/librbd/mock/MockJournal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ struct MockJournal {
MOCK_METHOD1(close, void(Context *));

MOCK_METHOD0(allocate_op_tid, uint64_t());
MOCK_METHOD2(append_op_event, void(uint64_t, journal::EventEntry&));

MOCK_METHOD3(append_op_event_mock, void(uint64_t, const journal::EventEntry&,
Context *));
void append_op_event(uint64_t op_tid, journal::EventEntry &&event_entry,
Context *on_safe) {
// googlemock doesn't support move semantics
append_op_event_mock(op_tid, event_entry, on_safe);
}

MOCK_METHOD2(commit_op_event, void(uint64_t, int));
};

Expand Down
3 changes: 3 additions & 0 deletions src/test/librbd/mock/MockObjectMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ struct MockObjectMap {
MOCK_METHOD1(lock, void(Context *on_finish));
MOCK_METHOD1(unlock, void(Context *on_finish));

MOCK_METHOD3(aio_resize, void(uint64_t new_size, uint8_t default_object_state,
Context *on_finish));

MOCK_METHOD2(snapshot_add, void(uint64_t snap_id, Context *on_finish));
MOCK_METHOD2(snapshot_remove, void(uint64_t snap_id, Context *on_finish));
};
Expand Down
Loading

0 comments on commit ce8fa3d

Please sign in to comment.