#include <boost/scope_exit.hpp>
namespace librbd {
+
+namespace {
+
+struct MockTestImageCtx : public librbd::MockImageCtx {
+ MockTestImageCtx(librbd::ImageCtx &image_ctx)
+ : librbd::MockImageCtx(image_ctx) {
+ }
+};
+
+} // anonymous namespace
+
namespace journal {
template <>
-struct TypeTraits<librbd::MockImageCtx> {
+struct TypeTraits<librbd::MockTestImageCtx> {
typedef ::journal::MockJournaler Journaler;
};
namespace image_sync {
template <>
-struct ObjectCopyRequest<librbd::MockImageCtx> {
+struct ObjectCopyRequest<librbd::MockTestImageCtx> {
static ObjectCopyRequest* s_instance;
- static ObjectCopyRequest* create(librbd::MockImageCtx *local_image_ctx,
- librbd::MockImageCtx *remote_image_ctx,
- const ImageCopyRequest<librbd::MockImageCtx>::SnapMap *snap_map,
+ static ObjectCopyRequest* create(librbd::MockTestImageCtx *local_image_ctx,
+ librbd::MockTestImageCtx *remote_image_ctx,
+ const ImageCopyRequest<librbd::MockTestImageCtx>::SnapMap *snap_map,
uint64_t object_number, Context *on_finish) {
assert(s_instance != nullptr);
Mutex::Locker locker(s_instance->lock);
Mutex lock;
Cond cond;
- const ImageCopyRequest<librbd::MockImageCtx>::SnapMap *snap_map = nullptr;
+ const ImageCopyRequest<librbd::MockTestImageCtx>::SnapMap *snap_map = nullptr;
std::map<uint64_t, Context *> object_contexts;
ObjectCopyRequest() : lock("lock") {
}
};
-ObjectCopyRequest<librbd::MockImageCtx>* ObjectCopyRequest<librbd::MockImageCtx>::s_instance = nullptr;
+ObjectCopyRequest<librbd::MockTestImageCtx>* ObjectCopyRequest<librbd::MockTestImageCtx>::s_instance = nullptr;
} // namespace image_sync
} // namespace mirror
// template definitions
#include "tools/rbd_mirror/image_sync/ImageCopyRequest.cc"
-template class rbd::mirror::image_sync::ImageCopyRequest<librbd::MockImageCtx>;
+template class rbd::mirror::image_sync::ImageCopyRequest<librbd::MockTestImageCtx>;
namespace rbd {
namespace mirror {
class TestMockImageSyncImageCopyRequest : public TestMockFixture {
public:
- typedef ImageCopyRequest<librbd::MockImageCtx> MockImageCopyRequest;
- typedef ObjectCopyRequest<librbd::MockImageCtx> MockObjectCopyRequest;
+ typedef ImageCopyRequest<librbd::MockTestImageCtx> MockImageCopyRequest;
+ typedef ObjectCopyRequest<librbd::MockTestImageCtx> MockObjectCopyRequest;
virtual void SetUp() {
TestMockFixture::SetUp();
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);
}));
}
- 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();
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) {
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;
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;
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;
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;
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;
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;
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;
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;
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);
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);
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);
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);
#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<librbd::MockImageCtx>;
+template class rbd::mirror::image_sync::ObjectCopyRequest<librbd::MockTestImageCtx>;
namespace rbd {
namespace mirror {
class TestMockImageSyncObjectCopyRequest : public TestMockFixture {
public:
- typedef ObjectCopyRequest<librbd::MockImageCtx> MockObjectCopyRequest;
+ typedef ObjectCopyRequest<librbd::MockTestImageCtx> MockObjectCopyRequest;
virtual void SetUp() {
TestMockFixture::SetUp();
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),
}
}
- 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);
}
}
- 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) {
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;
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;
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;
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;
}
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;
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;
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;
#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<librbd::MockImageCtx> {
+struct TypeTraits<librbd::MockTestImageCtx> {
typedef ::journal::MockJournaler Journaler;
};
namespace image_sync {
template <>
-struct SnapshotCreateRequest<librbd::MockImageCtx> {
+struct SnapshotCreateRequest<librbd::MockTestImageCtx> {
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,
MOCK_METHOD0(send, void());
};
-SnapshotCreateRequest<librbd::MockImageCtx>* SnapshotCreateRequest<librbd::MockImageCtx>::s_instance = nullptr;
+SnapshotCreateRequest<librbd::MockTestImageCtx>* SnapshotCreateRequest<librbd::MockTestImageCtx>::s_instance = nullptr;
} // namespace image_sync
} // namespace mirror
// template definitions
#include "tools/rbd_mirror/image_sync/SnapshotCopyRequest.cc"
-template class rbd::mirror::image_sync::SnapshotCopyRequest<librbd::MockImageCtx>;
+template class rbd::mirror::image_sync::SnapshotCopyRequest<librbd::MockTestImageCtx>;
namespace rbd {
namespace mirror {
class TestMockImageSyncSnapshotCopyRequest : public TestMockFixture {
public:
- typedef SnapshotCopyRequest<librbd::MockImageCtx> MockSnapshotCopyRequest;
- typedef SnapshotCreateRequest<librbd::MockImageCtx> MockSnapshotCreateRequest;
+ typedef SnapshotCopyRequest<librbd::MockTestImageCtx> MockSnapshotCopyRequest;
+ typedef SnapshotCreateRequest<librbd::MockTestImageCtx> MockSnapshotCreateRequest;
virtual void SetUp() {
TestMockFixture::SetUp();
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())
})));
}
- 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) {
})));
}
- 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) {
})));
}
- 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) {
})));
}
- 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),
.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,
};
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;
}
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;
}
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
#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<librbd::MockImageCtx>;
+template class rbd::mirror::image_sync::SnapshotCreateRequest<librbd::MockTestImageCtx>;
namespace rbd {
namespace mirror {
class TestMockImageSyncSnapshotCreateRequest : public TestMockFixture {
public:
- typedef SnapshotCreateRequest<librbd::MockImageCtx> MockSnapshotCreateRequest;
+ typedef SnapshotCreateRequest<librbd::MockTestImageCtx> MockSnapshotCreateRequest;
virtual void SetUp() {
TestMockFixture::SetUp();
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]() {
}))));
}
- 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));
.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,
};
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);
}
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);
}
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;
}
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;
}
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;
}
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);
}
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;
}
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);
}
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);
}
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);
}
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);
}
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);
#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<librbd::MockImageCtx> {
+struct TypeTraits<librbd::MockTestImageCtx> {
typedef ::journal::MockJournaler Journaler;
};
// template definitions
#include "tools/rbd_mirror/image_sync/SyncPointCreateRequest.cc"
-template class rbd::mirror::image_sync::SyncPointCreateRequest<librbd::MockImageCtx>;
+template class rbd::mirror::image_sync::SyncPointCreateRequest<librbd::MockTestImageCtx>;
namespace rbd {
namespace mirror {
class TestMockImageSyncSyncPointCreateRequest : public TestMockFixture {
public:
- typedef SyncPointCreateRequest<librbd::MockImageCtx> MockSyncPointCreateRequest;
+ typedef SyncPointCreateRequest<librbd::MockTestImageCtx> MockSyncPointCreateRequest;
virtual void SetUp() {
TestMockFixture::SetUp();
.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",
};
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;
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;
}
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;
}
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;
#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<librbd::MockImageCtx> {
+struct TypeTraits<librbd::MockTestImageCtx> {
typedef ::journal::MockJournaler Journaler;
};
// template definitions
#include "tools/rbd_mirror/image_sync/SyncPointPruneRequest.cc"
-template class rbd::mirror::image_sync::SyncPointPruneRequest<librbd::MockImageCtx>;
+template class rbd::mirror::image_sync::SyncPointPruneRequest<librbd::MockTestImageCtx>;
namespace rbd {
namespace mirror {
class TestMockImageSyncSyncPointPruneRequest : public TestMockFixture {
public:
- typedef SyncPointPruneRequest<librbd::MockImageCtx> MockSyncPointPruneRequest;
+ typedef SyncPointPruneRequest<librbd::MockTestImageCtx> MockSyncPointPruneRequest;
virtual void SetUp() {
TestMockFixture::SetUp();
.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,
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;
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;
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;
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;
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;
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;
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;
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;
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;
#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<librbd::MockImageCtx> {
+struct TypeTraits<librbd::MockTestImageCtx> {
typedef ::journal::MockJournaler Journaler;
};
// template definitions
#include "tools/rbd_mirror/ImageSync.cc"
-template class rbd::mirror::ImageSync<librbd::MockImageCtx>;
+template class rbd::mirror::ImageSync<librbd::MockTestImageCtx>;
namespace rbd {
namespace mirror {
namespace image_sync {
template <>
-class ImageCopyRequest<librbd::MockImageCtx> {
+class ImageCopyRequest<librbd::MockTestImageCtx> {
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,
};
template <>
-class SnapshotCopyRequest<librbd::MockImageCtx> {
+class SnapshotCopyRequest<librbd::MockTestImageCtx> {
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<librbd::ImageCtx>::SnapMap *snap_map,
journal::MockJournaler *journaler,
librbd::journal::MirrorPeerClientMeta *client_meta,
};
template <>
-class SyncPointCreateRequest<librbd::MockImageCtx> {
+class SyncPointCreateRequest<librbd::MockTestImageCtx> {
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,
};
template <>
-class SyncPointPruneRequest<librbd::MockImageCtx> {
+class SyncPointPruneRequest<librbd::MockTestImageCtx> {
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,
MOCK_METHOD0(send, void());
};
-ImageCopyRequest<librbd::MockImageCtx>* ImageCopyRequest<librbd::MockImageCtx>::s_instance = nullptr;
-SnapshotCopyRequest<librbd::MockImageCtx>* SnapshotCopyRequest<librbd::MockImageCtx>::s_instance = nullptr;
-SyncPointCreateRequest<librbd::MockImageCtx>* SyncPointCreateRequest<librbd::MockImageCtx>::s_instance = nullptr;
-SyncPointPruneRequest<librbd::MockImageCtx>* SyncPointPruneRequest<librbd::MockImageCtx>::s_instance = nullptr;
+ImageCopyRequest<librbd::MockTestImageCtx>* ImageCopyRequest<librbd::MockTestImageCtx>::s_instance = nullptr;
+SnapshotCopyRequest<librbd::MockTestImageCtx>* SnapshotCopyRequest<librbd::MockTestImageCtx>::s_instance = nullptr;
+SyncPointCreateRequest<librbd::MockTestImageCtx>* SyncPointCreateRequest<librbd::MockTestImageCtx>::s_instance = nullptr;
+SyncPointPruneRequest<librbd::MockTestImageCtx>* SyncPointPruneRequest<librbd::MockTestImageCtx>::s_instance = nullptr;
} // namespace image_sync
class TestMockImageSync : public TestMockFixture {
public:
- typedef ImageSync<librbd::MockImageCtx> MockImageSync;
- typedef image_sync::ImageCopyRequest<librbd::MockImageCtx> MockImageCopyRequest;
- typedef image_sync::SnapshotCopyRequest<librbd::MockImageCtx> MockSnapshotCopyRequest;
- typedef image_sync::SyncPointCreateRequest<librbd::MockImageCtx> MockSyncPointCreateRequest;
- typedef image_sync::SyncPointPruneRequest<librbd::MockImageCtx> MockSyncPointPruneRequest;
+ typedef ImageSync<librbd::MockTestImageCtx> MockImageSync;
+ typedef image_sync::ImageCopyRequest<librbd::MockTestImageCtx> MockImageCopyRequest;
+ typedef image_sync::SnapshotCopyRequest<librbd::MockTestImageCtx> MockSnapshotCopyRequest;
+ typedef image_sync::SyncPointCreateRequest<librbd::MockTestImageCtx> MockSyncPointCreateRequest;
+ typedef image_sync::SyncPointPruneRequest<librbd::MockTestImageCtx> MockSyncPointPruneRequest;
virtual void SetUp() {
TestMockFixture::SetUp();
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())
}
}
- 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) {
}));
}
- 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,
};
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;
}
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;
}
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;
}
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;
}
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;
#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<librbd::MockImageCtx> {
+struct TypeTraits<librbd::MockTestImageCtx> {
typedef ::journal::MockJournaler Journaler;
};
using ::testing::Invoke;
-typedef ImageSync<librbd::MockImageCtx> MockImageSync;
+typedef ImageSync<librbd::MockTestImageCtx> MockImageSync;
template<>
-class ImageSync<librbd::MockImageCtx> {
+class ImageSync<librbd::MockTestImageCtx> {
public:
static std::vector<MockImageSync *> 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,
// template definitions
#include "tools/rbd_mirror/ImageSyncThrottler.cc"
-template class rbd::mirror::ImageSyncThrottler<librbd::MockImageCtx>;
+template class rbd::mirror::ImageSyncThrottler<librbd::MockTestImageCtx>;
namespace rbd {
namespace mirror {
class TestMockImageSyncThrottler : public TestMockFixture {
public:
- typedef ImageSyncThrottler<librbd::MockImageCtx> MockImageSyncThrottler;
+ typedef ImageSyncThrottler<librbd::MockTestImageCtx> MockImageSyncThrottler;
virtual void SetUp() {
TestMockFixture::SetUp();
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();
}
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;