summaryrefslogtreecommitdiff
path: root/jstests/core/index_filter_commands.js
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2014-03-03 16:17:29 -0500
committerBenety Goh <benety@mongodb.com>2014-03-05 09:13:55 -0500
commit34bd3d0dd8e9c341a2f5f228cde741771af7ed25 (patch)
tree43203c6721083669271fa67696e802321fc74138 /jstests/core/index_filter_commands.js
parent1655fff18e64179ef4e36565f25b6c06e6b453a9 (diff)
downloadmongo-34bd3d0dd8e9c341a2f5f228cde741771af7ed25.tar.gz
SERVER-12964 updated plan cache and index filter commands to return empty results on non-existent collection or query shape
Diffstat (limited to 'jstests/core/index_filter_commands.js')
-rw-r--r--jstests/core/index_filter_commands.js26
1 files changed, 20 insertions, 6 deletions
diff --git a/jstests/core/index_filter_commands.js b/jstests/core/index_filter_commands.js
index cec2437fff0..c10fd3da0ca 100644
--- a/jstests/core/index_filter_commands.js
+++ b/jstests/core/index_filter_commands.js
@@ -47,8 +47,11 @@ var sortA1 = {a: -1};
//
// Utility function to list index filters.
-function getFilters() {
- var res = t.runCommand('planCacheListFilters');
+function getFilters(collection) {
+ if (collection == undefined) {
+ collection = t;
+ }
+ var res = collection.runCommand('planCacheListFilters');
print('planCacheListFilters() = ' + tojson(res));
assert.commandWorked(res, 'planCacheListFilters failed');
assert(res.hasOwnProperty('filters'), 'filters missing from planCacheListFilters result');
@@ -56,10 +59,12 @@ function getFilters() {
}
-// Check if key is in plan cache.
+// If query shape is in plan cache,
+// planCacheListPlans returns non-empty array of plans.
function planCacheContains(shape) {
var res = t.runCommand('planCacheListPlans', shape);
- return res.ok;
+ assert.commandWorked(res);
+ return res.plans.length > 0;
}
// Utility function to list plans for a query.
@@ -71,10 +76,12 @@ function getPlans(shape) {
return res.plans;
}
-// It is an error to retrieve index filters on a non-existent collection.
+// Attempting to retrieve index filters on a non-existent collection
+// will return empty results.
var missingCollection = db.jstests_index_filter_commands_missing;
missingCollection.drop();
-assert.commandFailed(missingCollection.runCommand('planCacheListFilters'));
+assert.eq(0, getFilters(missingCollection),
+ 'planCacheListFilters should return empty array on non-existent collection');
// Retrieve index filters from an empty test collection.
var filters = getFilters();
@@ -88,6 +95,10 @@ print('Winning plan (before setting index filters) = ' + tojson(planBeforeSetFil
// Check filterSet field in plan details
assert.eq(false, planBeforeSetFilter.filterSet, 'missing or invalid filterSet field in plan details');
+// Adding index filters to a non-existent collection should be an error.
+assert.commandFailed(missingCollection.runCommand('planCacheSetFilter',
+ {query: queryA1, sort: sortA1, projection: projectionA1, indexes: [indexA1B1, indexA1C1]}));
+
// Add index filters for simple query.
assert.commandWorked(t.runCommand('planCacheSetFilter',
{query: queryA1, sort: sortA1, projection: projectionA1, indexes: [indexA1B1, indexA1C1]}));
@@ -117,6 +128,9 @@ assert.eq(true, planAfterSetFilter.filterSet, 'missing or invalid filterSet fiel
t.find(queryA1, projectionA1).sort(sortA1).hint(indexA1).itcount();
// Clear filters
+// Clearing filters on a missing collection should be a no-op.
+assert.commandWorked(missingCollection.runCommand('planCacheClearFilters'));
+// Clear the filters set earlier.
assert.commandWorked(t.runCommand('planCacheClearFilters'));
filters = getFilters();
assert.eq(0, filters.length, 'filters not cleared after successful planCacheClearFilters command');