Skip to content

Commit f4d0882

Browse files
committed
PSMDB-1078: create StorageEngineImpl instance for inmemory_kv_engine_test
If the StorageEngineImpl is not created some of the tests fail due to missing the _mdb_catalog which is created in the StorageEngineImpl constructor.
1 parent 6d22b46 commit f4d0882

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

src/mongo/db/storage/inmemory/inmemory_kv_engine_test.cpp

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Copyright (C) 2018-present Percona and/or its affiliates. All rights reserved.
3737
#include "mongo/db/repl/repl_set_member_in_standalone_mode.h"
3838
#include "mongo/db/service_context.h"
3939
#include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h"
40+
#include "mongo/db/storage/storage_engine_impl.h"
4041
#include "mongo/db/global_settings.h"
4142
#include "mongo/unittest/temp_dir.h"
4243
#include "mongo/util/clock_source_mock.h"
@@ -50,7 +51,7 @@ namespace {
5051

5152
class InMemoryKVHarnessHelper : public KVHarnessHelper {
5253
public:
53-
InMemoryKVHarnessHelper(ServiceContext* svcCtx) : _dbpath("inmem-kv-harness") {
54+
InMemoryKVHarnessHelper(ServiceContext* svcCtx) : _dbpath("inmem-kv-harness"), _svcCtx(svcCtx) {
5455
if (!hasGlobalServiceContext())
5556
setGlobalServiceContext(ServiceContext::make());
5657
auto client = svcCtx->getService()->makeClient("opCtx");
@@ -68,40 +69,53 @@ class InMemoryKVHarnessHelper : public KVHarnessHelper {
6869
"log=(enabled=false),"
6970
"file_manager=(close_idle_time=0),"
7071
"checkpoint=(wait=0,log_size=0)";
71-
_engine.reset(new WiredTigerKVEngine(kInMemoryEngineName,
72-
_dbpath.path(),
73-
_cs.get(),
74-
std::move(wtConfig),
75-
WiredTigerExtensions::get(svcCtx),
76-
false,
77-
isReplSet,
78-
shouldRecoverFromOplogAsStandalone,
79-
replSetMemberInStandaloneMode));
72+
auto kv = std::make_unique<WiredTigerKVEngine>(kInMemoryEngineName,
73+
_dbpath.path(),
74+
_cs.get(),
75+
std::move(wtConfig),
76+
WiredTigerExtensions::get(svcCtx),
77+
false,
78+
isReplSet,
79+
shouldRecoverFromOplogAsStandalone,
80+
replSetMemberInStandaloneMode);
81+
8082
repl::ReplicationCoordinator::set(
8183
svcCtx,
8284
std::unique_ptr<repl::ReplicationCoordinator>(
8385
new repl::ReplicationCoordinatorMock(svcCtx, repl::ReplSettings())));
84-
_engine->notifyStorageStartupRecoveryComplete();
86+
87+
StorageEngineOptions options;
88+
_svcCtx->setStorageEngine(std::make_unique<StorageEngineImpl>(
89+
opCtx.get(), std::move(kv), std::unique_ptr<KVEngine>(), options));
90+
91+
getWiredTigerKVEngine()->notifyStorageStartupRecoveryComplete();
8592
}
8693

8794
~InMemoryKVHarnessHelper() override {
88-
_engine.reset(NULL);
95+
getWiredTigerKVEngine()->cleanShutdown(true);
96+
_svcCtx->clearStorageEngine();
8997
}
9098

9199
KVEngine* restartEngine() override {
92100
// Don't reset the engine since it doesn't persist anything
93101
// and all the data will be lost.
94-
return _engine.get();
102+
return getEngine();
95103
}
96104

97105
KVEngine* getEngine() override {
98-
return _engine.get();
106+
return _svcCtx->getStorageEngine()->getEngine();
99107
}
100108

101109
private:
110+
WiredTigerKVEngine* getWiredTigerKVEngine() {
111+
auto engine = dynamic_cast<WiredTigerKVEngine*>(_svcCtx->getStorageEngine()->getEngine());
112+
invariant(engine);
113+
return engine;
114+
}
115+
102116
const std::unique_ptr<ClockSource> _cs = std::make_unique<ClockSourceMock>();
103117
unittest::TempDir _dbpath;
104-
std::unique_ptr<WiredTigerKVEngine> _engine;
118+
ServiceContext* _svcCtx;
105119
};
106120

107121
std::unique_ptr<KVHarnessHelper> makeHelper(ServiceContext* svcCtx) {

0 commit comments

Comments
 (0)