diff options
author | Xiangyu Yao <xiangyu.yao@mongodb.com> | 2019-08-29 05:15:39 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-08-29 05:15:39 +0000 |
commit | ffd486c3ff049abc9f8a2c76b3e2b9dea970c19b (patch) | |
tree | 8e030dff77ff90c04aad143e14d1e2d924a92dcb /src/mongo/db/storage/sorted_data_interface_test_cursor_end_position.cpp | |
parent | 98413549db019381b09c85299cee53c31e284f17 (diff) | |
download | mongo-ffd486c3ff049abc9f8a2c76b3e2b9dea970c19b.tar.gz |
SERVER-42248 Remove SortedDataInterface::seek() which accepts a BSONObj
Diffstat (limited to 'src/mongo/db/storage/sorted_data_interface_test_cursor_end_position.cpp')
-rw-r--r-- | src/mongo/db/storage/sorted_data_interface_test_cursor_end_position.cpp | 61 |
1 files changed, 37 insertions, 24 deletions
diff --git a/src/mongo/db/storage/sorted_data_interface_test_cursor_end_position.cpp b/src/mongo/db/storage/sorted_data_interface_test_cursor_end_position.cpp index 20aba3337b3..129657e4912 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_cursor_end_position.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_cursor_end_position.cpp @@ -57,7 +57,8 @@ void testSetEndPosition_Next_Forward(bool unique, bool inclusive) { auto cursor = sorted->newCursor(opCtx.get()); cursor->setEndPosition(key3, inclusive); - ASSERT_EQ(cursor->seek(key1, true), IndexKeyEntry(key1, loc1)); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key1, true, true)), + IndexKeyEntry(key1, loc1)); ASSERT_EQ(cursor->next(), IndexKeyEntry(key2, loc1)); if (inclusive) { ASSERT_EQ(cursor->next(), IndexKeyEntry(key3, loc1)); @@ -100,7 +101,8 @@ void testSetEndPosition_Next_Reverse(bool unique, bool inclusive) { auto cursor = sorted->newCursor(opCtx.get(), false); cursor->setEndPosition(key3, inclusive); - ASSERT_EQ(cursor->seek(key5, true), IndexKeyEntry(key5, loc1)); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key5, false, true)), + IndexKeyEntry(key5, loc1)); ASSERT_EQ(cursor->next(), IndexKeyEntry(key4, loc1)); if (inclusive) { if (!unique) @@ -140,25 +142,25 @@ void testSetEndPosition_Seek_Forward(bool unique, bool inclusive) { cursor->setEndPosition(key3, inclusive); // Directly seeking past end is considered out of range. - ASSERT_EQ(cursor->seek(key4, true), boost::none); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key4, true, true)), boost::none); ASSERT_EQ(cursor->seekExact(key4), boost::none); // Seeking to key3 directly or indirectly is only returned if endPosition is inclusive. auto maybeKey3 = inclusive ? boost::make_optional(IndexKeyEntry(key3, loc1)) : boost::none; // direct - ASSERT_EQ(cursor->seek(key3, true), maybeKey3); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key3, true, true)), maybeKey3); ASSERT_EQ(cursor->seekExact(key3), maybeKey3); // indirect - ASSERT_EQ(cursor->seek(key2, true), maybeKey3); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key2, true, true)), maybeKey3); cursor->saveUnpositioned(); removeFromIndex(opCtx, sorted, {{key3, loc1}}); cursor->restore(); - ASSERT_EQ(cursor->seek(key2, true), boost::none); - ASSERT_EQ(cursor->seek(key3, true), boost::none); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key2, true, true)), boost::none); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key3, true, true)), boost::none); } TEST(SortedDataInterface, SetEndPosition_Seek_Forward_Unique_Inclusive) { testSetEndPosition_Seek_Forward(true, true); @@ -189,25 +191,25 @@ void testSetEndPosition_Seek_Reverse(bool unique, bool inclusive) { cursor->setEndPosition(key2, inclusive); // Directly seeking past end is considered out of range. - ASSERT_EQ(cursor->seek(key1, true), boost::none); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key1, false, true)), boost::none); ASSERT_EQ(cursor->seekExact(key1), boost::none); // Seeking to key2 directly or indirectly is only returned if endPosition is inclusive. auto maybeKey2 = inclusive ? boost::make_optional(IndexKeyEntry(key2, loc1)) : boost::none; // direct - ASSERT_EQ(cursor->seek(key2, true), maybeKey2); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key2, false, true)), maybeKey2); ASSERT_EQ(cursor->seekExact(key2), maybeKey2); // indirect - ASSERT_EQ(cursor->seek(key3, true), maybeKey2); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key3, false, true)), maybeKey2); cursor->saveUnpositioned(); removeFromIndex(opCtx, sorted, {{key2, loc1}}); cursor->restore(); - ASSERT_EQ(cursor->seek(key3, true), boost::none); - ASSERT_EQ(cursor->seek(key2, true), boost::none); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key3, false, true)), boost::none); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key2, false, true)), boost::none); } TEST(SortedDataInterface, SetEndPosition_Seek_Reverse_Unique_Inclusive) { testSetEndPosition_Seek_Reverse(true, true); @@ -238,7 +240,8 @@ void testSetEndPosition_Restore_Forward(bool unique) { auto cursor = sorted->newCursor(opCtx.get()); cursor->setEndPosition(key3, false); // Should never see key3 or key4. - ASSERT_EQ(cursor->seek(key1, true), IndexKeyEntry(key1, loc1)); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key1, true, true)), + IndexKeyEntry(key1, loc1)); cursor->save(); cursor->restore(); @@ -278,7 +281,8 @@ void testSetEndPosition_Restore_Reverse(bool unique) { auto cursor = sorted->newCursor(opCtx.get(), false); cursor->setEndPosition(key2, false); // Should never see key1 or key2. - ASSERT_EQ(cursor->seek(key4, true), IndexKeyEntry(key4, loc1)); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key4, false, true)), + IndexKeyEntry(key4, loc1)); cursor->save(); cursor->restore(); @@ -321,7 +325,8 @@ void testSetEndPosition_RestoreEndCursor_Forward(bool unique) { auto cursor = sorted->newCursor(opCtx.get()); cursor->setEndPosition(key2, true); - ASSERT_EQ(cursor->seek(key1, true), IndexKeyEntry(key1, loc1)); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key1, true, true)), + IndexKeyEntry(key1, loc1)); // A potential source of bugs is not restoring end cursor with saveUnpositioned(). cursor->saveUnpositioned(); @@ -333,7 +338,8 @@ void testSetEndPosition_RestoreEndCursor_Forward(bool unique) { }); cursor->restore(); - ASSERT_EQ(cursor->seek(key1, true), IndexKeyEntry(key1, loc1)); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key1, true, true)), + IndexKeyEntry(key1, loc1)); ASSERT_EQ(cursor->next(), IndexKeyEntry(key2, loc1)); ASSERT_EQ(cursor->next(), boost::none); } @@ -357,7 +363,8 @@ void testSetEndPosition_RestoreEndCursor_Reverse(bool unique) { auto cursor = sorted->newCursor(opCtx.get(), false); cursor->setEndPosition(key3, true); - ASSERT_EQ(cursor->seek(key4, true), IndexKeyEntry(key4, loc1)); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key4, false, true)), + IndexKeyEntry(key4, loc1)); cursor->saveUnpositioned(); insertToIndex(opCtx, @@ -368,7 +375,8 @@ void testSetEndPosition_RestoreEndCursor_Reverse(bool unique) { }); cursor->restore(); // must restore end cursor even with saveUnpositioned(). - ASSERT_EQ(cursor->seek(key4, true), IndexKeyEntry(key4, loc1)); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key4, false, true)), + IndexKeyEntry(key4, loc1)); ASSERT_EQ(cursor->next(), IndexKeyEntry(key3, loc1)); ASSERT_EQ(cursor->next(), boost::none); } @@ -395,7 +403,8 @@ void testSetEndPosition_Empty_Forward(bool unique, bool inclusive) { auto cursor = sorted->newCursor(opCtx.get()); cursor->setEndPosition(BSONObj(), inclusive); - ASSERT_EQ(cursor->seek(key1, true), IndexKeyEntry(key1, loc1)); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key1, true, true)), + IndexKeyEntry(key1, loc1)); ASSERT_EQ(cursor->next(), IndexKeyEntry(key2, loc1)); ASSERT_EQ(cursor->next(), IndexKeyEntry(key3, loc1)); ASSERT_EQ(cursor->next(), boost::none); @@ -427,7 +436,8 @@ void testSetEndPosition_Empty_Reverse(bool unique, bool inclusive) { auto cursor = sorted->newCursor(opCtx.get(), false); cursor->setEndPosition(BSONObj(), inclusive); - ASSERT_EQ(cursor->seek(key3, true), IndexKeyEntry(key3, loc1)); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key3, false, true)), + IndexKeyEntry(key3, loc1)); ASSERT_EQ(cursor->next(), IndexKeyEntry(key2, loc1)); ASSERT_EQ(cursor->next(), IndexKeyEntry(key1, loc1)); ASSERT_EQ(cursor->next(), boost::none); @@ -455,21 +465,24 @@ void testSetEndPosition_Character_Limits(bool unique, bool inclusive) { cursor->setEndPosition(key7, inclusive); if (inclusive) { - ASSERT_EQ(cursor->seek(key7, true), IndexKeyEntry(key7, loc1)); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key7, true, true)), + IndexKeyEntry(key7, loc1)); ASSERT_EQ(cursor->next(), boost::none); } else { - ASSERT_EQ(cursor->seek(key7, true), boost::none); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key7, true, true)), boost::none); } cursor = sorted->newCursor(opCtx.get()); cursor->setEndPosition(key8, inclusive); if (inclusive) { - ASSERT_EQ(cursor->seek(key7, true), IndexKeyEntry(key7, loc1)); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key7, true, true)), + IndexKeyEntry(key7, loc1)); ASSERT_EQ(cursor->next(), IndexKeyEntry(key8, loc1)); ASSERT_EQ(cursor->next(), boost::none); } else { - ASSERT_EQ(cursor->seek(key7, true), IndexKeyEntry(key7, loc1)); + ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key7, true, true)), + IndexKeyEntry(key7, loc1)); ASSERT_EQ(cursor->next(), boost::none); } } |