diff options
author | Spencer T Brody <spencer@mongodb.com> | 2016-06-21 18:26:43 -0400 |
---|---|---|
committer | Spencer T Brody <spencer@mongodb.com> | 2016-06-28 13:33:15 -0400 |
commit | a0351d0713a20f50d9084f98b4df0de11cfabe23 (patch) | |
tree | 1fea9e3f382b1d9878a36b44d48a0e40258c3369 /src/mongo/s/client/shard_local_test.cpp | |
parent | 99933bb71bd26684f08ac07ff3844df878bee01a (diff) | |
download | mongo-a0351d0713a20f50d9084f98b4df0de11cfabe23.tar.gz |
SERVER-23096 Move initialization of config.version and the config db indexes to the config server
Diffstat (limited to 'src/mongo/s/client/shard_local_test.cpp')
-rw-r--r-- | src/mongo/s/client/shard_local_test.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/mongo/s/client/shard_local_test.cpp b/src/mongo/s/client/shard_local_test.cpp index b334b7a95bb..b79fef28600 100644 --- a/src/mongo/s/client/shard_local_test.cpp +++ b/src/mongo/s/client/shard_local_test.cpp @@ -34,6 +34,7 @@ #include "mongo/db/catalog/database_holder.h" #include "mongo/db/client.h" #include "mongo/db/db_raii.h" +#include "mongo/db/query/cursor_response.h" #include "mongo/db/query/find_and_modify_request.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/repl/replication_coordinator_mock.h" @@ -67,6 +68,11 @@ protected: BSONObj sort, boost::optional<long long> limit); + /** + * Returns the index definitions that exist for the given collection. + */ + StatusWith<std::vector<BSONObj>> getIndexes(NamespaceString nss); + private: void setUp() override; void tearDown() override; @@ -103,6 +109,26 @@ StatusWith<Shard::CommandResponse> ShardLocalTest::runFindAndModifyRunCommand(Na Shard::RetryPolicy::kNoRetry); } +StatusWith<std::vector<BSONObj>> ShardLocalTest::getIndexes(NamespaceString nss) { + auto response = _shardLocal->runCommand(_txn.get(), + ReadPreferenceSetting{ReadPreference::PrimaryOnly}, + nss.db().toString(), + BSON("listIndexes" << nss.coll().toString()), + Shard::RetryPolicy::kIdempotent); + if (!response.isOK()) { + return response.getStatus(); + } + if (!response.getValue().commandStatus.isOK()) { + return response.getValue().commandStatus; + } + + auto cursorResponse = CursorResponse::parseFromBSON(response.getValue().response); + if (!cursorResponse.isOK()) { + return cursorResponse.getStatus(); + } + return cursorResponse.getValue().getBatch(); +} + /** * Takes a FindAndModify command's BSON response and parses it for the returned "value" field. */ @@ -210,5 +236,32 @@ TEST_F(ShardLocalTest, FindNoMatchingDocumentsEmpty) { ASSERT_EQUALS(size, docs.size()); } +TEST_F(ShardLocalTest, CreateIndex) { + NamespaceString nss("config.foo"); + + ASSERT_EQUALS(ErrorCodes::NamespaceNotFound, getIndexes(nss).getStatus()); + + Status status = + _shardLocal->createIndexOnConfig(_txn.get(), nss, BSON("a" << 1 << "b" << 1), true); + // Creating the index should implicitly create the collection + ASSERT_OK(status); + + auto indexes = unittest::assertGet(getIndexes(nss)); + // There should be the index we just added as well as the _id index + ASSERT_EQ(2U, indexes.size()); + + // Making an identical index should be a no-op. + status = _shardLocal->createIndexOnConfig(_txn.get(), nss, BSON("a" << 1 << "b" << 1), true); + ASSERT_OK(status); + indexes = unittest::assertGet(getIndexes(nss)); + ASSERT_EQ(2U, indexes.size()); + + // Trying to make the same index as non-unique should fail. + status = _shardLocal->createIndexOnConfig(_txn.get(), nss, BSON("a" << 1 << "b" << 1), false); + ASSERT_EQUALS(ErrorCodes::IndexOptionsConflict, status); + indexes = unittest::assertGet(getIndexes(nss)); + ASSERT_EQ(2U, indexes.size()); +} + } // namespace } // namespace mongo |