From 995a16ebcbe79fd14e6de3b25087373744238294 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Tue, 28 Jun 2016 15:18:51 -0400 Subject: [PATCH] test: ensure unique template specializations per test case With optimizations disabled, there can be cross translation unit symbol leaking that is not present when inlining is enabled. Signed-off-by: Jason Dillaman --- .../image_sync/test_mock_ImageCopyRequest.cc | 87 ++++++++------ .../image_sync/test_mock_ObjectCopyRequest.cc | 54 +++++---- .../test_mock_SnapshotCopyRequest.cc | 109 ++++++++++-------- .../test_mock_SnapshotCreateRequest.cc | 56 +++++---- .../test_mock_SyncPointCreateRequest.cc | 31 +++-- .../test_mock_SyncPointPruneRequest.cc | 43 ++++--- src/test/rbd_mirror/test_mock_ImageSync.cc | 83 +++++++------ .../test_mock_ImageSyncThrottler.cc | 33 ++++-- 8 files changed, 293 insertions(+), 203 deletions(-) diff --git a/src/test/rbd_mirror/image_sync/test_mock_ImageCopyRequest.cc b/src/test/rbd_mirror/image_sync/test_mock_ImageCopyRequest.cc index 3d0855f31af7..d924a3cab287 100644 --- a/src/test/rbd_mirror/image_sync/test_mock_ImageCopyRequest.cc +++ b/src/test/rbd_mirror/image_sync/test_mock_ImageCopyRequest.cc @@ -16,10 +16,21 @@ #include namespace librbd { + +namespace { + +struct MockTestImageCtx : public librbd::MockImageCtx { + MockTestImageCtx(librbd::ImageCtx &image_ctx) + : librbd::MockImageCtx(image_ctx) { + } +}; + +} // anonymous namespace + namespace journal { template <> -struct TypeTraits { +struct TypeTraits { typedef ::journal::MockJournaler Journaler; }; @@ -31,11 +42,11 @@ namespace mirror { namespace image_sync { template <> -struct ObjectCopyRequest { +struct ObjectCopyRequest { static ObjectCopyRequest* s_instance; - static ObjectCopyRequest* create(librbd::MockImageCtx *local_image_ctx, - librbd::MockImageCtx *remote_image_ctx, - const ImageCopyRequest::SnapMap *snap_map, + static ObjectCopyRequest* create(librbd::MockTestImageCtx *local_image_ctx, + librbd::MockTestImageCtx *remote_image_ctx, + const ImageCopyRequest::SnapMap *snap_map, uint64_t object_number, Context *on_finish) { assert(s_instance != nullptr); Mutex::Locker locker(s_instance->lock); @@ -50,7 +61,7 @@ struct ObjectCopyRequest { Mutex lock; Cond cond; - const ImageCopyRequest::SnapMap *snap_map = nullptr; + const ImageCopyRequest::SnapMap *snap_map = nullptr; std::map object_contexts; ObjectCopyRequest() : lock("lock") { @@ -58,7 +69,7 @@ struct ObjectCopyRequest { } }; -ObjectCopyRequest* ObjectCopyRequest::s_instance = nullptr; +ObjectCopyRequest* ObjectCopyRequest::s_instance = nullptr; } // namespace image_sync } // namespace mirror @@ -66,7 +77,7 @@ ObjectCopyRequest* ObjectCopyRequest // template definitions #include "tools/rbd_mirror/image_sync/ImageCopyRequest.cc" -template class rbd::mirror::image_sync::ImageCopyRequest; +template class rbd::mirror::image_sync::ImageCopyRequest; namespace rbd { namespace mirror { @@ -81,8 +92,8 @@ using ::testing::InvokeWithoutArgs; class TestMockImageSyncImageCopyRequest : public TestMockFixture { public: - typedef ImageCopyRequest MockImageCopyRequest; - typedef ObjectCopyRequest MockObjectCopyRequest; + typedef ImageCopyRequest MockImageCopyRequest; + typedef ObjectCopyRequest MockObjectCopyRequest; virtual void SetUp() { TestMockFixture::SetUp(); @@ -95,7 +106,7 @@ public: ASSERT_EQ(0, open_image(m_local_io_ctx, m_image_name, &m_local_image_ctx)); } - void expect_get_snap_id(librbd::MockImageCtx &mock_image_ctx) { + 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) { RWLock::RLocker snap_locker(mock_image_ctx.image_ctx->snap_lock); @@ -103,7 +114,7 @@ public: })); } - void expect_get_object_count(librbd::MockImageCtx &mock_image_ctx, + void expect_get_object_count(librbd::MockTestImageCtx &mock_image_ctx, uint64_t count) { EXPECT_CALL(mock_image_ctx, get_object_count(_)) .WillOnce(Return(count)).RetiresOnSaturation(); @@ -151,8 +162,8 @@ public: return *mock_object_copy_request.snap_map; } - MockImageCopyRequest *create_request(librbd::MockImageCtx &mock_remote_image_ctx, - librbd::MockImageCtx &mock_local_image_ctx, + MockImageCopyRequest *create_request(librbd::MockTestImageCtx &mock_remote_image_ctx, + librbd::MockTestImageCtx &mock_local_image_ctx, journal::MockJournaler &mock_journaler, librbd::journal::MirrorPeerSyncPoint &sync_point, Context *ctx) { @@ -199,8 +210,8 @@ TEST_F(TestMockImageSyncImageCopyRequest, SimpleImage) { ASSERT_EQ(0, create_snap("snap1")); m_client_meta.sync_points = {{"snap1", boost::none}}; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; MockObjectCopyRequest mock_object_copy_request; @@ -244,8 +255,8 @@ TEST_F(TestMockImageSyncImageCopyRequest, Throttled) { uint64_t object_count = 55; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; MockObjectCopyRequest mock_object_copy_request; @@ -306,8 +317,8 @@ TEST_F(TestMockImageSyncImageCopyRequest, SnapshotSubset) { ASSERT_EQ(0, create_snap("snap3")); m_client_meta.sync_points = {{"snap3", "snap2", boost::none}}; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; MockObjectCopyRequest mock_object_copy_request; @@ -344,8 +355,8 @@ TEST_F(TestMockImageSyncImageCopyRequest, RestartCatchup) { m_client_meta.sync_points = {{"snap1", boost::none}, {"snap2", "snap1", boost::none}}; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; MockObjectCopyRequest mock_object_copy_request; @@ -376,8 +387,8 @@ TEST_F(TestMockImageSyncImageCopyRequest, RestartPartialSync) { ASSERT_EQ(0, create_snap("snap1")); m_client_meta.sync_points = {{"snap1", librbd::journal::MirrorPeerSyncPoint::ObjectNumber{0U}}}; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; MockObjectCopyRequest mock_object_copy_request; @@ -413,8 +424,8 @@ TEST_F(TestMockImageSyncImageCopyRequest, Cancel) { ASSERT_EQ(0, create_snap("snap1")); m_client_meta.sync_points = {{"snap1", boost::none}}; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; MockObjectCopyRequest mock_object_copy_request; @@ -459,8 +470,8 @@ TEST_F(TestMockImageSyncImageCopyRequest, Cancel_Inflight_Sync) { ASSERT_EQ(0, create_snap("snap1")); m_client_meta.sync_points = {{"snap1", boost::none}}; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; MockObjectCopyRequest mock_object_copy_request; @@ -507,8 +518,8 @@ TEST_F(TestMockImageSyncImageCopyRequest, Cancel1) { ASSERT_EQ(0, create_snap("snap1")); m_client_meta.sync_points = {{"snap1", boost::none}}; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; MockObjectCopyRequest mock_object_copy_request; @@ -538,8 +549,8 @@ TEST_F(TestMockImageSyncImageCopyRequest, MissingSnap) { ASSERT_EQ(0, create_snap("snap1")); m_client_meta.sync_points = {{"missing-snap", boost::none}}; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; expect_get_snap_id(mock_remote_image_ctx); @@ -558,8 +569,8 @@ TEST_F(TestMockImageSyncImageCopyRequest, MissingFromSnap) { ASSERT_EQ(0, create_snap("snap1")); m_client_meta.sync_points = {{"snap1", "missing-snap", boost::none}}; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; expect_get_snap_id(mock_remote_image_ctx); @@ -580,8 +591,8 @@ TEST_F(TestMockImageSyncImageCopyRequest, EmptySnapMap) { m_client_meta.snap_seqs = {{0, 0}}; m_client_meta.sync_points = {{"snap2", "snap1", boost::none}}; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; expect_get_snap_id(mock_remote_image_ctx); @@ -602,8 +613,8 @@ TEST_F(TestMockImageSyncImageCopyRequest, EmptySnapSeqs) { m_client_meta.snap_seqs = {}; m_client_meta.sync_points = {{"snap2", "snap1", boost::none}}; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; expect_get_snap_id(mock_remote_image_ctx); diff --git a/src/test/rbd_mirror/image_sync/test_mock_ObjectCopyRequest.cc b/src/test/rbd_mirror/image_sync/test_mock_ObjectCopyRequest.cc index 69c4c6464652..c0d60db3bf89 100644 --- a/src/test/rbd_mirror/image_sync/test_mock_ObjectCopyRequest.cc +++ b/src/test/rbd_mirror/image_sync/test_mock_ObjectCopyRequest.cc @@ -14,9 +14,21 @@ #include "tools/rbd_mirror/Threads.h" #include "tools/rbd_mirror/image_sync/ObjectCopyRequest.h" +namespace librbd { +namespace { + +struct MockTestImageCtx : public librbd::MockImageCtx { + MockTestImageCtx(librbd::ImageCtx &image_ctx) + : librbd::MockImageCtx(image_ctx) { + } +}; + +} // anonymous namespace +} // namespace librbd + // template definitions #include "tools/rbd_mirror/image_sync/ObjectCopyRequest.cc" -template class rbd::mirror::image_sync::ObjectCopyRequest; +template class rbd::mirror::image_sync::ObjectCopyRequest; namespace rbd { namespace mirror { @@ -56,7 +68,7 @@ void scribble(librbd::ImageCtx *image_ctx, int num_ops, size_t max_size, class TestMockImageSyncObjectCopyRequest : public TestMockFixture { public: - typedef ObjectCopyRequest MockObjectCopyRequest; + typedef ObjectCopyRequest MockObjectCopyRequest; virtual void SetUp() { TestMockFixture::SetUp(); @@ -69,7 +81,7 @@ public: ASSERT_EQ(0, open_image(m_local_io_ctx, m_image_name, &m_local_image_ctx)); } - void expect_list_snaps(librbd::MockImageCtx &mock_image_ctx, + void expect_list_snaps(librbd::MockTestImageCtx &mock_image_ctx, librados::MockTestMemIoCtxImpl &mock_io_ctx, int r) { auto &expect = EXPECT_CALL(mock_io_ctx, list_snaps(mock_image_ctx.image_ctx->get_object_name(0), @@ -81,13 +93,13 @@ public: } } - void expect_get_object_name(librbd::MockImageCtx &mock_image_ctx) { + void expect_get_object_name(librbd::MockTestImageCtx &mock_image_ctx) { EXPECT_CALL(mock_image_ctx, get_object_name(0)) .WillOnce(Return(mock_image_ctx.image_ctx->get_object_name(0))); } - MockObjectCopyRequest *create_request(librbd::MockImageCtx &mock_remote_image_ctx, - librbd::MockImageCtx &mock_local_image_ctx, + MockObjectCopyRequest *create_request(librbd::MockTestImageCtx &mock_remote_image_ctx, + librbd::MockTestImageCtx &mock_local_image_ctx, Context *on_finish) { expect_get_object_name(mock_local_image_ctx); expect_get_object_name(mock_remote_image_ctx); @@ -155,7 +167,7 @@ public: } } - void expect_update_object_map(librbd::MockImageCtx &mock_image_ctx, + void expect_update_object_map(librbd::MockTestImageCtx &mock_image_ctx, librbd::MockObjectMap &mock_object_map, librados::snap_t snap_id, uint8_t state, int r) { @@ -289,8 +301,8 @@ public: TEST_F(TestMockImageSyncObjectCopyRequest, DNE) { ASSERT_EQ(0, create_snap("sync")); - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); librbd::MockObjectMap mock_object_map; mock_local_image_ctx.object_map = &mock_object_map; @@ -317,8 +329,8 @@ TEST_F(TestMockImageSyncObjectCopyRequest, Write) { scribble(m_remote_image_ctx, 10, 102400, &one); ASSERT_EQ(0, create_snap("sync")); - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); librbd::MockObjectMap mock_object_map; mock_local_image_ctx.object_map = &mock_object_map; @@ -352,8 +364,8 @@ TEST_F(TestMockImageSyncObjectCopyRequest, ReadError) { scribble(m_remote_image_ctx, 10, 102400, &one); ASSERT_EQ(0, create_snap("sync")); - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); librbd::MockObjectMap mock_object_map; mock_local_image_ctx.object_map = &mock_object_map; @@ -381,8 +393,8 @@ TEST_F(TestMockImageSyncObjectCopyRequest, WriteError) { scribble(m_remote_image_ctx, 10, 102400, &one); ASSERT_EQ(0, create_snap("sync")); - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); librbd::MockObjectMap mock_object_map; mock_local_image_ctx.object_map = &mock_object_map; @@ -424,8 +436,8 @@ TEST_F(TestMockImageSyncObjectCopyRequest, WriteSnaps) { } ASSERT_EQ(0, create_snap("sync")); - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); librbd::MockObjectMap mock_object_map; mock_local_image_ctx.object_map = &mock_object_map; @@ -471,8 +483,8 @@ TEST_F(TestMockImageSyncObjectCopyRequest, Trim) { trim_offset, one.range_end() - trim_offset)); ASSERT_EQ(0, create_snap("sync")); - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); librbd::MockObjectMap mock_object_map; mock_local_image_ctx.object_map = &mock_object_map; @@ -513,8 +525,8 @@ TEST_F(TestMockImageSyncObjectCopyRequest, Remove) { uint64_t object_size = 1 << m_remote_image_ctx->order; ASSERT_LE(0, m_remote_image_ctx->aio_work_queue->discard(0, object_size)); ASSERT_EQ(0, create_snap("sync")); - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); librbd::MockObjectMap mock_object_map; mock_local_image_ctx.object_map = &mock_object_map; diff --git a/src/test/rbd_mirror/image_sync/test_mock_SnapshotCopyRequest.cc b/src/test/rbd_mirror/image_sync/test_mock_SnapshotCopyRequest.cc index bcb9fd69d146..2fd026a7c5f6 100644 --- a/src/test/rbd_mirror/image_sync/test_mock_SnapshotCopyRequest.cc +++ b/src/test/rbd_mirror/image_sync/test_mock_SnapshotCopyRequest.cc @@ -15,10 +15,21 @@ #include "tools/rbd_mirror/Threads.h" namespace librbd { + +namespace { + +struct MockTestImageCtx : public librbd::MockImageCtx { + MockTestImageCtx(librbd::ImageCtx &image_ctx) + : librbd::MockImageCtx(image_ctx) { + } +}; + +} // anonymous namespace + namespace journal { template <> -struct TypeTraits { +struct TypeTraits { typedef ::journal::MockJournaler Journaler; }; @@ -30,9 +41,9 @@ namespace mirror { namespace image_sync { template <> -struct SnapshotCreateRequest { +struct SnapshotCreateRequest { static SnapshotCreateRequest* s_instance; - static SnapshotCreateRequest* create(librbd::MockImageCtx* image_ctx, + static SnapshotCreateRequest* create(librbd::MockTestImageCtx* image_ctx, const std::string &snap_name, uint64_t size, const librbd::parent_spec &parent_spec, @@ -52,7 +63,7 @@ struct SnapshotCreateRequest { MOCK_METHOD0(send, void()); }; -SnapshotCreateRequest* SnapshotCreateRequest::s_instance = nullptr; +SnapshotCreateRequest* SnapshotCreateRequest::s_instance = nullptr; } // namespace image_sync } // namespace mirror @@ -60,7 +71,7 @@ SnapshotCreateRequest* SnapshotCreateRequest; +template class rbd::mirror::image_sync::SnapshotCopyRequest; namespace rbd { namespace mirror { @@ -79,8 +90,8 @@ using ::testing::WithArg; class TestMockImageSyncSnapshotCopyRequest : public TestMockFixture { public: - typedef SnapshotCopyRequest MockSnapshotCopyRequest; - typedef SnapshotCreateRequest MockSnapshotCreateRequest; + typedef SnapshotCopyRequest MockSnapshotCopyRequest; + typedef SnapshotCreateRequest MockSnapshotCreateRequest; virtual void SetUp() { TestMockFixture::SetUp(); @@ -93,7 +104,7 @@ public: ASSERT_EQ(0, open_image(m_local_io_ctx, m_image_name, &m_local_image_ctx)); } - void expect_snap_create(librbd::MockImageCtx &mock_image_ctx, + void expect_snap_create(librbd::MockTestImageCtx &mock_image_ctx, MockSnapshotCreateRequest &mock_snapshot_create_request, const std::string &snap_name, uint64_t snap_id, int r) { EXPECT_CALL(mock_snapshot_create_request, send()) @@ -105,7 +116,7 @@ public: }))); } - void expect_snap_remove(librbd::MockImageCtx &mock_image_ctx, + void expect_snap_remove(librbd::MockTestImageCtx &mock_image_ctx, const std::string &snap_name, int r) { EXPECT_CALL(*mock_image_ctx.operations, execute_snap_remove(StrEq(snap_name), _)) .WillOnce(WithArg<1>(Invoke([this, r](Context *ctx) { @@ -113,7 +124,7 @@ public: }))); } - void expect_snap_protect(librbd::MockImageCtx &mock_image_ctx, + void expect_snap_protect(librbd::MockTestImageCtx &mock_image_ctx, const std::string &snap_name, int r) { EXPECT_CALL(*mock_image_ctx.operations, execute_snap_protect(StrEq(snap_name), _)) .WillOnce(WithArg<1>(Invoke([this, r](Context *ctx) { @@ -121,7 +132,7 @@ public: }))); } - void expect_snap_unprotect(librbd::MockImageCtx &mock_image_ctx, + void expect_snap_unprotect(librbd::MockTestImageCtx &mock_image_ctx, const std::string &snap_name, int r) { EXPECT_CALL(*mock_image_ctx.operations, execute_snap_unprotect(StrEq(snap_name), _)) .WillOnce(WithArg<1>(Invoke([this, r](Context *ctx) { @@ -129,14 +140,14 @@ public: }))); } - void expect_snap_is_protected(librbd::MockImageCtx &mock_image_ctx, + void expect_snap_is_protected(librbd::MockTestImageCtx &mock_image_ctx, uint64_t snap_id, bool is_protected, int r) { EXPECT_CALL(mock_image_ctx, is_snap_protected(snap_id, _)) .WillOnce(DoAll(SetArgPointee<1>(is_protected), Return(r))); } - void expect_snap_is_unprotected(librbd::MockImageCtx &mock_image_ctx, + void expect_snap_is_unprotected(librbd::MockTestImageCtx &mock_image_ctx, uint64_t snap_id, bool is_unprotected, int r) { EXPECT_CALL(mock_image_ctx, is_snap_unprotected(snap_id, _)) .WillOnce(DoAll(SetArgPointee<1>(is_unprotected), @@ -148,13 +159,13 @@ public: .WillOnce(WithArg<1>(CompleteContext(r))); } - static void inject_snap(librbd::MockImageCtx &mock_image_ctx, - uint64_t snap_id, const std::string &snap_name) { + static void inject_snap(librbd::MockTestImageCtx &mock_image_ctx, + uint64_t snap_id, const std::string &snap_name) { mock_image_ctx.snap_ids[snap_name] = snap_id; } - MockSnapshotCopyRequest *create_request(librbd::MockImageCtx &mock_remote_image_ctx, - librbd::MockImageCtx &mock_local_image_ctx, + MockSnapshotCopyRequest *create_request(librbd::MockTestImageCtx &mock_remote_image_ctx, + librbd::MockTestImageCtx &mock_local_image_ctx, journal::MockJournaler &mock_journaler, Context *on_finish) { return new MockSnapshotCopyRequest(&mock_local_image_ctx, @@ -200,8 +211,8 @@ public: }; TEST_F(TestMockImageSyncSnapshotCopyRequest, Empty) { - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; InSequence seq; @@ -219,8 +230,8 @@ TEST_F(TestMockImageSyncSnapshotCopyRequest, Empty) { } TEST_F(TestMockImageSyncSnapshotCopyRequest, UpdateClientError) { - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; InSequence seq; @@ -235,8 +246,8 @@ TEST_F(TestMockImageSyncSnapshotCopyRequest, UpdateClientError) { } TEST_F(TestMockImageSyncSnapshotCopyRequest, UpdateClientCancel) { - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; C_SaferCond ctx; @@ -261,8 +272,8 @@ TEST_F(TestMockImageSyncSnapshotCopyRequest, SnapCreate) { uint64_t remote_snap_id1 = m_remote_image_ctx->snap_ids["snap1"]; uint64_t remote_snap_id2 = m_remote_image_ctx->snap_ids["snap2"]; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); MockSnapshotCreateRequest mock_snapshot_create_request; journal::MockJournaler mock_journaler; @@ -287,8 +298,8 @@ TEST_F(TestMockImageSyncSnapshotCopyRequest, SnapCreate) { TEST_F(TestMockImageSyncSnapshotCopyRequest, SnapCreateError) { ASSERT_EQ(0, create_snap(m_remote_image_ctx, "snap1")); - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); MockSnapshotCreateRequest mock_snapshot_create_request; journal::MockJournaler mock_journaler; @@ -306,8 +317,8 @@ TEST_F(TestMockImageSyncSnapshotCopyRequest, SnapCreateError) { TEST_F(TestMockImageSyncSnapshotCopyRequest, SnapCreateCancel) { ASSERT_EQ(0, create_snap(m_remote_image_ctx, "snap1")); - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); MockSnapshotCreateRequest mock_snapshot_create_request; journal::MockJournaler mock_journaler; @@ -334,8 +345,8 @@ TEST_F(TestMockImageSyncSnapshotCopyRequest, SnapRemoveAndCreate) { uint64_t remote_snap_id1 = m_remote_image_ctx->snap_ids["snap1"]; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); MockSnapshotCreateRequest mock_snapshot_create_request; journal::MockJournaler mock_journaler; @@ -361,8 +372,8 @@ TEST_F(TestMockImageSyncSnapshotCopyRequest, SnapRemoveAndCreate) { TEST_F(TestMockImageSyncSnapshotCopyRequest, SnapRemoveError) { ASSERT_EQ(0, create_snap(m_local_image_ctx, "snap1")); - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; InSequence seq; @@ -386,8 +397,8 @@ TEST_F(TestMockImageSyncSnapshotCopyRequest, SnapUnprotect) { uint64_t local_snap_id1 = m_local_image_ctx->snap_ids["snap1"]; m_client_meta.snap_seqs[remote_snap_id1] = local_snap_id1; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; InSequence seq; @@ -416,8 +427,8 @@ TEST_F(TestMockImageSyncSnapshotCopyRequest, SnapUnprotectError) { uint64_t local_snap_id1 = m_local_image_ctx->snap_ids["snap1"]; m_client_meta.snap_seqs[remote_snap_id1] = local_snap_id1; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; InSequence seq; @@ -441,8 +452,8 @@ TEST_F(TestMockImageSyncSnapshotCopyRequest, SnapUnprotectCancel) { uint64_t local_snap_id1 = m_local_image_ctx->snap_ids["snap1"]; m_client_meta.snap_seqs[remote_snap_id1] = local_snap_id1; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; C_SaferCond ctx; @@ -471,8 +482,8 @@ TEST_F(TestMockImageSyncSnapshotCopyRequest, SnapUnprotectRemove) { uint64_t remote_snap_id1 = m_remote_image_ctx->snap_ids["snap1"]; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); MockSnapshotCreateRequest mock_snapshot_create_request; journal::MockJournaler mock_journaler; @@ -501,8 +512,8 @@ TEST_F(TestMockImageSyncSnapshotCopyRequest, SnapCreateProtect) { uint64_t remote_snap_id1 = m_remote_image_ctx->snap_ids["snap1"]; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); MockSnapshotCreateRequest mock_snapshot_create_request; journal::MockJournaler mock_journaler; @@ -532,8 +543,8 @@ TEST_F(TestMockImageSyncSnapshotCopyRequest, SnapProtect) { uint64_t local_snap_id1 = m_local_image_ctx->snap_ids["snap1"]; m_client_meta.snap_seqs[remote_snap_id1] = local_snap_id1; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; InSequence seq; @@ -562,8 +573,8 @@ TEST_F(TestMockImageSyncSnapshotCopyRequest, SnapProtectError) { uint64_t local_snap_id1 = m_local_image_ctx->snap_ids["snap1"]; m_client_meta.snap_seqs[remote_snap_id1] = local_snap_id1; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; InSequence seq; @@ -588,8 +599,8 @@ TEST_F(TestMockImageSyncSnapshotCopyRequest, SnapProtectCancel) { uint64_t local_snap_id1 = m_local_image_ctx->snap_ids["snap1"]; m_client_meta.snap_seqs[remote_snap_id1] = local_snap_id1; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; C_SaferCond ctx; diff --git a/src/test/rbd_mirror/image_sync/test_mock_SnapshotCreateRequest.cc b/src/test/rbd_mirror/image_sync/test_mock_SnapshotCreateRequest.cc index 8cf6217bf75b..c0105aeaa210 100644 --- a/src/test/rbd_mirror/image_sync/test_mock_SnapshotCreateRequest.cc +++ b/src/test/rbd_mirror/image_sync/test_mock_SnapshotCreateRequest.cc @@ -13,9 +13,21 @@ #include "tools/rbd_mirror/image_sync/SnapshotCreateRequest.h" #include "tools/rbd_mirror/Threads.h" +namespace librbd { +namespace { + +struct MockTestImageCtx : public librbd::MockImageCtx { + MockTestImageCtx(librbd::ImageCtx &image_ctx) + : librbd::MockImageCtx(image_ctx) { + } +}; + +} // anonymous namespace +} // namespace librbd + // template definitions #include "tools/rbd_mirror/image_sync/SnapshotCreateRequest.cc" -template class rbd::mirror::image_sync::SnapshotCreateRequest; +template class rbd::mirror::image_sync::SnapshotCreateRequest; namespace rbd { namespace mirror { @@ -32,7 +44,7 @@ using ::testing::WithArg; class TestMockImageSyncSnapshotCreateRequest : public TestMockFixture { public: - typedef SnapshotCreateRequest MockSnapshotCreateRequest; + typedef SnapshotCreateRequest MockSnapshotCreateRequest; virtual void SetUp() { TestMockFixture::SetUp(); @@ -42,31 +54,31 @@ public: ASSERT_EQ(0, open_image(m_local_io_ctx, m_image_name, &m_local_image_ctx)); } - void expect_test_features(librbd::MockImageCtx &mock_image_ctx, + void expect_test_features(librbd::MockTestImageCtx &mock_image_ctx, uint64_t features, bool enabled) { EXPECT_CALL(mock_image_ctx, test_features(features)) .WillOnce(Return(enabled)); } - void expect_set_size(librbd::MockImageCtx &mock_image_ctx, int r) { + void expect_set_size(librbd::MockTestImageCtx &mock_image_ctx, int r) { EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx), exec(mock_image_ctx.header_oid, _, StrEq("rbd"), StrEq("set_size"), _, _, _)) .WillOnce(Return(r)); } - void expect_remove_parent(librbd::MockImageCtx &mock_image_ctx, int r) { + void expect_remove_parent(librbd::MockTestImageCtx &mock_image_ctx, int r) { EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx), exec(mock_image_ctx.header_oid, _, StrEq("rbd"), StrEq("remove_parent"), _, _, _)) .WillOnce(Return(r)); } - void expect_set_parent(librbd::MockImageCtx &mock_image_ctx, int r) { + void expect_set_parent(librbd::MockTestImageCtx &mock_image_ctx, int r) { EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx), exec(mock_image_ctx.header_oid, _, StrEq("rbd"), StrEq("set_parent"), _, _, _)) .WillOnce(Return(r)); } - void expect_snap_create(librbd::MockImageCtx &mock_image_ctx, + void expect_snap_create(librbd::MockTestImageCtx &mock_image_ctx, const std::string &snap_name, uint64_t snap_id, int r) { EXPECT_CALL(*mock_image_ctx.operations, execute_snap_create(StrEq(snap_name), _, 0, true)) .WillOnce(DoAll(InvokeWithoutArgs([&mock_image_ctx, snap_id, snap_name]() { @@ -77,7 +89,7 @@ public: })))); } - void expect_object_map_resize(librbd::MockImageCtx &mock_image_ctx, + void expect_object_map_resize(librbd::MockTestImageCtx &mock_image_ctx, librados::snap_t snap_id, int r) { std::string oid(librbd::ObjectMap::object_map_name(mock_image_ctx.id, snap_id)); @@ -86,12 +98,12 @@ public: .WillOnce(Return(r)); } - static void inject_snap(librbd::MockImageCtx &mock_image_ctx, + static void inject_snap(librbd::MockTestImageCtx &mock_image_ctx, uint64_t snap_id, const std::string &snap_name) { mock_image_ctx.snap_ids[snap_name] = snap_id; } - MockSnapshotCreateRequest *create_request(librbd::MockImageCtx &mock_local_image_ctx, + MockSnapshotCreateRequest *create_request(librbd::MockTestImageCtx &mock_local_image_ctx, const std::string &snap_name, uint64_t size, const librbd::parent_spec &spec, @@ -105,7 +117,7 @@ public: }; TEST_F(TestMockImageSyncSnapshotCreateRequest, Resize) { - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); InSequence seq; expect_set_size(mock_local_image_ctx, 0); @@ -121,7 +133,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, Resize) { } TEST_F(TestMockImageSyncSnapshotCreateRequest, ResizeError) { - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); InSequence seq; expect_set_size(mock_local_image_ctx, -EINVAL); @@ -135,7 +147,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, ResizeError) { } TEST_F(TestMockImageSyncSnapshotCreateRequest, RemoveParent) { - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); mock_local_image_ctx.parent_md.spec.pool_id = 213; InSequence seq; @@ -153,7 +165,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, RemoveParent) { } TEST_F(TestMockImageSyncSnapshotCreateRequest, RemoveParentError) { - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); mock_local_image_ctx.parent_md.spec.pool_id = 213; InSequence seq; @@ -169,7 +181,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, RemoveParentError) { } TEST_F(TestMockImageSyncSnapshotCreateRequest, RemoveSetParent) { - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); mock_local_image_ctx.parent_md.spec.pool_id = 213; InSequence seq; @@ -189,7 +201,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, RemoveSetParent) { } TEST_F(TestMockImageSyncSnapshotCreateRequest, SetParentSpec) { - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); InSequence seq; expect_set_parent(mock_local_image_ctx, 0); @@ -207,7 +219,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, SetParentSpec) { } TEST_F(TestMockImageSyncSnapshotCreateRequest, SetParentOverlap) { - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); mock_local_image_ctx.parent_md.spec = {123, "test", 0}; InSequence seq; @@ -226,7 +238,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, SetParentOverlap) { } TEST_F(TestMockImageSyncSnapshotCreateRequest, SetParentError) { - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); InSequence seq; expect_set_parent(mock_local_image_ctx, -ESTALE); @@ -242,7 +254,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, SetParentError) { } TEST_F(TestMockImageSyncSnapshotCreateRequest, SnapCreate) { - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); InSequence seq; expect_snap_create(mock_local_image_ctx, "snap1", 10, 0); @@ -258,7 +270,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, SnapCreate) { } TEST_F(TestMockImageSyncSnapshotCreateRequest, SnapCreateError) { - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); InSequence seq; expect_snap_create(mock_local_image_ctx, "snap1", 10, -EINVAL); @@ -273,7 +285,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, SnapCreateError) { } TEST_F(TestMockImageSyncSnapshotCreateRequest, ResizeObjectMap) { - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); InSequence seq; expect_snap_create(mock_local_image_ctx, "snap1", 10, 0); @@ -290,7 +302,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, ResizeObjectMap) { } TEST_F(TestMockImageSyncSnapshotCreateRequest, ResizeObjectMapError) { - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); InSequence seq; expect_snap_create(mock_local_image_ctx, "snap1", 10, 0); 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 faff6a73e906..7fd32d4efe40 100644 --- a/src/test/rbd_mirror/image_sync/test_mock_SyncPointCreateRequest.cc +++ b/src/test/rbd_mirror/image_sync/test_mock_SyncPointCreateRequest.cc @@ -11,10 +11,21 @@ #include "tools/rbd_mirror/image_sync/SyncPointCreateRequest.h" namespace librbd { + +namespace { + +struct MockTestImageCtx : public librbd::MockImageCtx { + MockTestImageCtx(librbd::ImageCtx &image_ctx) + : librbd::MockImageCtx(image_ctx) { + } +}; + +} // anonymous namespace + namespace journal { template <> -struct TypeTraits { +struct TypeTraits { typedef ::journal::MockJournaler Journaler; }; @@ -23,7 +34,7 @@ struct TypeTraits { // template definitions #include "tools/rbd_mirror/image_sync/SyncPointCreateRequest.cc" -template class rbd::mirror::image_sync::SyncPointCreateRequest; +template class rbd::mirror::image_sync::SyncPointCreateRequest; namespace rbd { namespace mirror { @@ -35,7 +46,7 @@ using ::testing::WithArg; class TestMockImageSyncSyncPointCreateRequest : public TestMockFixture { public: - typedef SyncPointCreateRequest MockSyncPointCreateRequest; + typedef SyncPointCreateRequest MockSyncPointCreateRequest; virtual void SetUp() { TestMockFixture::SetUp(); @@ -50,17 +61,17 @@ public: .WillOnce(WithArg<1>(CompleteContext(r))); } - void expect_image_refresh(librbd::MockImageCtx &mock_remote_image_ctx, int r) { + void expect_image_refresh(librbd::MockTestImageCtx &mock_remote_image_ctx, int r) { EXPECT_CALL(*mock_remote_image_ctx.state, refresh(_)) .WillOnce(CompleteContext(r)); } - void expect_snap_create(librbd::MockImageCtx &mock_remote_image_ctx, int r) { + void expect_snap_create(librbd::MockTestImageCtx &mock_remote_image_ctx, int r) { EXPECT_CALL(*mock_remote_image_ctx.operations, snap_create(_, _)) .WillOnce(WithArg<1>(CompleteContext(r))); } - MockSyncPointCreateRequest *create_request(librbd::MockImageCtx &mock_remote_image_ctx, + MockSyncPointCreateRequest *create_request(librbd::MockTestImageCtx &mock_remote_image_ctx, journal::MockJournaler &mock_journaler, Context *ctx) { return new MockSyncPointCreateRequest(&mock_remote_image_ctx, "uuid", @@ -72,7 +83,7 @@ public: }; TEST_F(TestMockImageSyncSyncPointCreateRequest, Success) { - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); journal::MockJournaler mock_journaler; InSequence seq; @@ -94,7 +105,7 @@ TEST_F(TestMockImageSyncSyncPointCreateRequest, ResyncSuccess) { m_client_meta.sync_points.emplace_front("start snap", "", boost::none); auto sync_point = m_client_meta.sync_points.front(); - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); journal::MockJournaler mock_journaler; InSequence seq; @@ -115,7 +126,7 @@ TEST_F(TestMockImageSyncSyncPointCreateRequest, ResyncSuccess) { } TEST_F(TestMockImageSyncSyncPointCreateRequest, SnapshotExists) { - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); journal::MockJournaler mock_journaler; InSequence seq; @@ -137,7 +148,7 @@ TEST_F(TestMockImageSyncSyncPointCreateRequest, SnapshotExists) { } TEST_F(TestMockImageSyncSyncPointCreateRequest, ClientUpdateError) { - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); journal::MockJournaler mock_journaler; InSequence seq; 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 76844dcd617e..7d037654640b 100644 --- a/src/test/rbd_mirror/image_sync/test_mock_SyncPointPruneRequest.cc +++ b/src/test/rbd_mirror/image_sync/test_mock_SyncPointPruneRequest.cc @@ -11,10 +11,21 @@ #include "tools/rbd_mirror/image_sync/SyncPointPruneRequest.h" namespace librbd { + +namespace { + +struct MockTestImageCtx : public librbd::MockImageCtx { + MockTestImageCtx(librbd::ImageCtx &image_ctx) + : librbd::MockImageCtx(image_ctx) { + } +}; + +} // anonymous namespace + namespace journal { template <> -struct TypeTraits { +struct TypeTraits { typedef ::journal::MockJournaler Journaler; }; @@ -23,7 +34,7 @@ struct TypeTraits { // template definitions #include "tools/rbd_mirror/image_sync/SyncPointPruneRequest.cc" -template class rbd::mirror::image_sync::SyncPointPruneRequest; +template class rbd::mirror::image_sync::SyncPointPruneRequest; namespace rbd { namespace mirror { @@ -37,7 +48,7 @@ using ::testing::WithArg; class TestMockImageSyncSyncPointPruneRequest : public TestMockFixture { public: - typedef SyncPointPruneRequest MockSyncPointPruneRequest; + typedef SyncPointPruneRequest MockSyncPointPruneRequest; virtual void SetUp() { TestMockFixture::SetUp(); @@ -52,24 +63,24 @@ public: .WillOnce(WithArg<1>(CompleteContext(r))); } - void expect_get_snap_id(librbd::MockImageCtx &mock_remote_image_ctx, + void expect_get_snap_id(librbd::MockTestImageCtx &mock_remote_image_ctx, const std::string &snap_name, uint64_t snap_id) { EXPECT_CALL(mock_remote_image_ctx, get_snap_id(StrEq(snap_name))) .WillOnce(Return(snap_id)); } - void expect_image_refresh(librbd::MockImageCtx &mock_remote_image_ctx, int r) { + void expect_image_refresh(librbd::MockTestImageCtx &mock_remote_image_ctx, int r) { EXPECT_CALL(*mock_remote_image_ctx.state, refresh(_)) .WillOnce(CompleteContext(r)); } - void expect_snap_remove(librbd::MockImageCtx &mock_remote_image_ctx, + void expect_snap_remove(librbd::MockTestImageCtx &mock_remote_image_ctx, const std::string &snap_name, int r) { EXPECT_CALL(*mock_remote_image_ctx.operations, snap_remove(StrEq(snap_name), _)) .WillOnce(WithArg<1>(CompleteContext(r))); } - MockSyncPointPruneRequest *create_request(librbd::MockImageCtx &mock_remote_image_ctx, + MockSyncPointPruneRequest *create_request(librbd::MockTestImageCtx &mock_remote_image_ctx, journal::MockJournaler &mock_journaler, bool sync_complete, Context *ctx) { return new MockSyncPointPruneRequest(&mock_remote_image_ctx, sync_complete, @@ -85,7 +96,7 @@ TEST_F(TestMockImageSyncSyncPointPruneRequest, SyncInProgressSuccess) { client_meta.sync_points.emplace_front("snap1", boost::none); m_client_meta = client_meta; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); journal::MockJournaler mock_journaler; InSequence seq; @@ -107,7 +118,7 @@ TEST_F(TestMockImageSyncSyncPointPruneRequest, RestartedSyncInProgressSuccess) { client_meta.sync_points.emplace_front("snap1", boost::none); m_client_meta = client_meta; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); journal::MockJournaler mock_journaler; InSequence seq; @@ -132,7 +143,7 @@ TEST_F(TestMockImageSyncSyncPointPruneRequest, SyncInProgressMissingSnapSuccess) client_meta.sync_points.emplace_front("snap1", boost::none); m_client_meta = client_meta; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); journal::MockJournaler mock_journaler; InSequence seq; @@ -157,7 +168,7 @@ TEST_F(TestMockImageSyncSyncPointPruneRequest, SyncInProgressUnexpectedFromSnapS client_meta.sync_points.emplace_front("snap2", "snap1", boost::none); m_client_meta = client_meta; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); journal::MockJournaler mock_journaler; InSequence seq; @@ -183,7 +194,7 @@ TEST_F(TestMockImageSyncSyncPointPruneRequest, SyncCompleteSuccess) { m_client_meta = client_meta; ASSERT_EQ(librbd::journal::MIRROR_PEER_STATE_SYNCING, m_client_meta.state); - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); journal::MockJournaler mock_journaler; InSequence seq; @@ -206,7 +217,7 @@ TEST_F(TestMockImageSyncSyncPointPruneRequest, RestartedSyncCompleteSuccess) { client_meta.sync_points.emplace_front("snap1", boost::none); m_client_meta = client_meta; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); journal::MockJournaler mock_journaler; InSequence seq; @@ -228,7 +239,7 @@ TEST_F(TestMockImageSyncSyncPointPruneRequest, RestartedCatchUpSyncCompleteSucce client_meta.sync_points.emplace_front("snap2", "snap1", boost::none); m_client_meta = client_meta; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); journal::MockJournaler mock_journaler; InSequence seq; @@ -250,7 +261,7 @@ TEST_F(TestMockImageSyncSyncPointPruneRequest, SnapshotDNE) { client_meta.sync_points.emplace_front("snap1", boost::none); m_client_meta = client_meta; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); journal::MockJournaler mock_journaler; InSequence seq; @@ -272,7 +283,7 @@ TEST_F(TestMockImageSyncSyncPointPruneRequest, ClientUpdateError) { client_meta.sync_points.emplace_front("snap1", boost::none); m_client_meta = client_meta; - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); journal::MockJournaler mock_journaler; InSequence seq; diff --git a/src/test/rbd_mirror/test_mock_ImageSync.cc b/src/test/rbd_mirror/test_mock_ImageSync.cc index 4e58ac76cb77..3d3983adf76c 100644 --- a/src/test/rbd_mirror/test_mock_ImageSync.cc +++ b/src/test/rbd_mirror/test_mock_ImageSync.cc @@ -17,10 +17,21 @@ #include "tools/rbd_mirror/image_sync/SyncPointPruneRequest.h" namespace librbd { + +namespace { + +struct MockTestImageCtx : public librbd::MockImageCtx { + MockTestImageCtx(librbd::ImageCtx &image_ctx) + : librbd::MockImageCtx(image_ctx) { + } +}; + +} // anonymous namespace + namespace journal { template <> -struct TypeTraits { +struct TypeTraits { typedef ::journal::MockJournaler Journaler; }; @@ -29,7 +40,7 @@ struct TypeTraits { // template definitions #include "tools/rbd_mirror/ImageSync.cc" -template class rbd::mirror::ImageSync; +template class rbd::mirror::ImageSync; namespace rbd { namespace mirror { @@ -37,13 +48,13 @@ namespace mirror { namespace image_sync { template <> -class ImageCopyRequest { +class ImageCopyRequest { public: static ImageCopyRequest* s_instance; Context *on_finish; - static ImageCopyRequest* create(librbd::MockImageCtx *local_image_ctx, - librbd::MockImageCtx *remote_image_ctx, + static ImageCopyRequest* create(librbd::MockTestImageCtx *local_image_ctx, + librbd::MockTestImageCtx *remote_image_ctx, SafeTimer *timer, Mutex *timer_lock, journal::MockJournaler *journaler, librbd::journal::MirrorPeerClientMeta *client_meta, @@ -70,13 +81,13 @@ public: }; template <> -class SnapshotCopyRequest { +class SnapshotCopyRequest { public: static SnapshotCopyRequest* s_instance; Context *on_finish; - static SnapshotCopyRequest* create(librbd::MockImageCtx *local_image_ctx, - librbd::MockImageCtx *remote_image_ctx, + static SnapshotCopyRequest* create(librbd::MockTestImageCtx *local_image_ctx, + librbd::MockTestImageCtx *remote_image_ctx, SnapshotCopyRequest::SnapMap *snap_map, journal::MockJournaler *journaler, librbd::journal::MirrorPeerClientMeta *client_meta, @@ -102,12 +113,12 @@ public: }; template <> -class SyncPointCreateRequest { +class SyncPointCreateRequest { public: static SyncPointCreateRequest *s_instance; Context *on_finish; - static SyncPointCreateRequest* create(librbd::MockImageCtx *remote_image_ctx, + static SyncPointCreateRequest* create(librbd::MockTestImageCtx *remote_image_ctx, const std::string &mirror_uuid, journal::MockJournaler *journaler, librbd::journal::MirrorPeerClientMeta *client_meta, @@ -124,13 +135,13 @@ public: }; template <> -class SyncPointPruneRequest { +class SyncPointPruneRequest { public: static SyncPointPruneRequest *s_instance; Context *on_finish; bool sync_complete; - static SyncPointPruneRequest* create(librbd::MockImageCtx *remote_image_ctx, + static SyncPointPruneRequest* create(librbd::MockTestImageCtx *remote_image_ctx, bool sync_complete, journal::MockJournaler *journaler, librbd::journal::MirrorPeerClientMeta *client_meta, @@ -147,10 +158,10 @@ public: MOCK_METHOD0(send, void()); }; -ImageCopyRequest* ImageCopyRequest::s_instance = nullptr; -SnapshotCopyRequest* SnapshotCopyRequest::s_instance = nullptr; -SyncPointCreateRequest* SyncPointCreateRequest::s_instance = nullptr; -SyncPointPruneRequest* SyncPointPruneRequest::s_instance = nullptr; +ImageCopyRequest* ImageCopyRequest::s_instance = nullptr; +SnapshotCopyRequest* SnapshotCopyRequest::s_instance = nullptr; +SyncPointCreateRequest* SyncPointCreateRequest::s_instance = nullptr; +SyncPointPruneRequest* SyncPointPruneRequest::s_instance = nullptr; } // namespace image_sync @@ -163,11 +174,11 @@ using ::testing::InvokeWithoutArgs; class TestMockImageSync : public TestMockFixture { public: - typedef ImageSync MockImageSync; - typedef image_sync::ImageCopyRequest MockImageCopyRequest; - typedef image_sync::SnapshotCopyRequest MockSnapshotCopyRequest; - typedef image_sync::SyncPointCreateRequest MockSyncPointCreateRequest; - typedef image_sync::SyncPointPruneRequest MockSyncPointPruneRequest; + typedef ImageSync MockImageSync; + typedef image_sync::ImageCopyRequest MockImageCopyRequest; + typedef image_sync::SnapshotCopyRequest MockSnapshotCopyRequest; + typedef image_sync::SyncPointCreateRequest MockSyncPointCreateRequest; + typedef image_sync::SyncPointPruneRequest MockSyncPointPruneRequest; virtual void SetUp() { TestMockFixture::SetUp(); @@ -180,7 +191,7 @@ public: ASSERT_EQ(0, open_image(m_local_io_ctx, m_image_name, &m_local_image_ctx)); } - void expect_create_sync_point(librbd::MockImageCtx &mock_local_image_ctx, + void expect_create_sync_point(librbd::MockTestImageCtx &mock_local_image_ctx, MockSyncPointCreateRequest &mock_sync_point_create_request, int r) { EXPECT_CALL(mock_sync_point_create_request, send()) @@ -216,13 +227,13 @@ public: } } - void expect_create_object_map(librbd::MockImageCtx &mock_image_ctx, + void expect_create_object_map(librbd::MockTestImageCtx &mock_image_ctx, librbd::MockObjectMap *mock_object_map) { EXPECT_CALL(mock_image_ctx, create_object_map(CEPH_NOSNAP)) .WillOnce(Return(mock_object_map)); } - void expect_open_object_map(librbd::MockImageCtx &mock_image_ctx, + void expect_open_object_map(librbd::MockTestImageCtx &mock_image_ctx, librbd::MockObjectMap &mock_object_map) { EXPECT_CALL(mock_object_map, open(_)) .WillOnce(Invoke([this](Context *ctx) { @@ -248,8 +259,8 @@ public: })); } - MockImageSync *create_request(librbd::MockImageCtx &mock_remote_image_ctx, - librbd::MockImageCtx &mock_local_image_ctx, + MockImageSync *create_request(librbd::MockTestImageCtx &mock_remote_image_ctx, + librbd::MockTestImageCtx &mock_local_image_ctx, journal::MockJournaler &mock_journaler, Context *ctx) { return new MockImageSync(&mock_local_image_ctx, &mock_remote_image_ctx, @@ -264,8 +275,8 @@ public: }; TEST_F(TestMockImageSync, SimpleSync) { - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; MockImageCopyRequest mock_image_copy_request; MockSnapshotCopyRequest mock_snapshot_copy_request; @@ -294,8 +305,8 @@ TEST_F(TestMockImageSync, SimpleSync) { } TEST_F(TestMockImageSync, RestartSync) { - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; MockImageCopyRequest mock_image_copy_request; MockSnapshotCopyRequest mock_snapshot_copy_request; @@ -329,8 +340,8 @@ TEST_F(TestMockImageSync, RestartSync) { } TEST_F(TestMockImageSync, CancelImageCopy) { - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; MockImageCopyRequest mock_image_copy_request; MockSnapshotCopyRequest mock_snapshot_copy_request; @@ -367,8 +378,8 @@ TEST_F(TestMockImageSync, CancelImageCopy) { } TEST_F(TestMockImageSync, CancelAfterCopySnapshots) { - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; MockSnapshotCopyRequest mock_snapshot_copy_request; MockSyncPointCreateRequest mock_sync_point_create_request; @@ -397,8 +408,8 @@ TEST_F(TestMockImageSync, CancelAfterCopySnapshots) { } TEST_F(TestMockImageSync, CancelAfterCopyImage) { - librbd::MockImageCtx mock_remote_image_ctx(*m_remote_image_ctx); - librbd::MockImageCtx mock_local_image_ctx(*m_local_image_ctx); + librbd::MockTestImageCtx mock_remote_image_ctx(*m_remote_image_ctx); + librbd::MockTestImageCtx mock_local_image_ctx(*m_local_image_ctx); journal::MockJournaler mock_journaler; MockImageCopyRequest mock_image_copy_request; MockSnapshotCopyRequest mock_snapshot_copy_request; diff --git a/src/test/rbd_mirror/test_mock_ImageSyncThrottler.cc b/src/test/rbd_mirror/test_mock_ImageSyncThrottler.cc index 31829bda23f7..01f875c93977 100644 --- a/src/test/rbd_mirror/test_mock_ImageSyncThrottler.cc +++ b/src/test/rbd_mirror/test_mock_ImageSyncThrottler.cc @@ -21,10 +21,21 @@ #include "tools/rbd_mirror/ImageSync.h" namespace librbd { + +namespace { + +struct MockTestImageCtx : public librbd::MockImageCtx { + MockTestImageCtx(librbd::ImageCtx &image_ctx) + : librbd::MockImageCtx(image_ctx) { + } +}; + +} // anonymous namespace + namespace journal { template <> -struct TypeTraits { +struct TypeTraits { typedef ::journal::MockJournaler Journaler; }; @@ -36,18 +47,18 @@ namespace mirror { using ::testing::Invoke; -typedef ImageSync MockImageSync; +typedef ImageSync MockImageSync; template<> -class ImageSync { +class ImageSync { public: static std::vector instances; Context *on_finish; bool syncing = false; - static ImageSync* create(librbd::MockImageCtx *local_image_ctx, - librbd::MockImageCtx *remote_image_ctx, + static ImageSync* create(librbd::MockTestImageCtx *local_image_ctx, + librbd::MockTestImageCtx *remote_image_ctx, SafeTimer *timer, Mutex *timer_lock, const std::string &mirror_uuid, journal::MockJournaler *journaler, @@ -90,14 +101,14 @@ std::vector MockImageSync::instances; // template definitions #include "tools/rbd_mirror/ImageSyncThrottler.cc" -template class rbd::mirror::ImageSyncThrottler; +template class rbd::mirror::ImageSyncThrottler; namespace rbd { namespace mirror { class TestMockImageSyncThrottler : public TestMockFixture { public: - typedef ImageSyncThrottler MockImageSyncThrottler; + typedef ImageSyncThrottler MockImageSyncThrottler; virtual void SetUp() { TestMockFixture::SetUp(); @@ -111,8 +122,8 @@ public: mock_sync_throttler = new MockImageSyncThrottler(); - m_mock_local_image_ctx = new librbd::MockImageCtx(*m_local_image_ctx); - m_mock_remote_image_ctx = new librbd::MockImageCtx(*m_remote_image_ctx); + m_mock_local_image_ctx = new librbd::MockTestImageCtx(*m_local_image_ctx); + m_mock_remote_image_ctx = new librbd::MockTestImageCtx(*m_remote_image_ctx); m_mock_journaler = new journal::MockJournaler(); } @@ -153,8 +164,8 @@ public: librbd::ImageCtx *m_remote_image_ctx; librbd::ImageCtx *m_local_image_ctx; - librbd::MockImageCtx *m_mock_local_image_ctx; - librbd::MockImageCtx *m_mock_remote_image_ctx; + librbd::MockTestImageCtx *m_mock_local_image_ctx; + librbd::MockTestImageCtx *m_mock_remote_image_ctx; journal::MockJournaler *m_mock_journaler; librbd::journal::MirrorPeerClientMeta m_client_meta; MockImageSyncThrottler *mock_sync_throttler; -- 2.47.3