diff options
author | Tess Avitabile <tess.avitabile@mongodb.com> | 2016-04-28 16:36:11 -0400 |
---|---|---|
committer | Tess Avitabile <tess.avitabile@mongodb.com> | 2016-05-05 10:29:06 -0400 |
commit | f7a46a118288ba0ce45c7664777ea0e89c2eb845 (patch) | |
tree | d9ba6c6981072ce4b836617ebb1889ac17e4fcc2 /src/mongo/db/commands/plan_cache_commands_test.cpp | |
parent | f49018bca41048d8a4f729ccc0489ea6be073a20 (diff) | |
download | mongo-f7a46a118288ba0ce45c7664777ea0e89c2eb845.tar.gz |
SERVER-23610 CanonicalQuery should own a CollatorInterface
Diffstat (limited to 'src/mongo/db/commands/plan_cache_commands_test.cpp')
-rw-r--r-- | src/mongo/db/commands/plan_cache_commands_test.cpp | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/src/mongo/db/commands/plan_cache_commands_test.cpp b/src/mongo/db/commands/plan_cache_commands_test.cpp index 7234588fd37..ab811c7cf92 100644 --- a/src/mongo/db/commands/plan_cache_commands_test.cpp +++ b/src/mongo/db/commands/plan_cache_commands_test.cpp @@ -39,6 +39,7 @@ #include "mongo/db/operation_context_noop.h" #include "mongo/db/query/plan_ranker.h" #include "mongo/db/query/query_solution.h" +#include "mongo/db/query/query_test_service_context.h" #include "mongo/unittest/unittest.h" #include "mongo/util/mongoutils/str.h" @@ -125,9 +126,12 @@ TEST(PlanCacheCommandsTest, planCacheListQueryShapesEmpty) { } TEST(PlanCacheCommandsTest, planCacheListQueryShapesOneKey) { + QueryTestServiceContext serviceContext; + auto txn = serviceContext.makeOperationContext(); + // Create a canonical query auto statusWithCQ = CanonicalQuery::canonicalize( - nss, fromjson("{a: 1}"), ExtensionsCallbackDisallowExtensions()); + txn.get(), nss, fromjson("{a: 1}"), ExtensionsCallbackDisallowExtensions()); ASSERT_OK(statusWithCQ.getStatus()); unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue()); @@ -151,16 +155,18 @@ TEST(PlanCacheCommandsTest, planCacheListQueryShapesOneKey) { */ TEST(PlanCacheCommandsTest, planCacheClearAllShapes) { + QueryTestServiceContext serviceContext; + auto txn = serviceContext.makeOperationContext(); + // Create a canonical query auto statusWithCQ = CanonicalQuery::canonicalize( - nss, fromjson("{a: 1}"), ExtensionsCallbackDisallowExtensions()); + txn.get(), nss, fromjson("{a: 1}"), ExtensionsCallbackDisallowExtensions()); ASSERT_OK(statusWithCQ.getStatus()); unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue()); // Plan cache with one entry PlanCache planCache; QuerySolution qs; - OperationContextNoop txn; qs.cacheData.reset(createSolutionCacheData()); std::vector<QuerySolution*> solns; @@ -169,7 +175,7 @@ TEST(PlanCacheCommandsTest, planCacheClearAllShapes) { ASSERT_EQUALS(getShapes(planCache).size(), 1U); // Clear cache and confirm number of keys afterwards. - ASSERT_OK(PlanCacheClear::clear(&txn, &planCache, nss.ns(), BSONObj())); + ASSERT_OK(PlanCacheClear::clear(txn.get(), &planCache, nss.ns(), BSONObj())); ASSERT_EQUALS(getShapes(planCache).size(), 0U); } @@ -268,13 +274,16 @@ TEST(PlanCacheCommandsTest, planCacheClearUnknownKey) { } TEST(PlanCacheCommandsTest, planCacheClearOneKey) { + QueryTestServiceContext serviceContext; + auto txn = serviceContext.makeOperationContext(); + // Create 2 canonical queries. auto statusWithCQA = CanonicalQuery::canonicalize( - nss, fromjson("{a: 1}"), ExtensionsCallbackDisallowExtensions()); + txn.get(), nss, fromjson("{a: 1}"), ExtensionsCallbackDisallowExtensions()); ASSERT_OK(statusWithCQA.getStatus()); unique_ptr<CanonicalQuery> cqA = std::move(statusWithCQA.getValue()); auto statusWithCQB = CanonicalQuery::canonicalize( - nss, fromjson("{b: 1}"), ExtensionsCallbackDisallowExtensions()); + txn.get(), nss, fromjson("{b: 1}"), ExtensionsCallbackDisallowExtensions()); ASSERT_OK(statusWithCQB.getStatus()); unique_ptr<CanonicalQuery> cqB = std::move(statusWithCQB.getValue()); @@ -299,10 +308,9 @@ TEST(PlanCacheCommandsTest, planCacheClearOneKey) { // Drop {b: 1} from cache. Make sure {a: 1} is still in cache afterwards. BSONObjBuilder bob; - OperationContextNoop txn; - ASSERT_OK( - PlanCacheClear::clear(&txn, &planCache, nss.ns(), BSON("query" << cqB->getQueryObj()))); + ASSERT_OK(PlanCacheClear::clear( + txn.get(), &planCache, nss.ns(), BSON("query" << cqB->getQueryObj()))); vector<BSONObj> shapesAfter = getShapes(planCache); ASSERT_EQUALS(shapesAfter.size(), 1U); ASSERT_EQUALS(shapesAfter[0], shapeA); @@ -392,9 +400,12 @@ TEST(PlanCacheCommandsTest, planCacheListPlansUnknownKey) { } TEST(PlanCacheCommandsTest, planCacheListPlansOnlyOneSolutionTrue) { + QueryTestServiceContext serviceContext; + auto txn = serviceContext.makeOperationContext(); + // Create a canonical query auto statusWithCQ = CanonicalQuery::canonicalize( - nss, fromjson("{a: 1}"), ExtensionsCallbackDisallowExtensions()); + txn.get(), nss, fromjson("{a: 1}"), ExtensionsCallbackDisallowExtensions()); ASSERT_OK(statusWithCQ.getStatus()); unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue()); @@ -412,9 +423,12 @@ TEST(PlanCacheCommandsTest, planCacheListPlansOnlyOneSolutionTrue) { } TEST(PlanCacheCommandsTest, planCacheListPlansOnlyOneSolutionFalse) { + QueryTestServiceContext serviceContext; + auto txn = serviceContext.makeOperationContext(); + // Create a canonical query auto statusWithCQ = CanonicalQuery::canonicalize( - nss, fromjson("{a: 1}"), ExtensionsCallbackDisallowExtensions()); + txn.get(), nss, fromjson("{a: 1}"), ExtensionsCallbackDisallowExtensions()); ASSERT_OK(statusWithCQ.getStatus()); unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue()); |