summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/parsed_distinct_test.cpp
diff options
context:
space:
mode:
authorJames Wahlin <james.wahlin@10gen.com>2017-03-15 17:09:33 -0400
committerJames Wahlin <james.wahlin@10gen.com>2017-04-05 13:51:03 -0400
commitc3341d179db1c36722284676d99cb1c664fb1821 (patch)
treef69c9c00fc8df3ccf6db6df50a78319ff1e38950 /src/mongo/db/query/parsed_distinct_test.cpp
parent8765acc0fcc6ca3dd7158521ba8d864af4e0f2df (diff)
downloadmongo-c3341d179db1c36722284676d99cb1c664fb1821.tar.gz
SERVER-28040 Fix maxTimeMS/readPref/readConcern for sharded view query
Diffstat (limited to 'src/mongo/db/query/parsed_distinct_test.cpp')
-rw-r--r--src/mongo/db/query/parsed_distinct_test.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/mongo/db/query/parsed_distinct_test.cpp b/src/mongo/db/query/parsed_distinct_test.cpp
index 3a4f6ccb42e..68554d2637c 100644
--- a/src/mongo/db/query/parsed_distinct_test.cpp
+++ b/src/mongo/db/query/parsed_distinct_test.cpp
@@ -64,6 +64,74 @@ TEST(ParsedDistinctTest, ConvertToAggregationNoQuery) {
ASSERT_EQ(ar.getValue().getBatchSize(), AggregationRequest::kDefaultBatchSize);
ASSERT_EQ(ar.getValue().getNamespaceString(), testns);
ASSERT_BSONOBJ_EQ(ar.getValue().getCollation(), BSONObj());
+ ASSERT(ar.getValue().getReadConcern().isEmpty());
+ ASSERT(ar.getValue().getUnwrappedReadPref().isEmpty());
+ ASSERT(ar.getValue().getComment().empty());
+ ASSERT_EQUALS(ar.getValue().getMaxTimeMS(), 0u);
+
+ std::vector<BSONObj> expectedPipeline{
+ BSON("$unwind" << BSON("path"
+ << "$x"
+ << "preserveNullAndEmptyArrays"
+ << true)),
+ BSON("$group" << BSON("_id" << BSONNULL << "distinct" << BSON("$addToSet"
+ << "$x")))};
+ ASSERT(std::equal(expectedPipeline.begin(),
+ expectedPipeline.end(),
+ ar.getValue().getPipeline().begin(),
+ ar.getValue().getPipeline().end(),
+ SimpleBSONObjComparator::kInstance.makeEqualTo()));
+}
+
+TEST(ParsedDistinctTest, ConvertToAggregationWithAllOptions) {
+ QueryTestServiceContext serviceContext;
+ auto uniqueTxn = serviceContext.makeOperationContext();
+ OperationContext* opCtx = uniqueTxn.get();
+
+ auto pd = ParsedDistinct::parse(opCtx,
+ testns,
+ BSON("distinct"
+ << "testcoll"
+ << "key"
+ << "x"
+ << "hint"
+ << BSON("b" << 5)
+ << "collation"
+ << BSON("locale"
+ << "en_US")
+ << "readConcern"
+ << BSON("level"
+ << "linearizable")
+ << "$queryOptions"
+ << BSON("readPreference"
+ << "secondary")
+ << "comment"
+ << "aComment"
+ << "maxTimeMS"
+ << 100),
+ ExtensionsCallbackDisallowExtensions(),
+ !isExplain);
+ ASSERT_OK(pd.getStatus());
+
+ auto agg = pd.getValue().asAggregationCommand();
+ ASSERT_OK(agg);
+
+ auto ar = AggregationRequest::parseFromBSON(testns, agg.getValue());
+ ASSERT_OK(ar.getStatus());
+ ASSERT(!ar.getValue().getExplain());
+ ASSERT_EQ(ar.getValue().getBatchSize(), AggregationRequest::kDefaultBatchSize);
+ ASSERT_EQ(ar.getValue().getNamespaceString(), testns);
+ ASSERT_BSONOBJ_EQ(ar.getValue().getCollation(),
+ BSON("locale"
+ << "en_US"));
+ ASSERT_BSONOBJ_EQ(ar.getValue().getReadConcern(),
+ BSON("level"
+ << "linearizable"));
+ ASSERT_BSONOBJ_EQ(ar.getValue().getUnwrappedReadPref(),
+ BSON("readPreference"
+ << "secondary"));
+ ASSERT_EQUALS(ar.getValue().getComment(), "aComment");
+ ASSERT_EQUALS(ar.getValue().getMaxTimeMS(), 100u);
std::vector<BSONObj> expectedPipeline{
BSON("$unwind" << BSON("path"
@@ -100,6 +168,10 @@ TEST(ParsedDistinctTest, ConvertToAggregationWithQuery) {
ASSERT_EQ(ar.getValue().getBatchSize(), AggregationRequest::kDefaultBatchSize);
ASSERT_EQ(ar.getValue().getNamespaceString(), testns);
ASSERT_BSONOBJ_EQ(ar.getValue().getCollation(), BSONObj());
+ ASSERT(ar.getValue().getReadConcern().isEmpty());
+ ASSERT(ar.getValue().getUnwrappedReadPref().isEmpty());
+ ASSERT(ar.getValue().getComment().empty());
+ ASSERT_EQUALS(ar.getValue().getMaxTimeMS(), 0u);
std::vector<BSONObj> expectedPipeline{
BSON("$match" << BSON("z" << 7)),