summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/shard_key_index_util_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/s/shard_key_index_util_test.cpp')
-rw-r--r--src/mongo/db/s/shard_key_index_util_test.cpp32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/mongo/db/s/shard_key_index_util_test.cpp b/src/mongo/db/s/shard_key_index_util_test.cpp
index c9c1b4fdc23..73e8f78779e 100644
--- a/src/mongo/db/s/shard_key_index_util_test.cpp
+++ b/src/mongo/db/s/shard_key_index_util_test.cpp
@@ -203,9 +203,12 @@ TEST_F(ShardKeyIndexUtilTest, LastShardIndexWithSingleCandidate) {
createIndex(BSON("key" << BSON("x" << 1) << "name"
<< "x"
<< "v" << kIndexVersion));
+ createIndex(BSON("key" << BSON("x" << 1 << "y" << 1) << "name"
+ << "xy"
+ << "v" << kIndexVersion << "hidden" << true));
- ASSERT_TRUE(
- isLastShardKeyIndex(opCtx(), coll(), coll()->getIndexCatalog(), "x", BSON("x" << 1)));
+ ASSERT_TRUE(isLastNonHiddenShardKeyIndex(
+ opCtx(), coll(), coll()->getIndexCatalog(), "x", BSON("x" << 1)));
}
TEST_F(ShardKeyIndexUtilTest, LastShardIndexWithMultipleCandidates) {
@@ -219,8 +222,29 @@ TEST_F(ShardKeyIndexUtilTest, LastShardIndexWithMultipleCandidates) {
<< "xy"
<< "v" << kIndexVersion));
- ASSERT_FALSE(
- isLastShardKeyIndex(opCtx(), coll(), coll()->getIndexCatalog(), "x", BSON("x" << 1)));
+ ASSERT_FALSE(isLastNonHiddenShardKeyIndex(
+ opCtx(), coll(), coll()->getIndexCatalog(), "x", BSON("x" << 1)));
+}
+
+TEST_F(ShardKeyIndexUtilTest, LastShardIndexWithIncompatibleIndex) {
+ createIndex(BSON("key" << BSON("y" << 1) << "name"
+ << "y"
+ << "v" << kIndexVersion));
+ createIndex(BSON("key" << BSON("x" << 1) << "name"
+ << "x"
+ << "v" << kIndexVersion));
+
+ ASSERT_FALSE(isLastNonHiddenShardKeyIndex(
+ opCtx(), coll(), coll()->getIndexCatalog(), "y", BSON("x" << 1)));
+}
+
+TEST_F(ShardKeyIndexUtilTest, LastShardIndexWithNonExistingIndex) {
+ createIndex(BSON("key" << BSON("x" << 1) << "name"
+ << "x"
+ << "v" << kIndexVersion));
+
+ ASSERT_FALSE(isLastNonHiddenShardKeyIndex(
+ opCtx(), coll(), coll()->getIndexCatalog(), "y", BSON("x" << 1)));
}
} // namespace