summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/index_filter_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/index_filter_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/index_filter_commands_test.cpp')
-rw-r--r--src/mongo/db/commands/index_filter_commands_test.cpp86
1 files changed, 49 insertions, 37 deletions
diff --git a/src/mongo/db/commands/index_filter_commands_test.cpp b/src/mongo/db/commands/index_filter_commands_test.cpp
index 7da3619d1f7..5a0d7b6ce07 100644
--- a/src/mongo/db/commands/index_filter_commands_test.cpp
+++ b/src/mongo/db/commands/index_filter_commands_test.cpp
@@ -47,7 +47,7 @@ using std::string;
using std::unique_ptr;
using std::vector;
-static const char* ns = "test.t";
+static const NamespaceString nss("test.collection");
/**
* Utility function to get list of index filters from the query settings.
@@ -120,7 +120,7 @@ void addQueryShapeToPlanCache(PlanCache* planCache,
BSONObj projectionObj = fromjson(projectionStr);
// Create canonical query.
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, queryObj, sortObj, projectionObj);
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, queryObj, sortObj, projectionObj);
ASSERT_OK(statusWithCQ.getStatus());
std::unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -144,7 +144,7 @@ bool planCacheContains(const PlanCache& planCache,
BSONObj projectionObj = fromjson(projectionStr);
// Create canonical query.
- auto statusWithInputQuery = CanonicalQuery::canonicalize(ns, queryObj, sortObj, projectionObj);
+ auto statusWithInputQuery = CanonicalQuery::canonicalize(nss, queryObj, sortObj, projectionObj);
ASSERT_OK(statusWithInputQuery.getStatus());
unique_ptr<CanonicalQuery> inputQuery = std::move(statusWithInputQuery.getValue());
@@ -160,7 +160,7 @@ bool planCacheContains(const PlanCache& planCache,
// Alternatively, we could add key to PlanCacheEntry but that would be used in one place
// only.
auto statusWithCurrentQuery =
- CanonicalQuery::canonicalize(ns, entry->query, entry->sort, entry->projection);
+ CanonicalQuery::canonicalize(nss, entry->query, entry->sort, entry->projection);
ASSERT_OK(statusWithCurrentQuery.getStatus());
unique_ptr<CanonicalQuery> currentQuery = std::move(statusWithCurrentQuery.getValue());
@@ -193,21 +193,23 @@ TEST(IndexFilterCommandsTest, ClearFiltersInvalidParameter) {
OperationContextNoop txn;
// If present, query has to be an object.
- ASSERT_NOT_OK(ClearFilters::clear(&txn, &empty, &planCache, ns, fromjson("{query: 1234}")));
- // If present, sort must be an object.
ASSERT_NOT_OK(
- ClearFilters::clear(&txn, &empty, &planCache, ns, fromjson("{query: {a: 1}, sort: 1234}")));
+ ClearFilters::clear(&txn, &empty, &planCache, nss.ns(), fromjson("{query: 1234}")));
+ // If present, sort must be an object.
+ ASSERT_NOT_OK(ClearFilters::clear(
+ &txn, &empty, &planCache, nss.ns(), fromjson("{query: {a: 1}, sort: 1234}")));
// If present, projection must be an object.
ASSERT_NOT_OK(ClearFilters::clear(
- &txn, &empty, &planCache, ns, fromjson("{query: {a: 1}, projection: 1234}")));
+ &txn, &empty, &planCache, nss.ns(), fromjson("{query: {a: 1}, projection: 1234}")));
// Query must pass canonicalization.
ASSERT_NOT_OK(ClearFilters::clear(
- &txn, &empty, &planCache, ns, fromjson("{query: {a: {$no_such_op: 1}}}")));
+ &txn, &empty, &planCache, nss.ns(), fromjson("{query: {a: {$no_such_op: 1}}}")));
// Sort present without query is an error.
- ASSERT_NOT_OK(ClearFilters::clear(&txn, &empty, &planCache, ns, fromjson("{sort: {a: 1}}")));
+ ASSERT_NOT_OK(
+ ClearFilters::clear(&txn, &empty, &planCache, nss.ns(), fromjson("{sort: {a: 1}}")));
// Projection present without query is an error.
ASSERT_NOT_OK(ClearFilters::clear(
- &txn, &empty, &planCache, ns, fromjson("{projection: {_id: 0, a: 1}}")));
+ &txn, &empty, &planCache, nss.ns(), fromjson("{projection: {_id: 0, a: 1}}")));
}
TEST(IndexFilterCommandsTest, ClearNonexistentHint) {
@@ -215,15 +217,18 @@ TEST(IndexFilterCommandsTest, ClearNonexistentHint) {
PlanCache planCache;
OperationContextNoop txn;
- ASSERT_OK(SetFilter::set(
- &txn, &querySettings, &planCache, ns, fromjson("{query: {a: 1}, indexes: [{a: 1}]}")));
+ ASSERT_OK(SetFilter::set(&txn,
+ &querySettings,
+ &planCache,
+ nss.ns(),
+ fromjson("{query: {a: 1}, indexes: [{a: 1}]}")));
vector<BSONObj> filters = getFilters(querySettings);
ASSERT_EQUALS(filters.size(), 1U);
// Clear nonexistent hint.
// Command should succeed and cache should remain unchanged.
- ASSERT_OK(
- ClearFilters::clear(&txn, &querySettings, &planCache, ns, fromjson("{query: {b: 1}}")));
+ ASSERT_OK(ClearFilters::clear(
+ &txn, &querySettings, &planCache, nss.ns(), fromjson("{query: {b: 1}}")));
filters = getFilters(querySettings);
ASSERT_EQUALS(filters.size(), 1U);
}
@@ -237,46 +242,47 @@ TEST(IndexFilterCommandsTest, SetFilterInvalidParameter) {
PlanCache planCache;
OperationContextNoop txn;
- ASSERT_NOT_OK(SetFilter::set(&txn, &empty, &planCache, ns, fromjson("{}")));
+ ASSERT_NOT_OK(SetFilter::set(&txn, &empty, &planCache, nss.ns(), fromjson("{}")));
// Missing required query field.
- ASSERT_NOT_OK(SetFilter::set(&txn, &empty, &planCache, ns, fromjson("{indexes: [{a: 1}]}")));
+ ASSERT_NOT_OK(
+ SetFilter::set(&txn, &empty, &planCache, nss.ns(), fromjson("{indexes: [{a: 1}]}")));
// Missing required indexes field.
- ASSERT_NOT_OK(SetFilter::set(&txn, &empty, &planCache, ns, fromjson("{query: {a: 1}}")));
+ ASSERT_NOT_OK(SetFilter::set(&txn, &empty, &planCache, nss.ns(), fromjson("{query: {a: 1}}")));
// Query has to be an object.
ASSERT_NOT_OK(SetFilter::set(
- &txn, &empty, &planCache, ns, fromjson("{query: 1234, indexes: [{a: 1}, {b: 1}]}")));
+ &txn, &empty, &planCache, nss.ns(), fromjson("{query: 1234, indexes: [{a: 1}, {b: 1}]}")));
// Indexes field has to be an array.
- ASSERT_NOT_OK(
- SetFilter::set(&txn, &empty, &planCache, ns, fromjson("{query: {a: 1}, indexes: 1234}")));
+ ASSERT_NOT_OK(SetFilter::set(
+ &txn, &empty, &planCache, nss.ns(), fromjson("{query: {a: 1}, indexes: 1234}")));
// Array indexes field cannot empty.
- ASSERT_NOT_OK(
- SetFilter::set(&txn, &empty, &planCache, ns, fromjson("{query: {a: 1}, indexes: []}")));
+ ASSERT_NOT_OK(SetFilter::set(
+ &txn, &empty, &planCache, nss.ns(), fromjson("{query: {a: 1}, indexes: []}")));
// Elements in indexes have to be objects.
ASSERT_NOT_OK(SetFilter::set(
- &txn, &empty, &planCache, ns, fromjson("{query: {a: 1}, indexes: [{a: 1}, 99]}")));
+ &txn, &empty, &planCache, nss.ns(), fromjson("{query: {a: 1}, indexes: [{a: 1}, 99]}")));
// Objects in indexes cannot be empty.
ASSERT_NOT_OK(SetFilter::set(
- &txn, &empty, &planCache, ns, fromjson("{query: {a: 1}, indexes: [{a: 1}, {}]}")));
+ &txn, &empty, &planCache, nss.ns(), fromjson("{query: {a: 1}, indexes: [{a: 1}, {}]}")));
// If present, sort must be an object.
ASSERT_NOT_OK(
SetFilter::set(&txn,
&empty,
&planCache,
- ns,
+ nss.ns(),
fromjson("{query: {a: 1}, sort: 1234, indexes: [{a: 1}, {b: 1}]}")));
// If present, projection must be an object.
ASSERT_NOT_OK(
SetFilter::set(&txn,
&empty,
&planCache,
- ns,
+ nss.ns(),
fromjson("{query: {a: 1}, projection: 1234, indexes: [{a: 1}, {b: 1}]}")));
// Query must pass canonicalization.
ASSERT_NOT_OK(
SetFilter::set(&txn,
&empty,
&planCache,
- ns,
+ nss.ns(),
fromjson("{query: {a: {$no_such_op: 1}}, indexes: [{a: 1}, {b: 1}]}")));
}
@@ -292,7 +298,7 @@ TEST(IndexFilterCommandsTest, SetAndClearFilters) {
ASSERT_OK(SetFilter::set(&txn,
&querySettings,
&planCache,
- ns,
+ nss.ns(),
fromjson(
"{query: {a: 1, b: 1}, sort: {a: -1}, projection: {_id: 0, a: 1}, "
"indexes: [{a: 1}]}")));
@@ -312,7 +318,7 @@ TEST(IndexFilterCommandsTest, SetAndClearFilters) {
ASSERT_OK(SetFilter::set(&txn,
&querySettings,
&planCache,
- ns,
+ nss.ns(),
fromjson(
"{query: {b: 2, a: 3}, sort: {a: -1}, projection: {_id: 0, a: 1}, "
"indexes: [{a: 1, b: 1}]}")));
@@ -320,14 +326,20 @@ TEST(IndexFilterCommandsTest, SetAndClearFilters) {
ASSERT_EQUALS(filters.size(), 1U);
// Add hint for different query shape.
- ASSERT_OK(SetFilter::set(
- &txn, &querySettings, &planCache, ns, fromjson("{query: {b: 1}, indexes: [{b: 1}]}")));
+ ASSERT_OK(SetFilter::set(&txn,
+ &querySettings,
+ &planCache,
+ nss.ns(),
+ fromjson("{query: {b: 1}, indexes: [{b: 1}]}")));
filters = getFilters(querySettings);
ASSERT_EQUALS(filters.size(), 2U);
// Add hint for 3rd query shape. This is to prepare for ClearHint tests.
- ASSERT_OK(SetFilter::set(
- &txn, &querySettings, &planCache, ns, fromjson("{query: {a: 1}, indexes: [{a: 1}]}")));
+ ASSERT_OK(SetFilter::set(&txn,
+ &querySettings,
+ &planCache,
+ nss.ns(),
+ fromjson("{query: {a: 1}, indexes: [{a: 1}]}")));
filters = getFilters(querySettings);
ASSERT_EQUALS(filters.size(), 3U);
@@ -336,8 +348,8 @@ TEST(IndexFilterCommandsTest, SetAndClearFilters) {
addQueryShapeToPlanCache(&planCache, "{b: 1}", "{}", "{}");
// Clear single hint.
- ASSERT_OK(
- ClearFilters::clear(&txn, &querySettings, &planCache, ns, fromjson("{query: {a: 1}}")));
+ ASSERT_OK(ClearFilters::clear(
+ &txn, &querySettings, &planCache, nss.ns(), fromjson("{query: {a: 1}}")));
filters = getFilters(querySettings);
ASSERT_EQUALS(filters.size(), 2U);
@@ -346,7 +358,7 @@ TEST(IndexFilterCommandsTest, SetAndClearFilters) {
ASSERT_TRUE(planCacheContains(planCache, "{b: 1}", "{}", "{}"));
// Clear all filters
- ASSERT_OK(ClearFilters::clear(&txn, &querySettings, &planCache, ns, fromjson("{}")));
+ ASSERT_OK(ClearFilters::clear(&txn, &querySettings, &planCache, nss.ns(), fromjson("{}")));
filters = getFilters(querySettings);
ASSERT_TRUE(filters.empty());