static bool _filter_metadata_confs(const string &prefix, std::map<string, bool> &configs,
map<string, bufferlist> &pairs, map<string, bufferlist> *res);
+ // unit test mock helpers
+ static ImageCtx* create(const std::string &image_name,
+ const std::string &image_id,
+ const char *snap, IoCtx& p, bool read_only) {
+ return new ImageCtx(image_name, image_id, snap, p, read_only);
+ }
+ void destroy() {
+ delete this;
+ }
+
/**
* Either image_name or image_id must be set.
* If id is not known, pass the empty std::string,
librbd_test_la_CXXFLAGS = $(UNITTEST_CXXFLAGS)
noinst_LTLIBRARIES += librbd_test.la
+librbd_test_mock_la_SOURCES = \
+ test/librbd/mock/MockImageCtx.cc
+librbd_test_mock_la_CXXFLAGS = $(UNITTEST_CXXFLAGS)
+noinst_LTLIBRARIES += librbd_test_mock.la
+
unittest_librbd_SOURCES = \
test/librbd/test_main.cc \
test/librbd/test_mock_fixture.cc \
test/librbd/operation/test_mock_SnapshotUnprotectRequest.cc
unittest_librbd_CXXFLAGS = $(UNITTEST_CXXFLAGS) -DTEST_LIBRBD_INTERNALS
unittest_librbd_LDADD = \
- librbd_test.la librbd_api.la librbd_internal.la $(LIBRBD_TYPES) \
+ librbd_test.la librbd_test_mock.la \
+ librbd_api.la librbd_internal.la $(LIBRBD_TYPES) \
libcls_rbd_client.la libcls_lock_client.la \
libjournal.la libcls_journal_client.la \
librados_test_stub.la librados_internal.la \
unittest_rbd_mirror_CXXFLAGS = $(UNITTEST_CXXFLAGS)
unittest_rbd_mirror_LDADD = \
librbd_mirror_test.la \
+ librbd_test_mock.la \
librados_test_stub.la \
librbd_mirror_internal.la \
librbd_internal.la \
--- /dev/null
+// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "test/librbd/mock/MockImageCtx.h"
+
+namespace librbd {
+
+MockImageCtx* MockImageCtx::s_instance = nullptr;
+
+} // namespace librbd
#ifndef CEPH_TEST_LIBRBD_MOCK_IMAGE_CTX_H
#define CEPH_TEST_LIBRBD_MOCK_IMAGE_CTX_H
+#include "include/rados/librados.hpp"
#include "test/librbd/mock/MockAioImageRequestWQ.h"
#include "test/librbd/mock/MockContextWQ.h"
#include "test/librbd/mock/MockExclusiveLock.h"
#include "common/WorkQueue.h"
#include "librbd/ImageCtx.h"
#include "gmock/gmock.h"
+#include <string>
namespace librbd {
}
struct MockImageCtx {
+ static MockImageCtx *s_instance;
+ static MockImageCtx *create(const std::string &image_name,
+ const std::string &image_id,
+ const char *snap, librados::IoCtx& p,
+ bool read_only) {
+ assert(s_instance != nullptr);
+ return s_instance;
+ }
+
MockImageCtx(librbd::ImageCtx &image_ctx)
: image_ctx(&image_ctx),
cct(image_ctx.cct),
#define CEPH_TEST_LIBRBD_MOCK_OPERATIONS_H
#include "include/int_types.h"
+#include "include/rbd/librbd.hpp"
#include "gmock/gmock.h"
class Context;
typedef typename TypeTraits::Journaler Journaler;
typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta;
+ static ImageSync* create(ImageCtxT *local_image_ctx,
+ ImageCtxT *remote_image_ctx, SafeTimer *timer,
+ Mutex *timer_lock, const std::string &mirror_uuid,
+ Journaler *journaler,
+ MirrorPeerClientMeta *client_meta,
+ Context *on_finish) {
+ return new ImageSync(local_image_ctx, remote_image_ctx, timer, timer_lock,
+ mirror_uuid, journaler, client_meta, on_finish);
+ }
+
ImageSync(ImageCtxT *local_image_ctx, ImageCtxT *remote_image_ctx,
SafeTimer *timer, Mutex *timer_lock, const std::string &mirror_uuid,
Journaler *journaler, MirrorPeerClientMeta *client_meta,
void BootstrapRequest<I>::open_remote_image() {
dout(20) << dendl;
- // TODO: need factory method to support mocking
- m_remote_image_ctx = new I("", m_remote_image_id, nullptr, m_remote_io_ctx,
- false);
-
+ m_remote_image_ctx = I::create("", m_remote_image_id, nullptr,
+ m_remote_io_ctx, false);
Context *ctx = create_context_callback<
BootstrapRequest<I>, &BootstrapRequest<I>::handle_open_remote_image>(
this);
void BootstrapRequest<I>::image_sync() {
dout(20) << dendl;
- // TODO: need factory method to support mocking
Context *ctx = create_context_callback<
BootstrapRequest<I>, &BootstrapRequest<I>::handle_image_sync>(
this);
- ImageSync<I> *request = new ImageSync<I>(*m_local_image_ctx,
- m_remote_image_ctx, m_timer,
- m_timer_lock, m_mirror_uuid,
- m_journaler, m_client_meta, ctx);
+ ImageSync<I> *request = ImageSync<I>::create(*m_local_image_ctx,
+ m_remote_image_ctx, m_timer,
+ m_timer_lock, m_mirror_uuid,
+ m_journaler, m_client_meta, ctx);
request->start();
}
void OpenLocalImageRequest<I>::send_open_image() {
dout(20) << dendl;
- *m_local_image_ctx = new librbd::ImageCtx(m_local_image_name,
- m_local_image_id, nullptr,
- m_local_io_ctx, false);
+ *m_local_image_ctx = I::create(m_local_image_name, m_local_image_id, nullptr,
+ m_local_io_ctx, false);
(*m_local_image_ctx)->set_exclusive_lock_policy(
new MirrorExclusiveLockPolicy());
(*m_local_image_ctx)->set_journal_policy(