diff options
author | David Hatch <david.hatch@mongodb.com> | 2016-07-08 17:16:15 -0400 |
---|---|---|
committer | David Hatch <david.hatch@mongodb.com> | 2016-07-28 22:33:08 -0400 |
commit | 13448cde4947adb5c935bb034187480365cf692f (patch) | |
tree | 2cf01918467d33755976588fac7dedb530530c7a /src/mongo/db/repl/storage_interface_impl_test.cpp | |
parent | 3a9e531cd088b6c10bec4b1d9d6ea49b3db8ce7a (diff) | |
download | mongo-13448cde4947adb5c935bb034187480365cf692f.tar.gz |
SERVER-24239 Allow creation of indexes with the same key pattern.
Diffstat (limited to 'src/mongo/db/repl/storage_interface_impl_test.cpp')
-rw-r--r-- | src/mongo/db/repl/storage_interface_impl_test.cpp | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/src/mongo/db/repl/storage_interface_impl_test.cpp b/src/mongo/db/repl/storage_interface_impl_test.cpp index 43da79635cb..8c56cfc5fad 100644 --- a/src/mongo/db/repl/storage_interface_impl_test.cpp +++ b/src/mongo/db/repl/storage_interface_impl_test.cpp @@ -28,6 +28,7 @@ #include "mongo/platform/basic.h" +#include <boost/optional.hpp> #include <memory> #include "mongo/bson/bsonmisc.h" @@ -549,19 +550,19 @@ TEST_F(StorageInterfaceImplWithReplCoordTest, FindOneReturnsInvalidNamespaceIfCo auto txn = getOperationContext(); StorageInterfaceImpl storage; auto nss = makeNamespace(_agent); - auto keyPattern = BSON("_id" << 1); + auto indexName = "_id_"_sd; ASSERT_EQUALS(ErrorCodes::NamespaceNotFound, - storage.findOne(txn, nss, keyPattern, StorageInterface::ScanDirection::kForward)); + storage.findOne(txn, nss, indexName, StorageInterface::ScanDirection::kForward)); } TEST_F(StorageInterfaceImplWithReplCoordTest, FindOneReturnsIndexNotFoundIfIndexIsMissing) { auto txn = getOperationContext(); StorageInterfaceImpl storage; auto nss = makeNamespace(_agent); - auto keyPattern = BSON("x" << 1); + auto indexName = "nonexistent"_sd; ASSERT_OK(storage.createCollection(txn, nss, CollectionOptions())); ASSERT_EQUALS(ErrorCodes::IndexNotFound, - storage.findOne(txn, nss, keyPattern, StorageInterface::ScanDirection::kForward)); + storage.findOne(txn, nss, indexName, StorageInterface::ScanDirection::kForward)); } TEST_F(StorageInterfaceImplWithReplCoordTest, @@ -581,19 +582,19 @@ TEST_F(StorageInterfaceImplWithReplCoordTest, std::vector<BSONObj> docs = {BSON("_id" << 1), BSON("_id" << 1), BSON("_id" << 2)}; ASSERT_OK(loader->insertDocuments(docs.begin(), docs.end())); ASSERT_OK(loader->commit()); - auto keyPattern = BSON("x" << 1); + auto indexName = "x_1"_sd; ASSERT_EQUALS(ErrorCodes::IndexOptionsConflict, - storage.findOne(txn, nss, keyPattern, StorageInterface::ScanDirection::kForward)); + storage.findOne(txn, nss, indexName, StorageInterface::ScanDirection::kForward)); } TEST_F(StorageInterfaceImplWithReplCoordTest, FindOneReturnsCollectionIsEmptyIfCollectionIsEmpty) { auto txn = getOperationContext(); StorageInterfaceImpl storage; auto nss = makeNamespace(_agent); - auto keyPattern = BSON("_id" << 1); + auto indexName = "_id_"_sd; ASSERT_OK(storage.createCollection(txn, nss, CollectionOptions())); ASSERT_EQUALS(ErrorCodes::CollectionIsEmpty, - storage.findOne(txn, nss, keyPattern, StorageInterface::ScanDirection::kForward)); + storage.findOne(txn, nss, indexName, StorageInterface::ScanDirection::kForward)); } TEST_F(StorageInterfaceImplWithReplCoordTest, @@ -601,12 +602,12 @@ TEST_F(StorageInterfaceImplWithReplCoordTest, auto txn = getOperationContext(); StorageInterfaceImpl storage; auto nss = makeNamespace(_agent); - auto keyPattern = BSON("_id" << 1); + auto indexName = "_id_"_sd; ASSERT_OK(storage.createCollection(txn, nss, CollectionOptions())); ASSERT_OK( storage.insertDocuments(txn, nss, {BSON("_id" << 0), BSON("_id" << 1), BSON("_id" << 2)})); ASSERT_EQUALS(BSON("_id" << 0), - storage.findOne(txn, nss, keyPattern, StorageInterface::ScanDirection::kForward)); + storage.findOne(txn, nss, indexName, StorageInterface::ScanDirection::kForward)); // Check collection contents. OplogInterface returns documents in reverse natural order. OplogInterfaceLocal oplog(txn, nss.ns()); @@ -622,13 +623,12 @@ TEST_F(StorageInterfaceImplWithReplCoordTest, auto txn = getOperationContext(); StorageInterfaceImpl storage; auto nss = makeNamespace(_agent); - auto keyPattern = BSON("_id" << 1); + auto indexName = "_id_"_sd; ASSERT_OK(storage.createCollection(txn, nss, CollectionOptions())); ASSERT_OK( storage.insertDocuments(txn, nss, {BSON("_id" << 0), BSON("_id" << 1), BSON("_id" << 2)})); - ASSERT_EQUALS( - BSON("_id" << 2), - storage.findOne(txn, nss, keyPattern, StorageInterface::ScanDirection::kBackward)); + ASSERT_EQUALS(BSON("_id" << 2), + storage.findOne(txn, nss, indexName, StorageInterface::ScanDirection::kBackward)); // Check collection contents. OplogInterface returns documents in reverse natural order. OplogInterfaceLocal oplog(txn, nss.ns()); @@ -647,8 +647,9 @@ TEST_F(StorageInterfaceImplWithReplCoordTest, ASSERT_OK(storage.createCollection(txn, nss, CollectionOptions())); ASSERT_OK( storage.insertDocuments(txn, nss, {BSON("_id" << 1), BSON("_id" << 2), BSON("_id" << 0)})); - ASSERT_EQUALS(BSON("_id" << 1), - storage.findOne(txn, nss, BSONObj(), StorageInterface::ScanDirection::kForward)); + ASSERT_EQUALS( + BSON("_id" << 1), + storage.findOne(txn, nss, boost::none, StorageInterface::ScanDirection::kForward)); // Check collection contents. OplogInterface returns documents in reverse natural order. OplogInterfaceLocal oplog(txn, nss.ns()); @@ -667,8 +668,9 @@ TEST_F(StorageInterfaceImplWithReplCoordTest, ASSERT_OK(storage.createCollection(txn, nss, CollectionOptions())); ASSERT_OK( storage.insertDocuments(txn, nss, {BSON("_id" << 1), BSON("_id" << 2), BSON("_id" << 0)})); - ASSERT_EQUALS(BSON("_id" << 0), - storage.findOne(txn, nss, BSONObj(), StorageInterface::ScanDirection::kBackward)); + ASSERT_EQUALS( + BSON("_id" << 0), + storage.findOne(txn, nss, boost::none, StorageInterface::ScanDirection::kBackward)); // Check collection contents. OplogInterface returns documents in reverse natural order. OplogInterfaceLocal oplog(txn, nss.ns()); @@ -684,21 +686,21 @@ TEST_F(StorageInterfaceImplWithReplCoordTest, auto txn = getOperationContext(); StorageInterfaceImpl storage; auto nss = makeNamespace(_agent); - auto keyPattern = BSON("_id" << 1); + auto indexName = "_id_"_sd; ASSERT_EQUALS( ErrorCodes::NamespaceNotFound, - storage.deleteOne(txn, nss, keyPattern, StorageInterface::ScanDirection::kForward)); + storage.deleteOne(txn, nss, indexName, StorageInterface::ScanDirection::kForward)); } TEST_F(StorageInterfaceImplWithReplCoordTest, DeleteOneReturnsIndexNotFoundIfIndexIsMissing) { auto txn = getOperationContext(); StorageInterfaceImpl storage; auto nss = makeNamespace(_agent); - auto keyPattern = BSON("x" << 1); + auto indexName = "nonexistent"_sd; ASSERT_OK(storage.createCollection(txn, nss, CollectionOptions())); ASSERT_EQUALS( ErrorCodes::IndexNotFound, - storage.deleteOne(txn, nss, keyPattern, StorageInterface::ScanDirection::kForward)); + storage.deleteOne(txn, nss, indexName, StorageInterface::ScanDirection::kForward)); } TEST_F(StorageInterfaceImplWithReplCoordTest, @@ -706,11 +708,11 @@ TEST_F(StorageInterfaceImplWithReplCoordTest, auto txn = getOperationContext(); StorageInterfaceImpl storage; auto nss = makeNamespace(_agent); - auto keyPattern = BSON("_id" << 1); + auto indexName = "_id_"_sd; ASSERT_OK(storage.createCollection(txn, nss, CollectionOptions())); ASSERT_EQUALS( ErrorCodes::CollectionIsEmpty, - storage.deleteOne(txn, nss, keyPattern, StorageInterface::ScanDirection::kForward)); + storage.deleteOne(txn, nss, indexName, StorageInterface::ScanDirection::kForward)); } TEST_F(StorageInterfaceImplWithReplCoordTest, @@ -718,13 +720,13 @@ TEST_F(StorageInterfaceImplWithReplCoordTest, auto txn = getOperationContext(); StorageInterfaceImpl storage; auto nss = makeNamespace(_agent); - auto keyPattern = BSON("_id" << 1); + auto indexName = "_id_"_sd; ASSERT_OK(storage.createCollection(txn, nss, CollectionOptions())); ASSERT_OK( storage.insertDocuments(txn, nss, {BSON("_id" << 0), BSON("_id" << 1), BSON("_id" << 2)})); ASSERT_EQUALS( BSON("_id" << 0), - storage.deleteOne(txn, nss, keyPattern, StorageInterface::ScanDirection::kForward)); + storage.deleteOne(txn, nss, indexName, StorageInterface::ScanDirection::kForward)); // Check collection contents. OplogInterface returns documents in reverse natural order. OplogInterfaceLocal oplog(txn, nss.ns()); @@ -739,13 +741,13 @@ TEST_F(StorageInterfaceImplWithReplCoordTest, auto txn = getOperationContext(); StorageInterfaceImpl storage; auto nss = makeNamespace(_agent); - auto keyPattern = BSON("_id" << 1); + auto indexName = "_id_"_sd; ASSERT_OK(storage.createCollection(txn, nss, CollectionOptions())); ASSERT_OK( storage.insertDocuments(txn, nss, {BSON("_id" << 0), BSON("_id" << 1), BSON("_id" << 2)})); ASSERT_EQUALS( BSON("_id" << 2), - storage.deleteOne(txn, nss, keyPattern, StorageInterface::ScanDirection::kBackward)); + storage.deleteOne(txn, nss, indexName, StorageInterface::ScanDirection::kBackward)); // Check collection contents. OplogInterface returns documents in reverse natural order. OplogInterfaceLocal oplog(txn, nss.ns()); @@ -765,7 +767,7 @@ TEST_F(StorageInterfaceImplWithReplCoordTest, storage.insertDocuments(txn, nss, {BSON("_id" << 1), BSON("_id" << 2), BSON("_id" << 0)})); ASSERT_EQUALS( BSON("_id" << 1), - storage.deleteOne(txn, nss, BSONObj(), StorageInterface::ScanDirection::kForward)); + storage.deleteOne(txn, nss, boost::none, StorageInterface::ScanDirection::kForward)); // Check collection contents. OplogInterface returns documents in reverse natural order. OplogInterfaceLocal oplog(txn, nss.ns()); @@ -785,7 +787,7 @@ TEST_F(StorageInterfaceImplWithReplCoordTest, storage.insertDocuments(txn, nss, {BSON("_id" << 1), BSON("_id" << 2), BSON("_id" << 0)})); ASSERT_EQUALS( BSON("_id" << 0), - storage.deleteOne(txn, nss, BSONObj(), StorageInterface::ScanDirection::kBackward)); + storage.deleteOne(txn, nss, boost::none, StorageInterface::ScanDirection::kBackward)); // Check collection contents. OplogInterface returns documents in reverse natural order. OplogInterfaceLocal oplog(txn, nss.ns()); |