summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Cotter <matt.cotter@mongodb.com>2016-12-05 15:37:36 -0500
committerMatt Cotter <matt.cotter@mongodb.com>2016-12-07 18:51:01 -0500
commite91795212e7f274db6eb66efd5bbad8f144cdf32 (patch)
tree4a9ebc9e8975599cfb93c9d29b549f7f78eec278
parent7e606d787608a866ecbff87deced8c9072af265d (diff)
downloadmongo-e91795212e7f274db6eb66efd5bbad8f144cdf32.tar.gz
SERVER-27284 dedup symbol KVHarnessHelper::create
-rw-r--r--src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine_test.cpp15
-rw-r--r--src/mongo/db/storage/kv/SConscript5
-rw-r--r--src/mongo/db/storage/kv/kv_engine_test_harness.cpp20
-rw-r--r--src/mongo/db/storage/kv/kv_engine_test_harness.h9
-rw-r--r--src/mongo/db/storage/kv/kv_engine_test_snapshots.cpp2
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp13
6 files changed, 49 insertions, 15 deletions
diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine_test.cpp b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine_test.cpp
index def552757b1..949cdc5f670 100644
--- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine_test.cpp
+++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine_test.cpp
@@ -29,9 +29,13 @@
*/
#include "mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine.h"
+
+#include "mongo/base/init.h"
#include "mongo/db/storage/kv/kv_engine_test_harness.h"
+#include "mongo/stdx/memory.h"
namespace mongo {
+namespace {
class EphemeralForTestKVHarnessHelper : public KVHarnessHelper {
public:
@@ -51,7 +55,14 @@ private:
std::unique_ptr<EphemeralForTestEngine> _engine;
};
-KVHarnessHelper* KVHarnessHelper::create() {
- return new EphemeralForTestKVHarnessHelper();
+std::unique_ptr<KVHarnessHelper> makeHelper() {
+ return stdx::make_unique<EphemeralForTestKVHarnessHelper>();
}
+
+MONGO_INITIALIZER(RegisterKVHarnessFactory)(InitializerContext*) {
+ KVHarnessHelper::registerFactory(makeHelper);
+ return Status::OK();
}
+
+} // namespace
+} // namespace mongo
diff --git a/src/mongo/db/storage/kv/SConscript b/src/mongo/db/storage/kv/SConscript
index 8c3102e7a1a..56aa8d2d7d0 100644
--- a/src/mongo/db/storage/kv/SConscript
+++ b/src/mongo/db/storage/kv/SConscript
@@ -90,11 +90,6 @@ env.Library(
'$BUILD_DIR/mongo/util/clock_source_mock',
'kv_engine_core',
],
- LIBDEPS_TAGS=[
- # Depends on KVHarnessHelper::create which does not have a unique definition
- 'incomplete',
- ],
-
)
env.CppUnitTest(
diff --git a/src/mongo/db/storage/kv/kv_engine_test_harness.cpp b/src/mongo/db/storage/kv/kv_engine_test_harness.cpp
index a7e169a4610..8b60151c0ca 100644
--- a/src/mongo/db/storage/kv/kv_engine_test_harness.cpp
+++ b/src/mongo/db/storage/kv/kv_engine_test_harness.cpp
@@ -37,21 +37,24 @@
#include "mongo/db/storage/record_store.h"
#include "mongo/db/storage/sorted_data_interface.h"
#include "mongo/unittest/unittest.h"
+#include "mongo/util/assert_util.h"
#include "mongo/util/clock_source_mock.h"
namespace mongo {
+namespace {
using std::unique_ptr;
using std::string;
-namespace {
+stdx::function<std::unique_ptr<KVHarnessHelper>()> basicFactory =
+ []() -> std::unique_ptr<KVHarnessHelper> { fassertFailed(40355); };
+
class MyOperationContext : public OperationContextNoop {
public:
MyOperationContext(KVEngine* engine) : OperationContextNoop(engine->newRecoveryUnit()) {}
};
const std::unique_ptr<ClockSource> clock = stdx::make_unique<ClockSourceMock>();
-}
TEST(KVEngineTestHarness, SimpleRS1) {
unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create());
@@ -405,4 +408,15 @@ TEST(KVCatalogTest, DirectoryPerAndSplit1) {
uow.commit();
}
}
-}
+
+} // namespace
+
+std::unique_ptr<KVHarnessHelper> KVHarnessHelper::create() {
+ return basicFactory();
+};
+
+void KVHarnessHelper::registerFactory(stdx::function<std::unique_ptr<KVHarnessHelper>()> factory) {
+ basicFactory = std::move(factory);
+};
+
+} // namespace mongo
diff --git a/src/mongo/db/storage/kv/kv_engine_test_harness.h b/src/mongo/db/storage/kv/kv_engine_test_harness.h
index 1f9c1ebfa47..592e11b2a32 100644
--- a/src/mongo/db/storage/kv/kv_engine_test_harness.h
+++ b/src/mongo/db/storage/kv/kv_engine_test_harness.h
@@ -30,7 +30,10 @@
#pragma once
+#include <memory>
+
#include "mongo/db/storage/kv/kv_engine.h"
+#include "mongo/stdx/functional.h"
namespace mongo {
@@ -45,6 +48,8 @@ public:
virtual KVEngine* restartEngine() = 0;
- static KVHarnessHelper* create();
+ static std::unique_ptr<KVHarnessHelper> create();
+ static void registerFactory(stdx::function<std::unique_ptr<KVHarnessHelper>()> factory);
};
-}
+
+} // namespace mongo
diff --git a/src/mongo/db/storage/kv/kv_engine_test_snapshots.cpp b/src/mongo/db/storage/kv/kv_engine_test_snapshots.cpp
index 28d0d52b8af..ba97e3af5f8 100644
--- a/src/mongo/db/storage/kv/kv_engine_test_snapshots.cpp
+++ b/src/mongo/db/storage/kv/kv_engine_test_snapshots.cpp
@@ -168,7 +168,7 @@ public:
}
void setUp() override {
- helper.reset(KVHarnessHelper::create());
+ helper = KVHarnessHelper::create();
engine = helper->getEngine();
snapshotManager = helper->getEngine()->getSnapshotManager();
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp
index ffd62258388..fbf55d41b3c 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp
@@ -33,6 +33,7 @@
#include "mongo/db/storage/kv/kv_engine_test_harness.h"
+#include "mongo/base/init.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_record_store.h"
#include "mongo/stdx/memory.h"
@@ -40,6 +41,7 @@
#include "mongo/util/clock_source_mock.h"
namespace mongo {
+namespace {
class WiredTigerKVHarnessHelper : public KVHarnessHelper {
public:
@@ -69,7 +71,14 @@ private:
std::unique_ptr<WiredTigerKVEngine> _engine;
};
-KVHarnessHelper* KVHarnessHelper::create() {
- return new WiredTigerKVHarnessHelper();
+std::unique_ptr<KVHarnessHelper> makeHelper() {
+ return stdx::make_unique<WiredTigerKVHarnessHelper>();
}
+
+MONGO_INITIALIZER(RegisterKVHarnessFactory)(InitializerContext*) {
+ KVHarnessHelper::registerFactory(makeHelper);
+ return Status::OK();
}
+
+} // namespace
+} // namespace mongo