summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2015-04-09 14:40:10 -0400
committerMathias Stearn <mathias@10gen.com>2015-04-15 19:28:35 -0400
commita1a846bdc63b92474fcf3477aea472a7e11cd438 (patch)
tree440859b71041c4260c1359c0e0bda6fff14f179a /src/mongo/db/storage
parent6546083077887e8dc6ea47c26dc4631709a8ff99 (diff)
downloadmongo-a1a846bdc63b92474fcf3477aea472a7e11cd438.tar.gz
SERVER-17635 Improve SDI unittest helpers
* Added a declaritive way to set index contents * Use std::unique_ptr throughout
Diffstat (limited to 'src/mongo/db/storage')
-rw-r--r--src/mongo/db/storage/in_memory/in_memory_btree_impl_test.cpp19
-rw-r--r--src/mongo/db/storage/mmap_v1/btree/btree_interface_test.cpp26
-rw-r--r--src/mongo/db/storage/sorted_data_interface_test_bulkbuilder.cpp76
-rw-r--r--src/mongo/db/storage/sorted_data_interface_test_dupkeycheck.cpp48
-rw-r--r--src/mongo/db/storage/sorted_data_interface_test_fullvalidate.cpp16
-rw-r--r--src/mongo/db/storage/sorted_data_interface_test_harness.cpp47
-rw-r--r--src/mongo/db/storage/sorted_data_interface_test_harness.h41
-rw-r--r--src/mongo/db/storage/sorted_data_interface_test_isempty.cpp18
-rw-r--r--src/mongo/db/storage/sorted_data_interface_test_rollback.cpp40
-rw-r--r--src/mongo/db/storage/sorted_data_interface_test_spaceused.cpp26
-rw-r--r--src/mongo/db/storage/sorted_data_interface_test_touch.cpp22
-rw-r--r--src/mongo/db/storage/sorted_data_interface_test_unindex.cpp84
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_index_test.cpp21
13 files changed, 252 insertions, 232 deletions
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<SortedDataInterface> newSortedDataInterface( bool unique ) final {
+ return std::unique_ptr<SortedDataInterface>(getInMemoryBtreeImpl(_order, &_data));
}
- virtual RecoveryUnit* newRecoveryUnit() {
- return new InMemoryRecoveryUnit();
+ std::unique_ptr<RecoveryUnit> newRecoveryUnit() final {
+ return stdx::make_unique<InMemoryRecoveryUnit>();
}
private:
- shared_ptr<void> _data; // used by InMemoryBtreeImpl
+ boost::shared_ptr<void> _data; // used by InMemoryBtreeImpl
Ordering _order;
};
- HarnessHelper* newHarnessHelper() {
- return new InMemoryHarnessHelper();
+ std::unique_ptr<HarnessHelper> newHarnessHelper() {
+ return stdx::make_unique<InMemoryHarnessHelper>();
}
}
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<SortedDataInterface> sorted(getMMAPV1Interface(&_headManager,
- &_recordStore,
- &_cursorRegistry,
- _order,
- "a_1",
- 1));
+ std::unique_ptr<SortedDataInterface> newSortedDataInterface(bool unique) final {
+ std::unique_ptr<SortedDataInterface> 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<RecoveryUnit> newRecoveryUnit() final {
+ return stdx::make_unique<HeapRecordStoreBtreeRecoveryUnit>();
}
private:
@@ -67,8 +67,8 @@ namespace mongo {
Ordering _order;
};
- HarnessHelper* newHarnessHelper() {
- return new MyHarnessHelper();
+ std::unique_ptr<HarnessHelper> newHarnessHelper() {
+ return stdx::make_unique<MyHarnessHelper>();
}
}
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 <boost/scoped_ptr.hpp>
+#include <memory>
#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> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- scoped_ptr<SortedDataBuilderInterface> builder(
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<SortedDataBuilderInterface> builder(
sorted->getBulkBuilder( opCtx.get(), true ) );
ASSERT_OK( builder->addKey( key1, loc1 ) );
@@ -59,24 +57,24 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) );
}
}
// Add a compound key using a bulk builder.
TEST( SortedDataInterface, BuilderAddCompoundKey ) {
- scoped_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- scoped_ptr<SortedDataBuilderInterface> builder(
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<SortedDataBuilderInterface> builder(
sorted->getBulkBuilder( opCtx.get(), true ) );
ASSERT_OK( builder->addKey( compoundKey1a, loc1 ) );
@@ -84,7 +82,7 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( true ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( true ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- scoped_ptr<SortedDataBuilderInterface> builder(
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<SortedDataBuilderInterface> builder(
sorted->getBulkBuilder( opCtx.get(), false ) );
ASSERT_OK( builder->addKey( key1, loc1 ) );
@@ -112,7 +110,7 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- scoped_ptr<SortedDataBuilderInterface> builder(
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<SortedDataBuilderInterface> builder(
sorted->getBulkBuilder( opCtx.get(), true /* allow duplicates */ ) );
ASSERT_OK( builder->addKey( key1, loc1 ) );
@@ -139,24 +137,24 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT_EQUALS( 2, sorted->numEntries( opCtx.get() ) );
}
}
// Add multiple keys using a bulk builder.
TEST( SortedDataInterface, BuilderAddMultipleKeys ) {
- scoped_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- scoped_ptr<SortedDataBuilderInterface> builder(
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<SortedDataBuilderInterface> builder(
sorted->getBulkBuilder( opCtx.get(), true ) );
ASSERT_OK( builder->addKey( key1, loc1 ) );
@@ -166,24 +164,24 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT_EQUALS( 3, sorted->numEntries( opCtx.get() ) );
}
}
// Add multiple compound keys using a bulk builder.
TEST( SortedDataInterface, BuilderAddMultipleCompoundKeys ) {
- scoped_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- scoped_ptr<SortedDataBuilderInterface> builder(
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<SortedDataBuilderInterface> builder(
sorted->getBulkBuilder( opCtx.get(), true ) );
ASSERT_OK( builder->addKey( compoundKey1a, loc1 ) );
@@ -195,7 +193,7 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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 <boost/scoped_ptr.hpp>
+#include <memory>
#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> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( true ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( true ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
ASSERT_OK( sorted->insert( opCtx.get(), key1, loc1, false ) );
@@ -61,12 +59,12 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( true ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( true ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( true ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( true ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
ASSERT_OK( sorted->insert( opCtx.get(), key1, loc1, true ) );
@@ -118,12 +116,12 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( true ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( true ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
ASSERT_OK( sorted->insert( opCtx.get(), key1, loc1, true ) );
@@ -153,12 +151,12 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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 <boost/scoped_ptr.hpp>
+#include <memory>
#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> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
int nToInsert = 10;
for ( int i = 0; i < nToInsert; i++ ) {
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
BSONObj key = BSON( "" << i );
@@ -63,13 +61,13 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT_EQUALS( nToInsert, sorted->numEntries( opCtx.get() ) );
}
{
long long numKeysOut;
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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<SortedDataInterface> HarnessHelper::newSortedDataInterface(
+ bool unique,
+ std::initializer_list<IndexKeyEntry> toInsert) {
+ auto index = newSortedDataInterface(unique);
+ insertToIndex(this, index, toInsert);
+ return index;
+ }
+
+ void insertToIndex(ptr<OperationContext> txn,
+ 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));
+ }
+ wuow.commit();
+ }
TEST( SortedDataInterface, InsertWithDups1 ) {
const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
@@ -505,25 +522,17 @@ namespace mongo {
}
TEST( SortedDataInterface, Locate4 ) {
- const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
- const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
-
- {
- const std::unique_ptr<OperationContext> 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<OperationContext> opCtx( harnessHelper->newOperationContext() );
- const std::unique_ptr<SortedDataInterface::Cursor> 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<OperationContext> opCtx( harnessHelper->newOperationContext() );
- const std::unique_ptr<SortedDataInterface::Cursor> 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 <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/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<SortedDataInterface> newSortedDataInterface( bool unique ) = 0;
+ virtual std::unique_ptr<RecoveryUnit> newRecoveryUnit() = 0;
- virtual OperationContext* newOperationContext() {
- return new OperationContextNoop( newRecoveryUnit() );
+ virtual std::unique_ptr<OperationContext> newOperationContext() {
+ return stdx::make_unique<OperationContextNoop>(newRecoveryUnit().release());
}
+
+ /**
+ * Creates a new SDI with some initial data.
+ */
+ std::unique_ptr<SortedDataInterface> newSortedDataInterface(
+ bool unique,
+ std::initializer_list<IndexKeyEntry> toInsert);
};
- HarnessHelper* newHarnessHelper();
+ /**
+ * Inserts all entries in toInsert into index.
+ * ASSERT_OKs the inserts.
+ * Always uses dupsAllowed=true.
+ */
+ void insertToIndex(ptr<OperationContext> txn,
+ ptr<SortedDataInterface> index,
+ std::initializer_list<IndexKeyEntry> toInsert);
+
+ inline void insertToIndex(ptr<HarnessHelper> harness,
+ ptr<SortedDataInterface> index,
+ std::initializer_list<IndexKeyEntry> toInsert) {
+ insertToIndex(harness->newOperationContext(), index, toInsert);
+ }
+
+ std::unique_ptr<HarnessHelper> 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 <boost/scoped_ptr.hpp>
+#include <memory>
#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> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( true ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( true ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
ASSERT_OK( sorted->insert( opCtx.get(), key1, loc1, false ) );
@@ -61,12 +59,12 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( !sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
sorted->unindex( opCtx.get(), key1, loc1, false );
@@ -76,7 +74,7 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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 <boost/scoped_ptr.hpp>
+#include <memory>
#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> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( true ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( true ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
ASSERT_OK( sorted->insert( opCtx.get(), key1, loc1, false ) );
@@ -60,12 +58,12 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
ASSERT_OK( sorted->insert( opCtx.get(), key2, loc1, false ) );
@@ -75,7 +73,7 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
ASSERT_OK( sorted->insert( opCtx.get(), key1, loc1, true ) );
@@ -103,12 +101,12 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT_EQUALS( 2, sorted->numEntries( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
sorted->unindex( opCtx.get(), key2, loc2, true );
@@ -118,12 +116,12 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT_EQUALS( 2, sorted->numEntries( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
ASSERT_OK( sorted->insert( opCtx.get(), key3, loc3, true ) );
@@ -132,12 +130,12 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT_EQUALS( 3, sorted->numEntries( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
sorted->unindex( opCtx.get(), key1, loc1, true );
@@ -149,7 +147,7 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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 <boost/scoped_ptr.hpp>
+#include <memory>
#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> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ // const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
// ASSERT( sorted->getSpaceUsedBytes( opCtx.get() ) == 0 );
// }
}
// Verify that a nonempty index takes up some space.
TEST( SortedDataInterface, GetSpaceUsedBytesNonEmpty ) {
- scoped_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
int nToInsert = 10;
for ( int i = 0; i < nToInsert; i++ ) {
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
BSONObj key = BSON( "" << i );
@@ -80,7 +78,7 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ // const std::unique_ptr<OperationContext> 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<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ // const std::unique_ptr<OperationContext> 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 <boost/scoped_ptr.hpp>
+#include <memory>
#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> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( true ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( true ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
ASSERT_OK( sorted->insert( opCtx.get(), key1, loc1, false ) );
@@ -73,12 +71,12 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT_EQUALS( 3, sorted->numEntries( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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 <boost/scoped_ptr.hpp>
+#include <memory>
#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> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
ASSERT_OK( sorted->insert( opCtx.get(), key1, loc1, true ) );
@@ -59,12 +57,12 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
sorted->unindex( opCtx.get(), key1, loc1, true );
@@ -74,23 +72,23 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
ASSERT_OK( sorted->insert( opCtx.get(), compoundKey1a, loc1, true ) );
@@ -99,12 +97,12 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
sorted->unindex( opCtx.get(), compoundKey1a, loc1, true );
@@ -114,23 +112,23 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
ASSERT_OK( sorted->insert( opCtx.get(), key1, loc1, true ) );
@@ -140,12 +138,12 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT_EQUALS( 2, sorted->numEntries( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
sorted->unindex( opCtx.get(), key2, loc2, true );
@@ -155,12 +153,12 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
ASSERT_OK( sorted->insert( opCtx.get(), key3, loc3, true ) );
@@ -169,12 +167,12 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT_EQUALS( 2, sorted->numEntries( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
sorted->unindex( opCtx.get(), key1, loc1, true );
@@ -186,23 +184,23 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
ASSERT_OK( sorted->insert( opCtx.get(), key1, loc1, true ) );
@@ -212,12 +210,12 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT_EQUALS( 2, sorted->numEntries( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
sorted->unindex( opCtx.get(), key1, loc2, true );
@@ -227,12 +225,12 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT_EQUALS( 2, sorted->numEntries( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
{
WriteUnitOfWork uow( opCtx.get() );
sorted->unindex( opCtx.get(), key1, loc1, true);
@@ -258,23 +256,23 @@ namespace mongo {
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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> harnessHelper( newHarnessHelper() );
- scoped_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
+ const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
+ const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
ASSERT( sorted->isEmpty( opCtx.get() ) );
}
{
- scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
+ const std::unique_ptr<OperationContext> 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<SortedDataInterface> 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<WiredTigerIndexUnique>( &txn, uri, &desc );
+ return stdx::make_unique<WiredTigerIndexStandard>( &txn, uri, &desc );
}
- virtual RecoveryUnit* newRecoveryUnit() {
- return new WiredTigerRecoveryUnit( _sessionCache );
+ std::unique_ptr<RecoveryUnit> newRecoveryUnit() final {
+ return stdx::make_unique<WiredTigerRecoveryUnit>( _sessionCache );
}
private:
@@ -96,8 +97,8 @@ namespace mongo {
WiredTigerSessionCache* _sessionCache;
};
- HarnessHelper* newHarnessHelper() {
- return new MyHarnessHelper();
+ std::unique_ptr<HarnessHelper> newHarnessHelper() {
+ return stdx::make_unique<MyHarnessHelper>();
}
TEST(WiredTigerIndexTest, GenerateCreateStringEmptyDocument) {