summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage/sorted_data_interface_test_harness.cpp
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/sorted_data_interface_test_harness.cpp
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/sorted_data_interface_test_harness.cpp')
-rw-r--r--src/mongo/db/storage/sorted_data_interface_test_harness.cpp47
1 files changed, 28 insertions, 19 deletions
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)));