From a1a846bdc63b92474fcf3477aea472a7e11cd438 Mon Sep 17 00:00:00 2001 From: Mathias Stearn Date: Thu, 9 Apr 2015 14:40:10 -0400 Subject: SERVER-17635 Improve SDI unittest helpers * Added a declaritive way to set index contents * Use std::unique_ptr throughout --- .../in_memory/in_memory_btree_impl_test.cpp | 19 +++-- .../storage/mmap_v1/btree/btree_interface_test.cpp | 26 +++---- .../sorted_data_interface_test_bulkbuilder.cpp | 76 ++++++++++---------- .../sorted_data_interface_test_dupkeycheck.cpp | 48 ++++++------- .../sorted_data_interface_test_fullvalidate.cpp | 16 ++--- .../storage/sorted_data_interface_test_harness.cpp | 47 +++++++----- .../storage/sorted_data_interface_test_harness.h | 41 +++++++++-- .../storage/sorted_data_interface_test_isempty.cpp | 18 +++-- .../sorted_data_interface_test_rollback.cpp | 40 +++++------ .../sorted_data_interface_test_spaceused.cpp | 26 ++++--- .../storage/sorted_data_interface_test_touch.cpp | 22 +++--- .../storage/sorted_data_interface_test_unindex.cpp | 84 +++++++++++----------- .../storage/wiredtiger/wiredtiger_index_test.cpp | 21 +++--- 13 files changed, 252 insertions(+), 232 deletions(-) (limited to 'src/mongo/db/storage') diff --git a/src/mongo/db/storage/in_memory/in_memory_btree_impl_test.cpp b/src/mongo/db/storage/in_memory/in_memory_btree_impl_test.cpp index 0b1a6078571..560b2bb3e0b 100644 --- a/src/mongo/db/storage/in_memory/in_memory_btree_impl_test.cpp +++ b/src/mongo/db/storage/in_memory/in_memory_btree_impl_test.cpp @@ -34,33 +34,32 @@ #include "mongo/db/storage/in_memory/in_memory_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 { - using boost::shared_ptr; - - class InMemoryHarnessHelper : public HarnessHelper { + class InMemoryHarnessHelper final : public HarnessHelper { public: InMemoryHarnessHelper() : _order( Ordering::make( BSONObj() ) ) { } - virtual SortedDataInterface* newSortedDataInterface( bool unique ) { - return getInMemoryBtreeImpl(_order, &_data); + std::unique_ptr newSortedDataInterface( bool unique ) final { + return std::unique_ptr(getInMemoryBtreeImpl(_order, &_data)); } - virtual RecoveryUnit* newRecoveryUnit() { - return new InMemoryRecoveryUnit(); + std::unique_ptr newRecoveryUnit() final { + return stdx::make_unique(); } private: - shared_ptr _data; // used by InMemoryBtreeImpl + boost::shared_ptr _data; // used by InMemoryBtreeImpl Ordering _order; }; - HarnessHelper* newHarnessHelper() { - return new InMemoryHarnessHelper(); + std::unique_ptr newHarnessHelper() { + return stdx::make_unique(); } } 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 74458f3e5e7..48d9fe5319b 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 @@ -37,27 +37,27 @@ namespace mongo { using std::auto_ptr; - class MyHarnessHelper : public HarnessHelper { + class MyHarnessHelper final : public HarnessHelper { public: MyHarnessHelper() : _recordStore("a.b"), _order(Ordering::make(BSONObj())) { } - virtual SortedDataInterface* newSortedDataInterface(bool unique) { - auto_ptr sorted(getMMAPV1Interface(&_headManager, - &_recordStore, - &_cursorRegistry, - _order, - "a_1", - 1)); + std::unique_ptr newSortedDataInterface(bool unique) final { + std::unique_ptr sorted(getMMAPV1Interface(&_headManager, + &_recordStore, + &_cursorRegistry, + _order, + "a_1", + 1)); OperationContextNoop op; massertStatusOK(sorted->initAsEmpty(&op)); - return sorted.release(); + return sorted; } - virtual RecoveryUnit* newRecoveryUnit() { - return new HeapRecordStoreBtreeRecoveryUnit(); + std::unique_ptr newRecoveryUnit() final { + return stdx::make_unique(); } private: @@ -67,8 +67,8 @@ namespace mongo { Ordering _order; }; - HarnessHelper* newHarnessHelper() { - return new MyHarnessHelper(); + std::unique_ptr newHarnessHelper() { + return stdx::make_unique(); } } 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 8de85f0d5de..cb1f8fa0953 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_bulkbuilder.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_bulkbuilder.cpp @@ -30,28 +30,26 @@ #include "mongo/db/storage/sorted_data_interface_test_harness.h" -#include +#include #include "mongo/db/storage/sorted_data_interface.h" #include "mongo/unittest/unittest.h" namespace mongo { - using boost::scoped_ptr; - // Add a key using a bulk builder. TEST( SortedDataInterface, BuilderAddKey ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); - scoped_ptr builder( + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr builder( sorted->getBulkBuilder( opCtx.get(), true ) ); ASSERT_OK( builder->addKey( key1, loc1 ) ); @@ -59,24 +57,24 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) ); } } // Add a compound key using a bulk builder. TEST( SortedDataInterface, BuilderAddCompoundKey ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); - scoped_ptr builder( + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr builder( sorted->getBulkBuilder( opCtx.get(), true ) ); ASSERT_OK( builder->addKey( compoundKey1a, loc1 ) ); @@ -84,7 +82,7 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) ); } } @@ -93,17 +91,17 @@ namespace mongo { // the returned status is ErrorCodes::DuplicateKey when duplicates are // not allowed. TEST( SortedDataInterface, BuilderAddSameKey ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( true ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( true ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); - scoped_ptr builder( + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr builder( sorted->getBulkBuilder( opCtx.get(), false ) ); ASSERT_OK( builder->addKey( key1, loc1 ) ); @@ -112,7 +110,7 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) ); } } @@ -120,17 +118,17 @@ namespace mongo { // 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 ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); - scoped_ptr builder( + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr builder( sorted->getBulkBuilder( opCtx.get(), true /* allow duplicates */ ) ); ASSERT_OK( builder->addKey( key1, loc1 ) ); @@ -139,24 +137,24 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 2, sorted->numEntries( opCtx.get() ) ); } } // Add multiple keys using a bulk builder. TEST( SortedDataInterface, BuilderAddMultipleKeys ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); - scoped_ptr builder( + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr builder( sorted->getBulkBuilder( opCtx.get(), true ) ); ASSERT_OK( builder->addKey( key1, loc1 ) ); @@ -166,24 +164,24 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 3, sorted->numEntries( opCtx.get() ) ); } } // Add multiple compound keys using a bulk builder. TEST( SortedDataInterface, BuilderAddMultipleCompoundKeys ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); - scoped_ptr builder( + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr builder( sorted->getBulkBuilder( opCtx.get(), true ) ); ASSERT_OK( builder->addKey( compoundKey1a, loc1 ) ); @@ -195,7 +193,7 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 5, sorted->numEntries( opCtx.get() ) ); } } 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 56ddfc390a1..0d31abe6f19 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_dupkeycheck.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_dupkeycheck.cpp @@ -30,29 +30,27 @@ #include "mongo/db/storage/sorted_data_interface_test_harness.h" -#include +#include #include "mongo/db/storage/sorted_data_interface.h" #include "mongo/unittest/unittest.h" namespace mongo { - using boost::scoped_ptr; - // 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 ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( true ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( true ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); ASSERT_OK( sorted->insert( opCtx.get(), key1, loc1, false ) ); @@ -61,12 +59,12 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); ASSERT_OK( sorted->dupKeyCheck( opCtx.get(), key1, loc1 ) ); @@ -79,16 +77,16 @@ namespace mongo { // Verify that dupKeyCheck() returns an OK status for a key that does // not exist in the index. TEST( SortedDataInterface, DupKeyCheckEmpty ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( true ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( true ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); ASSERT_OK( sorted->dupKeyCheck( opCtx.get(), key1, loc1 ) ); @@ -100,16 +98,16 @@ namespace mongo { // 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 ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( true ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( true ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); ASSERT_OK( sorted->insert( opCtx.get(), key1, loc1, true ) ); @@ -118,12 +116,12 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); ASSERT_NOT_OK( sorted->dupKeyCheck( opCtx.get(), key1, RecordId::min() ) ); @@ -135,16 +133,16 @@ namespace mongo { // 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 ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( true ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( true ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); ASSERT_OK( sorted->insert( opCtx.get(), key1, loc1, true ) ); @@ -153,12 +151,12 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); ASSERT_NOT_OK( sorted->dupKeyCheck( opCtx.get(), key1, RecordId::max() ) ); 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 20ba21ec815..a7ee8544dc0 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_fullvalidate.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_fullvalidate.cpp @@ -30,29 +30,27 @@ #include "mongo/db/storage/sorted_data_interface_test_harness.h" -#include +#include #include "mongo/db/storage/sorted_data_interface.h" #include "mongo/unittest/unittest.h" namespace mongo { - using boost::scoped_ptr; - // 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 ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } int nToInsert = 10; for ( int i = 0; i < nToInsert; i++ ) { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); BSONObj key = BSON( "" << i ); @@ -63,13 +61,13 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( nToInsert, sorted->numEntries( opCtx.get() ) ); } { long long numKeysOut; - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); sorted->fullValidate(opCtx.get(), false, &numKeysOut, NULL); // fullValidate() can set numKeysOut as the number of existing keys or -1. ASSERT( numKeysOut == nToInsert || numKeysOut == -1 ); 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 066b6a0b1a9..38490d9a3ca 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_harness.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_harness.cpp @@ -36,6 +36,23 @@ #include "mongo/unittest/unittest.h" namespace mongo { + std::unique_ptr HarnessHelper::newSortedDataInterface( + bool unique, + std::initializer_list toInsert) { + auto index = newSortedDataInterface(unique); + insertToIndex(this, index, toInsert); + return index; + } + + void insertToIndex(ptr txn, + ptr index, + std::initializer_list toInsert) { + WriteUnitOfWork wuow(txn); + for (auto&& entry : toInsert) { + ASSERT_OK(index->insert(txn, entry.key, entry.loc, true)); + } + wuow.commit(); + } TEST( SortedDataInterface, InsertWithDups1 ) { const std::unique_ptr harnessHelper( newHarnessHelper() ); @@ -505,25 +522,17 @@ namespace mongo { } TEST( SortedDataInterface, Locate4 ) { - const std::unique_ptr harnessHelper( newHarnessHelper() ); - const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); - - { - const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); - { - WriteUnitOfWork uow( opCtx.get() ); - - ASSERT_OK( sorted->insert( opCtx.get(), BSON( "" << 1 ), RecordId(1,2), true ) ); - ASSERT_OK( sorted->insert( opCtx.get(), BSON( "" << 1 ), RecordId(1,4), true ) ); - ASSERT_OK( sorted->insert( opCtx.get(), BSON( "" << 1 ), RecordId(1,6), true ) ); - ASSERT_OK( sorted->insert( opCtx.get(), BSON( "" << 2 ), RecordId(1,8), true ) ); - uow.commit(); - } - } + auto harnessHelper = newHarnessHelper(); + auto sorted = harnessHelper->newSortedDataInterface(false, { + {BSON("" << 1), RecordId(1, 2)}, + {BSON("" << 1), RecordId(1, 4)}, + {BSON("" << 1), RecordId(1, 6)}, + {BSON("" << 2), RecordId(1, 8)}, + }); { - const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); - const std::unique_ptr cursor( sorted->newCursor(opCtx.get()) ); + auto opCtx = harnessHelper->newOperationContext(); + auto cursor = sorted->newCursor(opCtx.get()); ASSERT_EQ(cursor->seek(BSON("a" << 1), true), IndexKeyEntry(BSON("" << 1), RecordId(1, 2))); @@ -534,8 +543,8 @@ namespace mongo { } { - const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); - const std::unique_ptr cursor( sorted->newCursor(opCtx.get(), false) ); + auto opCtx = harnessHelper->newOperationContext(); + auto cursor = sorted->newCursor(opCtx.get(), false); ASSERT_EQ(cursor->seek(BSON("a" << 1), true), IndexKeyEntry(BSON("" << 1), RecordId(1, 6))); 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 3b830e1a313..c3e8446f4f4 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_harness.h +++ b/src/mongo/db/storage/sorted_data_interface_test_harness.h @@ -30,9 +30,15 @@ #pragma once +#include +#include + #include "mongo/db/jsobj.h" #include "mongo/db/operation_context_noop.h" #include "mongo/db/record_id.h" +#include "mongo/db/storage/sorted_data_interface.h" +#include "mongo/stdx/memory.h" +#include "mongo/util/ptr.h" namespace mongo { @@ -65,20 +71,41 @@ namespace mongo { const RecordId loc8( 10, 56 ); class RecoveryUnit; - class SortedDataInterface; class HarnessHelper { public: HarnessHelper(){} - virtual ~HarnessHelper(){} + virtual ~HarnessHelper() = default; - virtual SortedDataInterface* newSortedDataInterface( bool unique ) = 0; - virtual RecoveryUnit* newRecoveryUnit() = 0; + virtual std::unique_ptr newSortedDataInterface( bool unique ) = 0; + virtual std::unique_ptr newRecoveryUnit() = 0; - virtual OperationContext* newOperationContext() { - return new OperationContextNoop( newRecoveryUnit() ); + virtual std::unique_ptr newOperationContext() { + return stdx::make_unique(newRecoveryUnit().release()); } + + /** + * Creates a new SDI with some initial data. + */ + std::unique_ptr newSortedDataInterface( + bool unique, + std::initializer_list toInsert); }; - HarnessHelper* newHarnessHelper(); + /** + * Inserts all entries in toInsert into index. + * ASSERT_OKs the inserts. + * Always uses dupsAllowed=true. + */ + void insertToIndex(ptr txn, + ptr index, + std::initializer_list toInsert); + + inline void insertToIndex(ptr harness, + ptr index, + std::initializer_list toInsert) { + insertToIndex(harness->newOperationContext(), index, toInsert); + } + + std::unique_ptr newHarnessHelper(); } 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 d8d40a58cbc..8dcef9a3770 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_isempty.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_isempty.cpp @@ -30,29 +30,27 @@ #include "mongo/db/storage/sorted_data_interface_test_harness.h" -#include +#include #include "mongo/db/storage/sorted_data_interface.h" #include "mongo/unittest/unittest.h" namespace mongo { - using boost::scoped_ptr; - // 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 ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( true ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( true ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); ASSERT_OK( sorted->insert( opCtx.get(), key1, loc1, false ) ); @@ -61,12 +59,12 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( !sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); sorted->unindex( opCtx.get(), key1, loc1, false ); @@ -76,7 +74,7 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } } 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 b016b8f6a82..4b1125e5f07 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_rollback.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_rollback.cpp @@ -30,28 +30,26 @@ #include "mongo/db/storage/sorted_data_interface_test_harness.h" -#include +#include #include "mongo/db/storage/sorted_data_interface.h" #include "mongo/unittest/unittest.h" namespace mongo { - using boost::scoped_ptr; - // Insert multiple keys and verify that omitting the commit() // on the WriteUnitOfWork causes the changes to not become visible. TEST( SortedDataInterface, InsertWithoutCommit ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( true ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( true ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); ASSERT_OK( sorted->insert( opCtx.get(), key1, loc1, false ) ); @@ -60,12 +58,12 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); ASSERT_OK( sorted->insert( opCtx.get(), key2, loc1, false ) ); @@ -75,7 +73,7 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } } @@ -84,16 +82,16 @@ namespace mongo { // omitting the commit() on the WriteUnitOfWork causes the changes to // not become visible. TEST( SortedDataInterface, UnindexWithoutCommit ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); ASSERT_OK( sorted->insert( opCtx.get(), key1, loc1, true ) ); @@ -103,12 +101,12 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 2, sorted->numEntries( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); sorted->unindex( opCtx.get(), key2, loc2, true ); @@ -118,12 +116,12 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 2, sorted->numEntries( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); ASSERT_OK( sorted->insert( opCtx.get(), key3, loc3, true ) ); @@ -132,12 +130,12 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 3, sorted->numEntries( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); sorted->unindex( opCtx.get(), key1, loc1, true ); @@ -149,7 +147,7 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 3, sorted->numEntries( opCtx.get() ) ); } } 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 5332bd0afb0..49914ff161c 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_spaceused.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_spaceused.cpp @@ -30,46 +30,44 @@ #include "mongo/db/storage/sorted_data_interface_test_harness.h" -#include +#include #include "mongo/db/storage/sorted_data_interface.h" #include "mongo/unittest/unittest.h" namespace mongo { - using boost::scoped_ptr; - // Verify that an empty index takes up no space. TEST( SortedDataInterface, GetSpaceUsedBytesEmpty ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } // SERVER-15416 mmapv1 test harness does not use SimpleRecordStoreV1 as its record store // and HeapRecordStoreBtree::dataSize does not have an actual implementation // { - // scoped_ptr opCtx( harnessHelper->newOperationContext() ); + // const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); // ASSERT( sorted->getSpaceUsedBytes( opCtx.get() ) == 0 ); // } } // Verify that a nonempty index takes up some space. TEST( SortedDataInterface, GetSpaceUsedBytesNonEmpty ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } int nToInsert = 10; for ( int i = 0; i < nToInsert; i++ ) { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); BSONObj key = BSON( "" << i ); @@ -80,7 +78,7 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( nToInsert, sorted->numEntries( opCtx.get() ) ); } @@ -88,7 +86,7 @@ namespace mongo { // and HeapRecordStoreBtree::dataSize does not have an actual implementation // long long spaceUsedBytes; // { - // scoped_ptr opCtx( harnessHelper->newOperationContext() ); + // const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); // spaceUsedBytes = sorted->getSpaceUsedBytes( opCtx.get() ); // ASSERT( spaceUsedBytes > 0 ); // } @@ -96,7 +94,7 @@ namespace mongo { // { // // getSpaceUsedBytes() returns the same value when called multiple times // // and there were not interleaved write operations. - // scoped_ptr opCtx( harnessHelper->newOperationContext() ); + // const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); // ASSERT_EQUALS( spaceUsedBytes, sorted->getSpaceUsedBytes( opCtx.get() ) ); // ASSERT_EQUALS( spaceUsedBytes, sorted->getSpaceUsedBytes( opCtx.get() ) ); // } 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 f131660f4b0..83a3c314ef9 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_touch.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_touch.cpp @@ -30,22 +30,20 @@ #include "mongo/db/storage/sorted_data_interface_test_harness.h" -#include +#include #include "mongo/db/storage/sorted_data_interface.h" #include "mongo/unittest/unittest.h" namespace mongo { - using boost::scoped_ptr; - // Verify that calling touch() on an empty index returns an OK status. TEST( SortedDataInterface, TouchEmpty ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); Status status = sorted->touch( opCtx.get() ); ASSERT( status.isOK() || status.code() == ErrorCodes::CommandNotSupported ); } @@ -53,16 +51,16 @@ namespace mongo { // Verify that calling touch() on a nonempty index returns an OK status. TEST( SortedDataInterface, TouchNonEmpty ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( true ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( true ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); ASSERT_OK( sorted->insert( opCtx.get(), key1, loc1, false ) ); @@ -73,12 +71,12 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 3, sorted->numEntries( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); // XXX does not verify the index was brought into memory // (even if supported by storage engine) Status status = sorted->touch( opCtx.get() ); 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 64c2209325c..b15d1e883e2 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_unindex.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_unindex.cpp @@ -30,27 +30,25 @@ #include "mongo/db/storage/sorted_data_interface_test_harness.h" -#include +#include #include "mongo/db/storage/sorted_data_interface.h" #include "mongo/unittest/unittest.h" namespace mongo { - using boost::scoped_ptr; - // Insert a key and verify that it can be unindexed. TEST( SortedDataInterface, Unindex ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); ASSERT_OK( sorted->insert( opCtx.get(), key1, loc1, true ) ); @@ -59,12 +57,12 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); sorted->unindex( opCtx.get(), key1, loc1, true ); @@ -74,23 +72,23 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } } // Insert a compound key and verify that it can be unindexed. TEST( SortedDataInterface, UnindexCompoundKey ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); ASSERT_OK( sorted->insert( opCtx.get(), compoundKey1a, loc1, true ) ); @@ -99,12 +97,12 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); sorted->unindex( opCtx.get(), compoundKey1a, loc1, true ); @@ -114,23 +112,23 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } } // Insert multiple, distinct keys and verify that they can be unindexed. TEST( SortedDataInterface, UnindexMultipleDistinct ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); ASSERT_OK( sorted->insert( opCtx.get(), key1, loc1, true ) ); @@ -140,12 +138,12 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 2, sorted->numEntries( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); sorted->unindex( opCtx.get(), key2, loc2, true ); @@ -155,12 +153,12 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); ASSERT_OK( sorted->insert( opCtx.get(), key3, loc3, true ) ); @@ -169,12 +167,12 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 2, sorted->numEntries( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); sorted->unindex( opCtx.get(), key1, loc1, true ); @@ -186,23 +184,23 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } } // Insert the same key multiple times and verify that each occurrence can be unindexed. TEST( SortedDataInterface, UnindexMultipleSameKey ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); ASSERT_OK( sorted->insert( opCtx.get(), key1, loc1, true ) ); @@ -212,12 +210,12 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 2, sorted->numEntries( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); sorted->unindex( opCtx.get(), key1, loc2, true ); @@ -227,12 +225,12 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); ASSERT_OK( sorted->insert( opCtx.get(), key1, loc3, true /* allow duplicates */ ) ); @@ -241,12 +239,12 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT_EQUALS( 2, sorted->numEntries( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); sorted->unindex( opCtx.get(), key1, loc1, true); @@ -258,23 +256,23 @@ namespace mongo { } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } } // Call unindex() on a nonexistent key and verify the result is false. TEST( SortedDataInterface, UnindexEmpty ) { - scoped_ptr harnessHelper( newHarnessHelper() ); - scoped_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); + const std::unique_ptr harnessHelper( newHarnessHelper() ); + const std::unique_ptr sorted( harnessHelper->newSortedDataInterface( false ) ); { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); ASSERT( sorted->isEmpty( opCtx.get() ) ); } { - scoped_ptr opCtx( harnessHelper->newOperationContext() ); + const std::unique_ptr opCtx( harnessHelper->newOperationContext() ); { WriteUnitOfWork uow( opCtx.get() ); sorted->unindex( opCtx.get(), key1, loc1, true ); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index_test.cpp index c6b15b74a3f..b78f11564ba 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_index_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index_test.cpp @@ -42,6 +42,7 @@ #include "mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h" #include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.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" @@ -49,7 +50,7 @@ namespace mongo { using std::string; - class MyHarnessHelper : public HarnessHelper { + class MyHarnessHelper final : public HarnessHelper { public: MyHarnessHelper() : _dbpath( "wt_test" ), _conn( NULL ) { @@ -60,14 +61,14 @@ namespace mongo { _sessionCache = new WiredTigerSessionCache( _conn ); } - ~MyHarnessHelper() { + ~MyHarnessHelper() final { delete _sessionCache; _conn->close(_conn, NULL); } - virtual SortedDataInterface* newSortedDataInterface( bool unique ) { + std::unique_ptr newSortedDataInterface( bool unique ) final { std::string ns = "test.wt"; - OperationContextNoop txn( newRecoveryUnit() ); + OperationContextNoop txn( newRecoveryUnit().release() ); BSONObj spec = BSON( "key" << BSON( "a" << 1 ) << "name" << "testIndex" << @@ -82,12 +83,12 @@ namespace mongo { invariantWTOK( WiredTigerIndex::Create(&txn, uri, result.getValue())); if ( unique ) - return new WiredTigerIndexUnique( &txn, uri, &desc ); - return new WiredTigerIndexStandard( &txn, uri, &desc ); + return stdx::make_unique( &txn, uri, &desc ); + return stdx::make_unique( &txn, uri, &desc ); } - virtual RecoveryUnit* newRecoveryUnit() { - return new WiredTigerRecoveryUnit( _sessionCache ); + std::unique_ptr newRecoveryUnit() final { + return stdx::make_unique( _sessionCache ); } private: @@ -96,8 +97,8 @@ namespace mongo { WiredTigerSessionCache* _sessionCache; }; - HarnessHelper* newHarnessHelper() { - return new MyHarnessHelper(); + std::unique_ptr newHarnessHelper() { + return stdx::make_unique(); } TEST(WiredTigerIndexTest, GenerateCreateStringEmptyDocument) { -- cgit v1.2.1