summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/plan_cache_commands_test.cpp
diff options
context:
space:
mode:
authorQingyang Chen <qingyang.chen@10gen.com>2015-07-23 19:32:02 -0400
committerQingyang Chen <qingyang.chen@10gen.com>2015-07-27 17:12:16 -0400
commit5b759f3b3b704c93c59173789e393fcad6ee48f7 (patch)
tree0ee533b5b91d63665b23b7f7fd622bf5c1747322 /src/mongo/db/commands/plan_cache_commands_test.cpp
parent3da765b38f8e0893ed471b2cb93e62c2686cbec1 (diff)
downloadmongo-5b759f3b3b704c93c59173789e393fcad6ee48f7.tar.gz
SERVER-19235 CQ::canonicalize() to use NamespaceString rather than std::string
Diffstat (limited to 'src/mongo/db/commands/plan_cache_commands_test.cpp')
-rw-r--r--src/mongo/db/commands/plan_cache_commands_test.cpp75
1 files changed, 40 insertions, 35 deletions
diff --git a/src/mongo/db/commands/plan_cache_commands_test.cpp b/src/mongo/db/commands/plan_cache_commands_test.cpp
index c1216ea197d..7ffe832473b 100644
--- a/src/mongo/db/commands/plan_cache_commands_test.cpp
+++ b/src/mongo/db/commands/plan_cache_commands_test.cpp
@@ -49,7 +49,7 @@ using std::string;
using std::unique_ptr;
using std::vector;
-static const char* ns = "test.t";
+static const NamespaceString nss("test.collection");
/**
* Tests for planCacheListQueryShapes
@@ -125,7 +125,7 @@ TEST(PlanCacheCommandsTest, planCacheListQueryShapesEmpty) {
TEST(PlanCacheCommandsTest, planCacheListQueryShapesOneKey) {
// Create a canonical query
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, fromjson("{a: 1}"));
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, fromjson("{a: 1}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -150,7 +150,7 @@ TEST(PlanCacheCommandsTest, planCacheListQueryShapesOneKey) {
TEST(PlanCacheCommandsTest, planCacheClearAllShapes) {
// Create a canonical query
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, fromjson("{a: 1}"));
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, fromjson("{a: 1}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -166,7 +166,7 @@ TEST(PlanCacheCommandsTest, planCacheClearAllShapes) {
ASSERT_EQUALS(getShapes(planCache).size(), 1U);
// Clear cache and confirm number of keys afterwards.
- ASSERT_OK(PlanCacheClear::clear(&txn, &planCache, ns, BSONObj()));
+ ASSERT_OK(PlanCacheClear::clear(&txn, &planCache, nss.ns(), BSONObj()));
ASSERT_EQUALS(getShapes(planCache).size(), 0U);
}
@@ -181,52 +181,55 @@ TEST(PlanCacheCommandsTest, Canonicalize) {
OperationContextNoop txn;
// Missing query field
- ASSERT_NOT_OK(PlanCacheCommand::canonicalize(&txn, ns, fromjson("{}")).getStatus());
+ ASSERT_NOT_OK(PlanCacheCommand::canonicalize(&txn, nss.ns(), fromjson("{}")).getStatus());
// Query needs to be an object
- ASSERT_NOT_OK(PlanCacheCommand::canonicalize(&txn, ns, fromjson("{query: 1}")).getStatus());
- // Sort needs to be an object
ASSERT_NOT_OK(
- PlanCacheCommand::canonicalize(&txn, ns, fromjson("{query: {}, sort: 1}")).getStatus());
- // Bad query (invalid sort order)
- ASSERT_NOT_OK(PlanCacheCommand::canonicalize(&txn, ns, fromjson("{query: {}, sort: {a: 0}}"))
+ PlanCacheCommand::canonicalize(&txn, nss.ns(), fromjson("{query: 1}")).getStatus());
+ // Sort needs to be an object
+ ASSERT_NOT_OK(PlanCacheCommand::canonicalize(&txn, nss.ns(), fromjson("{query: {}, sort: 1}"))
.getStatus());
+ // Bad query (invalid sort order)
+ ASSERT_NOT_OK(PlanCacheCommand::canonicalize(
+ &txn, nss.ns(), fromjson("{query: {}, sort: {a: 0}}")).getStatus());
// Valid parameters
- auto statusWithCQ = PlanCacheCommand::canonicalize(&txn, ns, fromjson("{query: {a: 1, b: 1}}"));
+ auto statusWithCQ =
+ PlanCacheCommand::canonicalize(&txn, nss.ns(), fromjson("{query: {a: 1, b: 1}}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> query = std::move(statusWithCQ.getValue());
// Equivalent query should generate same key.
- statusWithCQ = PlanCacheCommand::canonicalize(&txn, ns, fromjson("{query: {b: 1, a: 1}}"));
+ statusWithCQ =
+ PlanCacheCommand::canonicalize(&txn, nss.ns(), fromjson("{query: {b: 1, a: 1}}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> equivQuery = std::move(statusWithCQ.getValue());
ASSERT_EQUALS(planCache.computeKey(*query), planCache.computeKey(*equivQuery));
// Sort query should generate different key from unsorted query.
statusWithCQ = PlanCacheCommand::canonicalize(
- &txn, ns, fromjson("{query: {a: 1, b: 1}, sort: {a: 1, b: 1}}"));
+ &txn, nss.ns(), fromjson("{query: {a: 1, b: 1}, sort: {a: 1, b: 1}}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> sortQuery1 = std::move(statusWithCQ.getValue());
ASSERT_NOT_EQUALS(planCache.computeKey(*query), planCache.computeKey(*sortQuery1));
// Confirm sort arguments are properly delimited (SERVER-17158)
- statusWithCQ =
- PlanCacheCommand::canonicalize(&txn, ns, fromjson("{query: {a: 1, b: 1}, sort: {aab: 1}}"));
+ statusWithCQ = PlanCacheCommand::canonicalize(
+ &txn, nss.ns(), fromjson("{query: {a: 1, b: 1}, sort: {aab: 1}}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> sortQuery2 = std::move(statusWithCQ.getValue());
ASSERT_NOT_EQUALS(planCache.computeKey(*sortQuery1), planCache.computeKey(*sortQuery2));
// Changing order and/or value of predicates should not change key
statusWithCQ = PlanCacheCommand::canonicalize(
- &txn, ns, fromjson("{query: {b: 3, a: 3}, sort: {a: 1, b: 1}}"));
+ &txn, nss.ns(), fromjson("{query: {b: 3, a: 3}, sort: {a: 1, b: 1}}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> sortQuery3 = std::move(statusWithCQ.getValue());
ASSERT_EQUALS(planCache.computeKey(*sortQuery1), planCache.computeKey(*sortQuery3));
// Projected query should generate different key from unprojected query.
statusWithCQ = PlanCacheCommand::canonicalize(
- &txn, ns, fromjson("{query: {a: 1, b: 1}, projection: {_id: 0, a: 1}}"));
+ &txn, nss.ns(), fromjson("{query: {a: 1, b: 1}, projection: {_id: 0, a: 1}}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> projectionQuery = std::move(statusWithCQ.getValue());
ASSERT_NOT_EQUALS(planCache.computeKey(*query), planCache.computeKey(*projectionQuery));
@@ -241,32 +244,32 @@ TEST(PlanCacheCommandsTest, planCacheClearInvalidParameter) {
OperationContextNoop txn;
// Query field type must be BSON object.
- ASSERT_NOT_OK(PlanCacheClear::clear(&txn, &planCache, ns, fromjson("{query: 12345}")));
+ ASSERT_NOT_OK(PlanCacheClear::clear(&txn, &planCache, nss.ns(), fromjson("{query: 12345}")));
ASSERT_NOT_OK(
- PlanCacheClear::clear(&txn, &planCache, ns, fromjson("{query: /keyisnotregex/}")));
+ PlanCacheClear::clear(&txn, &planCache, nss.ns(), fromjson("{query: /keyisnotregex/}")));
// Query must pass canonicalization.
- ASSERT_NOT_OK(
- PlanCacheClear::clear(&txn, &planCache, ns, fromjson("{query: {a: {$no_such_op: 1}}}")));
+ ASSERT_NOT_OK(PlanCacheClear::clear(
+ &txn, &planCache, nss.ns(), fromjson("{query: {a: {$no_such_op: 1}}}")));
// Sort present without query is an error.
- ASSERT_NOT_OK(PlanCacheClear::clear(&txn, &planCache, ns, fromjson("{sort: {a: 1}}")));
+ ASSERT_NOT_OK(PlanCacheClear::clear(&txn, &planCache, nss.ns(), fromjson("{sort: {a: 1}}")));
// Projection present without query is an error.
- ASSERT_NOT_OK(
- PlanCacheClear::clear(&txn, &planCache, ns, fromjson("{projection: {_id: 0, a: 1}}")));
+ ASSERT_NOT_OK(PlanCacheClear::clear(
+ &txn, &planCache, nss.ns(), fromjson("{projection: {_id: 0, a: 1}}")));
}
TEST(PlanCacheCommandsTest, planCacheClearUnknownKey) {
PlanCache planCache;
OperationContextNoop txn;
- ASSERT_OK(PlanCacheClear::clear(&txn, &planCache, ns, fromjson("{query: {a: 1}}")));
+ ASSERT_OK(PlanCacheClear::clear(&txn, &planCache, nss.ns(), fromjson("{query: {a: 1}}")));
}
TEST(PlanCacheCommandsTest, planCacheClearOneKey) {
// Create 2 canonical queries.
- auto statusWithCQA = CanonicalQuery::canonicalize(ns, fromjson("{a: 1}"));
+ auto statusWithCQA = CanonicalQuery::canonicalize(nss, fromjson("{a: 1}"));
ASSERT_OK(statusWithCQA.getStatus());
unique_ptr<CanonicalQuery> cqA = std::move(statusWithCQA.getValue());
- auto statusWithCQB = CanonicalQuery::canonicalize(ns, fromjson("{b: 1}"));
+ auto statusWithCQB = CanonicalQuery::canonicalize(nss, fromjson("{b: 1}"));
ASSERT_OK(statusWithCQB.getStatus());
unique_ptr<CanonicalQuery> cqB = std::move(statusWithCQB.getValue());
@@ -293,7 +296,8 @@ TEST(PlanCacheCommandsTest, planCacheClearOneKey) {
BSONObjBuilder bob;
OperationContextNoop txn;
- ASSERT_OK(PlanCacheClear::clear(&txn, &planCache, ns, BSON("query" << cqB->getQueryObj())));
+ ASSERT_OK(
+ PlanCacheClear::clear(&txn, &planCache, nss.ns(), BSON("query" << cqB->getQueryObj())));
vector<BSONObj> shapesAfter = getShapes(planCache);
ASSERT_EQUALS(shapesAfter.size(), 1U);
ASSERT_EQUALS(shapesAfter[0], shapeA);
@@ -347,7 +351,7 @@ vector<BSONObj> getPlans(const PlanCache& planCache,
BSONObjBuilder bob;
BSONObj cmdObj = BSON("query" << query << "sort" << sort << "projection" << projection);
- ASSERT_OK(PlanCacheListPlans::list(&txn, planCache, ns, cmdObj, &bob));
+ ASSERT_OK(PlanCacheListPlans::list(&txn, planCache, nss.ns(), cmdObj, &bob));
BSONObj resultObj = bob.obj();
BSONElement plansElt = resultObj.getField("plans");
ASSERT_EQUALS(plansElt.type(), mongo::Array);
@@ -364,12 +368,12 @@ TEST(PlanCacheCommandsTest, planCacheListPlansInvalidParameter) {
OperationContextNoop txn;
// Missing query field is not ok.
- ASSERT_NOT_OK(PlanCacheListPlans::list(&txn, planCache, ns, BSONObj(), &ignored));
+ ASSERT_NOT_OK(PlanCacheListPlans::list(&txn, planCache, nss.ns(), BSONObj(), &ignored));
// Query field type must be BSON object.
ASSERT_NOT_OK(
- PlanCacheListPlans::list(&txn, planCache, ns, fromjson("{query: 12345}"), &ignored));
+ PlanCacheListPlans::list(&txn, planCache, nss.ns(), fromjson("{query: 12345}"), &ignored));
ASSERT_NOT_OK(PlanCacheListPlans::list(
- &txn, planCache, ns, fromjson("{query: /keyisnotregex/}"), &ignored));
+ &txn, planCache, nss.ns(), fromjson("{query: /keyisnotregex/}"), &ignored));
}
TEST(PlanCacheCommandsTest, planCacheListPlansUnknownKey) {
@@ -378,12 +382,13 @@ TEST(PlanCacheCommandsTest, planCacheListPlansUnknownKey) {
OperationContextNoop txn;
BSONObjBuilder ignored;
- ASSERT_OK(PlanCacheListPlans::list(&txn, planCache, ns, fromjson("{query: {a: 1}}"), &ignored));
+ ASSERT_OK(
+ PlanCacheListPlans::list(&txn, planCache, nss.ns(), fromjson("{query: {a: 1}}"), &ignored));
}
TEST(PlanCacheCommandsTest, planCacheListPlansOnlyOneSolutionTrue) {
// Create a canonical query
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, fromjson("{a: 1}"));
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, fromjson("{a: 1}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -402,7 +407,7 @@ TEST(PlanCacheCommandsTest, planCacheListPlansOnlyOneSolutionTrue) {
TEST(PlanCacheCommandsTest, planCacheListPlansOnlyOneSolutionFalse) {
// Create a canonical query
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, fromjson("{a: 1}"));
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, fromjson("{a: 1}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());