#include "test/rbd_mirror/test_mock_fixture.h"
#include "librbd/journal/TypeTraits.h"
-#include "tools/rbd_mirror/ImageSyncThrottler.h"
+#include "tools/rbd_mirror/InstanceWatcher.h"
#include "tools/rbd_mirror/Threads.h"
#include "tools/rbd_mirror/image_replayer/BootstrapRequest.h"
#include "tools/rbd_mirror/image_replayer/CloseImageRequest.h"
class ProgressContext;
template<>
-struct ImageSyncThrottler<librbd::MockTestImageCtx> {
- MOCK_METHOD10(start_sync, void(librbd::MockTestImageCtx *local_image_ctx,
- librbd::MockTestImageCtx *remote_image_ctx,
- SafeTimer *timer, Mutex *timer_lock,
- const std::string &mirror_uuid,
- ::journal::MockJournaler *journaler,
- librbd::journal::MirrorPeerClientMeta *client_meta,
- ContextWQ *work_queue, Context *on_finish,
- ProgressContext *progress_ctx));
- MOCK_METHOD2(cancel_sync, void(librados::IoCtx &local_io_ctx,
- const std::string& mirror_uuid));
+struct ImageSync<librbd::MockTestImageCtx> {
+ static ImageSync* s_instance;
+ Context *on_finish = nullptr;
+
+ 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,
+ librbd::journal::MirrorPeerClientMeta *client_meta, ContextWQ *work_queue,
+ InstanceWatcher<librbd::MockTestImageCtx> *instance_watcher,
+ Context *on_finish, ProgressContext *progress_ctx) {
+ assert(s_instance != nullptr);
+ s_instance->on_finish = on_finish;
+ return s_instance;
+ }
+
+ ImageSync() {
+ assert(s_instance == nullptr);
+ s_instance = this;
+ }
+ ~ImageSync() {
+ s_instance = nullptr;
+ }
+
+ MOCK_METHOD0(get, void());
+ MOCK_METHOD0(put, void());
+ MOCK_METHOD0(send, void());
+ MOCK_METHOD0(cancel, void());
+};
+
+ImageSync<librbd::MockTestImageCtx>*
+ ImageSync<librbd::MockTestImageCtx>::s_instance = nullptr;
+
+template<>
+struct InstanceWatcher<librbd::MockTestImageCtx> {
};
namespace image_replayer {
class TestMockImageReplayerBootstrapRequest : public TestMockFixture {
public:
- typedef ImageSyncThrottlerRef<librbd::MockTestImageCtx> MockImageSyncThrottler;
typedef BootstrapRequest<librbd::MockTestImageCtx> MockBootstrapRequest;
typedef CloseImageRequest<librbd::MockTestImageCtx> MockCloseImageRequest;
typedef CreateImageRequest<librbd::MockTestImageCtx> MockCreateImageRequest;
+ typedef ImageSync<librbd::MockTestImageCtx> MockImageSync;
+ typedef InstanceWatcher<librbd::MockTestImageCtx> MockInstanceWatcher;
typedef IsPrimaryRequest<librbd::MockTestImageCtx> MockIsPrimaryRequest;
typedef OpenImageRequest<librbd::MockTestImageCtx> MockOpenImageRequest;
typedef OpenLocalImageRequest<librbd::MockTestImageCtx> MockOpenLocalImageRequest;
}));
}
- void expect_image_sync(MockImageSyncThrottler image_sync_throttler,
- int r) {
- EXPECT_CALL(*image_sync_throttler, start_sync(_, _, _, _,
- StrEq("local mirror uuid"),
- _, _, _, _, _))
- .WillOnce(WithArg<8>(Invoke([this, r](Context *on_finish) {
- m_threads->work_queue->queue(on_finish, r);
- })));
+ void expect_image_sync(MockImageSync &mock_image_sync, int r) {
+ EXPECT_CALL(mock_image_sync, get());
+ EXPECT_CALL(mock_image_sync, send())
+ .WillOnce(Invoke([this, &mock_image_sync, r]() {
+ m_threads->work_queue->queue(mock_image_sync.on_finish, r);
+ }));
+ EXPECT_CALL(mock_image_sync, put());
}
bufferlist encode_tag_data(const librbd::journal::TagData &tag_data) {
return bl;
}
- MockBootstrapRequest *create_request(MockImageSyncThrottler mock_image_sync_throttler,
+ MockBootstrapRequest *create_request(MockInstanceWatcher *mock_instance_watcher,
::journal::MockJournaler &mock_journaler,
const std::string &local_image_id,
const std::string &remote_image_id,
Context *on_finish) {
return new MockBootstrapRequest(m_local_io_ctx,
m_remote_io_ctx,
- mock_image_sync_throttler,
+ mock_instance_watcher,
&m_local_test_image_ctx,
local_image_id,
remote_image_id,
expect_close_image(mock_close_image_request, mock_remote_image_ctx, 0);
C_SaferCond ctx;
- MockImageSyncThrottler mock_image_sync_throttler(
- new ImageSyncThrottler<librbd::MockTestImageCtx>());
+ MockInstanceWatcher mock_instance_watcher;
MockBootstrapRequest *request = create_request(
- mock_image_sync_throttler, mock_journaler, mock_local_image_ctx.id,
+ &mock_instance_watcher, mock_journaler, mock_local_image_ctx.id,
mock_remote_image_ctx.id, "global image id", "local mirror uuid",
"remote mirror uuid", &ctx);
request->send();
expect_close_image(mock_close_image_request, mock_remote_image_ctx, 0);
C_SaferCond ctx;
- MockImageSyncThrottler mock_image_sync_throttler(
- new ImageSyncThrottler<librbd::MockTestImageCtx>());
+ MockInstanceWatcher mock_instance_watcher;
MockBootstrapRequest *request = create_request(
- mock_image_sync_throttler, mock_journaler, mock_local_image_ctx.id,
+ &mock_instance_watcher, mock_journaler, mock_local_image_ctx.id,
mock_remote_image_ctx.id, "global image id", "local mirror uuid",
"remote mirror uuid", &ctx);
request->send();
expect_close_image(mock_close_image_request, mock_remote_image_ctx, 0);
C_SaferCond ctx;
- MockImageSyncThrottler mock_image_sync_throttler(
- new ImageSyncThrottler<librbd::MockTestImageCtx>());
+ MockInstanceWatcher mock_instance_watcher;
MockBootstrapRequest *request = create_request(
- mock_image_sync_throttler, mock_journaler, mock_local_image_ctx.id,
+ &mock_instance_watcher, mock_journaler, mock_local_image_ctx.id,
mock_remote_image_ctx.id, "global image id", "local mirror uuid",
"remote mirror uuid", &ctx);
request->send();
expect_close_image(mock_close_image_request, mock_remote_image_ctx, 0);
C_SaferCond ctx;
- MockImageSyncThrottler mock_image_sync_throttler(
- new ImageSyncThrottler<librbd::MockTestImageCtx>());
+ MockInstanceWatcher mock_instance_watcher;
MockBootstrapRequest *request = create_request(
- mock_image_sync_throttler, mock_journaler, mock_local_image_ctx.id,
+ &mock_instance_watcher, mock_journaler, mock_local_image_ctx.id,
mock_remote_image_ctx.id, "global image id", "local mirror uuid",
"remote mirror uuid", &ctx);
request->send();
expect_close_image(mock_close_image_request, mock_remote_image_ctx, 0);
C_SaferCond ctx;
- MockImageSyncThrottler mock_image_sync_throttler(
- new ImageSyncThrottler<librbd::MockTestImageCtx>());
+ MockInstanceWatcher mock_instance_watcher;
MockBootstrapRequest *request = create_request(
- mock_image_sync_throttler, mock_journaler, mock_local_image_ctx.id,
+ &mock_instance_watcher, mock_journaler, mock_local_image_ctx.id,
mock_remote_image_ctx.id, "global image id", "local mirror uuid",
"remote mirror uuid", &ctx);
request->send();
expect_close_image(mock_close_image_request, mock_remote_image_ctx, 0);
C_SaferCond ctx;
- MockImageSyncThrottler mock_image_sync_throttler(
- new ImageSyncThrottler<librbd::MockTestImageCtx>());
+ MockInstanceWatcher mock_instance_watcher;
MockBootstrapRequest *request = create_request(
- mock_image_sync_throttler, mock_journaler, mock_local_image_ctx.id,
+ &mock_instance_watcher, mock_journaler, mock_local_image_ctx.id,
mock_remote_image_ctx.id, "global image id", "local mirror uuid",
"remote mirror uuid", &ctx);
m_do_resync = false;
expect_journaler_update_client(mock_journaler, client_data, 0);
// sync the remote image to the local image
- MockImageSyncThrottler mock_image_sync_throttler(
- new ImageSyncThrottler<librbd::MockTestImageCtx>());
- expect_image_sync(mock_image_sync_throttler, 0);
+ MockImageSync mock_image_sync;
+ expect_image_sync(mock_image_sync, 0);
MockCloseImageRequest mock_close_image_request;
expect_close_image(mock_close_image_request, mock_remote_image_ctx, 0);
C_SaferCond ctx;
+ MockInstanceWatcher mock_instance_watcher;
MockBootstrapRequest *request = create_request(
- mock_image_sync_throttler, mock_journaler, "",
+ &mock_instance_watcher, mock_journaler, "",
mock_remote_image_ctx.id, "global image id", "local mirror uuid",
"remote mirror uuid", &ctx);
request->send();
expect_journaler_update_client(mock_journaler, client_data, 0);
// sync the remote image to the local image
- MockImageSyncThrottler mock_image_sync_throttler(
- new ImageSyncThrottler<librbd::MockTestImageCtx>());
- expect_image_sync(mock_image_sync_throttler, 0);
+ MockImageSync mock_image_sync;
+ expect_image_sync(mock_image_sync, 0);
MockCloseImageRequest mock_close_image_request;
expect_close_image(mock_close_image_request, mock_remote_image_ctx, 0);
C_SaferCond ctx;
+ MockInstanceWatcher mock_instance_watcher;
MockBootstrapRequest *request = create_request(
- mock_image_sync_throttler, mock_journaler, "",
+ &mock_instance_watcher, mock_journaler, "",
mock_remote_image_ctx.id, "global image id", "local mirror uuid",
"remote mirror uuid", &ctx);
request->send();