summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage/sorted_data_interface_test_harness.cpp
diff options
context:
space:
mode:
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.cpp789
1 files changed, 389 insertions, 400 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 286c3038f8c..13929c7eacc 100644
--- a/src/mongo/db/storage/sorted_data_interface_test_harness.cpp
+++ b/src/mongo/db/storage/sorted_data_interface_test_harness.cpp
@@ -37,535 +37,524 @@
#include "mongo/unittest/unittest.h"
namespace mongo {
- std::unique_ptr<SortedDataInterface> HarnessHelper::newSortedDataInterface(
- bool unique,
- std::initializer_list<IndexKeyEntry> toInsert) {
- invariant(std::is_sorted(toInsert.begin(), toInsert.end(),
- IndexEntryComparison(Ordering::make(BSONObj()))));
-
- auto index = newSortedDataInterface(unique);
- insertToIndex(this, index, toInsert);
- return index;
- }
-
- void insertToIndex(unowned_ptr<OperationContext> txn,
- unowned_ptr<SortedDataInterface> index,
- std::initializer_list<IndexKeyEntry> toInsert) {
- WriteUnitOfWork wuow(txn);
- for (auto&& entry : toInsert) {
- ASSERT_OK(index->insert(txn, entry.key, entry.loc, true));
- }
- wuow.commit();
+std::unique_ptr<SortedDataInterface> HarnessHelper::newSortedDataInterface(
+ bool unique, std::initializer_list<IndexKeyEntry> toInsert) {
+ invariant(std::is_sorted(
+ toInsert.begin(), toInsert.end(), IndexEntryComparison(Ordering::make(BSONObj()))));
+
+ auto index = newSortedDataInterface(unique);
+ insertToIndex(this, index, toInsert);
+ return index;
+}
+
+void insertToIndex(unowned_ptr<OperationContext> txn,
+ unowned_ptr<SortedDataInterface> index,
+ std::initializer_list<IndexKeyEntry> toInsert) {
+ WriteUnitOfWork wuow(txn);
+ for (auto&& entry : toInsert) {
+ ASSERT_OK(index->insert(txn, entry.key, entry.loc, true));
}
-
- void removeFromIndex(unowned_ptr<OperationContext> txn,
- unowned_ptr<SortedDataInterface> index,
- std::initializer_list<IndexKeyEntry> toRemove) {
- WriteUnitOfWork wuow(txn);
- for (auto&& entry : toRemove) {
- index->unindex(txn, entry.key, entry.loc, true);
- }
- wuow.commit();
+ wuow.commit();
+}
+
+void removeFromIndex(unowned_ptr<OperationContext> txn,
+ unowned_ptr<SortedDataInterface> index,
+ std::initializer_list<IndexKeyEntry> toRemove) {
+ WriteUnitOfWork wuow(txn);
+ for (auto&& entry : toRemove) {
+ index->unindex(txn, entry.key, entry.loc, true);
}
+ wuow.commit();
+}
- TEST( SortedDataInterface, InsertWithDups1 ) {
- const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
- const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
+TEST(SortedDataInterface, InsertWithDups1) {
+ const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper());
+ const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false));
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- {
- WriteUnitOfWork uow( opCtx.get() );
- sorted->insert( opCtx.get(), BSON( "" << 1 ), RecordId( 5, 2 ), true );
- uow.commit();
- }
+ WriteUnitOfWork uow(opCtx.get());
+ sorted->insert(opCtx.get(), BSON("" << 1), RecordId(5, 2), true);
+ uow.commit();
}
+ }
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- {
- WriteUnitOfWork uow( opCtx.get() );
- sorted->insert( opCtx.get(), BSON( "" << 1 ), RecordId( 6, 2 ), true );
- uow.commit();
- }
+ WriteUnitOfWork uow(opCtx.get());
+ sorted->insert(opCtx.get(), BSON("" << 1), RecordId(6, 2), true);
+ uow.commit();
}
+ }
- {
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- ASSERT_EQUALS( 2, sorted->numEntries( opCtx.get() ) );
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
+ ASSERT_EQUALS(2, sorted->numEntries(opCtx.get()));
- long long x = 0;
- sorted->fullValidate(opCtx.get(), false, &x, NULL);
- ASSERT_EQUALS( 2, x );
- }
+ long long x = 0;
+ sorted->fullValidate(opCtx.get(), false, &x, NULL);
+ ASSERT_EQUALS(2, x);
}
+}
- TEST( SortedDataInterface, InsertWithDups2 ) {
- 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() );
- sorted->insert( opCtx.get(), BSON( "" << 1 ), RecordId( 5, 18 ), true );
- uow.commit();
- }
- }
+TEST(SortedDataInterface, InsertWithDups2) {
+ const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper());
+ const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false));
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- {
- WriteUnitOfWork uow( opCtx.get() );
- sorted->insert( opCtx.get(), BSON( "" << 1 ), RecordId( 5, 20 ), true );
- uow.commit();
- }
+ WriteUnitOfWork uow(opCtx.get());
+ sorted->insert(opCtx.get(), BSON("" << 1), RecordId(5, 18), true);
+ uow.commit();
}
+ }
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- ASSERT_EQUALS( 2, sorted->numEntries( opCtx.get() ) );
+ WriteUnitOfWork uow(opCtx.get());
+ sorted->insert(opCtx.get(), BSON("" << 1), RecordId(5, 20), true);
+ uow.commit();
}
}
- TEST( SortedDataInterface, InsertWithDups3AndRollback ) {
- const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
- const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
+ ASSERT_EQUALS(2, sorted->numEntries(opCtx.get()));
+ }
+}
- {
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- {
- WriteUnitOfWork uow( opCtx.get() );
- sorted->insert( opCtx.get(), BSON( "" << 1 ), RecordId( 5, 18 ), true );
- uow.commit();
- }
- }
+TEST(SortedDataInterface, InsertWithDups3AndRollback) {
+ const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper());
+ const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false));
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- {
- WriteUnitOfWork uow( opCtx.get() );
- sorted->insert( opCtx.get(), BSON( "" << 1 ), RecordId( 5, 20 ), true );
- // no commit
- }
+ WriteUnitOfWork uow(opCtx.get());
+ sorted->insert(opCtx.get(), BSON("" << 1), RecordId(5, 18), true);
+ uow.commit();
}
+ }
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) );
+ WriteUnitOfWork uow(opCtx.get());
+ sorted->insert(opCtx.get(), BSON("" << 1), RecordId(5, 20), true);
+ // no commit
}
}
- TEST( SortedDataInterface, InsertNoDups1 ) {
- const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
- const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( true ) );
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
+ ASSERT_EQUALS(1, sorted->numEntries(opCtx.get()));
+ }
+}
- {
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- {
- WriteUnitOfWork uow( opCtx.get() );
- sorted->insert( opCtx.get(), BSON( "" << 1 ), RecordId( 5, 18 ), false );
- uow.commit();
- }
- }
+TEST(SortedDataInterface, InsertNoDups1) {
+ const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper());
+ const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(true));
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- {
- WriteUnitOfWork uow( opCtx.get() );
- sorted->insert( opCtx.get(), BSON( "" << 2 ), RecordId( 5, 20 ), false );
- uow.commit();
- }
+ WriteUnitOfWork uow(opCtx.get());
+ sorted->insert(opCtx.get(), BSON("" << 1), RecordId(5, 18), false);
+ uow.commit();
}
+ }
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- ASSERT_EQUALS( 2, sorted->numEntries( opCtx.get() ) );
+ WriteUnitOfWork uow(opCtx.get());
+ sorted->insert(opCtx.get(), BSON("" << 2), RecordId(5, 20), false);
+ uow.commit();
}
-
}
- TEST( SortedDataInterface, InsertNoDups2 ) {
- const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
- const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( true ) );
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
+ ASSERT_EQUALS(2, sorted->numEntries(opCtx.get()));
+ }
+}
- {
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- {
- WriteUnitOfWork uow( opCtx.get() );
- sorted->insert( opCtx.get(), BSON( "" << 1 ), RecordId( 5, 2 ), false );
- uow.commit();
- }
- }
+TEST(SortedDataInterface, InsertNoDups2) {
+ const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper());
+ const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(true));
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- {
- WriteUnitOfWork uow( opCtx.get() );
- sorted->insert( opCtx.get(), BSON( "" << 1 ), RecordId( 5, 4 ), false );
- uow.commit();
- }
+ WriteUnitOfWork uow(opCtx.get());
+ sorted->insert(opCtx.get(), BSON("" << 1), RecordId(5, 2), false);
+ uow.commit();
}
+ }
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) );
+ WriteUnitOfWork uow(opCtx.get());
+ sorted->insert(opCtx.get(), BSON("" << 1), RecordId(5, 4), false);
+ uow.commit();
}
+ }
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
+ ASSERT_EQUALS(1, sorted->numEntries(opCtx.get()));
}
+}
- TEST( SortedDataInterface, Unindex1 ) {
- 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() );
- sorted->insert( opCtx.get(), BSON( "" << 1 ), RecordId( 5, 18 ), true );
- uow.commit();
- }
- }
+TEST(SortedDataInterface, Unindex1) {
+ const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper());
+ const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false));
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) );
+ WriteUnitOfWork uow(opCtx.get());
+ sorted->insert(opCtx.get(), BSON("" << 1), RecordId(5, 18), true);
+ uow.commit();
}
+ }
- {
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- {
- WriteUnitOfWork uow( opCtx.get() );
- sorted->unindex( opCtx.get(), BSON( "" << 1 ), RecordId( 5, 20 ), true );
- ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) );
- uow.commit();
- }
- }
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
+ ASSERT_EQUALS(1, sorted->numEntries(opCtx.get()));
+ }
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) );
+ WriteUnitOfWork uow(opCtx.get());
+ sorted->unindex(opCtx.get(), BSON("" << 1), RecordId(5, 20), true);
+ ASSERT_EQUALS(1, sorted->numEntries(opCtx.get()));
+ uow.commit();
}
+ }
- {
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- {
- WriteUnitOfWork uow( opCtx.get() );
- sorted->unindex( opCtx.get(), BSON( "" << 2 ), RecordId( 5, 18 ), true );
- ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) );
- uow.commit();
- }
- }
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
+ ASSERT_EQUALS(1, sorted->numEntries(opCtx.get()));
+ }
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) );
+ WriteUnitOfWork uow(opCtx.get());
+ sorted->unindex(opCtx.get(), BSON("" << 2), RecordId(5, 18), true);
+ ASSERT_EQUALS(1, sorted->numEntries(opCtx.get()));
+ uow.commit();
}
+ }
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
+ ASSERT_EQUALS(1, sorted->numEntries(opCtx.get()));
+ }
- {
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- {
- WriteUnitOfWork uow( opCtx.get() );
- sorted->unindex( opCtx.get(), BSON( "" << 1 ), RecordId( 5, 18 ), true );
- ASSERT( sorted->isEmpty( opCtx.get() ) );
- uow.commit();
- }
- }
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- ASSERT( sorted->isEmpty( opCtx.get() ) );
+ WriteUnitOfWork uow(opCtx.get());
+ sorted->unindex(opCtx.get(), BSON("" << 1), RecordId(5, 18), true);
+ ASSERT(sorted->isEmpty(opCtx.get()));
+ uow.commit();
}
+ }
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
+ ASSERT(sorted->isEmpty(opCtx.get()));
}
+}
- TEST( SortedDataInterface, Unindex2Rollback ) {
- 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() );
- sorted->insert( opCtx.get(), BSON( "" << 1 ), RecordId( 5, 18 ), true );
- uow.commit();
- }
- }
+TEST(SortedDataInterface, Unindex2Rollback) {
+ const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper());
+ const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false));
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) );
+ WriteUnitOfWork uow(opCtx.get());
+ sorted->insert(opCtx.get(), BSON("" << 1), RecordId(5, 18), true);
+ uow.commit();
}
+ }
- {
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- {
- WriteUnitOfWork uow( opCtx.get() );
- sorted->unindex( opCtx.get(), BSON( "" << 1 ), RecordId( 5, 18 ), true );
- ASSERT( sorted->isEmpty( opCtx.get() ) );
- // no commit
- }
- }
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
+ ASSERT_EQUALS(1, sorted->numEntries(opCtx.get()));
+ }
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- ASSERT_EQUALS( 1, sorted->numEntries( opCtx.get() ) );
+ WriteUnitOfWork uow(opCtx.get());
+ sorted->unindex(opCtx.get(), BSON("" << 1), RecordId(5, 18), true);
+ ASSERT(sorted->isEmpty(opCtx.get()));
+ // no commit
}
-
}
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
+ ASSERT_EQUALS(1, sorted->numEntries(opCtx.get()));
+ }
+}
- TEST( SortedDataInterface, CursorIterate1 ) {
- const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
- const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
- int N = 5;
- for ( int i = 0; i < N; i++ ) {
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- {
- WriteUnitOfWork uow( opCtx.get() );
- ASSERT_OK( sorted->insert( opCtx.get(), BSON( "" << i ), RecordId( 5, i * 2 ), true ) );
- uow.commit();
- }
- }
+TEST(SortedDataInterface, CursorIterate1) {
+ const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper());
+ const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false));
+ int N = 5;
+ for (int i = 0; i < N; i++) {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- const std::unique_ptr<SortedDataInterface::Cursor> cursor( sorted->newCursor(opCtx.get()) );
- int n = 0;
- for (auto entry = cursor->seek(BSONObj(), true); entry; entry = cursor->next()) {
- ASSERT_EQ(entry, IndexKeyEntry(BSON("" << n), RecordId(5, n * 2)));
- n++;
- }
- ASSERT_EQUALS( N, n );
+ WriteUnitOfWork uow(opCtx.get());
+ ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << i), RecordId(5, i * 2), true));
+ uow.commit();
}
-
-
}
- TEST( SortedDataInterface, CursorIterate1WithSaveRestore ) {
- const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
- const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
-
- int N = 5;
- for ( int i = 0; i < N; i++ ) {
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- {
- WriteUnitOfWork uow( opCtx.get() );
- sorted->insert( opCtx.get(), BSON( "" << i ), RecordId( 5, i * 2 ), true );
- uow.commit();
- }
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
+ const std::unique_ptr<SortedDataInterface::Cursor> cursor(sorted->newCursor(opCtx.get()));
+ int n = 0;
+ for (auto entry = cursor->seek(BSONObj(), true); entry; entry = cursor->next()) {
+ ASSERT_EQ(entry, IndexKeyEntry(BSON("" << n), RecordId(5, n * 2)));
+ n++;
}
+ ASSERT_EQUALS(N, n);
+ }
+}
+
+TEST(SortedDataInterface, CursorIterate1WithSaveRestore) {
+ const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper());
+ const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false));
+ int N = 5;
+ for (int i = 0; i < N; i++) {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- const std::unique_ptr<SortedDataInterface::Cursor> cursor( sorted->newCursor(opCtx.get()) );
- int n = 0;
- for (auto entry = cursor->seek(BSONObj(), true); entry; entry = cursor->next()) {
- ASSERT_EQ(entry, IndexKeyEntry(BSON("" << n), RecordId(5, n * 2)));
- n++;
- cursor->savePositioned();
- cursor->restore( opCtx.get() );
- }
- ASSERT_EQUALS( N, n );
+ WriteUnitOfWork uow(opCtx.get());
+ sorted->insert(opCtx.get(), BSON("" << i), RecordId(5, i * 2), true);
+ uow.commit();
}
-
}
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
+ const std::unique_ptr<SortedDataInterface::Cursor> cursor(sorted->newCursor(opCtx.get()));
+ int n = 0;
+ for (auto entry = cursor->seek(BSONObj(), true); entry; entry = cursor->next()) {
+ ASSERT_EQ(entry, IndexKeyEntry(BSON("" << n), RecordId(5, n * 2)));
+ n++;
+ cursor->savePositioned();
+ cursor->restore(opCtx.get());
+ }
+ ASSERT_EQUALS(N, n);
+ }
+}
- TEST( SortedDataInterface, CursorIterateAllDupKeysWithSaveRestore ) {
- const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
- const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
- int N = 5;
- for ( int i = 0; i < N; i++ ) {
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- {
- WriteUnitOfWork uow( opCtx.get() );
- sorted->insert( opCtx.get(), BSON( "" << 5 ), RecordId( 5, i * 2 ), true );
- uow.commit();
- }
- }
+TEST(SortedDataInterface, CursorIterateAllDupKeysWithSaveRestore) {
+ const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper());
+ const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false));
+ int N = 5;
+ for (int i = 0; i < N; i++) {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- const std::unique_ptr<SortedDataInterface::Cursor> cursor( sorted->newCursor(opCtx.get()) );
- int n = 0;
- for (auto entry = cursor->seek(BSONObj(), true); entry; entry = cursor->next()) {
- ASSERT_EQ(entry, IndexKeyEntry(BSON("" << 5), RecordId(5, n * 2)));
- n++;
- cursor->savePositioned();
- cursor->restore( opCtx.get() );
- }
- ASSERT_EQUALS( N, n );
+ WriteUnitOfWork uow(opCtx.get());
+ sorted->insert(opCtx.get(), BSON("" << 5), RecordId(5, i * 2), true);
+ uow.commit();
}
-
}
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
+ const std::unique_ptr<SortedDataInterface::Cursor> cursor(sorted->newCursor(opCtx.get()));
+ int n = 0;
+ for (auto entry = cursor->seek(BSONObj(), true); entry; entry = cursor->next()) {
+ ASSERT_EQ(entry, IndexKeyEntry(BSON("" << 5), RecordId(5, n * 2)));
+ n++;
+ cursor->savePositioned();
+ cursor->restore(opCtx.get());
+ }
+ ASSERT_EQUALS(N, n);
+ }
+}
- TEST( SortedDataInterface, Locate1 ) {
- const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
- const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
-
- BSONObj key = BSON( "" << 1 );
- RecordId loc( 5, 16 );
- {
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- const std::unique_ptr<SortedDataInterface::Cursor> cursor( sorted->newCursor(opCtx.get()) );
- ASSERT( !cursor->seek( key, true ) );
- }
+TEST(SortedDataInterface, Locate1) {
+ 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() );
- Status res = sorted->insert( opCtx.get(), key, loc, true );
- ASSERT_OK( res );
- uow.commit();
- }
- }
+ BSONObj key = BSON("" << 1);
+ RecordId loc(5, 16);
- {
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- const std::unique_ptr<SortedDataInterface::Cursor> cursor( sorted->newCursor(opCtx.get()) );
- ASSERT_EQ(cursor->seek(key, true), IndexKeyEntry(key, loc));
- }
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
+ const std::unique_ptr<SortedDataInterface::Cursor> cursor(sorted->newCursor(opCtx.get()));
+ ASSERT(!cursor->seek(key, true));
}
- TEST( SortedDataInterface, Locate2 ) {
- 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( "" << 2 ), RecordId(1,4), true ) );
- ASSERT_OK( sorted->insert( opCtx.get(), BSON( "" << 3 ), RecordId(1,6), true ) );
- uow.commit();
- }
- }
-
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- const std::unique_ptr<SortedDataInterface::Cursor> cursor( sorted->newCursor(opCtx.get()) );
- ASSERT_EQ(cursor->seek(BSON("a" << 2), true),
- IndexKeyEntry(BSON("" << 2), RecordId(1, 4)));
-
- ASSERT_EQ(cursor->next(), IndexKeyEntry(BSON("" << 3), RecordId(1, 6)));
- ASSERT_EQ(cursor->next(), boost::none);
+ WriteUnitOfWork uow(opCtx.get());
+ Status res = sorted->insert(opCtx.get(), key, loc, true);
+ ASSERT_OK(res);
+ uow.commit();
}
}
- TEST( SortedDataInterface, Locate2Empty ) {
- const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
- const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
+ const std::unique_ptr<SortedDataInterface::Cursor> cursor(sorted->newCursor(opCtx.get()));
+ ASSERT_EQ(cursor->seek(key, true), IndexKeyEntry(key, loc));
+ }
+}
- {
- 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( "" << 2 ), RecordId(1,4), true ) );
- ASSERT_OK( sorted->insert( opCtx.get(), BSON( "" << 3 ), RecordId(1,6), true ) );
- uow.commit();
- }
- }
+TEST(SortedDataInterface, Locate2) {
+ const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper());
+ const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false));
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- const std::unique_ptr<SortedDataInterface::Cursor> cursor( sorted->newCursor(opCtx.get()) );
- ASSERT_EQ(cursor->seek(BSONObj(), true), IndexKeyEntry(BSON("" << 1), RecordId(1, 2)));
- }
+ WriteUnitOfWork uow(opCtx.get());
- {
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- const std::unique_ptr<SortedDataInterface::Cursor> cursor( sorted->newCursor(opCtx.get(), false) );
- ASSERT_EQ(cursor->seek(BSONObj(), false), boost::none);
+ ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 1), RecordId(1, 2), true));
+ ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 2), RecordId(1, 4), true));
+ ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 3), RecordId(1, 6), true));
+ uow.commit();
}
-
}
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
+ const std::unique_ptr<SortedDataInterface::Cursor> cursor(sorted->newCursor(opCtx.get()));
+ ASSERT_EQ(cursor->seek(BSON("a" << 2), true), IndexKeyEntry(BSON("" << 2), RecordId(1, 4)));
- TEST( SortedDataInterface, Locate3Descending ) {
- const std::unique_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
- const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface( false ) );
+ ASSERT_EQ(cursor->next(), IndexKeyEntry(BSON("" << 3), RecordId(1, 6)));
+ ASSERT_EQ(cursor->next(), boost::none);
+ }
+}
- auto buildEntry = [](int i) { return IndexKeyEntry(BSON("" << i), RecordId(1, i*2)); };
+TEST(SortedDataInterface, Locate2Empty) {
+ const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper());
+ const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false));
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
{
- const std::unique_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
- for ( int i = 0; i < 10; i++ ) {
- if ( i == 6 )
- continue;
- WriteUnitOfWork uow( opCtx.get() );
- auto entry = buildEntry(i);
- ASSERT_OK( sorted->insert( opCtx.get(), entry.key, entry.loc, true ) );
- uow.commit();
- }
+ WriteUnitOfWork uow(opCtx.get());
+
+ ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 1), RecordId(1, 2), true));
+ ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 2), RecordId(1, 4), true));
+ ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 3), RecordId(1, 6), true));
+ uow.commit();
}
+ }
+ {
const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
- std::unique_ptr<SortedDataInterface::Cursor> cursor(sorted->newCursor(opCtx.get(), true));
- ASSERT_EQ(cursor->seek(BSON("" << 5), true), buildEntry(5));
- ASSERT_EQ(cursor->next(), buildEntry(7));
+ const std::unique_ptr<SortedDataInterface::Cursor> cursor(sorted->newCursor(opCtx.get()));
+ ASSERT_EQ(cursor->seek(BSONObj(), true), IndexKeyEntry(BSON("" << 1), RecordId(1, 2)));
+ }
- cursor = sorted->newCursor(opCtx.get(), /*forward*/false);
- ASSERT_EQ(cursor->seek(BSON("" << 5), /*inclusive*/false), buildEntry(4));
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
+ const std::unique_ptr<SortedDataInterface::Cursor> cursor(
+ sorted->newCursor(opCtx.get(), false));
+ ASSERT_EQ(cursor->seek(BSONObj(), false), boost::none);
+ }
+}
- cursor = sorted->newCursor(opCtx.get(), /*forward*/false);
- ASSERT_EQ(cursor->seek(BSON("" << 5), /*inclusive*/true), buildEntry(5));
- ASSERT_EQ(cursor->next(), buildEntry(4));
- cursor = sorted->newCursor(opCtx.get(), /*forward*/false);
- ASSERT_EQ(cursor->seek(BSON("" << 5), /*inclusive*/false), buildEntry(4));
- ASSERT_EQ(cursor->next(), buildEntry(3));
+TEST(SortedDataInterface, Locate3Descending) {
+ const std::unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper());
+ const std::unique_ptr<SortedDataInterface> sorted(harnessHelper->newSortedDataInterface(false));
- cursor = sorted->newCursor(opCtx.get(), /*forward*/false);
- ASSERT_EQ(cursor->seek(BSON("" << 6), /*inclusive*/true), buildEntry(5));
- ASSERT_EQ(cursor->next(), buildEntry(4));
+ auto buildEntry = [](int i) { return IndexKeyEntry(BSON("" << i), RecordId(1, i * 2)); };
- cursor = sorted->newCursor(opCtx.get(), /*forward*/false);
- ASSERT_EQ(cursor->seek(BSON("" << 500), /*inclusive*/true), buildEntry(9));
- ASSERT_EQ(cursor->next(), buildEntry(8));
+ {
+ const std::unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
+ for (int i = 0; i < 10; i++) {
+ if (i == 6)
+ continue;
+ WriteUnitOfWork uow(opCtx.get());
+ auto entry = buildEntry(i);
+ ASSERT_OK(sorted->insert(opCtx.get(), entry.key, entry.loc, true));
+ uow.commit();
+ }
}
- TEST( SortedDataInterface, Locate4 ) {
- 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());
+ std::unique_ptr<SortedDataInterface::Cursor> cursor(sorted->newCursor(opCtx.get(), true));
+ ASSERT_EQ(cursor->seek(BSON("" << 5), true), buildEntry(5));
+ ASSERT_EQ(cursor->next(), buildEntry(7));
+
+ cursor = sorted->newCursor(opCtx.get(), /*forward*/ false);
+ ASSERT_EQ(cursor->seek(BSON("" << 5), /*inclusive*/ false), buildEntry(4));
+
+ cursor = sorted->newCursor(opCtx.get(), /*forward*/ false);
+ ASSERT_EQ(cursor->seek(BSON("" << 5), /*inclusive*/ true), buildEntry(5));
+ ASSERT_EQ(cursor->next(), buildEntry(4));
+
+ cursor = sorted->newCursor(opCtx.get(), /*forward*/ false);
+ ASSERT_EQ(cursor->seek(BSON("" << 5), /*inclusive*/ false), buildEntry(4));
+ ASSERT_EQ(cursor->next(), buildEntry(3));
+
+ cursor = sorted->newCursor(opCtx.get(), /*forward*/ false);
+ ASSERT_EQ(cursor->seek(BSON("" << 6), /*inclusive*/ true), buildEntry(5));
+ ASSERT_EQ(cursor->next(), buildEntry(4));
+
+ cursor = sorted->newCursor(opCtx.get(), /*forward*/ false);
+ ASSERT_EQ(cursor->seek(BSON("" << 500), /*inclusive*/ true), buildEntry(9));
+ ASSERT_EQ(cursor->next(), buildEntry(8));
+}
+
+TEST(SortedDataInterface, Locate4) {
+ 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)},
+ });
+
+ {
+ auto opCtx = harnessHelper->newOperationContext();
+ auto cursor = sorted->newCursor(opCtx.get());
+ ASSERT_EQ(cursor->seek(BSON("a" << 1), true), IndexKeyEntry(BSON("" << 1), RecordId(1, 2)));
+
+ ASSERT_EQ(cursor->next(), IndexKeyEntry(BSON("" << 1), RecordId(1, 4)));
+ ASSERT_EQ(cursor->next(), IndexKeyEntry(BSON("" << 1), RecordId(1, 6)));
+ ASSERT_EQ(cursor->next(), IndexKeyEntry(BSON("" << 2), RecordId(1, 8)));
+ ASSERT_EQ(cursor->next(), boost::none);
+ }
- {
- auto opCtx = harnessHelper->newOperationContext();
- auto cursor = sorted->newCursor(opCtx.get());
- ASSERT_EQ(cursor->seek(BSON("a" << 1), true),
- IndexKeyEntry(BSON("" << 1), RecordId(1, 2)));
-
- ASSERT_EQ(cursor->next(), IndexKeyEntry(BSON("" << 1), RecordId(1, 4)));
- ASSERT_EQ(cursor->next(), IndexKeyEntry(BSON("" << 1), RecordId(1, 6)));
- ASSERT_EQ(cursor->next(), IndexKeyEntry(BSON("" << 2), RecordId(1, 8)));
- ASSERT_EQ(cursor->next(), boost::none);
- }
+ {
+ 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)));
- {
- 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)));
-
- ASSERT_EQ(cursor->next(), IndexKeyEntry(BSON("" << 1), RecordId(1, 4)));
- ASSERT_EQ(cursor->next(), IndexKeyEntry(BSON("" << 1), RecordId(1, 2)));
- ASSERT_EQ(cursor->next(), boost::none);
- }
+ ASSERT_EQ(cursor->next(), IndexKeyEntry(BSON("" << 1), RecordId(1, 4)));
+ ASSERT_EQ(cursor->next(), IndexKeyEntry(BSON("" << 1), RecordId(1, 2)));
+ ASSERT_EQ(cursor->next(), boost::none);
}
+}
-} // namespace mongo
+} // namespace mongo