summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/query_request_test.cpp
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2017-07-13 09:27:56 -0400
committerMathias Stearn <mathias@10gen.com>2017-07-26 15:13:34 -0400
commit84ef4754b61003c63a480ac009fe2302970b00c9 (patch)
treea04948da01af49265a4ab366d79dc146b1e398a4 /src/mongo/db/query/query_request_test.cpp
parent8b36e1d65f4b1730e7fc6086a0e1f429e48ba695 (diff)
downloadmongo-84ef4754b61003c63a480ac009fe2302970b00c9.tar.gz
SERVER-28509 DBClientCursor now uses read commands
Diffstat (limited to 'src/mongo/db/query/query_request_test.cpp')
-rw-r--r--src/mongo/db/query/query_request_test.cpp69
1 files changed, 67 insertions, 2 deletions
diff --git a/src/mongo/db/query/query_request_test.cpp b/src/mongo/db/query/query_request_test.cpp
index f64a5429faf..4910b769af9 100644
--- a/src/mongo/db/query/query_request_test.cpp
+++ b/src/mongo/db/query/query_request_test.cpp
@@ -32,6 +32,7 @@
#include <boost/optional.hpp>
#include <boost/optional/optional_io.hpp>
+#include "mongo/db/dbmessage.h"
#include "mongo/db/json.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/pipeline/aggregation_request.h"
@@ -1336,10 +1337,11 @@ TEST(QueryRequestTest, ParseFromLegacyObjMetaOpComment) {
"$comment: {b: 2, c: {d: 'ParseFromLegacyObjMetaOpComment'}}}");
const NamespaceString nss("test.testns");
unique_ptr<QueryRequest> qr(
- assertGet(QueryRequest::fromLegacyQueryForTest(nss, queryObj, BSONObj(), 0, 0, 0)));
+ assertGet(QueryRequest::fromLegacyQuery(nss, queryObj, BSONObj(), 0, 0, 0)));
// Ensure that legacy comment meta-operator is parsed to a string comment
ASSERT_EQ(qr->getComment(), "{ b: 2, c: { d: \"ParseFromLegacyObjMetaOpComment\" } }");
+ ASSERT_BSONOBJ_EQ(qr->getFilter(), fromjson("{a: 1}"));
}
TEST(QueryRequestTest, ParseFromLegacyStringMetaOpComment) {
@@ -1348,9 +1350,72 @@ TEST(QueryRequestTest, ParseFromLegacyStringMetaOpComment) {
"$comment: 'ParseFromLegacyStringMetaOpComment'}");
const NamespaceString nss("test.testns");
unique_ptr<QueryRequest> qr(
- assertGet(QueryRequest::fromLegacyQueryForTest(nss, queryObj, BSONObj(), 0, 0, 0)));
+ assertGet(QueryRequest::fromLegacyQuery(nss, queryObj, BSONObj(), 0, 0, 0)));
ASSERT_EQ(qr->getComment(), "ParseFromLegacyStringMetaOpComment");
+ ASSERT_BSONOBJ_EQ(qr->getFilter(), fromjson("{a: 1}"));
+}
+
+TEST(QueryRequestTest, ParseFromLegacyQuery) {
+ const auto kSkip = 1;
+ const auto kNToReturn = 2;
+
+ BSONObj queryObj = fromjson(R"({
+ query: {query: 1},
+ orderby: {sort: 1},
+ $hint: {hint: 1},
+ $explain: false,
+ $min: {x: 'min'},
+ $max: {x: 'max'},
+ $maxScan: 7
+ })");
+ const NamespaceString nss("test.testns");
+ unique_ptr<QueryRequest> qr(assertGet(QueryRequest::fromLegacyQuery(
+ nss, queryObj, BSON("proj" << 1), kSkip, kNToReturn, QueryOption_Exhaust)));
+
+ ASSERT_EQ(qr->nss(), nss);
+ ASSERT_BSONOBJ_EQ(qr->getFilter(), fromjson("{query: 1}"));
+ ASSERT_BSONOBJ_EQ(qr->getProj(), fromjson("{proj: 1}"));
+ ASSERT_BSONOBJ_EQ(qr->getSort(), fromjson("{sort: 1}"));
+ ASSERT_BSONOBJ_EQ(qr->getHint(), fromjson("{hint: 1}"));
+ ASSERT_BSONOBJ_EQ(qr->getMin(), fromjson("{x: 'min'}"));
+ ASSERT_BSONOBJ_EQ(qr->getMax(), fromjson("{x: 'max'}"));
+ ASSERT_EQ(qr->getSkip(), boost::optional<long long>(kSkip));
+ ASSERT_EQ(qr->getNToReturn(), boost::optional<long long>(kNToReturn));
+ ASSERT_EQ(qr->wantMore(), true);
+ ASSERT_EQ(qr->isExplain(), false);
+ ASSERT_EQ(qr->getMaxScan(), 7);
+ ASSERT_EQ(qr->isSlaveOk(), false);
+ ASSERT_EQ(qr->isOplogReplay(), false);
+ ASSERT_EQ(qr->isNoCursorTimeout(), false);
+ ASSERT_EQ(qr->isAwaitData(), false);
+ ASSERT_EQ(qr->isExhaust(), true);
+ ASSERT_EQ(qr->isAllowPartialResults(), false);
+ ASSERT_EQ(qr->getOptions(), QueryOption_Exhaust);
+}
+
+TEST(QueryRequestTest, ParseFromLegacyQueryUnwrapped) {
+ BSONObj queryObj = fromjson(R"({
+ foo: 1
+ })");
+ const NamespaceString nss("test.testns");
+ unique_ptr<QueryRequest> qr(assertGet(
+ QueryRequest::fromLegacyQuery(nss, queryObj, BSONObj(), 0, 0, QueryOption_Exhaust)));
+
+ ASSERT_EQ(qr->nss(), nss);
+ ASSERT_BSONOBJ_EQ(qr->getFilter(), fromjson("{foo: 1}"));
+}
+
+TEST(QueryRequestTest, ParseFromLegacyQueryTooNegativeNToReturn) {
+ BSONObj queryObj = fromjson(R"({
+ foo: 1
+ })");
+ const NamespaceString nss("test.testns");
+
+ ASSERT_NOT_OK(
+ QueryRequest::fromLegacyQuery(
+ nss, queryObj, BSONObj(), 0, std::numeric_limits<int>::min(), QueryOption_Exhaust)
+ .getStatus());
}
} // namespace mongo