summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/auto_split_vector_test.cpp
diff options
context:
space:
mode:
authorTommaso Tocci <tommaso.tocci@mongodb.com>2022-02-04 08:40:22 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-02-16 12:59:22 +0000
commit227fea5dfb7c1b313411a54c51534059386fdc53 (patch)
treedd9bf37a1e4ab993b797538e39aa8987f2f5f941 /src/mongo/db/s/auto_split_vector_test.cpp
parent985d83b45b397c3b9ec0f2faca2127faad2e6d74 (diff)
downloadmongo-227fea5dfb7c1b313411a54c51534059386fdc53.tar.gz
SERVER-63239 Do not throw exception in AutoSplitVector on empty ranges
(cherry picked from commit 1bbb1d0c7ef1844c20571183df8ca98055e10b5b)
Diffstat (limited to 'src/mongo/db/s/auto_split_vector_test.cpp')
-rw-r--r--src/mongo/db/s/auto_split_vector_test.cpp32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/mongo/db/s/auto_split_vector_test.cpp b/src/mongo/db/s/auto_split_vector_test.cpp
index d93a6065a85..45371606529 100644
--- a/src/mongo/db/s/auto_split_vector_test.cpp
+++ b/src/mongo/db/s/auto_split_vector_test.cpp
@@ -121,26 +121,46 @@ class AutoSplitVectorTest10MB : public AutoSplitVectorTest {
auto opCtx = operationContext();
- DBDirectClient client(opCtx);
- client.createIndex(kNss.ns(), BSON(kPattern << 1));
-
insertNDocsOf1MB(opCtx, 10 /* nDocs */);
+
+ DBDirectClient client(opCtx);
ASSERT_EQUALS(10, client.count(kNss));
}
};
// Throw exception upon calling autoSplitVector on dropped/unexisting collection
-TEST_F(AutoSplitVectorTest10MB, NoCollection) {
+TEST_F(AutoSplitVectorTest, NoCollection) {
ASSERT_THROWS_CODE(autoSplitVector(operationContext(),
NamespaceString("dummy", "collection"),
BSON(kPattern << 1) /* shard key pattern */,
- BSON(kPattern << 0) /* min */,
- BSON(kPattern << 100) /* max */,
+ BSON(kPattern << kMinBSONKey) /* min */,
+ BSON(kPattern << kMaxBSONKey) /* max */,
1 * 1024 * 1024 /* max chunk size in bytes*/),
DBException,
ErrorCodes::NamespaceNotFound);
}
+TEST_F(AutoSplitVectorTest, EmptyCollection) {
+ const auto splitKey = autoSplitVector(operationContext(),
+ kNss,
+ BSON(kPattern << 1) /* shard key pattern */,
+ BSON(kPattern << kMinBSONKey) /* min */,
+ BSON(kPattern << kMaxBSONKey) /* max */,
+ 1 * 1024 * 1024 /* max chunk size in bytes*/);
+ ASSERT_EQ(0, splitKey.size());
+}
+
+TEST_F(AutoSplitVectorTest10MB, EmptyRange) {
+ const auto splitKey = autoSplitVector(operationContext(),
+ kNss,
+ BSON(kPattern << 1) /* shard key pattern */,
+ BSON(kPattern << kMinBSONKey) /* min */,
+ BSON(kPattern << -10) /* max */,
+ 1 * 1024 * 1024 /* max chunk size in bytes*/);
+ ASSERT_EQ(0, splitKey.size());
+}
+
+
// No split points if estimated `data size < max chunk size`
TEST_F(AutoSplitVectorTest10MB, NoSplitIfDataLessThanMaxChunkSize) {
std::vector<BSONObj> splitKeys = autoSplit(operationContext(), 11 /* maxChunkSizeMB */);