Skip to content

Commit

Permalink
rbd-mirror: fix the unittest for new CloneRequest
Browse files Browse the repository at this point in the history
Signed-off-by: Dongsheng Yang <[email protected]>
  • Loading branch information
yangdongsheng committed Mar 16, 2017
1 parent 372e848 commit 8283cb5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 90 deletions.
102 changes: 47 additions & 55 deletions src/test/rbd_mirror/image_replayer/test_mock_CreateImageRequest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "tools/rbd_mirror/image_replayer/OpenImageRequest.h"
#include "tools/rbd_mirror/image_replayer/OpenLocalImageRequest.h"
#include "librbd/image/CreateRequest.h"
#include "tools/rbd_mirror/image_replayer/Utils.h"
#include "librbd/image/CloneRequest.h"
#include "tools/rbd_mirror/Threads.h"

namespace librbd {
Expand Down Expand Up @@ -67,50 +67,44 @@ struct CreateRequest<librbd::MockTestImageCtx> {
CreateRequest<librbd::MockTestImageCtx>*
CreateRequest<librbd::MockTestImageCtx>::s_instance = nullptr;

} // namespace image
} // namespace librbd

namespace rbd {
namespace mirror {
namespace image_replayer {
template<>
struct CloneRequest<librbd::MockTestImageCtx> {
static CloneRequest *s_instance;
Context *on_finish = nullptr;

struct CreateCloneImage {
static CreateCloneImage *s_instance;
static CreateCloneImage *get_instance() {
static CloneRequest *create(librbd::MockTestImageCtx *p_imctx,
IoCtx &c_ioctx, const std::string &c_name,
ImageOptions c_options,
const std::string &non_primary_global_image_id,
const std::string &primary_mirror_uuid,
MockContextWQ *op_work_queue, Context *on_finish) {
assert(s_instance != nullptr);
s_instance->on_finish = on_finish;
s_instance->construct(p_imctx);
return s_instance;
}

CreateCloneImage() {
assert(s_instance == nullptr);
CloneRequest() {
s_instance = this;
}
~CreateCloneImage() {

~CloneRequest() {
s_instance = nullptr;
}

MOCK_METHOD3(clone, int(const std::string &image_name,
const std::string &non_primary_global_image_id,
const std::string &primary_mirror_uuid));
MOCK_METHOD0(send, void());
MOCK_METHOD1(construct, void(librbd::MockTestImageCtx *p_imctx));
};

CreateCloneImage *CreateCloneImage::s_instance = nullptr;

namespace utils {
CloneRequest<librbd::MockTestImageCtx>*
CloneRequest<librbd::MockTestImageCtx>::s_instance = nullptr;

template <>
int clone_image<librbd::MockTestImageCtx>(librbd::MockTestImageCtx *p_imctx,
librados::IoCtx& c_ioctx,
const char *c_name,
librbd::ImageOptions& c_opts,
const std::string &non_primary_global_image_id,
const std::string &remote_mirror_uuid) {
return CreateCloneImage::get_instance()->clone(c_name,
non_primary_global_image_id,
remote_mirror_uuid);
}
} // namespace image
} // namespace librbd

} // namespace utils
namespace rbd {
namespace mirror {
namespace image_replayer {

template<>
struct CloseImageRequest<librbd::MockTestImageCtx> {
Expand Down Expand Up @@ -199,6 +193,7 @@ MATCHER_P(IsSameIoCtx, io_ctx, "") {
class TestMockImageReplayerCreateImageRequest : public TestMockFixture {
public:
typedef librbd::image::CreateRequest<librbd::MockTestImageCtx> MockCreateRequest;
typedef librbd::image::CloneRequest<librbd::MockTestImageCtx> MockCloneRequest;
typedef CreateImageRequest<librbd::MockTestImageCtx> MockCreateImageRequest;
typedef OpenImageRequest<librbd::MockTestImageCtx> MockOpenImageRequest;
typedef CloseImageRequest<librbd::MockTestImageCtx> MockCloseImageRequest;
Expand Down Expand Up @@ -295,13 +290,14 @@ class TestMockImageReplayerCreateImageRequest : public TestMockFixture {
})));
}

void expect_clone_image(CreateCloneImage &create_clone_image,
const std::string &local_image_name,
const std::string &global_image_id,
const std::string &remote_mirror_uuid, int r) {
EXPECT_CALL(create_clone_image, clone(local_image_name, global_image_id,
remote_mirror_uuid))
.WillOnce(Return(r));
void expect_clone_image(MockCloneRequest &mock_clone_request,
librbd::MockTestImageCtx &mock_parent_imctx,
int r) {
EXPECT_CALL(mock_clone_request, construct(&mock_parent_imctx));
EXPECT_CALL(mock_clone_request, send())
.WillOnce(Invoke([this, &mock_clone_request, r]() {
m_threads->work_queue->queue(mock_clone_request.on_finish, r);
}));
}

void expect_close_image(MockCloseImageRequest &mock_close_image_request,
Expand Down Expand Up @@ -373,7 +369,7 @@ TEST_F(TestMockImageReplayerCreateImageRequest, Clone) {
librbd::MockTestImageCtx mock_remote_parent_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_parent_image_ctx(*local_image_ctx);
librbd::MockTestImageCtx mock_remote_clone_image_ctx(*remote_clone_image_ctx);
CreateCloneImage create_clone_image;
MockCloneRequest mock_clone_request;
MockOpenImageRequest mock_open_image_request;
MockCloseImageRequest mock_close_image_request;

Expand All @@ -388,8 +384,7 @@ TEST_F(TestMockImageReplayerCreateImageRequest, Clone) {
expect_open_image(mock_open_image_request, m_local_io_ctx,
"local parent id", mock_local_parent_image_ctx, 0);
expect_snap_set(mock_local_parent_image_ctx, "snap", 0);
expect_clone_image(create_clone_image, "image name", "global uuid",
"remote uuid", 0);
expect_clone_image(mock_clone_request, mock_local_parent_image_ctx, 0);
expect_close_image(mock_close_image_request, mock_local_parent_image_ctx, 0);
expect_close_image(mock_close_image_request, mock_remote_parent_image_ctx, 0);

Expand All @@ -411,7 +406,7 @@ TEST_F(TestMockImageReplayerCreateImageRequest, CloneGetGlobalImageIdError) {
&remote_clone_image_ctx));

librbd::MockTestImageCtx mock_remote_clone_image_ctx(*remote_clone_image_ctx);
CreateCloneImage create_clone_image;
MockCloneRequest mock_clone_request;

InSequence seq;
expect_ioctx_create(m_remote_io_ctx);
Expand All @@ -436,7 +431,7 @@ TEST_F(TestMockImageReplayerCreateImageRequest, CloneGetLocalParentImageIdError)
&remote_clone_image_ctx));

librbd::MockTestImageCtx mock_remote_clone_image_ctx(*remote_clone_image_ctx);
CreateCloneImage create_clone_image;
MockCloneRequest mock_clone_request;

InSequence seq;
expect_ioctx_create(m_remote_io_ctx);
Expand All @@ -463,7 +458,7 @@ TEST_F(TestMockImageReplayerCreateImageRequest, CloneOpenRemoteParentError) {

librbd::MockTestImageCtx mock_remote_parent_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_remote_clone_image_ctx(*remote_clone_image_ctx);
CreateCloneImage create_clone_image;
MockCloneRequest mock_clone_request;
MockOpenImageRequest mock_open_image_request;

InSequence seq;
Expand Down Expand Up @@ -500,7 +495,7 @@ TEST_F(TestMockImageReplayerCreateImageRequest, CloneOpenLocalParentError) {
librbd::MockTestImageCtx mock_remote_parent_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_parent_image_ctx(*local_image_ctx);
librbd::MockTestImageCtx mock_remote_clone_image_ctx(*remote_clone_image_ctx);
CreateCloneImage create_clone_image;
MockCloneRequest mock_clone_request;
MockOpenImageRequest mock_open_image_request;
MockCloseImageRequest mock_close_image_request;

Expand Down Expand Up @@ -541,7 +536,7 @@ TEST_F(TestMockImageReplayerCreateImageRequest, CloneSnapSetError) {
librbd::MockTestImageCtx mock_remote_parent_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_parent_image_ctx(*local_image_ctx);
librbd::MockTestImageCtx mock_remote_clone_image_ctx(*remote_clone_image_ctx);
CreateCloneImage create_clone_image;
MockCloneRequest mock_clone_request;
MockOpenImageRequest mock_open_image_request;
MockCloseImageRequest mock_close_image_request;

Expand Down Expand Up @@ -584,7 +579,7 @@ TEST_F(TestMockImageReplayerCreateImageRequest, CloneError) {
librbd::MockTestImageCtx mock_remote_parent_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_parent_image_ctx(*local_image_ctx);
librbd::MockTestImageCtx mock_remote_clone_image_ctx(*remote_clone_image_ctx);
CreateCloneImage create_clone_image;
MockCloneRequest mock_clone_request;
MockOpenImageRequest mock_open_image_request;
MockCloseImageRequest mock_close_image_request;

Expand All @@ -599,8 +594,7 @@ TEST_F(TestMockImageReplayerCreateImageRequest, CloneError) {
expect_open_image(mock_open_image_request, m_local_io_ctx,
"local parent id", mock_local_parent_image_ctx, 0);
expect_snap_set(mock_local_parent_image_ctx, "snap", 0);
expect_clone_image(create_clone_image, "image name", "global uuid",
"remote uuid", -EINVAL);
expect_clone_image(mock_clone_request, mock_local_parent_image_ctx, -EINVAL);
expect_close_image(mock_close_image_request, mock_local_parent_image_ctx, 0);
expect_close_image(mock_close_image_request, mock_remote_parent_image_ctx, 0);

Expand Down Expand Up @@ -629,7 +623,7 @@ TEST_F(TestMockImageReplayerCreateImageRequest, CloneLocalParentCloseError) {
librbd::MockTestImageCtx mock_remote_parent_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_parent_image_ctx(*local_image_ctx);
librbd::MockTestImageCtx mock_remote_clone_image_ctx(*remote_clone_image_ctx);
CreateCloneImage create_clone_image;
MockCloneRequest mock_clone_request;
MockOpenImageRequest mock_open_image_request;
MockCloseImageRequest mock_close_image_request;

Expand All @@ -644,8 +638,7 @@ TEST_F(TestMockImageReplayerCreateImageRequest, CloneLocalParentCloseError) {
expect_open_image(mock_open_image_request, m_local_io_ctx,
"local parent id", mock_local_parent_image_ctx, 0);
expect_snap_set(mock_local_parent_image_ctx, "snap", 0);
expect_clone_image(create_clone_image, "image name", "global uuid",
"remote uuid", 0);
expect_clone_image(mock_clone_request, mock_local_parent_image_ctx, 0);
expect_close_image(mock_close_image_request, mock_local_parent_image_ctx, -EINVAL);
expect_close_image(mock_close_image_request, mock_remote_parent_image_ctx, 0);

Expand Down Expand Up @@ -674,7 +667,7 @@ TEST_F(TestMockImageReplayerCreateImageRequest, CloneRemoteParentCloseError) {
librbd::MockTestImageCtx mock_remote_parent_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_parent_image_ctx(*local_image_ctx);
librbd::MockTestImageCtx mock_remote_clone_image_ctx(*remote_clone_image_ctx);
CreateCloneImage create_clone_image;
MockCloneRequest mock_clone_request;
MockOpenImageRequest mock_open_image_request;
MockCloseImageRequest mock_close_image_request;

Expand All @@ -689,8 +682,7 @@ TEST_F(TestMockImageReplayerCreateImageRequest, CloneRemoteParentCloseError) {
expect_open_image(mock_open_image_request, m_local_io_ctx,
"local parent id", mock_local_parent_image_ctx, 0);
expect_snap_set(mock_local_parent_image_ctx, "snap", 0);
expect_clone_image(create_clone_image, "image name", "global uuid",
"remote uuid", 0);
expect_clone_image(mock_clone_request, mock_local_parent_image_ctx, 0);
expect_close_image(mock_close_image_request, mock_local_parent_image_ctx, 0);
expect_close_image(mock_close_image_request, mock_remote_parent_image_ctx, -EINVAL);

Expand Down
35 changes: 0 additions & 35 deletions src/tools/rbd_mirror/image_replayer/Utils.h

This file was deleted.

0 comments on commit 8283cb5

Please sign in to comment.