diff options
Diffstat (limited to 'src/mongo/db/storage')
46 files changed, 538 insertions, 309 deletions
diff --git a/src/mongo/db/storage/SConscript b/src/mongo/db/storage/SConscript index 77313398079..367471e186b 100644 --- a/src/mongo/db/storage/SConscript +++ b/src/mongo/db/storage/SConscript @@ -85,6 +85,18 @@ env.Library( ) env.Library( + target='test_harness_helper', + source=[ + 'test_harness_helper.cpp', + ], + LIBDEPS=[ + '$BUILD_DIR/mongo/db/storage/storage_options', + '$BUILD_DIR/mongo/db/service_context', + ], + +) + +env.Library( target='sorted_data_interface_test_harness', source=[ 'sorted_data_interface_test_bulkbuilder.cpp', @@ -110,10 +122,7 @@ env.Library( '$BUILD_DIR/mongo/db/service_context', '$BUILD_DIR/mongo/unittest/unittest', 'index_entry_comparison', - ], - LIBDEPS_TAGS=[ - # Depends on newHarnessHelper, which does not have a unique definition - 'incomplete', + 'test_harness_helper', ], ) @@ -143,11 +152,8 @@ env.Library( '$BUILD_DIR/mongo/db/service_context', '$BUILD_DIR/mongo/db/storage/storage_options', '$BUILD_DIR/mongo/unittest/unittest', + 'test_harness_helper', ], - LIBDEPS_TAGS=[ - # Depends on newHarnessHelper, which does not have a unique definition - 'incomplete', - ], ) env.Library( diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl_test.cpp b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl_test.cpp index 5a91de906f2..49cbc6d1762 100644 --- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl_test.cpp +++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl_test.cpp @@ -31,16 +31,19 @@ #include "mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.h" +#include "mongo/base/init.h" #include "mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.h" #include "mongo/db/storage/sorted_data_interface_test_harness.h" #include "mongo/stdx/memory.h" #include "mongo/unittest/unittest.h" namespace mongo { +namespace { -class EphemeralForTestHarnessHelper final : public HarnessHelper { +class EphemeralForBtreeImplTestHarnessHelper final + : public virtual SortedDataInterfaceHarnessHelper { public: - EphemeralForTestHarnessHelper() : _order(Ordering::make(BSONObj())) {} + EphemeralForBtreeImplTestHarnessHelper() : _order(Ordering::make(BSONObj())) {} std::unique_ptr<SortedDataInterface> newSortedDataInterface(bool unique) final { return std::unique_ptr<SortedDataInterface>( @@ -56,7 +59,13 @@ private: Ordering _order; }; -std::unique_ptr<HarnessHelper> newHarnessHelper() { - return stdx::make_unique<EphemeralForTestHarnessHelper>(); +std::unique_ptr<HarnessHelper> makeHarnessHelper() { + return stdx::make_unique<EphemeralForBtreeImplTestHarnessHelper>(); } + +MONGO_INITIALIZER(RegisterHarnessFactory)(InitializerContext* const) { + mongo::registerHarnessHelperFactory(makeHarnessHelper); + return Status::OK(); } +} // namespace +} // namespace mongo diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store_test.cpp b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store_test.cpp index 5fa803ea2e0..153c34e2779 100644 --- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store_test.cpp +++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store_test.cpp @@ -32,27 +32,31 @@ #include "mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store.h" +#include "mongo/base/init.h" #include "mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.h" #include "mongo/db/storage/record_store_test_harness.h" +#include "mongo/stdx/memory.h" #include "mongo/unittest/unittest.h" namespace mongo { +namespace { -class EphemeralForTestHarnessHelper final : public HarnessHelper { +class EphemeralForTestHarnessHelper final : public RecordStoreHarnessHelper { public: EphemeralForTestHarnessHelper() {} std::unique_ptr<RecordStore> newNonCappedRecordStore() final { return stdx::make_unique<EphemeralForTestRecordStore>("a.b", &data); } + std::unique_ptr<RecordStore> newCappedRecordStore(int64_t cappedSizeBytes, int64_t cappedMaxDocs) final { return stdx::make_unique<EphemeralForTestRecordStore>( "a.b", &data, true, cappedSizeBytes, cappedMaxDocs); } - RecoveryUnit* newRecoveryUnit() final { - return new EphemeralForTestRecoveryUnit(); + std::unique_ptr<RecoveryUnit> newRecoveryUnit() final { + return stdx::make_unique<EphemeralForTestRecoveryUnit>(); } bool supportsDocLocking() final { @@ -62,7 +66,13 @@ public: std::shared_ptr<void> data; }; -std::unique_ptr<HarnessHelper> newHarnessHelper() { +std::unique_ptr<HarnessHelper> makeHarnessHelper() { return stdx::make_unique<EphemeralForTestHarnessHelper>(); } + +MONGO_INITIALIZER(RegisterHarnessFactory)(InitializerContext* const) { + mongo::registerHarnessHelperFactory(makeHarnessHelper); + return Status::OK(); } +} // namespace +} // namespace mongo diff --git a/src/mongo/db/storage/mmap_v1/btree/btree_interface_test.cpp b/src/mongo/db/storage/mmap_v1/btree/btree_interface_test.cpp index 7008562cc76..59bde328780 100644 --- a/src/mongo/db/storage/mmap_v1/btree/btree_interface_test.cpp +++ b/src/mongo/db/storage/mmap_v1/btree/btree_interface_test.cpp @@ -29,16 +29,20 @@ */ #include "mongo/db/storage/mmap_v1/btree/btree_interface.h" + +#include "mongo/base/init.h" #include "mongo/db/index/index_descriptor.h" #include "mongo/db/storage/mmap_v1/btree/btree_test_help.h" #include "mongo/db/storage/sorted_data_interface_test_harness.h" +#include "mongo/stdx/memory.h" #include "mongo/unittest/unittest.h" namespace mongo { +namespace { using std::unique_ptr; -class MyHarnessHelper final : public HarnessHelper { +class MyHarnessHelper final : public SortedDataInterfaceHarnessHelper { public: MyHarnessHelper() : _recordStore("a.b"), _order(Ordering::make(BSONObj())) {} @@ -67,7 +71,13 @@ private: Ordering _order; }; -std::unique_ptr<HarnessHelper> newHarnessHelper() { +std::unique_ptr<HarnessHelper> makeHarnessHelper() { return stdx::make_unique<MyHarnessHelper>(); } + +MONGO_INITIALIZER(RegisterHarnessFactory)(InitializerContext* const) { + mongo::registerHarnessHelperFactory(makeHarnessHelper); + return Status::OK(); } +} // namespace +} // namespace mongo diff --git a/src/mongo/db/storage/mmap_v1/mmap_v1_record_store_test.cpp b/src/mongo/db/storage/mmap_v1/mmap_v1_record_store_test.cpp index 0328ea2d7c5..29c7e0e92c7 100644 --- a/src/mongo/db/storage/mmap_v1/mmap_v1_record_store_test.cpp +++ b/src/mongo/db/storage/mmap_v1/mmap_v1_record_store_test.cpp @@ -30,6 +30,7 @@ #include "mongo/platform/basic.h" +#include "mongo/base/init.h" #include "mongo/db/operation_context_noop.h" #include "mongo/db/storage/mmap_v1/extent.h" #include "mongo/db/storage/mmap_v1/record.h" @@ -42,35 +43,38 @@ #include "mongo/unittest/unittest.h" namespace mongo { +namespace { -class MyHarnessHelper : public HarnessHelper { +class MyHarnessHelper : public RecordStoreHarnessHelper { public: MyHarnessHelper() {} virtual std::unique_ptr<RecordStore> newNonCappedRecordStore() { OperationContextNoop txn; - DummyRecordStoreV1MetaData* md = new DummyRecordStoreV1MetaData(false, 0); + auto md = stdx::make_unique<DummyRecordStoreV1MetaData>(false, 0); md->setUserFlag(&txn, CollectionOptions::Flag_NoPadding); - return stdx::make_unique<SimpleRecordStoreV1>(&txn, "a.b", md, &_em, false); + return stdx::make_unique<SimpleRecordStoreV1>(&txn, "a.b", md.release(), &_em, false); } std::unique_ptr<RecordStore> newCappedRecordStore(int64_t cappedMaxSize, int64_t cappedMaxDocs) final { OperationContextNoop txn; - DummyRecordStoreV1MetaData* md = new DummyRecordStoreV1MetaData(true, 0); - auto rs = stdx::make_unique<CappedRecordStoreV1>(&txn, nullptr, "a.b", md, &_em, false); + auto md = stdx::make_unique<DummyRecordStoreV1MetaData>(true, 0); + auto md_ptr = md.get(); + std::unique_ptr<RecordStore> rs = + stdx::make_unique<CappedRecordStoreV1>(&txn, nullptr, "a.b", md.release(), &_em, false); LocAndSize records[] = {{}}; LocAndSize drecs[] = {{DiskLoc(0, 1000), 1000}, {}}; md->setCapExtent(&txn, DiskLoc(0, 0)); md->setCapFirstNewRecord(&txn, DiskLoc().setInvalid()); - initializeV1RS(&txn, records, drecs, NULL, &_em, md); + initializeV1RS(&txn, records, drecs, NULL, &_em, md_ptr); - return std::move(rs); + return rs; } - virtual RecoveryUnit* newRecoveryUnit() { - return new RecoveryUnitNoop(); + std::unique_ptr<RecoveryUnit> newRecoveryUnit() override { + return stdx::make_unique<RecoveryUnitNoop>(); } bool supportsDocLocking() final { @@ -81,7 +85,13 @@ private: DummyExtentManager _em; }; -std::unique_ptr<HarnessHelper> newHarnessHelper() { +std::unique_ptr<HarnessHelper> makeHarnessHelper() { return stdx::make_unique<MyHarnessHelper>(); } + +MONGO_INITIALIZER(RegisterHarnessFactory)(InitializerContext* const) { + mongo::registerHarnessHelperFactory(makeHarnessHelper); + return Status::OK(); } +} // namespace +} // namespace mongo diff --git a/src/mongo/db/storage/record_store_test_capped_visibility.cpp b/src/mongo/db/storage/record_store_test_capped_visibility.cpp index 1498d307ecc..3669edb391f 100644 --- a/src/mongo/db/storage/record_store_test_capped_visibility.cpp +++ b/src/mongo/db/storage/record_store_test_capped_visibility.cpp @@ -52,10 +52,8 @@ RecordId doInsert(unowned_ptr<OperationContext> txn, unowned_ptr<RecordStore> rs ASSERT_EQ(record->id, id); \ }((EXPR), (ID)); -} // namespace - TEST(RecordStore_CappedVisibility, EmptyInitialState) { - auto harness = newHarnessHelper(); + const auto harness = newRecordStoreHarnessHelper(); if (!harness->supportsDocLocking()) return; @@ -117,7 +115,7 @@ TEST(RecordStore_CappedVisibility, EmptyInitialState) { } TEST(RecordStore_CappedVisibility, NonEmptyInitialState) { - auto harness = newHarnessHelper(); + const auto harness = newRecordStoreHarnessHelper(); if (!harness->supportsDocLocking()) return; @@ -189,4 +187,5 @@ TEST(RecordStore_CappedVisibility, NonEmptyInitialState) { ASSERT_ID_EQ(rs->getCursor(longLivedOp.get())->seekExact(otherId), otherId); } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/record_store_test_datafor.cpp b/src/mongo/db/storage/record_store_test_datafor.cpp index aa97da93979..a1935dc0d93 100644 --- a/src/mongo/db/storage/record_store_test_datafor.cpp +++ b/src/mongo/db/storage/record_store_test_datafor.cpp @@ -37,17 +37,18 @@ #include "mongo/db/storage/record_store.h" #include "mongo/unittest/unittest.h" -using std::string; -using std::stringstream; namespace mongo { +namespace { +using std::string; +using std::stringstream; using std::unique_ptr; // Insert a record and verify its contents by calling dataFor() // on the returned RecordId. TEST(RecordStoreTestHarness, DataFor) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -87,7 +88,7 @@ TEST(RecordStoreTestHarness, DataFor) { // Insert multiple records and verify their contents by calling dataFor() // on each of the returned RecordIds. TEST(RecordStoreTestHarness, DataForMultiple) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -132,4 +133,5 @@ TEST(RecordStoreTestHarness, DataForMultiple) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/record_store_test_datasize.cpp b/src/mongo/db/storage/record_store_test_datasize.cpp index cf8b1bf8360..a7f234ea7f4 100644 --- a/src/mongo/db/storage/record_store_test_datasize.cpp +++ b/src/mongo/db/storage/record_store_test_datasize.cpp @@ -36,16 +36,17 @@ #include "mongo/db/storage/record_store.h" #include "mongo/unittest/unittest.h" -using std::string; -using std::stringstream; namespace mongo { +namespace { +using std::string; +using std::stringstream; using std::unique_ptr; // Verify that an empty collection takes up no space. TEST(RecordStoreTestHarness, DataSizeEmpty) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -61,7 +62,7 @@ TEST(RecordStoreTestHarness, DataSizeEmpty) { // Verify that a nonempty collection takes up some space. TEST(RecordStoreTestHarness, DataSizeNonEmpty) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -96,4 +97,5 @@ TEST(RecordStoreTestHarness, DataSizeNonEmpty) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/record_store_test_deleterecord.cpp b/src/mongo/db/storage/record_store_test_deleterecord.cpp index f3261d1c4d1..0a7dc44d6f0 100644 --- a/src/mongo/db/storage/record_store_test_deleterecord.cpp +++ b/src/mongo/db/storage/record_store_test_deleterecord.cpp @@ -38,16 +38,17 @@ #include "mongo/db/storage/record_store.h" #include "mongo/unittest/unittest.h" -using std::string; -using std::stringstream; namespace mongo { +namespace { +using std::string; +using std::stringstream; using std::unique_ptr; // Insert a record and try to delete it. TEST(RecordStoreTestHarness, DeleteRecord) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -91,7 +92,7 @@ TEST(RecordStoreTestHarness, DeleteRecord) { // Insert multiple records and try to delete them. TEST(RecordStoreTestHarness, DeleteMultipleRecords) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -137,4 +138,5 @@ TEST(RecordStoreTestHarness, DeleteMultipleRecords) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/record_store_test_harness.cpp b/src/mongo/db/storage/record_store_test_harness.cpp index 8c59bff89fb..12df12c7765 100644 --- a/src/mongo/db/storage/record_store_test_harness.cpp +++ b/src/mongo/db/storage/record_store_test_harness.cpp @@ -37,12 +37,13 @@ #include "mongo/unittest/unittest.h" namespace mongo { +namespace { using std::unique_ptr; using std::string; TEST(RecordStoreTestHarness, Simple1) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -102,12 +103,15 @@ namespace { class DummyDocWriter final : public DocWriter { public: virtual ~DummyDocWriter() {} + virtual void writeDocument(char* buf) const { memcpy(buf, "eliot", 6); } + virtual size_t documentSize() const { return 6; } + virtual bool addPadding() const { return false; } @@ -116,7 +120,7 @@ public: TEST(RecordStoreTestHarness, Simple1InsertDocWroter) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); RecordId loc1; @@ -138,7 +142,7 @@ TEST(RecordStoreTestHarness, Simple1InsertDocWroter) { } TEST(RecordStoreTestHarness, Delete1) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -183,7 +187,7 @@ TEST(RecordStoreTestHarness, Delete1) { } TEST(RecordStoreTestHarness, Delete2) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -226,7 +230,7 @@ TEST(RecordStoreTestHarness, Delete2) { } TEST(RecordStoreTestHarness, Update1) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -288,7 +292,7 @@ TEST(RecordStoreTestHarness, Update1) { } TEST(RecordStoreTestHarness, UpdateInPlace1) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); if (!rs->updateWithDamagesSupported()) @@ -342,7 +346,7 @@ TEST(RecordStoreTestHarness, UpdateInPlace1) { TEST(RecordStoreTestHarness, Truncate1) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -394,7 +398,7 @@ TEST(RecordStoreTestHarness, Truncate1) { TEST(RecordStoreTestHarness, Cursor1) { const int N = 10; - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -444,4 +448,5 @@ TEST(RecordStoreTestHarness, Cursor1) { ASSERT(!cursor->next()); } } -} +} // namespace +} // namespace mongo diff --git a/src/mongo/db/storage/record_store_test_harness.h b/src/mongo/db/storage/record_store_test_harness.h index 09d028a97bd..e92a350003e 100644 --- a/src/mongo/db/storage/record_store_test_harness.h +++ b/src/mongo/db/storage/record_store_test_harness.h @@ -34,6 +34,7 @@ #include "mongo/db/operation_context_noop.h" #include "mongo/db/service_context_noop.h" +#include "mongo/db/storage/test_harness_helper.h" #include "mongo/stdx/memory.h" namespace mongo { @@ -41,47 +42,23 @@ namespace mongo { class RecordStore; class RecoveryUnit; -class HarnessHelper { +class RecordStoreHarnessHelper : public HarnessHelper { public: - HarnessHelper() : _serviceContext(), _client(_serviceContext.makeClient("hh")) {} - virtual ~HarnessHelper() {} - virtual std::unique_ptr<RecordStore> newNonCappedRecordStore() = 0; static const int64_t kDefaultCapedSizeBytes = 16 * 1024 * 1024; virtual std::unique_ptr<RecordStore> newCappedRecordStore( int64_t cappedSizeBytes = kDefaultCapedSizeBytes, int64_t cappedMaxDocs = -1) = 0; - virtual ServiceContext::UniqueOperationContext newOperationContext(Client* client) { - auto opCtx = client->makeOperationContext(); - opCtx->setRecoveryUnit(newRecoveryUnit(), OperationContext::kNotInUnitOfWork); - return opCtx; - } - - ServiceContext::UniqueOperationContext newOperationContext() { - return newOperationContext(_client.get()); - } - /** * Currently this requires that it is possible to have two independent open write operations * at the same time one the same thread (with separate Clients, OperationContexts, and * RecoveryUnits). */ virtual bool supportsDocLocking() = 0; - - Client* client() { - return _client.get(); - } - ServiceContext* serviceContext() { - return &_serviceContext; - } - -private: - virtual RecoveryUnit* newRecoveryUnit() = 0; - - ServiceContextNoop _serviceContext; - ServiceContext::UniqueClient _client; }; -std::unique_ptr<HarnessHelper> newHarnessHelper(); +inline std::unique_ptr<RecordStoreHarnessHelper> newRecordStoreHarnessHelper() { + return dynamic_ptr_cast<RecordStoreHarnessHelper>(newHarnessHelper()); } +} // namespace mongo diff --git a/src/mongo/db/storage/record_store_test_insertrecord.cpp b/src/mongo/db/storage/record_store_test_insertrecord.cpp index f1d04e72b18..5446eefbd18 100644 --- a/src/mongo/db/storage/record_store_test_insertrecord.cpp +++ b/src/mongo/db/storage/record_store_test_insertrecord.cpp @@ -30,25 +30,23 @@ #include "mongo/platform/basic.h" -#include "mongo/db/storage/record_store_test_harness.h" - - #include "mongo/db/record_id.h" #include "mongo/db/storage/record_data.h" #include "mongo/db/storage/record_store.h" #include "mongo/db/storage/record_store_test_docwriter.h" +#include "mongo/db/storage/record_store_test_harness.h" #include "mongo/unittest/unittest.h" -using std::string; -using std::stringstream; - namespace mongo { +namespace { +using std::string; +using std::stringstream; using std::unique_ptr; // Insert a record and verify the number of entries in the collection is 1. TEST(RecordStoreTestHarness, InsertRecord) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -79,7 +77,7 @@ TEST(RecordStoreTestHarness, InsertRecord) { // Insert multiple records and verify the number of entries in the collection // equals the number that were inserted. TEST(RecordStoreTestHarness, InsertMultipleRecords) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -114,7 +112,7 @@ TEST(RecordStoreTestHarness, InsertMultipleRecords) { // Insert a record using a DocWriter and verify the number of entries // in the collection is 1. TEST(RecordStoreTestHarness, InsertRecordUsingDocWriter) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -145,7 +143,7 @@ TEST(RecordStoreTestHarness, InsertRecordUsingDocWriter) { // Insert multiple records using a DocWriter and verify the number of entries // in the collection equals the number that were inserted. TEST(RecordStoreTestHarness, InsertMultipleRecordsUsingDocWriter) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -176,4 +174,5 @@ TEST(RecordStoreTestHarness, InsertMultipleRecordsUsingDocWriter) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/record_store_test_manyiter.cpp b/src/mongo/db/storage/record_store_test_manyiter.cpp index bed787057e4..1f60d9f84b3 100644 --- a/src/mongo/db/storage/record_store_test_manyiter.cpp +++ b/src/mongo/db/storage/record_store_test_manyiter.cpp @@ -38,18 +38,18 @@ #include "mongo/db/storage/record_store.h" #include "mongo/unittest/unittest.h" +namespace mongo { +namespace { + using std::set; using std::string; using std::stringstream; using std::vector; - -namespace mongo { - using std::unique_ptr; // Create multiple iterators over an empty record store. TEST(RecordStoreTestHarness, GetManyIteratorsEmpty) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -68,7 +68,7 @@ TEST(RecordStoreTestHarness, GetManyIteratorsEmpty) { // Create multiple iterators over a nonempty record store. TEST(RecordStoreTestHarness, GetManyIteratorsNonEmpty) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -113,4 +113,5 @@ TEST(RecordStoreTestHarness, GetManyIteratorsNonEmpty) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/record_store_test_randomiter.cpp b/src/mongo/db/storage/record_store_test_randomiter.cpp index dbb34c00fb4..4fa04ba7440 100644 --- a/src/mongo/db/storage/record_store_test_randomiter.cpp +++ b/src/mongo/db/storage/record_store_test_randomiter.cpp @@ -30,24 +30,23 @@ #include "mongo/platform/basic.h" -#include "mongo/db/storage/record_store_test_harness.h" - - #include "mongo/db/record_id.h" #include "mongo/db/storage/record_data.h" #include "mongo/db/storage/record_store.h" +#include "mongo/db/storage/record_store_test_harness.h" #include "mongo/unittest/unittest.h" +namespace mongo { +namespace { + using std::unique_ptr; using std::set; using std::string; using std::stringstream; -namespace mongo { - // Create a random iterator for empty record store. TEST(RecordStoreTestHarness, GetRandomIteratorEmpty) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -68,7 +67,7 @@ TEST(RecordStoreTestHarness, GetRandomIteratorEmpty) { // Insert multiple records and create a random iterator for the record store TEST(RecordStoreTestHarness, GetRandomIteratorNonEmpty) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -129,7 +128,7 @@ TEST(RecordStoreTestHarness, GetRandomIteratorNonEmpty) { // Insert a single record. Create a random iterator pointing to that single record. // Then check we'll retrieve the record. TEST(RecordStoreTestHarness, GetRandomIteratorSingleton) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -182,4 +181,5 @@ TEST(RecordStoreTestHarness, GetRandomIteratorSingleton) { } } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/record_store_test_recorditer.cpp b/src/mongo/db/storage/record_store_test_recorditer.cpp index e2cba18ea94..aa6c158bf3e 100644 --- a/src/mongo/db/storage/record_store_test_recorditer.cpp +++ b/src/mongo/db/storage/record_store_test_recorditer.cpp @@ -40,17 +40,18 @@ #include "mongo/db/storage/record_store.h" #include "mongo/unittest/unittest.h" +namespace mongo { +namespace { + using std::unique_ptr; using std::string; using std::stringstream; -namespace mongo { - // Insert multiple records and iterate through them in the forward direction. // When curr() or getNext() is called on an iterator positioned at EOF, // the iterator returns RecordId() and stays at EOF. TEST(RecordStoreTestHarness, IterateOverMultipleRecords) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -101,7 +102,7 @@ TEST(RecordStoreTestHarness, IterateOverMultipleRecords) { // When curr() or getNext() is called on an iterator positioned at EOF, // the iterator returns RecordId() and stays at EOF. TEST(RecordStoreTestHarness, IterateOverMultipleRecordsReversed) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -152,7 +153,7 @@ TEST(RecordStoreTestHarness, IterateOverMultipleRecordsReversed) { // Insert multiple records and try to create a forward iterator // starting at an interior position. TEST(RecordStoreTestHarness, IterateStartFromMiddle) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -204,7 +205,7 @@ TEST(RecordStoreTestHarness, IterateStartFromMiddle) { // Insert multiple records and try to create a reverse iterator // starting at an interior position. TEST(RecordStoreTestHarness, IterateStartFromMiddleReversed) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -257,7 +258,7 @@ TEST(RecordStoreTestHarness, IterateStartFromMiddleReversed) { // is EOF. Add an additional record, saving and restoring the iterator state, and check // that the iterator remains EOF. TEST(RecordStoreTestHarness, RecordIteratorEOF) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -328,7 +329,7 @@ TEST(RecordStoreTestHarness, RecordIteratorEOF) { // Test calling save and restore after each call to next TEST(RecordStoreTestHarness, RecordIteratorSaveRestore) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -390,7 +391,7 @@ TEST(RecordStoreTestHarness, RecordIteratorSaveRestore) { // Insert two records, and iterate a cursor to EOF. Seek the same cursor to the first and ensure // that next() returns the second record. TEST(RecordStoreTestHarness, SeekAfterEofAndContinue) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); @@ -442,4 +443,5 @@ TEST(RecordStoreTestHarness, SeekAfterEofAndContinue) { ASSERT(!cursor->next()); } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/record_store_test_recordstore.cpp b/src/mongo/db/storage/record_store_test_recordstore.cpp index 3f9603575fa..840d7eb8286 100644 --- a/src/mongo/db/storage/record_store_test_recordstore.cpp +++ b/src/mongo/db/storage/record_store_test_recordstore.cpp @@ -36,14 +36,15 @@ #include "mongo/db/storage/record_store.h" #include "mongo/unittest/unittest.h" +namespace mongo { +namespace { + using std::unique_ptr; using std::string; -namespace mongo { - // Verify that the name of the record store is not NULL and nonempty. TEST(RecordStoreTestHarness, RecordStoreName) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -54,7 +55,7 @@ TEST(RecordStoreTestHarness, RecordStoreName) { // Verify that the namespace of the record store is nonempty. TEST(RecordStoreTestHarness, Namespace) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -65,9 +66,10 @@ TEST(RecordStoreTestHarness, Namespace) { // Call isCapped() on a non-capped collection and verify the result is false. TEST(RecordStoreTestHarness, IsNotCapped) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); ASSERT(!rs->isCapped()); } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/record_store_test_repairiter.cpp b/src/mongo/db/storage/record_store_test_repairiter.cpp index eca6c3fdc1d..b7423f964d6 100644 --- a/src/mongo/db/storage/record_store_test_repairiter.cpp +++ b/src/mongo/db/storage/record_store_test_repairiter.cpp @@ -38,16 +38,17 @@ #include "mongo/db/storage/record_store.h" #include "mongo/unittest/unittest.h" +namespace mongo { +namespace { + using std::unique_ptr; using std::set; using std::string; using std::stringstream; -namespace mongo { - // Create an iterator for repairing an empty record store. TEST(RecordStoreTestHarness, GetIteratorForRepairEmpty) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -69,7 +70,7 @@ TEST(RecordStoreTestHarness, GetIteratorForRepairEmpty) { // Insert multiple records and create an iterator for repairing the record store, // even though the it has not been corrupted. TEST(RecordStoreTestHarness, GetIteratorForRepairNonEmpty) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -122,7 +123,7 @@ TEST(RecordStoreTestHarness, GetIteratorForRepairNonEmpty) { // Then invalidate the record and ensure that the repair iterator responds correctly. // See SERVER-16300. TEST(RecordStoreTestHarness, GetIteratorForRepairInvalidateSingleton) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -167,4 +168,5 @@ TEST(RecordStoreTestHarness, GetIteratorForRepairInvalidateSingleton) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/record_store_test_storagesize.cpp b/src/mongo/db/storage/record_store_test_storagesize.cpp index cedcc930bab..d525446449a 100644 --- a/src/mongo/db/storage/record_store_test_storagesize.cpp +++ b/src/mongo/db/storage/record_store_test_storagesize.cpp @@ -36,15 +36,16 @@ #include "mongo/db/storage/record_store.h" #include "mongo/unittest/unittest.h" +namespace mongo { +namespace { + using std::unique_ptr; using std::string; using std::stringstream; -namespace mongo { - // Verify that a nonempty collection maybe takes up some space on disk. TEST(RecordStoreTestHarness, StorageSizeNonEmpty) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -79,4 +80,5 @@ TEST(RecordStoreTestHarness, StorageSizeNonEmpty) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/record_store_test_touch.cpp b/src/mongo/db/storage/record_store_test_touch.cpp index 74fb7a2f0a7..fe45e3bf9de 100644 --- a/src/mongo/db/storage/record_store_test_touch.cpp +++ b/src/mongo/db/storage/record_store_test_touch.cpp @@ -36,15 +36,16 @@ #include "mongo/db/storage/record_store.h" #include "mongo/unittest/unittest.h" +namespace mongo { +namespace { + using std::unique_ptr; using std::string; using std::stringstream; -namespace mongo { - // Verify that calling touch() on an empty collection returns an OK status. TEST(RecordStoreTestHarness, TouchEmpty) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -66,7 +67,7 @@ TEST(RecordStoreTestHarness, TouchEmpty) { // Insert multiple records, and verify that calling touch() on a nonempty collection // returns an OK status. TEST(RecordStoreTestHarness, TouchNonEmpty) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -111,7 +112,7 @@ TEST(RecordStoreTestHarness, TouchNonEmpty) { // Verify that calling touch() on an empty collection returns an OK status, // even when NULL is passed in for the stats output. TEST(RecordStoreTestHarness, TouchEmptyWithNullStats) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -130,7 +131,7 @@ TEST(RecordStoreTestHarness, TouchEmptyWithNullStats) { // Insert multiple records, and verify that calling touch() on a nonempty collection // returns an OK status, even when NULL is passed in for the stats output. TEST(RecordStoreTestHarness, TouchNonEmptyWithNullStats) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -169,4 +170,5 @@ TEST(RecordStoreTestHarness, TouchNonEmptyWithNullStats) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/record_store_test_truncate.cpp b/src/mongo/db/storage/record_store_test_truncate.cpp index bb485c9ade8..d1d79fbabaa 100644 --- a/src/mongo/db/storage/record_store_test_truncate.cpp +++ b/src/mongo/db/storage/record_store_test_truncate.cpp @@ -36,15 +36,16 @@ #include "mongo/db/storage/record_store.h" #include "mongo/unittest/unittest.h" +namespace mongo { +namespace { + using std::unique_ptr; using std::string; using std::stringstream; -namespace mongo { - // Verify that calling truncate() on an already empty collection returns an OK status. TEST(RecordStoreTestHarness, TruncateEmpty) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -70,7 +71,7 @@ TEST(RecordStoreTestHarness, TruncateEmpty) { // Insert multiple records, and verify that calling truncate() on a nonempty collection // removes all of them and returns an OK status. TEST(RecordStoreTestHarness, TruncateNonEmpty) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -114,4 +115,5 @@ TEST(RecordStoreTestHarness, TruncateNonEmpty) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/record_store_test_updaterecord.cpp b/src/mongo/db/storage/record_store_test_updaterecord.cpp index cc2285aa6d0..4b55ae00e12 100644 --- a/src/mongo/db/storage/record_store_test_updaterecord.cpp +++ b/src/mongo/db/storage/record_store_test_updaterecord.cpp @@ -39,15 +39,16 @@ #include "mongo/db/storage/record_store_test_harness.h" #include "mongo/unittest/unittest.h" +namespace mongo { +namespace { + using std::unique_ptr; using std::string; using std::stringstream; -namespace mongo { - // Insert a record and try to update it. TEST(RecordStoreTestHarness, UpdateRecord) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -108,7 +109,7 @@ TEST(RecordStoreTestHarness, UpdateRecord) { // Insert multiple records and try to update them. TEST(RecordStoreTestHarness, UpdateMultipleRecords) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -180,7 +181,7 @@ TEST(RecordStoreTestHarness, UpdateMultipleRecords) { // Insert a record, try to update it, and examine how the UpdateNotifier is called. TEST(RecordStoreTestHarness, UpdateRecordWithMoveNotifier) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -243,4 +244,5 @@ TEST(RecordStoreTestHarness, UpdateRecordWithMoveNotifier) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/record_store_test_updatewithdamages.cpp b/src/mongo/db/storage/record_store_test_updatewithdamages.cpp index 97627963cab..207b70eaa5a 100644 --- a/src/mongo/db/storage/record_store_test_updatewithdamages.cpp +++ b/src/mongo/db/storage/record_store_test_updatewithdamages.cpp @@ -38,14 +38,15 @@ #include "mongo/db/storage/record_store.h" #include "mongo/unittest/unittest.h" +namespace mongo { +namespace { + using std::unique_ptr; using std::string; -namespace mongo { - // Insert a record and try to perform an in-place update on it. TEST(RecordStoreTestHarness, UpdateWithDamages) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); if (!rs->updateWithDamagesSupported()) @@ -110,7 +111,7 @@ TEST(RecordStoreTestHarness, UpdateWithDamages) { // Insert a record and try to perform an in-place update on it with a DamageVector // containing overlapping DamageEvents. TEST(RecordStoreTestHarness, UpdateWithOverlappingDamageEvents) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); if (!rs->updateWithDamagesSupported()) @@ -173,7 +174,7 @@ TEST(RecordStoreTestHarness, UpdateWithOverlappingDamageEvents) { // containing overlapping DamageEvents. The changes should be applied in the order // specified by the DamageVector, and not -- for instance -- by the targetOffset. TEST(RecordStoreTestHarness, UpdateWithOverlappingDamageEventsReversed) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); if (!rs->updateWithDamagesSupported()) @@ -234,7 +235,7 @@ TEST(RecordStoreTestHarness, UpdateWithOverlappingDamageEventsReversed) { // Insert a record and try to call updateWithDamages() with an empty DamageVector. TEST(RecordStoreTestHarness, UpdateWithNoDamages) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); if (!rs->updateWithDamagesSupported()) @@ -286,4 +287,5 @@ TEST(RecordStoreTestHarness, UpdateWithNoDamages) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/record_store_test_validate.cpp b/src/mongo/db/storage/record_store_test_validate.cpp index 0654b43829c..032f36ebe18 100644 --- a/src/mongo/db/storage/record_store_test_validate.cpp +++ b/src/mongo/db/storage/record_store_test_validate.cpp @@ -45,7 +45,7 @@ namespace { // Verify that calling validate() on an empty collection returns an OK status. TEST(RecordStoreTestHarness, ValidateEmpty) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -68,7 +68,7 @@ TEST(RecordStoreTestHarness, ValidateEmpty) { // Verify that calling validate() on an empty collection returns an OK status. TEST(RecordStoreTestHarness, ValidateEmptyAndScanData) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { @@ -91,7 +91,7 @@ TEST(RecordStoreTestHarness, ValidateEmptyAndScanData) { // Verify that calling validate() on an empty collection returns an OK status. TEST(RecordStoreTestHarness, FullValidateEmptyAndScanData) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); { diff --git a/src/mongo/db/storage/record_store_test_validate.h b/src/mongo/db/storage/record_store_test_validate.h index 88e01d7bf2e..f76b100b0ef 100644 --- a/src/mongo/db/storage/record_store_test_validate.h +++ b/src/mongo/db/storage/record_store_test_validate.h @@ -37,7 +37,6 @@ #include "mongo/unittest/unittest.h" namespace mongo { -namespace { class ValidateAdaptorSpy : public ValidateAdaptor { public: @@ -66,7 +65,8 @@ private: class ValidateTest : public mongo::unittest::Test { public: ValidateTest() - : _harnessHelper(newHarnessHelper()), _rs(_harnessHelper->newNonCappedRecordStore()) {} + : _harnessHelper(newRecordStoreHarnessHelper()), + _rs(_harnessHelper->newNonCappedRecordStore()) {} ServiceContext::UniqueOperationContext newOperationContext() { return _harnessHelper->newOperationContext(); @@ -110,10 +110,9 @@ public: } private: - std::unique_ptr<HarnessHelper> _harnessHelper; + std::unique_ptr<RecordStoreHarnessHelper> _harnessHelper; std::unique_ptr<RecordStore> _rs; std::set<std::string> _remain; }; -} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/sorted_data_interface_test_bulkbuilder.cpp b/src/mongo/db/storage/sorted_data_interface_test_bulkbuilder.cpp index a12a589d259..a70fceb3015 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_bulkbuilder.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_bulkbuilder.cpp @@ -36,10 +36,11 @@ #include "mongo/unittest/unittest.h" namespace mongo { +namespace { // Add a key using a bulk builder. TEST(SortedDataInterface, BuilderAddKey) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -64,7 +65,7 @@ TEST(SortedDataInterface, BuilderAddKey) { // Add a compound key using a bulk builder. TEST(SortedDataInterface, BuilderAddCompoundKey) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -91,7 +92,7 @@ TEST(SortedDataInterface, BuilderAddCompoundKey) { // the returned status is ErrorCodes::DuplicateKey when duplicates are // not allowed. TEST(SortedDataInterface, BuilderAddSameKey) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(true)); { @@ -118,7 +119,7 @@ TEST(SortedDataInterface, BuilderAddSameKey) { // Add the same key multiple times using a bulk builder and verify that // the returned status is OK when duplicates are allowed. TEST(SortedDataInterface, BuilderAddSameKeyWithDupsAllowed) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -144,7 +145,7 @@ TEST(SortedDataInterface, BuilderAddSameKeyWithDupsAllowed) { // Add multiple keys using a bulk builder. TEST(SortedDataInterface, BuilderAddMultipleKeys) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -171,7 +172,7 @@ TEST(SortedDataInterface, BuilderAddMultipleKeys) { // Add multiple compound keys using a bulk builder. TEST(SortedDataInterface, BuilderAddMultipleCompoundKeys) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -198,4 +199,5 @@ TEST(SortedDataInterface, BuilderAddMultipleCompoundKeys) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/sorted_data_interface_test_cursor.cpp b/src/mongo/db/storage/sorted_data_interface_test_cursor.cpp index dcda494d541..7640bf19005 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_cursor.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_cursor.cpp @@ -36,10 +36,11 @@ #include "mongo/unittest/unittest.h" namespace mongo { +namespace { // Verify that a forward cursor is positioned at EOF when the index is empty. TEST(SortedDataInterface, CursorIsEOFWhenEmpty) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -60,7 +61,7 @@ TEST(SortedDataInterface, CursorIsEOFWhenEmpty) { // Verify that a reverse cursor is positioned at EOF when the index is empty. TEST(SortedDataInterface, CursorIsEOFWhenEmptyReversed) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -83,7 +84,7 @@ TEST(SortedDataInterface, CursorIsEOFWhenEmptyReversed) { // Call advance() on a forward cursor until it is exhausted. // When a cursor positioned at EOF is advanced, it stays at EOF. TEST(SortedDataInterface, ExhaustCursor) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -125,7 +126,7 @@ TEST(SortedDataInterface, ExhaustCursor) { // Call advance() on a reverse cursor until it is exhausted. // When a cursor positioned at EOF is advanced, it stays at EOF. TEST(SortedDataInterface, ExhaustCursorReversed) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -165,4 +166,5 @@ TEST(SortedDataInterface, ExhaustCursorReversed) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/sorted_data_interface_test_cursor_advanceto.cpp b/src/mongo/db/storage/sorted_data_interface_test_cursor_advanceto.cpp index 5a7dff46889..10661d2bd46 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_cursor_advanceto.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_cursor_advanceto.cpp @@ -36,6 +36,7 @@ #include "mongo/unittest/unittest.h" namespace mongo { +namespace { // Insert multiple single-field keys and advance to each of them // using a forward cursor by specifying their exact key. When @@ -43,7 +44,7 @@ namespace mongo { // positioned at the first occurrence of that key in ascending // order by RecordId. TEST(SortedDataInterface, AdvanceTo) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -98,7 +99,7 @@ TEST(SortedDataInterface, AdvanceTo) { // positioned at the first occurrence of that key in descending // order by RecordId (last occurrence in index order). TEST(SortedDataInterface, AdvanceToReversed) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -152,7 +153,7 @@ TEST(SortedDataInterface, AdvanceToReversed) { // the smaller one. Ending position is on the smaller one since a seek describes where to go // and should not be effected by current position. TEST(SortedDataInterface, AdvanceToKeyBeforeCursorPosition) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -196,7 +197,7 @@ TEST(SortedDataInterface, AdvanceToKeyBeforeCursorPosition) { // the larger one. Ending position is on the larger one since a seek describes where to go // and should not be effected by current position. TEST(SortedDataInterface, AdvanceToKeyAfterCursorPositionReversed) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -243,7 +244,7 @@ TEST(SortedDataInterface, AdvanceToKeyAfterCursorPositionReversed) { // the cursor should remain at its current position. An exclusive seek will // position the cursor on the next position, which may be EOF. TEST(SortedDataInterface, AdvanceToKeyAtCursorPosition) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -288,7 +289,7 @@ TEST(SortedDataInterface, AdvanceToKeyAtCursorPosition) { // the cursor should remain at its current position. An exclusive seek will // position the cursor on the next position, which may be EOF. TEST(SortedDataInterface, AdvanceToKeyAtCursorPositionReversed) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -333,7 +334,7 @@ TEST(SortedDataInterface, AdvanceToKeyAtCursorPositionReversed) { // When advanceTo() is called in non-inclusive mode, the cursor is // positioned at the key that comes after the one specified. TEST(SortedDataInterface, AdvanceToExclusive) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -387,7 +388,7 @@ TEST(SortedDataInterface, AdvanceToExclusive) { // When advanceTo() is called in non-inclusive mode, the cursor is // positioned at the key that comes before the one specified. TEST(SortedDataInterface, AdvanceToExclusiveReversed) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -441,7 +442,7 @@ TEST(SortedDataInterface, AdvanceToExclusiveReversed) { // each of them using a forward cursor by specifying a key between their // exact key and the current position of the cursor. TEST(SortedDataInterface, AdvanceToIndirect) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); BSONObj unusedKey = key6; // larger than any inserted key @@ -491,7 +492,7 @@ TEST(SortedDataInterface, AdvanceToIndirect) { // each of them using a reverse cursor by specifying a key between their // exact key and the current position of the cursor. TEST(SortedDataInterface, AdvanceToIndirectReversed) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); BSONObj unusedKey = key0; // smaller than any inserted key @@ -544,7 +545,7 @@ TEST(SortedDataInterface, AdvanceToIndirectReversed) { // is called in non-inclusive mode, the cursor is positioned at the key // that comes after the one specified. TEST(SortedDataInterface, AdvanceToIndirectExclusive) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); BSONObj unusedKey = key6; // larger than any inserted key @@ -601,7 +602,7 @@ TEST(SortedDataInterface, AdvanceToIndirectExclusive) { // is called in non-inclusive mode, the cursor is positioned at the key // that comes before the one specified. TEST(SortedDataInterface, AdvanceToIndirectExclusiveReversed) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); BSONObj unusedKey = key0; // smaller than any inserted key @@ -653,4 +654,5 @@ TEST(SortedDataInterface, AdvanceToIndirectExclusiveReversed) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/sorted_data_interface_test_cursor_end_position.cpp b/src/mongo/db/storage/sorted_data_interface_test_cursor_end_position.cpp index 195f9e0a184..9eb167c0516 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_cursor_end_position.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_cursor_end_position.cpp @@ -34,9 +34,10 @@ #include "mongo/unittest/unittest.h" namespace mongo { +namespace { // Tests setEndPosition with next(). void testSetEndPosition_Next_Forward(bool unique, bool inclusive) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface( unique, @@ -75,7 +76,7 @@ TEST(SortedDataInterface, SetEndPosition_Next_Forward_Standard_Exclusive) { } void testSetEndPosition_Next_Reverse(bool unique, bool inclusive) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface( unique, @@ -115,7 +116,7 @@ TEST(SortedDataInterface, SetEndPosition_Next_Reverse_Standard_Exclusive) { // Tests setEndPosition with seek() and seekExact(). void testSetEndPosition_Seek_Forward(bool unique, bool inclusive) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, { @@ -163,7 +164,7 @@ TEST(SortedDataInterface, SetEndPosition_Seek_Forward_Standard_Exclusive) { } void testSetEndPosition_Seek_Reverse(bool unique, bool inclusive) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, { @@ -212,7 +213,7 @@ TEST(SortedDataInterface, SetEndPosition_Seek_Reverse_Standard_Exclusive) { // Test that restore never lands on the wrong side of the endPosition. void testSetEndPosition_Restore_Forward(bool unique) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface( unique, @@ -248,7 +249,7 @@ TEST(SortedDataInterface, SetEndPosition_Restore_Forward_Standard) { } void testSetEndPosition_Restore_Reverse(bool unique) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface( unique, @@ -289,7 +290,7 @@ TEST(SortedDataInterface, SetEndPosition_Restore_Reverse_Standard) { // (since implementations are free not to use end cursors) but implementations that incorrectly // restore end cursors would tend to fail this test. void testSetEndPosition_RestoreEndCursor_Forward(bool unique) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, { @@ -323,7 +324,7 @@ TEST(SortedDataInterface, SetEndPosition_RestoreEndCursor_Forward_Standard) { } void testSetEndPosition_RestoreEndCursor_Reverse(bool unique) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, { @@ -358,7 +359,7 @@ TEST(SortedDataInterface, SetEndPosition_RestoreEndCursor_Reverse_Unique) { // setEndPosition with empty BSONObj is supposed to mean "no end position", regardless of // inclusive flag or direction. void testSetEndPosition_Empty_Forward(bool unique, bool inclusive) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, @@ -388,7 +389,7 @@ TEST(SortedDataInterface, SetEndPosition_Empty_Forward_Standard_Exclusive) { } void testSetEndPosition_Empty_Reverse(bool unique, bool inclusive) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, @@ -416,4 +417,5 @@ TEST(SortedDataInterface, SetEndPosition_Empty_Reverse_Standard_Inclusive) { TEST(SortedDataInterface, SetEndPosition_Empty_Reverse_Standard_Exclusive) { testSetEndPosition_Empty_Reverse(false, false); } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/sorted_data_interface_test_cursor_locate.cpp b/src/mongo/db/storage/sorted_data_interface_test_cursor_locate.cpp index 6d0f05c0cf2..c3ae7e4f4a1 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_cursor_locate.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_cursor_locate.cpp @@ -36,11 +36,12 @@ #include "mongo/unittest/unittest.h" namespace mongo { +namespace { // Insert a key and try to locate it using a forward cursor // by specifying its exact key and RecordId. TEST(SortedDataInterface, Locate) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -70,7 +71,7 @@ TEST(SortedDataInterface, Locate) { // Insert a key and try to locate it using a reverse cursor // by specifying its exact key and RecordId. TEST(SortedDataInterface, LocateReversed) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -102,7 +103,7 @@ TEST(SortedDataInterface, LocateReversed) { // Insert a compound key and try to locate it using a forward cursor // by specifying its exact key and RecordId. TEST(SortedDataInterface, LocateCompoundKey) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -132,7 +133,7 @@ TEST(SortedDataInterface, LocateCompoundKey) { // Insert a compound key and try to locate it using a reverse cursor // by specifying its exact key and RecordId. TEST(SortedDataInterface, LocateCompoundKeyReversed) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -164,7 +165,7 @@ TEST(SortedDataInterface, LocateCompoundKeyReversed) { // Insert multiple keys and try to locate them using a forward cursor // by specifying their exact key and RecordId. TEST(SortedDataInterface, LocateMultiple) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -219,7 +220,7 @@ TEST(SortedDataInterface, LocateMultiple) { // Insert multiple keys and try to locate them using a reverse cursor // by specifying their exact key and RecordId. TEST(SortedDataInterface, LocateMultipleReversed) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -277,7 +278,7 @@ TEST(SortedDataInterface, LocateMultipleReversed) { // Insert multiple compound keys and try to locate them using a forward cursor // by specifying their exact key and RecordId. TEST(SortedDataInterface, LocateMultipleCompoundKeys) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -333,7 +334,7 @@ TEST(SortedDataInterface, LocateMultipleCompoundKeys) { // Insert multiple compound keys and try to locate them using a reverse cursor // by specifying their exact key and RecordId. TEST(SortedDataInterface, LocateMultipleCompoundKeysReversed) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -392,7 +393,7 @@ TEST(SortedDataInterface, LocateMultipleCompoundKeysReversed) { // Insert multiple keys and try to locate them using a forward cursor // by specifying either a smaller key or RecordId. TEST(SortedDataInterface, LocateIndirect) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -442,7 +443,7 @@ TEST(SortedDataInterface, LocateIndirect) { // Insert multiple keys and try to locate them using a reverse cursor // by specifying either a larger key or RecordId. TEST(SortedDataInterface, LocateIndirectReversed) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -495,7 +496,7 @@ TEST(SortedDataInterface, LocateIndirectReversed) { // Insert multiple compound keys and try to locate them using a forward cursor // by specifying either a smaller key or RecordId. TEST(SortedDataInterface, LocateIndirectCompoundKeys) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -547,7 +548,7 @@ TEST(SortedDataInterface, LocateIndirectCompoundKeys) { // Insert multiple compound keys and try to locate them using a reverse cursor // by specifying either a larger key or RecordId. TEST(SortedDataInterface, LocateIndirectCompoundKeysReversed) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -603,7 +604,7 @@ TEST(SortedDataInterface, LocateIndirectCompoundKeysReversed) { // Call locate on a forward cursor of an empty index and verify that the cursor // is positioned at EOF. TEST(SortedDataInterface, LocateEmpty) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -623,7 +624,7 @@ TEST(SortedDataInterface, LocateEmpty) { // Call locate on a reverse cursor of an empty index and verify that the cursor // is positioned at EOF. TEST(SortedDataInterface, LocateEmptyReversed) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -641,4 +642,5 @@ TEST(SortedDataInterface, LocateEmptyReversed) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/sorted_data_interface_test_cursor_saverestore.cpp b/src/mongo/db/storage/sorted_data_interface_test_cursor_saverestore.cpp index 1e711d449e3..895fc0c52a8 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_cursor_saverestore.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_cursor_saverestore.cpp @@ -36,12 +36,13 @@ #include "mongo/unittest/unittest.h" namespace mongo { +namespace { // Insert multiple keys and try to iterate through all of them // using a forward cursor while calling savePosition() and // restorePosition() in succession. TEST(SortedDataInterface, SaveAndRestorePositionWhileIterateCursor) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -86,7 +87,7 @@ TEST(SortedDataInterface, SaveAndRestorePositionWhileIterateCursor) { // using a reverse cursor while calling savePosition() and // restorePosition() in succession. TEST(SortedDataInterface, SaveAndRestorePositionWhileIterateCursorReversed) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -133,7 +134,7 @@ TEST(SortedDataInterface, SaveAndRestorePositionWhileIterateCursorReversed) { // restorePosition() in succession. Verify that the RecordId is saved // as part of the current position of the cursor. TEST(SortedDataInterface, SaveAndRestorePositionWhileIterateCursorWithDupKeys) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -178,7 +179,7 @@ TEST(SortedDataInterface, SaveAndRestorePositionWhileIterateCursorWithDupKeys) { // restorePosition() in succession. Verify that the RecordId is saved // as part of the current position of the cursor. TEST(SortedDataInterface, SaveAndRestorePositionWhileIterateCursorWithDupKeysReversed) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -222,7 +223,7 @@ TEST(SortedDataInterface, SaveAndRestorePositionWhileIterateCursorWithDupKeysRev // Call savePosition() on a forward cursor without ever calling restorePosition(). // May be useful to run this test under valgrind to verify there are no leaks. TEST(SortedDataInterface, SavePositionWithoutRestore) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(true)); { @@ -254,7 +255,7 @@ TEST(SortedDataInterface, SavePositionWithoutRestore) { // Call savePosition() on a reverse cursor without ever calling restorePosition(). // May be useful to run this test under valgrind to verify there are no leaks. TEST(SortedDataInterface, SavePositionWithoutRestoreReversed) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -287,7 +288,7 @@ TEST(SortedDataInterface, SavePositionWithoutRestoreReversed) { // Ensure that restore lands as close as possible to original position, even if data inserted // while saved. void testSaveAndRestorePositionSeesNewInserts(bool forward, bool unique) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, { @@ -321,7 +322,7 @@ TEST(SortedDataInterface, SaveAndRestorePositionSeesNewInserts_Reverse_Standard) // Ensure that repeated restores lands as close as possible to original position, even if data // inserted while saved and the current position removed. void testSaveAndRestorePositionSeesNewInsertsAfterRemove(bool forward, bool unique) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, { @@ -361,7 +362,7 @@ TEST(SortedDataInterface, SaveAndRestorePositionSeesNewInsertsAfterRemove_Revers // inserted while saved and the current position removed in a way that temporarily makes the // cursor EOF. void testSaveAndRestorePositionSeesNewInsertsAfterEOF(bool forward, bool unique) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(false, { @@ -401,7 +402,7 @@ TEST(SortedDataInterface, SaveAndRestorePositionSeesNewInsertsAfterEOF_Reverse_S // Make sure we restore to a RecordId at or ahead of save point if same key. TEST(SortedDataInterface, SaveAndRestorePositionStandardIndexConsidersRecordId_Forward) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(/*isUnique*/ false, @@ -441,7 +442,7 @@ TEST(SortedDataInterface, SaveAndRestorePositionStandardIndexConsidersRecordId_F // Test that cursors over unique indices will never return the same key twice. TEST(SortedDataInterface, SaveAndRestorePositionUniqueIndexWontReturnDupKeys_Forward) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface( /*isUnique*/ true, {{key1, loc1}, {key2, loc2}, {key3, loc2}, {key4, loc2}}); @@ -481,7 +482,7 @@ TEST(SortedDataInterface, SaveAndRestorePositionUniqueIndexWontReturnDupKeys_For // Make sure we restore to a RecordId at or ahead of save point if same key on reverse cursor. TEST(SortedDataInterface, SaveAndRestorePositionStandardIndexConsidersRecordId_Reverse) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(/*isUnique*/ false, @@ -521,7 +522,7 @@ TEST(SortedDataInterface, SaveAndRestorePositionStandardIndexConsidersRecordId_R // Test that reverse cursors over unique indices will never return the same key twice. TEST(SortedDataInterface, SaveAndRestorePositionUniqueIndexWontReturnDupKeys_Reverse) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface( /*isUnique*/ true, {{key1, loc1}, {key2, loc1}, {key3, loc1}, {key4, loc2}}); @@ -561,7 +562,7 @@ TEST(SortedDataInterface, SaveAndRestorePositionUniqueIndexWontReturnDupKeys_Rev // Ensure that SaveUnpositioned allows later use of the cursor. TEST(SortedDataInterface, SaveUnpositionedAndRestore) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(false, @@ -585,4 +586,5 @@ TEST(SortedDataInterface, SaveUnpositionedAndRestore) { ASSERT_EQ(cursor->seek(key3, true), IndexKeyEntry(key3, loc1)); } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/sorted_data_interface_test_cursor_seek_exact.cpp b/src/mongo/db/storage/sorted_data_interface_test_cursor_seek_exact.cpp index ae22f28c52b..28c4aa9de97 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_cursor_seek_exact.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_cursor_seek_exact.cpp @@ -34,9 +34,10 @@ #include "mongo/unittest/unittest.h" namespace mongo { +namespace { // Tests seekExact when it hits something. void testSeekExact_Hit(bool unique, bool forward) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, @@ -68,7 +69,7 @@ TEST(SortedDataInterface, SeekExact_Hit_Standard_Reverse) { // Tests seekExact when it doesn't hit the query. void testSeekExact_Miss(bool unique, bool forward) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, { @@ -101,7 +102,7 @@ TEST(SortedDataInterface, SeekExact_Miss_Standard_Reverse) { // Tests seekExact on forward cursor when it hits something with dup keys. Doesn't make sense // for unique indexes. TEST(SortedDataInterface, SeekExact_HitWithDups_Forward) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface( false, @@ -120,7 +121,7 @@ TEST(SortedDataInterface, SeekExact_HitWithDups_Forward) { // Tests seekExact on reverse cursor when it hits something with dup keys. Doesn't make sense // for unique indexes. TEST(SortedDataInterface, SeekExact_HitWithDups_Reverse) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface( false, @@ -135,4 +136,5 @@ TEST(SortedDataInterface, SeekExact_HitWithDups_Reverse) { ASSERT_EQ(cursor->next(), IndexKeyEntry(key1, loc1)); ASSERT_EQ(cursor->next(), boost::none); } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/sorted_data_interface_test_dupkeycheck.cpp b/src/mongo/db/storage/sorted_data_interface_test_dupkeycheck.cpp index c52ff7cc644..d0053632b69 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_dupkeycheck.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_dupkeycheck.cpp @@ -36,12 +36,13 @@ #include "mongo/unittest/unittest.h" namespace mongo { +namespace { // Insert a key and verify that dupKeyCheck() returns a non-OK status for // the same key. When dupKeyCheck() is called with the exact (key, RecordId) // pair that was inserted, it should still return an OK status. TEST(SortedDataInterface, DupKeyCheckAfterInsert) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(true)); { @@ -77,7 +78,7 @@ TEST(SortedDataInterface, DupKeyCheckAfterInsert) { // Verify that dupKeyCheck() returns an OK status for a key that does // not exist in the index. TEST(SortedDataInterface, DupKeyCheckEmpty) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(true)); { @@ -98,7 +99,7 @@ TEST(SortedDataInterface, DupKeyCheckEmpty) { // Insert a key and verify that dupKeyCheck() acknowledges the duplicate key, even // when the insert key is located at a RecordId that comes after the one specified. TEST(SortedDataInterface, DupKeyCheckWhenDiskLocBefore) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(true)); { @@ -133,7 +134,7 @@ TEST(SortedDataInterface, DupKeyCheckWhenDiskLocBefore) { // Insert a key and verify that dupKeyCheck() acknowledges the duplicate key, even // when the insert key is located at a RecordId that comes before the one specified. TEST(SortedDataInterface, DupKeyCheckWhenDiskLocAfter) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(true)); { @@ -165,4 +166,5 @@ TEST(SortedDataInterface, DupKeyCheckWhenDiskLocAfter) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/sorted_data_interface_test_fullvalidate.cpp b/src/mongo/db/storage/sorted_data_interface_test_fullvalidate.cpp index ce0a31fcc53..69ff4f42154 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_fullvalidate.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_fullvalidate.cpp @@ -36,11 +36,12 @@ #include "mongo/unittest/unittest.h" namespace mongo { +namespace { // Insert multiple keys and verify that fullValidate() either sets // the `numKeysOut` as the number of entries in the index, or as -1. TEST(SortedDataInterface, FullValidate) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -74,4 +75,5 @@ TEST(SortedDataInterface, FullValidate) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/sorted_data_interface_test_harness.cpp b/src/mongo/db/storage/sorted_data_interface_test_harness.cpp index 8e99d7d3461..57461bcf0d4 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_harness.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_harness.cpp @@ -36,9 +36,9 @@ #include "mongo/db/storage/sorted_data_interface.h" #include "mongo/unittest/unittest.h" -namespace mongo { -std::unique_ptr<SortedDataInterface> HarnessHelper::newSortedDataInterface( - bool unique, std::initializer_list<IndexKeyEntry> toInsert) { +auto mongo::SortedDataInterfaceHarnessHelper::newSortedDataInterface( + bool unique, std::initializer_list<IndexKeyEntry> toInsert) + -> std::unique_ptr<SortedDataInterface> { invariant(std::is_sorted( toInsert.begin(), toInsert.end(), IndexEntryComparison(Ordering::make(BSONObj())))); @@ -47,9 +47,9 @@ std::unique_ptr<SortedDataInterface> HarnessHelper::newSortedDataInterface( return index; } -void insertToIndex(unowned_ptr<OperationContext> txn, - unowned_ptr<SortedDataInterface> index, - std::initializer_list<IndexKeyEntry> toInsert) { +void mongo::insertToIndex(unowned_ptr<OperationContext> txn, + unowned_ptr<SortedDataInterface> index, + std::initializer_list<IndexKeyEntry> toInsert) { WriteUnitOfWork wuow(txn); for (auto&& entry : toInsert) { ASSERT_OK(index->insert(txn, entry.key, entry.loc, true)); @@ -57,9 +57,9 @@ void insertToIndex(unowned_ptr<OperationContext> txn, wuow.commit(); } -void removeFromIndex(unowned_ptr<OperationContext> txn, - unowned_ptr<SortedDataInterface> index, - std::initializer_list<IndexKeyEntry> toRemove) { +void mongo::removeFromIndex(unowned_ptr<OperationContext> txn, + unowned_ptr<SortedDataInterface> index, + std::initializer_list<IndexKeyEntry> toRemove) { WriteUnitOfWork wuow(txn); for (auto&& entry : toRemove) { index->unindex(txn, entry.key, entry.loc, true); @@ -67,8 +67,11 @@ void removeFromIndex(unowned_ptr<OperationContext> txn, wuow.commit(); } +namespace mongo { +namespace { + TEST(SortedDataInterface, InsertWithDups1) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -100,7 +103,7 @@ TEST(SortedDataInterface, InsertWithDups1) { } TEST(SortedDataInterface, InsertWithDups2) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -128,7 +131,7 @@ TEST(SortedDataInterface, InsertWithDups2) { } TEST(SortedDataInterface, InsertWithDups3AndRollback) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -156,7 +159,7 @@ TEST(SortedDataInterface, InsertWithDups3AndRollback) { } TEST(SortedDataInterface, InsertNoDups1) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(true)); { @@ -184,7 +187,7 @@ TEST(SortedDataInterface, InsertNoDups1) { } TEST(SortedDataInterface, InsertNoDups2) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(true)); { @@ -212,7 +215,7 @@ TEST(SortedDataInterface, InsertNoDups2) { } TEST(SortedDataInterface, Unindex1) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -277,7 +280,7 @@ TEST(SortedDataInterface, Unindex1) { } TEST(SortedDataInterface, Unindex2Rollback) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -312,7 +315,7 @@ TEST(SortedDataInterface, Unindex2Rollback) { TEST(SortedDataInterface, CursorIterate1) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); int N = 5; @@ -338,7 +341,7 @@ TEST(SortedDataInterface, CursorIterate1) { } TEST(SortedDataInterface, CursorIterate1WithSaveRestore) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); int N = 5; @@ -367,7 +370,7 @@ TEST(SortedDataInterface, CursorIterate1WithSaveRestore) { TEST(SortedDataInterface, CursorIterateAllDupKeysWithSaveRestore) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); int N = 5; @@ -396,7 +399,7 @@ TEST(SortedDataInterface, CursorIterateAllDupKeysWithSaveRestore) { TEST(SortedDataInterface, Locate1) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); BSONObj key = BSON("" << 1); @@ -426,7 +429,7 @@ TEST(SortedDataInterface, Locate1) { } TEST(SortedDataInterface, Locate2) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -452,7 +455,7 @@ TEST(SortedDataInterface, Locate2) { } TEST(SortedDataInterface, Locate2Empty) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -483,7 +486,7 @@ TEST(SortedDataInterface, Locate2Empty) { TEST(SortedDataInterface, Locate3Descending) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); auto buildEntry = [](int i) { return IndexKeyEntry(BSON("" << i), RecordId(1, i * 2)); }; @@ -526,7 +529,7 @@ TEST(SortedDataInterface, Locate3Descending) { } TEST(SortedDataInterface, Locate4) { - auto harnessHelper = newHarnessHelper(); + const auto harnessHelper = newSortedDataInterfaceHarnessHelper(); auto sorted = harnessHelper->newSortedDataInterface(false, { {BSON("" << 1), RecordId(1, 2)}, @@ -557,4 +560,5 @@ TEST(SortedDataInterface, Locate4) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/sorted_data_interface_test_harness.h b/src/mongo/db/storage/sorted_data_interface_test_harness.h index 37e991221f8..def0ed88813 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_harness.h +++ b/src/mongo/db/storage/sorted_data_interface_test_harness.h @@ -39,6 +39,7 @@ #include "mongo/db/service_context.h" #include "mongo/db/service_context_noop.h" #include "mongo/db/storage/sorted_data_interface.h" +#include "mongo/db/storage/test_harness_helper.h" #include "mongo/stdx/memory.h" #include "mongo/util/unowned_ptr.h" @@ -84,23 +85,9 @@ const RecordId loc8(0, 56); class RecoveryUnit; -class HarnessHelper { +class SortedDataInterfaceHarnessHelper : public virtual HarnessHelper { public: - HarnessHelper() : _serviceContext(), _client(_serviceContext.makeClient("hh")) {} - virtual ~HarnessHelper() {} - virtual std::unique_ptr<SortedDataInterface> newSortedDataInterface(bool unique) = 0; - virtual std::unique_ptr<RecoveryUnit> newRecoveryUnit() = 0; - - ServiceContext::UniqueOperationContext newOperationContext(Client* client) { - auto opCtx = client->makeOperationContext(); - opCtx->setRecoveryUnit(newRecoveryUnit().release(), OperationContext::kNotInUnitOfWork); - return opCtx; - } - - ServiceContext::UniqueOperationContext newOperationContext() { - return newOperationContext(_client.get()); - } /** * Creates a new SDI with some initial data. @@ -109,18 +96,6 @@ public: */ std::unique_ptr<SortedDataInterface> newSortedDataInterface( bool unique, std::initializer_list<IndexKeyEntry> toInsert); - - Client* client() { - return _client.get(); - } - - ServiceContext* serviceContext() { - return &_serviceContext; - } - -private: - ServiceContextNoop _serviceContext; - ServiceContext::UniqueClient _client; }; /** @@ -158,5 +133,7 @@ inline void removeFromIndex(unowned_ptr<HarnessHelper> harness, removeFromIndex(harness->newOperationContext(client.get()), index, toRemove); } -std::unique_ptr<HarnessHelper> newHarnessHelper(); +inline std::unique_ptr<SortedDataInterfaceHarnessHelper> newSortedDataInterfaceHarnessHelper() { + return dynamic_ptr_cast<SortedDataInterfaceHarnessHelper>(newHarnessHelper()); +} } diff --git a/src/mongo/db/storage/sorted_data_interface_test_insert.cpp b/src/mongo/db/storage/sorted_data_interface_test_insert.cpp index 5c10b1f6828..b7d90c797fe 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_insert.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_insert.cpp @@ -36,10 +36,11 @@ #include "mongo/unittest/unittest.h" namespace mongo { +namespace { // Insert a key and verify that the number of entries in the index equals 1. TEST(SortedDataInterface, Insert) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -64,7 +65,7 @@ TEST(SortedDataInterface, Insert) { // Insert a compound key and verify that the number of entries in the index equals 1. TEST(SortedDataInterface, InsertCompoundKey) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -91,7 +92,7 @@ TEST(SortedDataInterface, InsertCompoundKey) { // number of entries in the index equals the number that were inserted, even // when duplicates are not allowed. TEST(SortedDataInterface, InsertSameDiskLoc) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -133,7 +134,7 @@ TEST(SortedDataInterface, InsertSameDiskLoc) { // number of entries in the index equals the number that were inserted, even // when duplicates are allowed. TEST(SortedDataInterface, InsertSameDiskLocWithDupsAllowed) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(true)); { @@ -174,7 +175,7 @@ TEST(SortedDataInterface, InsertSameDiskLocWithDupsAllowed) { // Insert the same key multiple times and verify that only 1 entry exists // in the index when duplicates are not allowed. TEST(SortedDataInterface, InsertSameKey) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(true)); { @@ -220,7 +221,7 @@ namespace { // removing all but one loc each time and verifying the correct loc remains. void _testInsertSameKeyWithDupsAllowed(const RecordId locs[3]) { for (int keeper = 0; keeper < 3; keeper++) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface(true)); @@ -283,7 +284,7 @@ TEST(SortedDataInterface, InsertSameKeyWithDupsAllowedLocsDescending) { // Insert multiple keys and verify that the number of entries // in the index equals the number that were inserted. TEST(SortedDataInterface, InsertMultiple) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(true)); { @@ -324,7 +325,7 @@ TEST(SortedDataInterface, InsertMultiple) { // Insert multiple compound keys and verify that the number of entries // in the index equals the number that were inserted. TEST(SortedDataInterface, InsertMultipleCompoundKeys) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(true)); { @@ -364,4 +365,5 @@ TEST(SortedDataInterface, InsertMultipleCompoundKeys) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/sorted_data_interface_test_isempty.cpp b/src/mongo/db/storage/sorted_data_interface_test_isempty.cpp index 52a2b60b311..b98c401400c 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_isempty.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_isempty.cpp @@ -36,12 +36,13 @@ #include "mongo/unittest/unittest.h" namespace mongo { +namespace { // Verify that isEmpty() returns true when the index is empty, // returns false when a key is inserted, and returns true again // when that is unindex. TEST(SortedDataInterface, IsEmpty) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(true)); { @@ -79,4 +80,5 @@ TEST(SortedDataInterface, IsEmpty) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/sorted_data_interface_test_rand_cursor.cpp b/src/mongo/db/storage/sorted_data_interface_test_rand_cursor.cpp index 123776e1d8c..afada4a0fc1 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_rand_cursor.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_rand_cursor.cpp @@ -43,10 +43,11 @@ using std::string; using std::stringstream; namespace mongo { +namespace { // A random iterator should never return any entries from an empty index. TEST(SortedDataInterface, GetRandomIteratorEmpty) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(true)); { @@ -68,7 +69,7 @@ TEST(SortedDataInterface, GetRandomIteratorEmpty) { // General test for 'randomness' of the cursor. With N entries in the index, we should see at least // N/4 distinct entries after iterating N - 1 times. TEST(SortedDataInterface, GetRandomIteratorNonEmpty) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -125,7 +126,7 @@ TEST(SortedDataInterface, GetRandomIteratorNonEmpty) { // With only a single entry in the index, we should always receive that entry via a random cursor. TEST(SortedDataInterface, GetRandomIteratorSingleton) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(true)); { @@ -185,7 +186,7 @@ TEST(SortedDataInterface, GetRandomIteratorSingleton) { // With enough samples, we should eventually have returned every document in the tree at least once. TEST(SortedDataInterface, GetRandomIteratorLargeDocs) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(true)); // Seed the random number generator. @@ -243,4 +244,5 @@ TEST(SortedDataInterface, GetRandomIteratorLargeDocs) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/sorted_data_interface_test_rollback.cpp b/src/mongo/db/storage/sorted_data_interface_test_rollback.cpp index fe980b0f129..a6e5cff31db 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_rollback.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_rollback.cpp @@ -36,11 +36,12 @@ #include "mongo/unittest/unittest.h" namespace mongo { +namespace { // Insert multiple keys and verify that omitting the commit() // on the WriteUnitOfWork causes the changes to not become visible. TEST(SortedDataInterface, InsertWithoutCommit) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(true)); { @@ -82,7 +83,7 @@ TEST(SortedDataInterface, InsertWithoutCommit) { // omitting the commit() on the WriteUnitOfWork causes the changes to // not become visible. TEST(SortedDataInterface, UnindexWithoutCommit) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -152,4 +153,5 @@ TEST(SortedDataInterface, UnindexWithoutCommit) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/sorted_data_interface_test_spaceused.cpp b/src/mongo/db/storage/sorted_data_interface_test_spaceused.cpp index 70f44980c8d..bff24f97e68 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_spaceused.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_spaceused.cpp @@ -36,10 +36,11 @@ #include "mongo/unittest/unittest.h" namespace mongo { +namespace { // Verify that an empty index takes up no space. TEST(SortedDataInterface, GetSpaceUsedBytesEmpty) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -58,7 +59,7 @@ TEST(SortedDataInterface, GetSpaceUsedBytesEmpty) { // Verify that a nonempty index takes up some space. TEST(SortedDataInterface, GetSpaceUsedBytesNonEmpty) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -103,4 +104,5 @@ TEST(SortedDataInterface, GetSpaceUsedBytesNonEmpty) { // } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/sorted_data_interface_test_touch.cpp b/src/mongo/db/storage/sorted_data_interface_test_touch.cpp index a54fb010832..b83c78fa6f6 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_touch.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_touch.cpp @@ -36,10 +36,11 @@ #include "mongo/unittest/unittest.h" namespace mongo { +namespace { // Verify that calling touch() on an empty index returns an OK status. TEST(SortedDataInterface, TouchEmpty) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -51,7 +52,7 @@ TEST(SortedDataInterface, TouchEmpty) { // Verify that calling touch() on a nonempty index returns an OK status. TEST(SortedDataInterface, TouchNonEmpty) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(true)); { @@ -84,4 +85,5 @@ TEST(SortedDataInterface, TouchNonEmpty) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/sorted_data_interface_test_unindex.cpp b/src/mongo/db/storage/sorted_data_interface_test_unindex.cpp index 1e217651fc4..3dde7859d9b 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_unindex.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_unindex.cpp @@ -36,10 +36,11 @@ #include "mongo/unittest/unittest.h" namespace mongo { +namespace { // Insert a key and verify that it can be unindexed. TEST(SortedDataInterface, Unindex) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -79,7 +80,7 @@ TEST(SortedDataInterface, Unindex) { // Insert a compound key and verify that it can be unindexed. TEST(SortedDataInterface, UnindexCompoundKey) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -119,7 +120,7 @@ TEST(SortedDataInterface, UnindexCompoundKey) { // Insert multiple, distinct keys and verify that they can be unindexed. TEST(SortedDataInterface, UnindexMultipleDistinct) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -191,7 +192,7 @@ TEST(SortedDataInterface, UnindexMultipleDistinct) { // Insert the same key multiple times and verify that each occurrence can be unindexed. TEST(SortedDataInterface, UnindexMultipleSameKey) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -263,7 +264,7 @@ TEST(SortedDataInterface, UnindexMultipleSameKey) { // Call unindex() on a nonexistent key and verify the result is false. TEST(SortedDataInterface, UnindexEmpty) { - const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newSortedDataInterfaceHarnessHelper()); const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false)); { @@ -282,4 +283,5 @@ TEST(SortedDataInterface, UnindexEmpty) { } } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/test_harness_helper.cpp b/src/mongo/db/storage/test_harness_helper.cpp new file mode 100644 index 00000000000..62d99709c29 --- /dev/null +++ b/src/mongo/db/storage/test_harness_helper.cpp @@ -0,0 +1,51 @@ +/** + * Copyright (C) 2016 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/db/storage/test_harness_helper.h" + +#include <exception> +#include <stdexcept> + +#include "mongo/util/assert_util.h" + +namespace mongo { +namespace { +stdx::function<std::unique_ptr<HarnessHelper>()> basicHarnessFactory; +} // namespace +} // namespace mongo + + +mongo::HarnessHelper::~HarnessHelper() = default; + +void mongo::registerHarnessHelperFactory(stdx::function<std::unique_ptr<HarnessHelper>()> factory) { + basicHarnessFactory = std::move(factory); +} + +auto mongo::newHarnessHelper() -> std::unique_ptr<HarnessHelper> { + return basicHarnessFactory(); +} diff --git a/src/mongo/db/storage/test_harness_helper.h b/src/mongo/db/storage/test_harness_helper.h new file mode 100644 index 00000000000..935d54cbb86 --- /dev/null +++ b/src/mongo/db/storage/test_harness_helper.h @@ -0,0 +1,101 @@ +/** + * Copyright (C) 2016 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#pragma once + +#include <cstdint> +#include <initializer_list> +#include <memory> + +#include "mongo/db/jsobj.h" +#include "mongo/db/operation_context_noop.h" +#include "mongo/db/record_id.h" +#include "mongo/db/service_context.h" +#include "mongo/db/service_context_noop.h" +#include "mongo/db/storage/sorted_data_interface.h" +#include "mongo/stdx/functional.h" +#include "mongo/stdx/memory.h" +#include "mongo/util/unowned_ptr.h" + +namespace mongo { +class HarnessHelper { +public: + virtual ~HarnessHelper() = 0; + + explicit HarnessHelper() = default; + + virtual ServiceContext::UniqueOperationContext newOperationContext(Client* const client) { + auto opCtx = client->makeOperationContext(); + opCtx->setRecoveryUnit(newRecoveryUnit().release(), OperationContext::kNotInUnitOfWork); + return opCtx; + } + + virtual ServiceContext::UniqueOperationContext newOperationContext() { + return newOperationContext(_client.get()); + } + + Client* client() const { + return _client.get(); + } + + ServiceContext* serviceContext() { + return &_serviceContext; + } + + const ServiceContext* serviceContext() const { + return &_serviceContext; + } + +private: + virtual std::unique_ptr<RecoveryUnit> newRecoveryUnit() = 0; + + ServiceContextNoop _serviceContext; + ServiceContext::UniqueClient _client = _serviceContext.makeClient("hh"); +}; + +namespace harness_helper_detail { +template <typename Target, typename Current> +std::unique_ptr<Target> noexcept_ptr_conversion(std::unique_ptr<Current>&& p, Target& t) noexcept { + p.release(); + return std::unique_ptr<Target>(std::addressof(t)); +} +} // namespace harness_helper_detail + +extern void registerHarnessHelperFactory(stdx::function<std::unique_ptr<HarnessHelper>()> factory); + +template <typename Target, typename Current> +std::unique_ptr<Target> dynamic_ptr_cast(std::unique_ptr<Current>&& p) { + if (!p) { + throw std::runtime_error("Must not be null."); + } + Target& target = dynamic_cast<Target&>(*p); + return harness_helper_detail::noexcept_ptr_conversion(std::move(p), target); +} + +std::unique_ptr<HarnessHelper> newHarnessHelper(); +} // namespace mongo diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index_test.cpp index 4173f8ed455..47c1c81d352 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_index_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index_test.cpp @@ -30,7 +30,9 @@ #include "mongo/platform/basic.h" +#include <memory> +#include "mongo/base/init.h" #include "mongo/bson/bsonobjbuilder.h" #include "mongo/db/catalog/index_catalog_entry.h" #include "mongo/db/index/index_descriptor.h" @@ -47,10 +49,11 @@ #include "mongo/unittest/unittest.h" namespace mongo { +namespace { using std::string; -class MyHarnessHelper final : public HarnessHelper { +class MyHarnessHelper final : public SortedDataInterfaceHarnessHelper { public: MyHarnessHelper() : _dbpath("wt_test"), _conn(NULL) { const char* config = "create,cache_size=1G,"; @@ -98,10 +101,15 @@ private: WiredTigerSessionCache* _sessionCache; }; -std::unique_ptr<HarnessHelper> newHarnessHelper() { +std::unique_ptr<HarnessHelper> makeHarnessHelper() { return stdx::make_unique<MyHarnessHelper>(); } +MONGO_INITIALIZER(RegisterHarnessFactory)(InitializerContext* const) { + mongo::registerHarnessHelperFactory(makeHarnessHelper); + return Status::OK(); +} + TEST(WiredTigerIndexTest, GenerateCreateStringEmptyDocument) { BSONObj spec = fromjson("{}"); StatusWith<std::string> result = WiredTigerIndex::parseIndexOptions(spec); @@ -142,4 +150,5 @@ TEST(WiredTigerIndexTest, GenerateCreateStringValidConfigStringOption) { ASSERT_EQ(WiredTigerIndex::parseIndexOptions(spec), std::string("prefix_compression=true,")); } +} // namespace } // namespace mongo diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp index a720028bc9c..a76f51c4a44 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp @@ -1,5 +1,3 @@ -// wiredtiger_record_store_test.cpp - /** * Copyright (C) 2014 MongoDB Inc. * @@ -30,10 +28,12 @@ #include "mongo/platform/basic.h" +#include <memory> #include <sstream> #include <string> #include "mongo/base/checked_cast.h" +#include "mongo/base/init.h" #include "mongo/base/string_data.h" #include "mongo/bson/bsonobjbuilder.h" #include "mongo/db/concurrency/write_conflict_exception.h" @@ -46,18 +46,20 @@ #include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h" #include "mongo/db/storage/wiredtiger/wiredtiger_size_storer.h" #include "mongo/db/storage/wiredtiger/wiredtiger_util.h" +#include "mongo/stdx/memory.h" #include "mongo/unittest/temp_dir.h" #include "mongo/unittest/unittest.h" #include "mongo/util/fail_point.h" #include "mongo/util/scopeguard.h" namespace mongo { +namespace { using std::unique_ptr; using std::string; using std::stringstream; -class WiredTigerHarnessHelper final : public HarnessHelper { +class WiredTigerHarnessHelper final : public RecordStoreHarnessHelper { public: static WT_CONNECTION* createConnection(StringData dbpath, StringData extraStrings) { WT_CONNECTION* conn = NULL; @@ -144,8 +146,8 @@ public: &txn, ns, uri, kWiredTigerEngineName, true, false, cappedMaxSize, cappedMaxDocs); } - RecoveryUnit* newRecoveryUnit() final { - return new WiredTigerRecoveryUnit(_sessionCache); + std::unique_ptr<RecoveryUnit> newRecoveryUnit() final { + return stdx::make_unique<WiredTigerRecoveryUnit>(_sessionCache); } bool supportsDocLocking() final { @@ -162,10 +164,15 @@ private: WiredTigerSessionCache* _sessionCache; }; -std::unique_ptr<HarnessHelper> newHarnessHelper() { +std::unique_ptr<HarnessHelper> makeHarnessHelper() { return stdx::make_unique<WiredTigerHarnessHelper>(); } +MONGO_INITIALIZER(RegisterHarnessFactory)(InitializerContext* const) { + mongo::registerHarnessHelperFactory(makeHarnessHelper); + return Status::OK(); +} + TEST(WiredTigerRecordStoreTest, GenerateCreateStringEmptyDocument) { BSONObj spec = fromjson("{}"); StatusWith<std::string> result = WiredTigerRecordStore::parseOptionsField(spec); @@ -208,7 +215,7 @@ TEST(WiredTigerRecordStoreTest, GenerateCreateStringValidConfigStringOption) { } TEST(WiredTigerRecordStoreTest, Isolation1) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); RecordId id1; @@ -259,7 +266,7 @@ TEST(WiredTigerRecordStoreTest, Isolation1) { } TEST(WiredTigerRecordStoreTest, Isolation2) { - unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper()); + const auto harnessHelper(newRecordStoreHarnessHelper()); unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore()); RecordId id1; @@ -1554,4 +1561,5 @@ TEST(WiredTigerRecordStoreTest, OplogStones_AscendingOrder) { } } +} // namespace } // namespace mongo |