summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorJason Dillaman <dillaman@redhat.com>2020-01-08 05:44:25 +0100
committerJason Dillaman <dillaman@redhat.com>2020-01-09 16:48:52 +0100
commita6d1d1226277eba4fcf71560865502b5673ed541 (patch)
treee818d33b922c7914484b5a840b74a8cb6602d6db /src/test
parentrbd-mirror: helper abstraction layer for image sync points (diff)
downloadceph-a6d1d1226277eba4fcf71560865502b5673ed541.tar.xz
ceph-a6d1d1226277eba4fcf71560865502b5673ed541.zip
rbd-mirror: switch image sync to use abstract sync point handler
This removes all journal-specific code from the image sync path. Signed-off-by: Jason Dillaman <dillaman@redhat.com>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc50
-rw-r--r--src/test/rbd_mirror/image_sync/test_mock_SyncPointCreateRequest.cc108
-rw-r--r--src/test/rbd_mirror/image_sync/test_mock_SyncPointPruneRequest.cc261
-rw-r--r--src/test/rbd_mirror/mock/image_sync/MockSyncPointHandler.h29
-rw-r--r--src/test/rbd_mirror/test_ImageSync.cc20
-rw-r--r--src/test/rbd_mirror/test_mock_ImageSync.cc146
6 files changed, 384 insertions, 230 deletions
diff --git a/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc b/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc
index 5b3bbb4f901..ee83b6a5121 100644
--- a/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc
+++ b/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc
@@ -12,12 +12,15 @@
#include "tools/rbd_mirror/image_replayer/OpenLocalImageRequest.h"
#include "tools/rbd_mirror/image_replayer/PrepareLocalImageRequest.h"
#include "tools/rbd_mirror/image_replayer/PrepareRemoteImageRequest.h"
+#include "tools/rbd_mirror/image_replayer/StateBuilder.h"
#include "tools/rbd_mirror/image_replayer/journal/CreateLocalImageRequest.h"
#include "tools/rbd_mirror/image_replayer/journal/PrepareReplayRequest.h"
+#include "tools/rbd_mirror/image_replayer/journal/StateBuilder.h"
#include "test/journal/mock/MockJournaler.h"
#include "test/librados_test_stub/MockTestMemIoCtxImpl.h"
#include "test/librbd/mock/MockImageCtx.h"
#include "test/librbd/mock/MockJournal.h"
+#include "test/rbd_mirror/mock/image_sync/MockSyncPointHandler.h"
namespace librbd {
@@ -99,13 +102,13 @@ struct ImageSync<librbd::MockTestImageCtx> {
Context *on_finish = nullptr;
static ImageSync* create(
+ Threads<librbd::MockTestImageCtx>* threads,
librbd::MockTestImageCtx *local_image_ctx,
librbd::MockTestImageCtx *remote_image_ctx,
- SafeTimer *timer, ceph::mutex *timer_lock,
- const std::string &mirror_uuid, ::journal::MockJournaler *journaler,
- librbd::journal::MirrorPeerClientMeta *client_meta, ContextWQ *work_queue,
+ const std::string &local_mirror_uuid,
+ image_sync::SyncPointHandler* sync_point_handler,
InstanceWatcher<librbd::MockTestImageCtx> *instance_watcher,
- Context *on_finish, ProgressContext *progress_ctx) {
+ ProgressContext *progress_ctx, Context *on_finish) {
ceph_assert(s_instance != nullptr);
s_instance->on_finish = on_finish;
return s_instance;
@@ -292,6 +295,16 @@ struct PrepareRemoteImageRequest<librbd::MockTestImageCtx> {
MOCK_METHOD0(send, void());
};
+template<>
+struct StateBuilder<librbd::MockTestImageCtx> {
+ virtual ~StateBuilder() {}
+
+ void destroy_sync_point_handler() {
+ }
+ void destroy() {
+ }
+};
+
CloseImageRequest<librbd::MockTestImageCtx>*
CloseImageRequest<librbd::MockTestImageCtx>::s_instance = nullptr;
OpenImageRequest<librbd::MockTestImageCtx>*
@@ -376,10 +389,36 @@ struct PrepareReplayRequest<librbd::MockTestImageCtx> {
MOCK_METHOD0(send, void());
};
+template<>
+struct StateBuilder<librbd::MockTestImageCtx>
+ : image_replayer::StateBuilder<librbd::MockTestImageCtx>{
+ static StateBuilder* s_instance;
+
+ ::journal::MockJournaler* remote_journaler = nullptr;
+ librbd::journal::MirrorPeerClientMeta remote_client_meta;
+
+ image_sync::MockSyncPointHandler mock_sync_point_handler;
+
+ static StateBuilder* create(const std::string&) {
+ ceph_assert(s_instance != nullptr);
+ return s_instance;
+ }
+
+ image_sync::MockSyncPointHandler* create_sync_point_handler() {
+ return &mock_sync_point_handler;
+ }
+
+ StateBuilder() {
+ s_instance = this;
+ }
+};
+
CreateLocalImageRequest<librbd::MockTestImageCtx>*
CreateLocalImageRequest<librbd::MockTestImageCtx>::s_instance = nullptr;
PrepareReplayRequest<librbd::MockTestImageCtx>*
PrepareReplayRequest<librbd::MockTestImageCtx>::s_instance = nullptr;
+StateBuilder<librbd::MockTestImageCtx>*
+ StateBuilder<librbd::MockTestImageCtx>::s_instance = nullptr;
} // namespace journal
} // namespace image_replayer
@@ -419,6 +458,7 @@ public:
typedef PrepareRemoteImageRequest<librbd::MockTestImageCtx> MockPrepareRemoteImageRequest;
typedef journal::CreateLocalImageRequest<librbd::MockTestImageCtx> MockCreateLocalImageRequest;
typedef journal::PrepareReplayRequest<librbd::MockTestImageCtx> MockPrepareReplayRequest;
+ typedef journal::StateBuilder<librbd::MockTestImageCtx> MockStateBuilder;
typedef librbd::mirror::GetInfoRequest<librbd::MockTestImageCtx> MockGetMirrorInfoRequest;
typedef std::list<cls::journal::Tag> Tags;
@@ -1047,6 +1087,7 @@ TEST_F(TestMockImageReplayerBootstrapRequest, PrepareReplaySyncing) {
expect_prepare_replay(mock_prepare_replay_request, false, true, 0);
// image sync
+ MockStateBuilder mock_state_builder;
MockImageSync mock_image_sync;
expect_image_sync(mock_image_sync, 0);
@@ -1167,6 +1208,7 @@ TEST_F(TestMockImageReplayerBootstrapRequest, ImageSyncError) {
expect_prepare_replay(mock_prepare_replay_request, false, true, 0);
// image sync
+ MockStateBuilder mock_state_builder;
MockImageSync mock_image_sync;
expect_image_sync(mock_image_sync, -EINVAL);
diff --git a/src/test/rbd_mirror/image_sync/test_mock_SyncPointCreateRequest.cc b/src/test/rbd_mirror/image_sync/test_mock_SyncPointCreateRequest.cc
index 37556257a3f..69c2f388384 100644
--- a/src/test/rbd_mirror/image_sync/test_mock_SyncPointCreateRequest.cc
+++ b/src/test/rbd_mirror/image_sync/test_mock_SyncPointCreateRequest.cc
@@ -3,11 +3,9 @@
#include "test/rbd_mirror/test_mock_fixture.h"
#include "include/rbd/librbd.hpp"
-#include "librbd/journal/Types.h"
-#include "librbd/journal/TypeTraits.h"
-#include "test/journal/mock/MockJournaler.h"
#include "test/librados_test_stub/MockTestMemIoCtxImpl.h"
#include "test/librbd/mock/MockImageCtx.h"
+#include "test/rbd_mirror/mock/image_sync/MockSyncPointHandler.h"
#include "tools/rbd_mirror/image_sync/SyncPointCreateRequest.h"
namespace librbd {
@@ -22,26 +20,20 @@ struct MockTestImageCtx : public librbd::MockImageCtx {
} // anonymous namespace
-namespace journal {
-
-template <>
-struct TypeTraits<librbd::MockTestImageCtx> {
- typedef ::journal::MockJournaler Journaler;
-};
-
-} // namespace journal
} // namespace librbd
// template definitions
#include "tools/rbd_mirror/image_sync/SyncPointCreateRequest.cc"
-template class rbd::mirror::image_sync::SyncPointCreateRequest<librbd::MockTestImageCtx>;
namespace rbd {
namespace mirror {
namespace image_sync {
using ::testing::_;
+using ::testing::DoAll;
using ::testing::InSequence;
+using ::testing::Invoke;
+using ::testing::Return;
using ::testing::WithArg;
class TestMockImageSyncSyncPointCreateRequest : public TestMockFixture {
@@ -56,9 +48,27 @@ public:
ASSERT_EQ(0, open_image(m_remote_io_ctx, m_image_name, &m_remote_image_ctx));
}
- void expect_update_client(journal::MockJournaler &mock_journaler, int r) {
- EXPECT_CALL(mock_journaler, update_client(_, _))
- .WillOnce(WithArg<1>(CompleteContext(r)));
+ void expect_get_snap_seqs(MockSyncPointHandler& mock_sync_point_handler) {
+ EXPECT_CALL(mock_sync_point_handler, get_snap_seqs())
+ .WillRepeatedly(Return(librbd::SnapSeqs{}));
+ }
+
+ void expect_get_sync_points(MockSyncPointHandler& mock_sync_point_handler) {
+ EXPECT_CALL(mock_sync_point_handler, get_sync_points())
+ .WillRepeatedly(Invoke([this]() {
+ return m_sync_points;
+ }));
+ }
+
+ void expect_update_sync_points(MockSyncPointHandler& mock_sync_point_handler,
+ int r) {
+ EXPECT_CALL(mock_sync_point_handler, update_sync_points(_, _, false, _))
+ .WillOnce(DoAll(WithArg<1>(Invoke([this, r](const SyncPoints& sync_points) {
+ if (r >= 0) {
+ m_sync_points = sync_points;
+ }
+ })),
+ WithArg<3>(CompleteContext(r))));
}
void expect_image_refresh(librbd::MockTestImageCtx &mock_remote_image_ctx, int r) {
@@ -72,98 +82,112 @@ public:
}
MockSyncPointCreateRequest *create_request(librbd::MockTestImageCtx &mock_remote_image_ctx,
- journal::MockJournaler &mock_journaler,
+ MockSyncPointHandler& mock_sync_point_handler,
Context *ctx) {
return new MockSyncPointCreateRequest(&mock_remote_image_ctx, "uuid",
- &mock_journaler, &m_client_meta, ctx);
+ &mock_sync_point_handler, ctx);
}
librbd::ImageCtx *m_remote_image_ctx;
- librbd::journal::MirrorPeerClientMeta m_client_meta;
+ SyncPoints m_sync_points;
};
TEST_F(TestMockImageSyncSyncPointCreateRequest, Success) {
librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
- journal::MockJournaler mock_journaler;
+ MockSyncPointHandler mock_sync_point_handler;
+
+ expect_get_snap_seqs(mock_sync_point_handler);
+ expect_get_sync_points(mock_sync_point_handler);
InSequence seq;
- expect_update_client(mock_journaler, 0);
+ expect_update_sync_points(mock_sync_point_handler, 0);
expect_image_refresh(mock_remote_image_ctx, 0);
expect_snap_create(mock_remote_image_ctx, 0);
expect_image_refresh(mock_remote_image_ctx, 0);
C_SaferCond ctx;
MockSyncPointCreateRequest *req = create_request(mock_remote_image_ctx,
- mock_journaler, &ctx);
+ mock_sync_point_handler,
+ &ctx);
req->send();
ASSERT_EQ(0, ctx.wait());
- ASSERT_EQ(1U, m_client_meta.sync_points.size());
+ ASSERT_EQ(1U, m_sync_points.size());
}
TEST_F(TestMockImageSyncSyncPointCreateRequest, ResyncSuccess) {
- m_client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
- "start snap",
- "",
- boost::none);
- auto sync_point = m_client_meta.sync_points.front();
+ m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "start snap",
+ "", boost::none);
+ auto sync_point = m_sync_points.front();
librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
- journal::MockJournaler mock_journaler;
+ MockSyncPointHandler mock_sync_point_handler;
+
+ expect_get_snap_seqs(mock_sync_point_handler);
+ expect_get_sync_points(mock_sync_point_handler);
InSequence seq;
- expect_update_client(mock_journaler, 0);
+ expect_update_sync_points(mock_sync_point_handler, 0);
expect_image_refresh(mock_remote_image_ctx, 0);
expect_snap_create(mock_remote_image_ctx, 0);
expect_image_refresh(mock_remote_image_ctx, 0);
C_SaferCond ctx;
MockSyncPointCreateRequest *req = create_request(mock_remote_image_ctx,
- mock_journaler, &ctx);
+ mock_sync_point_handler,
+ &ctx);
req->send();
ASSERT_EQ(0, ctx.wait());
- ASSERT_EQ(2U, m_client_meta.sync_points.size());
- ASSERT_EQ(sync_point, m_client_meta.sync_points.front());
- ASSERT_EQ("start snap", m_client_meta.sync_points.back().from_snap_name);
+ ASSERT_EQ(2U, m_sync_points.size());
+ ASSERT_EQ(sync_point, m_sync_points.front());
+ ASSERT_EQ("start snap", m_sync_points.back().from_snap_name);
}
TEST_F(TestMockImageSyncSyncPointCreateRequest, SnapshotExists) {
librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
- journal::MockJournaler mock_journaler;
+ MockSyncPointHandler mock_sync_point_handler;
+
+ expect_get_snap_seqs(mock_sync_point_handler);
+ expect_get_sync_points(mock_sync_point_handler);
InSequence seq;
- expect_update_client(mock_journaler, 0);
+ expect_update_sync_points(mock_sync_point_handler, 0);
expect_image_refresh(mock_remote_image_ctx, 0);
expect_snap_create(mock_remote_image_ctx, -EEXIST);
- expect_update_client(mock_journaler, 0);
+ expect_update_sync_points(mock_sync_point_handler, 0);
expect_image_refresh(mock_remote_image_ctx, 0);
expect_snap_create(mock_remote_image_ctx, 0);
expect_image_refresh(mock_remote_image_ctx, 0);
C_SaferCond ctx;
MockSyncPointCreateRequest *req = create_request(mock_remote_image_ctx,
- mock_journaler, &ctx);
+ mock_sync_point_handler,
+ &ctx);
req->send();
ASSERT_EQ(0, ctx.wait());
- ASSERT_EQ(1U, m_client_meta.sync_points.size());
+ ASSERT_EQ(1U, m_sync_points.size());
}
TEST_F(TestMockImageSyncSyncPointCreateRequest, ClientUpdateError) {
librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
- journal::MockJournaler mock_journaler;
+ MockSyncPointHandler mock_sync_point_handler;
+
+ expect_get_snap_seqs(mock_sync_point_handler);
+ expect_get_sync_points(mock_sync_point_handler);
InSequence seq;
- expect_update_client(mock_journaler, -EINVAL);
+ expect_update_sync_points(mock_sync_point_handler, -EINVAL);
C_SaferCond ctx;
MockSyncPointCreateRequest *req = create_request(mock_remote_image_ctx,
- mock_journaler, &ctx);
+ mock_sync_point_handler,
+ &ctx);
req->send();
ASSERT_EQ(-EINVAL, ctx.wait());
- ASSERT_TRUE(m_client_meta.sync_points.empty());
+ ASSERT_TRUE(m_sync_points.empty());
}
} // namespace image_sync
diff --git a/src/test/rbd_mirror/image_sync/test_mock_SyncPointPruneRequest.cc b/src/test/rbd_mirror/image_sync/test_mock_SyncPointPruneRequest.cc
index d230944e1b2..bd13f3cd00b 100644
--- a/src/test/rbd_mirror/image_sync/test_mock_SyncPointPruneRequest.cc
+++ b/src/test/rbd_mirror/image_sync/test_mock_SyncPointPruneRequest.cc
@@ -3,11 +3,9 @@
#include "test/rbd_mirror/test_mock_fixture.h"
#include "include/rbd/librbd.hpp"
-#include "librbd/journal/Types.h"
-#include "librbd/journal/TypeTraits.h"
-#include "test/journal/mock/MockJournaler.h"
#include "test/librados_test_stub/MockTestMemIoCtxImpl.h"
#include "test/librbd/mock/MockImageCtx.h"
+#include "test/rbd_mirror/mock/image_sync/MockSyncPointHandler.h"
#include "tools/rbd_mirror/image_sync/SyncPointPruneRequest.h"
namespace librbd {
@@ -22,14 +20,6 @@ struct MockTestImageCtx : public librbd::MockImageCtx {
} // anonymous namespace
-namespace journal {
-
-template <>
-struct TypeTraits<librbd::MockTestImageCtx> {
- typedef ::journal::MockJournaler Journaler;
-};
-
-} // namespace journal
} // namespace librbd
// template definitions
@@ -41,7 +31,9 @@ namespace mirror {
namespace image_sync {
using ::testing::_;
+using ::testing::DoAll;
using ::testing::InSequence;
+using ::testing::Invoke;
using ::testing::Return;
using ::testing::StrEq;
using ::testing::WithArg;
@@ -58,9 +50,27 @@ public:
ASSERT_EQ(0, open_image(m_remote_io_ctx, m_image_name, &m_remote_image_ctx));
}
- void expect_update_client(journal::MockJournaler &mock_journaler, int r) {
- EXPECT_CALL(mock_journaler, update_client(_, _))
- .WillOnce(WithArg<1>(CompleteContext(r)));
+ void expect_get_snap_seqs(MockSyncPointHandler& mock_sync_point_handler) {
+ EXPECT_CALL(mock_sync_point_handler, get_snap_seqs())
+ .WillRepeatedly(Return(librbd::SnapSeqs{}));
+ }
+
+ void expect_get_sync_points(MockSyncPointHandler& mock_sync_point_handler) {
+ EXPECT_CALL(mock_sync_point_handler, get_sync_points())
+ .WillRepeatedly(Invoke([this]() {
+ return m_sync_points;
+ }));
+ }
+
+ void expect_update_sync_points(MockSyncPointHandler& mock_sync_point_handler,
+ bool complete, int r) {
+ EXPECT_CALL(mock_sync_point_handler, update_sync_points(_, _, complete, _))
+ .WillOnce(DoAll(WithArg<1>(Invoke([this, r](const SyncPoints& sync_points) {
+ if (r >= 0) {
+ m_sync_points = sync_points;
+ }
+ })),
+ WithArg<3>(CompleteContext(r))));
}
void expect_get_snap_id(librbd::MockTestImageCtx &mock_remote_image_ctx,
@@ -81,256 +91,255 @@ public:
}
MockSyncPointPruneRequest *create_request(librbd::MockTestImageCtx &mock_remote_image_ctx,
- journal::MockJournaler &mock_journaler,
+ MockSyncPointHandler& mock_sync_point_handler,
bool sync_complete, Context *ctx) {
return new MockSyncPointPruneRequest(&mock_remote_image_ctx, sync_complete,
- &mock_journaler, &m_client_meta, ctx);
+ &mock_sync_point_handler, ctx);
}
librbd::ImageCtx *m_remote_image_ctx;
- librbd::journal::MirrorPeerClientMeta m_client_meta;
+ SyncPoints m_sync_points;
};
TEST_F(TestMockImageSyncSyncPointPruneRequest, SyncInProgressSuccess) {
- librbd::journal::MirrorPeerClientMeta client_meta;
- client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
- "snap1",
- boost::none);
- m_client_meta = client_meta;
+ m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap1",
+ "", boost::none);
+ auto sync_points = m_sync_points;
librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
- journal::MockJournaler mock_journaler;
+ MockSyncPointHandler mock_sync_point_handler;
+
+ expect_get_snap_seqs(mock_sync_point_handler);
+ expect_get_sync_points(mock_sync_point_handler);
InSequence seq;
expect_get_snap_id(mock_remote_image_ctx, "snap1", 123);
expect_image_refresh(mock_remote_image_ctx, 0);
- expect_update_client(mock_journaler, 0);
+ expect_update_sync_points(mock_sync_point_handler, false, 0);
C_SaferCond ctx;
MockSyncPointPruneRequest *req = create_request(mock_remote_image_ctx,
- mock_journaler, false, &ctx);
+ mock_sync_point_handler,
+ false, &ctx);
req->send();
ASSERT_EQ(0, ctx.wait());
- ASSERT_EQ(client_meta, m_client_meta);
+ ASSERT_EQ(sync_points, m_sync_points);
}
TEST_F(TestMockImageSyncSyncPointPruneRequest, RestartedSyncInProgressSuccess) {
- librbd::journal::MirrorPeerClientMeta client_meta;
- client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
- "snap2",
- "snap1", boost::none);
- client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
- "snap1",
- boost::none);
- m_client_meta = client_meta;
+ m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap2",
+ "snap1", boost::none);
+ m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap1", "",
+ boost::none);
+ auto sync_points = m_sync_points;
librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
- journal::MockJournaler mock_journaler;
+ MockSyncPointHandler mock_sync_point_handler;
+
+ expect_get_snap_seqs(mock_sync_point_handler);
+ expect_get_sync_points(mock_sync_point_handler);
InSequence seq;
expect_get_snap_id(mock_remote_image_ctx, "snap1", 123);
expect_snap_remove(mock_remote_image_ctx, "snap2", 0);
expect_image_refresh(mock_remote_image_ctx, 0);
- expect_update_client(mock_journaler, 0);
+ expect_update_sync_points(mock_sync_point_handler, false, 0);
C_SaferCond ctx;
MockSyncPointPruneRequest *req = create_request(mock_remote_image_ctx,
- mock_journaler, false, &ctx);
+ mock_sync_point_handler,
+ false, &ctx);
req->send();
ASSERT_EQ(0, ctx.wait());
- client_meta.sync_points.pop_back();
- ASSERT_EQ(client_meta, m_client_meta);
+ sync_points.pop_back();
+ ASSERT_EQ(sync_points, m_sync_points);
}
TEST_F(TestMockImageSyncSyncPointPruneRequest, SyncInProgressMissingSnapSuccess) {
- librbd::journal::MirrorPeerClientMeta client_meta;
- client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
- "snap2",
- "snap1",
- boost::none);
- client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
- "snap1",
- boost::none);
- m_client_meta = client_meta;
+ m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap2",
+ "snap1", boost::none);
+ m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap1", "",
+ boost::none);
librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
- journal::MockJournaler mock_journaler;
+ MockSyncPointHandler mock_sync_point_handler;
+
+ expect_get_snap_seqs(mock_sync_point_handler);
+ expect_get_sync_points(mock_sync_point_handler);
InSequence seq;
expect_get_snap_id(mock_remote_image_ctx, "snap1", CEPH_NOSNAP);
expect_snap_remove(mock_remote_image_ctx, "snap2", 0);
expect_snap_remove(mock_remote_image_ctx, "snap1", 0);
expect_image_refresh(mock_remote_image_ctx, 0);
- expect_update_client(mock_journaler, 0);
+ expect_update_sync_points(mock_sync_point_handler, false, 0);
C_SaferCond ctx;
MockSyncPointPruneRequest *req = create_request(mock_remote_image_ctx,
- mock_journaler, false, &ctx);
+ mock_sync_point_handler,
+ false, &ctx);
req->send();
ASSERT_EQ(0, ctx.wait());
- client_meta.sync_points.clear();
- ASSERT_EQ(client_meta, m_client_meta);
+ ASSERT_EQ(SyncPoints{}, m_sync_points);
}
TEST_F(TestMockImageSyncSyncPointPruneRequest, SyncInProgressUnexpectedFromSnapSuccess) {
- librbd::journal::MirrorPeerClientMeta client_meta;
- client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
- "snap2",
- "snap1",
- boost::none);
- m_client_meta = client_meta;
+ m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap2",
+ "snap1", boost::none);
librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
- journal::MockJournaler mock_journaler;
+ MockSyncPointHandler mock_sync_point_handler;
+
+ expect_get_snap_seqs(mock_sync_point_handler);
+ expect_get_sync_points(mock_sync_point_handler);
InSequence seq;
expect_get_snap_id(mock_remote_image_ctx, "snap2", 124);
expect_snap_remove(mock_remote_image_ctx, "snap2", 0);
expect_snap_remove(mock_remote_image_ctx, "snap1", 0);
expect_image_refresh(mock_remote_image_ctx, 0);
- expect_update_client(mock_journaler, 0);
+ expect_update_sync_points(mock_sync_point_handler, false, 0);
C_SaferCond ctx;
MockSyncPointPruneRequest *req = create_request(mock_remote_image_ctx,
- mock_journaler, false, &ctx);
+ mock_sync_point_handler,
+ false, &ctx);
req->send();
ASSERT_EQ(0, ctx.wait());
- client_meta.sync_points.clear();
- ASSERT_EQ(client_meta, m_client_meta);
+ ASSERT_EQ(SyncPoints(), m_sync_points);
}
TEST_F(TestMockImageSyncSyncPointPruneRequest, SyncCompleteSuccess) {
- librbd::journal::MirrorPeerClientMeta client_meta;
- client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
- "snap1",
- boost::none);
- m_client_meta = client_meta;
- ASSERT_EQ(librbd::journal::MIRROR_PEER_STATE_SYNCING, m_client_meta.state);
+ m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap1",
+ "", boost::none);
librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
- journal::MockJournaler mock_journaler;
+ MockSyncPointHandler mock_sync_point_handler;
+
+ expect_get_snap_seqs(mock_sync_point_handler);
+ expect_get_sync_points(mock_sync_point_handler);
InSequence seq;
expect_snap_remove(mock_remote_image_ctx, "snap1", 0);
expect_image_refresh(mock_remote_image_ctx, 0);
- expect_update_client(mock_journaler, 0);
+ expect_update_sync_points(mock_sync_point_handler, true, 0);
C_SaferCond ctx;
MockSyncPointPruneRequest *req = create_request(mock_remote_image_ctx,
- mock_journaler, true, &ctx);
+ mock_sync_point_handler,
+ true, &ctx);
req->send();
ASSERT_EQ(0, ctx.wait());
- ASSERT_TRUE(m_client_meta.sync_points.empty());
- ASSERT_EQ(librbd::journal::MIRROR_PEER_STATE_REPLAYING, m_client_meta.state);
+ ASSERT_TRUE(m_sync_points.empty());
}
TEST_F(TestMockImageSyncSyncPointPruneRequest, RestartedSyncCompleteSuccess) {
- librbd::journal::MirrorPeerClientMeta client_meta;
- client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
- "snap2",
- "snap1",
- boost::none);
- client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
- "snap1",
- boost::none);
- m_client_meta = client_meta;
+ m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap2",
+ "snap1", boost::none);
+ m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap1",
+ "", boost::none);
+ auto sync_points = m_sync_points;
librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
- journal::MockJournaler mock_journaler;
+ MockSyncPointHandler mock_sync_point_handler;
+
+ expect_get_snap_seqs(mock_sync_point_handler);
+ expect_get_sync_points(mock_sync_point_handler);
InSequence seq;
expect_image_refresh(mock_remote_image_ctx, 0);
- expect_update_client(mock_journaler, 0);
+ expect_update_sync_points(mock_sync_point_handler, true, 0);
C_SaferCond ctx;
MockSyncPointPruneRequest *req = create_request(mock_remote_image_ctx,
- mock_journaler, true, &ctx);
+ mock_sync_point_handler,
+ true, &ctx);
req->send();
ASSERT_EQ(0, ctx.wait());
- client_meta.sync_points.pop_front();
- ASSERT_EQ(client_meta, m_client_meta);
+ sync_points.pop_front();
+ ASSERT_EQ(sync_points, m_sync_points);
}
TEST_F(TestMockImageSyncSyncPointPruneRequest, RestartedCatchUpSyncCompleteSuccess) {
- librbd::journal::MirrorPeerClientMeta client_meta;
- client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
- "snap3",
- "snap2",
- boost::none);
- client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
- "snap2",
- "snap1",
- boost::none);
- m_client_meta = client_meta;
+ m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap3",
+ "snap2", boost::none);
+ m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap2",
+ "snap1", boost::none);
+ auto sync_points = m_sync_points;
librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
- journal::MockJournaler mock_journaler;
+ MockSyncPointHandler mock_sync_point_handler;
+
+ expect_get_snap_seqs(mock_sync_point_handler);
+ expect_get_sync_points(mock_sync_point_handler);
InSequence seq;
expect_snap_remove(mock_remote_image_ctx, "snap1", 0);
expect_image_refresh(mock_remote_image_ctx, 0);
- expect_update_client(mock_journaler, 0);
+ expect_update_sync_points(mock_sync_point_handler, true, 0);
C_SaferCond ctx;
MockSyncPointPruneRequest *req = create_request(mock_remote_image_ctx,
- mock_journaler, true, &ctx);
+ mock_sync_point_handler,
+ true, &ctx);
req->send();
ASSERT_EQ(0, ctx.wait());
- client_meta.sync_points.pop_front();
- ASSERT_EQ(client_meta, m_client_meta);
+ sync_points.pop_front();
+ ASSERT_EQ(sync_points, m_sync_points);
}
TEST_F(TestMockImageSyncSyncPointPruneRequest, SnapshotDNE) {
- librbd::journal::MirrorPeerClientMeta client_meta;
- client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
- "snap1",
- boost::none);
- m_client_meta = client_meta;
+ m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap1",
+ "", boost::none);
librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
- journal::MockJournaler mock_journaler;
+ MockSyncPointHandler mock_sync_point_handler;
+
+ expect_get_snap_seqs(mock_sync_point_handler);
+ expect_get_sync_points(mock_sync_point_handler);
InSequence seq;
expect_snap_remove(mock_remote_image_ctx, "snap1", -ENOENT);
expect_image_refresh(mock_remote_image_ctx, 0);
- expect_update_client(mock_journaler, 0);
+ expect_update_sync_points(mock_sync_point_handler, true, 0);
C_SaferCond ctx;
MockSyncPointPruneRequest *req = create_request(mock_remote_image_ctx,
- mock_journaler, true, &ctx);
+ mock_sync_point_handler,
+ true, &ctx);
req->send();
ASSERT_EQ(0, ctx.wait());
- ASSERT_TRUE(m_client_meta.sync_points.empty());
+ ASSERT_TRUE(m_sync_points.empty());
}
TEST_F(TestMockImageSyncSyncPointPruneRequest, ClientUpdateError) {
- librbd::journal::MirrorPeerClientMeta client_meta;
- client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
- "snap2",
- "snap1",
- boost::none);
- client_meta.sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(),
- "snap1",
- boost::none);
- m_client_meta = client_meta;
+ m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap2",
+ "snap1", boost::none);
+ m_sync_points.emplace_front(cls::rbd::UserSnapshotNamespace(), "snap1",
+ "", boost::none);
+ auto sync_points = m_sync_points;
librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
- journal::MockJournaler mock_journaler;
+ MockSyncPointHandler mock_sync_point_handler;
+
+ expect_get_snap_seqs(mock_sync_point_handler);
+ expect_get_sync_points(mock_sync_point_handler);
InSequence seq;
expect_image_refresh(mock_remote_image_ctx, 0);
- expect_update_client(mock_journaler, -EINVAL);
+ expect_update_sync_points(mock_sync_point_handler, true, -EINVAL);
C_SaferCond ctx;
MockSyncPointPruneRequest *req = create_request(mock_remote_image_ctx,
- mock_journaler, true, &ctx);
+ mock_sync_point_handler,
+ true, &ctx);
req->send();
ASSERT_EQ(-EINVAL, ctx.wait());
- ASSERT_EQ(client_meta, m_client_meta);
+ ASSERT_EQ(sync_points, m_sync_points);
}
} // namespace image_sync
diff --git a/src/test/rbd_mirror/mock/image_sync/MockSyncPointHandler.h b/src/test/rbd_mirror/mock/image_sync/MockSyncPointHandler.h
new file mode 100644
index 00000000000..b6263cbdfdd
--- /dev/null
+++ b/src/test/rbd_mirror/mock/image_sync/MockSyncPointHandler.h
@@ -0,0 +1,29 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#ifndef CEPH_MOCK_IMAGE_SYNC_SYNC_POINT_HANDLER_H
+#define CEPH_MOCK_IMAGE_SYNC_SYNC_POINT_HANDLER_H
+
+#include "tools/rbd_mirror/image_sync/Types.h"
+#include <gmock/gmock.h>
+
+struct Context;
+
+namespace rbd {
+namespace mirror {
+namespace image_sync {
+
+struct MockSyncPointHandler : public SyncPointHandler{
+ MOCK_CONST_METHOD0(get_sync_points, SyncPoints());
+ MOCK_CONST_METHOD0(get_snap_seqs, librbd::SnapSeqs());
+
+ MOCK_METHOD4(update_sync_points, void(const librbd::SnapSeqs&,
+ const SyncPoints&,
+ bool, Context*));
+};
+
+} // namespace image_sync
+} // namespace mirror
+} // namespace rbd
+
+#endif // CEPH_MOCK_IMAGE_SYNC_SYNC_POINT_HANDLER_H
diff --git a/src/test/rbd_mirror/test_ImageSync.cc b/src/test/rbd_mirror/test_ImageSync.cc
index b585ea571fb..c8aab54b0b5 100644
--- a/src/test/rbd_mirror/test_ImageSync.cc
+++ b/src/test/rbd_mirror/test_ImageSync.cc
@@ -21,6 +21,7 @@
#include "tools/rbd_mirror/InstanceWatcher.h"
#include "tools/rbd_mirror/Threads.h"
#include "tools/rbd_mirror/Throttler.h"
+#include "tools/rbd_mirror/image_replayer/journal/StateBuilder.h"
void register_test_image_sync() {
}
@@ -92,11 +93,21 @@ public:
encode(client_data, client_data_bl);
ASSERT_EQ(0, m_remote_journaler->register_client(client_data_bl));
+
+ m_state_builder = rbd::mirror::image_replayer::journal::StateBuilder<
+ librbd::ImageCtx>::create("global image id");
+ m_state_builder->remote_journaler = m_remote_journaler;
+ m_state_builder->remote_client_meta = m_client_meta;
+ m_sync_point_handler = m_state_builder->create_sync_point_handler();
}
void TearDown() override {
m_instance_watcher->handle_release_leader();
+ m_state_builder->remote_journaler = nullptr;
+ m_state_builder->destroy_sync_point_handler();
+ m_state_builder->destroy();
+
delete m_remote_journaler;
delete m_instance_watcher;
delete m_image_sync_throttler;
@@ -119,10 +130,9 @@ public:
}
ImageSync<> *create_request(Context *ctx) {
- return new ImageSync<>(m_local_image_ctx, m_remote_image_ctx,
- m_threads->timer, &m_threads->timer_lock,
- "mirror-uuid", m_remote_journaler, &m_client_meta,
- m_threads->work_queue, m_instance_watcher, ctx);
+ return new ImageSync<>(m_threads, m_local_image_ctx, m_remote_image_ctx,
+ "mirror-uuid", m_sync_point_handler,
+ m_instance_watcher, nullptr, ctx);
}
librbd::ImageCtx *m_remote_image_ctx;
@@ -131,6 +141,8 @@ public:
rbd::mirror::InstanceWatcher<> *m_instance_watcher;
::journal::Journaler *m_remote_journaler;
librbd::journal::MirrorPeerClientMeta m_client_meta;
+ rbd::mirror::image_replayer::journal::StateBuilder<librbd::ImageCtx>* m_state_builder = nullptr;
+ rbd::mirror::image_sync::SyncPointHandler* m_sync_point_handler = nullptr;
};
TEST_F(TestImageSync, Empty) {
diff --git a/src/test/rbd_mirror/test_mock_ImageSync.cc b/src/test/rbd_mirror/test_mock_ImageSync.cc
index f7c24a4370b..b86d4bee88c 100644
--- a/src/test/rbd_mirror/test_mock_ImageSync.cc
+++ b/src/test/rbd_mirror/test_mock_ImageSync.cc
@@ -4,11 +4,9 @@
#include "test/rbd_mirror/test_mock_fixture.h"
#include "include/rbd/librbd.hpp"
#include "librbd/DeepCopyRequest.h"
-#include "librbd/journal/Types.h"
-#include "librbd/journal/TypeTraits.h"
-#include "test/journal/mock/MockJournaler.h"
#include "test/librados_test_stub/MockTestMemIoCtxImpl.h"
#include "test/librbd/mock/MockImageCtx.h"
+#include "test/rbd_mirror/mock/image_sync/MockSyncPointHandler.h"
#include "tools/rbd_mirror/ImageSync.h"
#include "tools/rbd_mirror/Threads.h"
#include "tools/rbd_mirror/image_sync/SyncPointCreateRequest.h"
@@ -26,15 +24,6 @@ struct MockTestImageCtx : public librbd::MockImageCtx {
} // anonymous namespace
-namespace journal {
-
-template <>
-struct TypeTraits<librbd::MockTestImageCtx> {
- typedef ::journal::MockJournaler Journaler;
-};
-
-} // namespace journal
-
template <>
class DeepCopyRequest<librbd::MockTestImageCtx> {
public:
@@ -78,6 +67,18 @@ template class rbd::mirror::ImageSync<librbd::MockTestImageCtx>;
namespace rbd {
namespace mirror {
+template <>
+struct Threads<librbd::MockTestImageCtx> {
+ ceph::mutex &timer_lock;
+ SafeTimer *timer;
+ ContextWQ *work_queue;
+
+ Threads(Threads<librbd::ImageCtx> *threads)
+ : timer_lock(threads->timer_lock), timer(threads->timer),
+ work_queue(threads->work_queue) {
+ }
+};
+
template<>
struct InstanceWatcher<librbd::MockTestImageCtx> {
MOCK_METHOD2(notify_sync_request, void(const std::string, Context *));
@@ -95,8 +96,7 @@ public:
static SyncPointCreateRequest* create(librbd::MockTestImageCtx *remote_image_ctx,
const std::string &mirror_uuid,
- journal::MockJournaler *journaler,
- librbd::journal::MirrorPeerClientMeta *client_meta,
+ image_sync::SyncPointHandler* sync_point_handler,
Context *on_finish) {
ceph_assert(s_instance != nullptr);
s_instance->on_finish = on_finish;
@@ -118,8 +118,7 @@ public:
static SyncPointPruneRequest* create(librbd::MockTestImageCtx *remote_image_ctx,
bool sync_complete,
- journal::MockJournaler *journaler,
- librbd::journal::MirrorPeerClientMeta *client_meta,
+ image_sync::SyncPointHandler* sync_point_handler,
Context *on_finish) {
ceph_assert(s_instance != nullptr);
s_instance->on_finish = on_finish;
@@ -149,10 +148,12 @@ using ::testing::InvokeWithoutArgs;
class TestMockImageSync : public TestMockFixture {
public:
+ typedef Threads<librbd::MockTestImageCtx> MockThreads;
typedef ImageSync<librbd::MockTestImageCtx> MockImageSync;
typedef InstanceWatcher<librbd::MockTestImageCtx> MockInstanceWatcher;
typedef image_sync::SyncPointCreateRequest<librbd::MockTestImageCtx> MockSyncPointCreateRequest;
typedef image_sync::SyncPointPruneRequest<librbd::MockTestImageCtx> MockSyncPointPruneRequest;
+ typedef image_sync::MockSyncPointHandler MockSyncPointHandler;
typedef librbd::DeepCopyRequest<librbd::MockTestImageCtx> MockImageCopyRequest;
void SetUp() override {
@@ -198,9 +199,8 @@ public:
if (r == 0) {
mock_local_image_ctx.snap_ids[{cls::rbd::UserSnapshotNamespace(),
"snap1"}] = 123;
- m_client_meta.sync_points.emplace_back(cls::rbd::UserSnapshotNamespace(),
- "snap1",
- boost::none);
+ m_sync_points.emplace_back(cls::rbd::UserSnapshotNamespace(),
+ "snap1", "", boost::none);
}
m_threads->work_queue->queue(mock_sync_point_create_request.on_finish, r);
}));
@@ -213,9 +213,10 @@ public:
}));
}
- void expect_flush_sync_point(journal::MockJournaler &mock_journaler, int r) {
- EXPECT_CALL(mock_journaler, update_client(_, _))
- .WillOnce(WithArg<1>(CompleteContext(r)));
+ void expect_flush_sync_point(MockSyncPointHandler& mock_sync_point_handler,
+ int r) {
+ EXPECT_CALL(mock_sync_point_handler, update_sync_points(_, _, false, _))
+ .WillOnce(WithArg<3>(CompleteContext(r)));
}
void expect_prune_sync_point(MockSyncPointPruneRequest &mock_sync_point_prune_request,
@@ -223,12 +224,12 @@ public:
EXPECT_CALL(mock_sync_point_prune_request, send())
.WillOnce(Invoke([this, &mock_sync_point_prune_request, sync_complete, r]() {
ASSERT_EQ(sync_complete, mock_sync_point_prune_request.sync_complete);
- if (r == 0 && !m_client_meta.sync_points.empty()) {
+ if (r == 0 && !m_sync_points.empty()) {
if (sync_complete) {
- m_client_meta.sync_points.pop_front();
+ m_sync_points.pop_front();
} else {
- while (m_client_meta.sync_points.size() > 1) {
- m_client_meta.sync_points.pop_back();
+ while (m_sync_points.size() > 1) {
+ m_sync_points.pop_back();
}
}
}
@@ -236,88 +237,114 @@ public:
}));
}
- MockImageSync *create_request(librbd::MockTestImageCtx &mock_remote_image_ctx,
+ void expect_get_snap_seqs(MockSyncPointHandler& mock_sync_point_handler) {
+ EXPECT_CALL(mock_sync_point_handler, get_snap_seqs())
+ .WillRepeatedly(Return(librbd::SnapSeqs{}));
+ }
+
+ void expect_get_sync_points(MockSyncPointHandler& mock_sync_point_handler) {
+ EXPECT_CALL(mock_sync_point_handler, get_sync_points())
+ .WillRepeatedly(Invoke([this]() {
+ return m_sync_points;
+ }));
+ }
+
+ MockImageSync *create_request(MockThreads& mock_threads,
+ librbd::MockTestImageCtx &mock_remote_image_ctx,
librbd::MockTestImageCtx &mock_local_image_ctx,
- journal::MockJournaler &mock_journaler,
+ MockSyncPointHandler& mock_sync_point_handler,
MockInstanceWatcher &mock_instance_watcher,
Context *ctx) {
- return new MockImageSync(&mock_local_image_ctx, &mock_remote_image_ctx,
- m_threads->timer, &m_threads->timer_lock,
- "mirror-uuid", &mock_journaler, &m_client_meta,
- m_threads->work_queue, &mock_instance_watcher,
- ctx);
+ return new MockImageSync(&mock_threads, &mock_local_image_ctx,
+ &mock_remote_image_ctx,
+ "mirror-uuid", &mock_sync_point_handler,
+ &mock_instance_watcher, nullptr, ctx);
}
librbd::ImageCtx *m_remote_image_ctx;
librbd::ImageCtx *m_local_image_ctx;
- librbd::journal::MirrorPeerClientMeta m_client_meta;
+
+ image_sync::SyncPoints m_sync_points;
};
TEST_F(TestMockImageSync, SimpleSync) {
+ MockThreads mock_threads(m_threads);
librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
- journal::MockJournaler mock_journaler;
+ MockSyncPointHandler mock_sync_point_handler;
MockInstanceWatcher mock_instance_watcher;
MockImageCopyRequest mock_image_copy_request;
MockSyncPointCreateRequest mock_sync_point_create_request;
MockSyncPointPruneRequest mock_sync_point_prune_request;
+ expect_get_snap_seqs(mock_sync_point_handler);
+ expect_get_sync_points(mock_sync_point_handler);
+
InSequence seq;
expect_notify_sync_request(mock_instance_watcher, mock_local_image_ctx.id, 0);
expect_create_sync_point(mock_local_image_ctx, mock_sync_point_create_request, 0);
expect_get_snap_id(mock_remote_image_ctx);
expect_copy_image(mock_image_copy_request, 0);
- expect_flush_sync_point(mock_journaler, 0);
+ expect_flush_sync_point(mock_sync_point_handler, 0);
expect_prune_sync_point(mock_sync_point_prune_request, true, 0);
expect_notify_sync_complete(mock_instance_watcher, mock_local_image_ctx.id);
C_SaferCond ctx;
- MockImageSync *request = create_request(mock_remote_image_ctx,
- mock_local_image_ctx, mock_journaler,
+ MockImageSync *request = create_request(mock_threads, mock_remote_image_ctx,
+ mock_local_image_ctx,
+ mock_sync_point_handler,
mock_instance_watcher, &ctx);
request->send();
ASSERT_EQ(0, ctx.wait());
}
TEST_F(TestMockImageSync, RestartSync) {
+ MockThreads mock_threads(m_threads);
librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
- journal::MockJournaler mock_journaler;
+ MockSyncPointHandler mock_sync_point_handler;
MockInstanceWatcher mock_instance_watcher;
MockImageCopyRequest mock_image_copy_request;
MockSyncPointCreateRequest mock_sync_point_create_request;
MockSyncPointPruneRequest mock_sync_point_prune_request;
- m_client_meta.sync_points = {{cls::rbd::UserSnapshotNamespace(), "snap1", boost::none},
- {cls::rbd::UserSnapshotNamespace(), "snap2", "snap1", boost::none}};
+ m_sync_points = {{cls::rbd::UserSnapshotNamespace(), "snap1", "", boost::none},
+ {cls::rbd::UserSnapshotNamespace(), "snap2", "snap1", boost::none}};
mock_local_image_ctx.snap_ids[{cls::rbd::UserSnapshotNamespace(), "snap1"}] = 123;
mock_local_image_ctx.snap_ids[{cls::rbd::UserSnapshotNamespace(), "snap2"}] = 234;
expect_test_features(mock_local_image_ctx);
+ expect_get_snap_seqs(mock_sync_point_handler);
+ expect_get_sync_points(mock_sync_point_handler);
InSequence seq;
expect_notify_sync_request(mock_instance_watcher, mock_local_image_ctx.id, 0);
expect_prune_sync_point(mock_sync_point_prune_request, false, 0);
expect_get_snap_id(mock_remote_image_ctx);
expect_copy_image(mock_image_copy_request, 0);
- expect_flush_sync_point(mock_journaler, 0);
+ expect_flush_sync_point(mock_sync_point_handler, 0);
expect_prune_sync_point(mock_sync_point_prune_request, true, 0);
expect_notify_sync_complete(mock_instance_watcher, mock_local_image_ctx.id);
C_SaferCond ctx;
- MockImageSync *request = create_request(mock_remote_image_ctx,
- mock_local_image_ctx, mock_journaler,
+ MockImageSync *request = create_request(mock_threads, mock_remote_image_ctx,
+ mock_local_image_ctx,
+ mock_sync_point_handler,
mock_instance_watcher, &ctx);
request->send();
ASSERT_EQ(0, ctx.wait());
}
TEST_F(TestMockImageSync, CancelNotifySyncRequest) {
+ MockThreads mock_threads(m_threads);
librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
- journal::MockJournaler mock_journaler;
+ MockSyncPointHandler mock_sync_point_handler;
MockInstanceWatcher mock_instance_watcher;
+ expect_get_snap_seqs(mock_sync_point_handler);
+ expect_get_sync_points(mock_sync_point_handler);
+
InSequence seq;
Context *on_sync_start = nullptr;
C_SaferCond notify_sync_ctx;
@@ -337,8 +364,9 @@ TEST_F(TestMockImageSync, CancelNotifySyncRequest) {
}));
C_SaferCond ctx;
- MockImageSync *request = create_request(mock_remote_image_ctx,
- mock_local_image_ctx, mock_journaler,
+ MockImageSync *request = create_request(mock_threads, mock_remote_image_ctx,
+ mock_local_image_ctx,
+ mock_sync_point_handler,
mock_instance_watcher, &ctx);
request->get();
request->send();
@@ -352,15 +380,18 @@ TEST_F(TestMockImageSync, CancelNotifySyncRequest) {
}
TEST_F(TestMockImageSync, CancelImageCopy) {
+ MockThreads mock_threads(m_threads);
librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
- journal::MockJournaler mock_journaler;
+ MockSyncPointHandler mock_sync_point_handler;
MockInstanceWatcher mock_instance_watcher;
MockImageCopyRequest mock_image_copy_request;
MockSyncPointCreateRequest mock_sync_point_create_request;
MockSyncPointPruneRequest mock_sync_point_prune_request;
- m_client_meta.sync_points = {{cls::rbd::UserSnapshotNamespace(), "snap1", boost::none}};
+ m_sync_points = {{cls::rbd::UserSnapshotNamespace(), "snap1", "", boost::none}};
+ expect_get_snap_seqs(mock_sync_point_handler);
+ expect_get_sync_points(mock_sync_point_handler);
InSequence seq;
expect_notify_sync_request(mock_instance_watcher, mock_local_image_ctx.id, 0);
@@ -378,8 +409,9 @@ TEST_F(TestMockImageSync, CancelImageCopy) {
expect_notify_sync_complete(mock_instance_watcher, mock_local_image_ctx.id);
C_SaferCond ctx;
- MockImageSync *request = create_request(mock_remote_image_ctx,
- mock_local_image_ctx, mock_journaler,
+ MockImageSync *request = create_request(mock_threads, mock_remote_image_ctx,
+ mock_local_image_ctx,
+ mock_sync_point_handler,
mock_instance_watcher, &ctx);
request->get();
request->send();
@@ -394,18 +426,24 @@ TEST_F(TestMockImageSync, CancelImageCopy) {
}
TEST_F(TestMockImageSync, CancelAfterCopyImage) {
+ MockThreads mock_threads(m_threads);
librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx);
librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx);
- journal::MockJournaler mock_journaler;
+ MockSyncPointHandler mock_sync_point_handler;
MockInstanceWatcher mock_instance_watcher;
MockImageCopyRequest mock_image_copy_request;
MockSyncPointCreateRequest mock_sync_point_create_request;
MockSyncPointPruneRequest mock_sync_point_prune_request;
C_SaferCond ctx;
- MockImageSync *request = create_request(mock_remote_image_ctx,
- mock_local_image_ctx, mock_journaler,
+ MockImageSync *request = create_request(mock_threads, mock_remote_image_ctx,
+ mock_local_image_ctx,
+ mock_sync_point_handler,
mock_instance_watcher, &ctx);
+
+ expect_get_snap_seqs(mock_sync_point_handler);
+ expect_get_sync_points(mock_sync_point_handler);
+
InSequence seq;
expect_notify_sync_request(mock_instance_watcher, mock_local_image_ctx.id, 0);
expect_create_sync_point(mock_local_image_ctx, mock_sync_point_create_request, 0);