Skip to content

Commit

Permalink
Fix unittest_rbd_mirror
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorDenisov committed Jan 26, 2017
1 parent ff640a6 commit 091316d
Show file tree
Hide file tree
Showing 23 changed files with 234 additions and 114 deletions.
4 changes: 3 additions & 1 deletion src/test/librbd/mock/MockImageState.h
Expand Up @@ -6,6 +6,8 @@

#include <gmock/gmock.h>

#include "cls/rbd/cls_rbd_types.h"

class Context;

namespace librbd {
Expand All @@ -19,7 +21,7 @@ struct MockImageState {
MOCK_METHOD0(close, int());
MOCK_METHOD1(close, void(Context*));

MOCK_METHOD2(snap_set, void(const std::string &, Context*));
MOCK_METHOD3(snap_set, void(const std::string &, const cls::rbd::SnapshotNamespace &, Context*));

MOCK_METHOD1(prepare_lock, void(Context*));
MOCK_METHOD0(handle_prepare_lock_complete, void());
Expand Down
3 changes: 2 additions & 1 deletion src/test/librbd/mock/MockOperations.h
Expand Up @@ -33,7 +33,8 @@ struct MockOperations {
Context *on_finish,
uint64_t journal_op_tid,
bool skip_object_map));
MOCK_METHOD2(snap_remove, void(const std::string &snap_name,
MOCK_METHOD3(snap_remove, void(const std::string &snap_name,
const cls::rbd::SnapshotNamespace &snap_namespace,
Context *on_finish));
MOCK_METHOD3(execute_snap_remove, void(const std::string &snap_name,
const cls::rbd::SnapshotNamespace &snap_namespace,
Expand Down
Expand Up @@ -222,7 +222,8 @@ class TestMockImageReplayerCreateImageRequest : public TestMockFixture {
ictx->state->open(false);
EXPECT_EQ(0, ictx->operations->snap_create(snap_name.c_str(),
cls::rbd::UserSnapshotNamespace()));
EXPECT_EQ(0, ictx->operations->snap_protect(snap_name.c_str()));
EXPECT_EQ(0, ictx->operations->snap_protect(snap_name.c_str(),
cls::rbd::UserSnapshotNamespace()));
ictx->state->close();
}

Expand Down Expand Up @@ -291,8 +292,8 @@ class TestMockImageReplayerCreateImageRequest : public TestMockFixture {

void expect_snap_set(librbd::MockTestImageCtx &mock_image_ctx,
const std::string &snap_name, int r) {
EXPECT_CALL(*mock_image_ctx.state, snap_set(StrEq(snap_name), _))
.WillOnce(WithArg<1>(Invoke([this, r](Context *on_finish) {
EXPECT_CALL(*mock_image_ctx.state, snap_set(StrEq(snap_name), _, _))
.WillOnce(WithArg<2>(Invoke([this, r](Context *on_finish) {
m_threads->work_queue->queue(on_finish, r);
})));
}
Expand Down
Expand Up @@ -144,7 +144,7 @@ TEST_F(TestMockImageReplayerEventPreprocessor, PreprocessSnapRename) {
expect_image_refresh(mock_local_image_ctx, 0);
expect_update_client(mock_remote_journaler, 0);

mock_local_image_ctx.snap_ids = {{"snap", 6}};
mock_local_image_ctx.snap_ids = {{{cls::rbd::UserSnapshotNamespace(), "snap"}, 6}};
mock_local_image_ctx.snap_info = {
{6, librbd::SnapInfo{"snap", cls::rbd::UserSnapshotNamespace(), 0U, {}, 0U, 0U}}};
MockEventPreprocessor event_preprocessor(mock_local_image_ctx,
Expand Down Expand Up @@ -244,7 +244,7 @@ TEST_F(TestMockImageReplayerEventPreprocessor, PreprocessClientUpdateError) {
expect_image_refresh(mock_local_image_ctx, 0);
expect_update_client(mock_remote_journaler, -EINVAL);

mock_local_image_ctx.snap_ids = {{"snap", 6}};
mock_local_image_ctx.snap_ids = {{{cls::rbd::UserSnapshotNamespace(), "snap"}, 6}};
mock_local_image_ctx.snap_info = {
{6, librbd::SnapInfo{"snap", cls::rbd::UserSnapshotNamespace(), 0U, {}, 0U, 0U}}};
MockEventPreprocessor event_preprocessor(mock_local_image_ctx,
Expand Down
45 changes: 29 additions & 16 deletions src/test/rbd_mirror/image_sync/test_mock_ImageCopyRequest.cc
Expand Up @@ -107,10 +107,10 @@ class TestMockImageSyncImageCopyRequest : public TestMockFixture {
}

void expect_get_snap_id(librbd::MockTestImageCtx &mock_image_ctx) {
EXPECT_CALL(mock_image_ctx, get_snap_id(_))
.WillRepeatedly(Invoke([&mock_image_ctx](std::string snap_name) {
EXPECT_CALL(mock_image_ctx, get_snap_id(_, _))
.WillRepeatedly(Invoke([&mock_image_ctx](std::string snap_name, cls::rbd::SnapshotNamespace snap_namespace) {
assert(mock_image_ctx.image_ctx->snap_lock.is_locked());
return mock_image_ctx.image_ctx->get_snap_id(snap_name);
return mock_image_ctx.image_ctx->get_snap_id(snap_name, snap_namespace);
}));
}

Expand Down Expand Up @@ -206,7 +206,9 @@ class TestMockImageSyncImageCopyRequest : public TestMockFixture {

TEST_F(TestMockImageSyncImageCopyRequest, SimpleImage) {
ASSERT_EQ(0, create_snap("snap1"));
m_client_meta.sync_points = {{"snap1", boost::none}};
m_client_meta.sync_points = {{"snap1",
boost::none,
cls::rbd::UserSnapshotNamespace()}};

librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
Expand Down Expand Up @@ -237,7 +239,9 @@ TEST_F(TestMockImageSyncImageCopyRequest, SimpleImage) {

TEST_F(TestMockImageSyncImageCopyRequest, Throttled) {
ASSERT_EQ(0, create_snap("snap1"));
m_client_meta.sync_points = {{"snap1", boost::none}};
m_client_meta.sync_points = {{"snap1",
boost::none,
cls::rbd::UserSnapshotNamespace()}};

std::string update_sync_age;;
ASSERT_EQ(0, _rados->conf_get("rbd_mirror_sync_point_update_age", update_sync_age));
Expand Down Expand Up @@ -313,7 +317,7 @@ TEST_F(TestMockImageSyncImageCopyRequest, SnapshotSubset) {
ASSERT_EQ(0, create_snap("snap1"));
ASSERT_EQ(0, create_snap("snap2"));
ASSERT_EQ(0, create_snap("snap3"));
m_client_meta.sync_points = {{"snap3", "snap2", boost::none}};
m_client_meta.sync_points = {{"snap3", "snap2", boost::none, cls::rbd::UserSnapshotNamespace()}};

librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
Expand Down Expand Up @@ -350,8 +354,8 @@ TEST_F(TestMockImageSyncImageCopyRequest, SnapshotSubset) {
TEST_F(TestMockImageSyncImageCopyRequest, RestartCatchup) {
ASSERT_EQ(0, create_snap("snap1"));
ASSERT_EQ(0, create_snap("snap2"));
m_client_meta.sync_points = {{"snap1", boost::none},
{"snap2", "snap1", boost::none}};
m_client_meta.sync_points = {{"snap1", boost::none, cls::rbd::UserSnapshotNamespace()},
{"snap2", "snap1", boost::none, cls::rbd::UserSnapshotNamespace()}};

librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
Expand Down Expand Up @@ -383,7 +387,7 @@ TEST_F(TestMockImageSyncImageCopyRequest, RestartCatchup) {

TEST_F(TestMockImageSyncImageCopyRequest, RestartPartialSync) {
ASSERT_EQ(0, create_snap("snap1"));
m_client_meta.sync_points = {{"snap1", librbd::journal::MirrorPeerSyncPoint::ObjectNumber{0U}}};
m_client_meta.sync_points = {{"snap1", librbd::journal::MirrorPeerSyncPoint::ObjectNumber{0U}, cls::rbd::UserSnapshotNamespace()}};

librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
Expand Down Expand Up @@ -420,7 +424,7 @@ TEST_F(TestMockImageSyncImageCopyRequest, Cancel) {
} BOOST_SCOPE_EXIT_END;

ASSERT_EQ(0, create_snap("snap1"));
m_client_meta.sync_points = {{"snap1", boost::none}};
m_client_meta.sync_points = {{"snap1", boost::none, cls::rbd::UserSnapshotNamespace()}};

librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
Expand Down Expand Up @@ -466,7 +470,7 @@ TEST_F(TestMockImageSyncImageCopyRequest, Cancel_Inflight_Sync) {
} BOOST_SCOPE_EXIT_END;

ASSERT_EQ(0, create_snap("snap1"));
m_client_meta.sync_points = {{"snap1", boost::none}};
m_client_meta.sync_points = {{"snap1", boost::none, cls::rbd::UserSnapshotNamespace()}};

librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
Expand Down Expand Up @@ -514,7 +518,7 @@ TEST_F(TestMockImageSyncImageCopyRequest, Cancel_Inflight_Sync) {

TEST_F(TestMockImageSyncImageCopyRequest, Cancel1) {
ASSERT_EQ(0, create_snap("snap1"));
m_client_meta.sync_points = {{"snap1", boost::none}};
m_client_meta.sync_points = {{"snap1", boost::none, cls::rbd::UserSnapshotNamespace()}};

librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
Expand Down Expand Up @@ -545,7 +549,7 @@ TEST_F(TestMockImageSyncImageCopyRequest, Cancel1) {

TEST_F(TestMockImageSyncImageCopyRequest, MissingSnap) {
ASSERT_EQ(0, create_snap("snap1"));
m_client_meta.sync_points = {{"missing-snap", boost::none}};
m_client_meta.sync_points = {{"missing-snap", boost::none, cls::rbd::UserSnapshotNamespace()}};

librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
Expand All @@ -565,7 +569,10 @@ TEST_F(TestMockImageSyncImageCopyRequest, MissingSnap) {

TEST_F(TestMockImageSyncImageCopyRequest, MissingFromSnap) {
ASSERT_EQ(0, create_snap("snap1"));
m_client_meta.sync_points = {{"snap1", "missing-snap", boost::none}};
m_client_meta.sync_points = {{"snap1",
"missing-snap",
boost::none,
cls::rbd::UserSnapshotNamespace()}};

librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
Expand All @@ -587,7 +594,10 @@ TEST_F(TestMockImageSyncImageCopyRequest, EmptySnapMap) {
ASSERT_EQ(0, create_snap("snap1"));
ASSERT_EQ(0, create_snap("snap2"));
m_client_meta.snap_seqs = {{0, 0}};
m_client_meta.sync_points = {{"snap2", "snap1", boost::none}};
m_client_meta.sync_points = {{"snap2",
"snap1",
boost::none,
cls::rbd::UserSnapshotNamespace()}};

librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
Expand All @@ -609,7 +619,10 @@ TEST_F(TestMockImageSyncImageCopyRequest, EmptySnapSeqs) {
ASSERT_EQ(0, create_snap("snap1"));
ASSERT_EQ(0, create_snap("snap2"));
m_client_meta.snap_seqs = {};
m_client_meta.sync_points = {{"snap2", "snap1", boost::none}};
m_client_meta.sync_points = {{"snap2",
"snap1",
boost::none,
cls::rbd::UserSnapshotNamespace()}};

librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
Expand Down
22 changes: 16 additions & 6 deletions src/test/rbd_mirror/image_sync/test_mock_ObjectCopyRequest.cc
Expand Up @@ -223,13 +223,15 @@ class TestMockImageSyncObjectCopyRequest : public TestMockFixture {
librados::snap_t snap_id) {
auto it = std::find_if(image_ctx->snap_ids.begin(),
image_ctx->snap_ids.end(),
[snap_id](const std::pair<std::string, librados::snap_t> &pair) {
[snap_id](const std::pair<std::pair<cls::rbd::SnapshotNamespace,
std::string>,
librados::snap_t> &pair) {
return (pair.second == snap_id);
});
if (it == image_ctx->snap_ids.end()) {
return "";
}
return it->first;
return it->first.second;
}

int compare_objects() {
Expand All @@ -253,12 +255,16 @@ class TestMockImageSyncObjectCopyRequest : public TestMockFixture {
std::cout << "comparing '" << snap_name << " (" << remote_snap_id
<< " to " << local_snap_id << ")" << std::endl;

r = librbd::snap_set(m_remote_image_ctx, snap_name.c_str());
r = librbd::snap_set(m_remote_image_ctx,
snap_name.c_str(),
cls::rbd::UserSnapshotNamespace());
if (r < 0) {
return r;
}

r = librbd::snap_set(m_local_image_ctx, snap_name.c_str());
r = librbd::snap_set(m_local_image_ctx,
snap_name.c_str(),
cls::rbd::UserSnapshotNamespace());
if (r < 0) {
return r;
}
Expand All @@ -284,11 +290,15 @@ class TestMockImageSyncObjectCopyRequest : public TestMockFixture {
}
}

r = librbd::snap_set(m_remote_image_ctx, nullptr);
r = librbd::snap_set(m_remote_image_ctx,
nullptr,
cls::rbd::UserSnapshotNamespace());
if (r < 0) {
return r;
}
r = librbd::snap_set(m_local_image_ctx, nullptr);
r = librbd::snap_set(m_local_image_ctx,
nullptr,
cls::rbd::UserSnapshotNamespace());
if (r < 0) {
return r;
}
Expand Down

0 comments on commit 091316d

Please sign in to comment.