From 02c26720a46bdb6e2048600d9b4c31ef31927fac Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Mon, 27 Oct 2014 17:10:25 +0100 Subject: [PATCH] fixed test --- UnitTests/Makefile.unittests | 2 +- ...erchange-adjacent-enumerations-cluster.js} | 0 ...change-adjacent-enumerations-noncluster.js | 219 ++++++++++++++++++ 3 files changed, 220 insertions(+), 1 deletion(-) rename js/server/tests/{aql-optimizer-rule-interchange-adjacent-enumerations.js => aql-optimizer-rule-interchange-adjacent-enumerations-cluster.js} (100%) create mode 100644 js/server/tests/aql-optimizer-rule-interchange-adjacent-enumerations-noncluster.js diff --git a/UnitTests/Makefile.unittests b/UnitTests/Makefile.unittests index a6aeb30706..1362bd84aa 100755 --- a/UnitTests/Makefile.unittests +++ b/UnitTests/Makefile.unittests @@ -618,7 +618,7 @@ SHELL_SERVER_AQL = @top_srcdir@/js/server/tests/aql-arithmetic.js \ @top_srcdir@/js/server/tests/aql-modify-noncluster-serializetest.js \ @top_srcdir@/js/server/tests/aql-operators.js \ @top_srcdir@/js/server/tests/aql-optimizer-dynamic-bounds.js \ - @top_srcdir@/js/server/tests/aql-optimizer-rule-interchange-adjacent-enumerations.js \ + @top_srcdir@/js/server/tests/aql-optimizer-rule-interchange-adjacent-enumerations-noncluster.js \ @top_srcdir@/js/server/tests/aql-optimizer-rule-move-calculations-up.js \ @top_srcdir@/js/server/tests/aql-optimizer-rule-move-filters-up.js \ @top_srcdir@/js/server/tests/aql-optimizer-rule-remove-redundant-calculations.js \ diff --git a/js/server/tests/aql-optimizer-rule-interchange-adjacent-enumerations.js b/js/server/tests/aql-optimizer-rule-interchange-adjacent-enumerations-cluster.js similarity index 100% rename from js/server/tests/aql-optimizer-rule-interchange-adjacent-enumerations.js rename to js/server/tests/aql-optimizer-rule-interchange-adjacent-enumerations-cluster.js diff --git a/js/server/tests/aql-optimizer-rule-interchange-adjacent-enumerations-noncluster.js b/js/server/tests/aql-optimizer-rule-interchange-adjacent-enumerations-noncluster.js new file mode 100644 index 0000000000..2babefbadb --- /dev/null +++ b/js/server/tests/aql-optimizer-rule-interchange-adjacent-enumerations-noncluster.js @@ -0,0 +1,219 @@ +/*global _, require, exports, assertTrue, assertEqual, AQL_EXECUTE, AQL_EXPLAIN */ +//////////////////////////////////////////////////////////////////////////////// +/// @brief tests for optimizer rules +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2010-2012 triagens GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is triAGENS GmbH, Cologne, Germany +/// +/// @author Jan Steemann +/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +var jsunity = require("jsunity"); +var errors = require("internal").errors; +var helper = require("org/arangodb/aql-helper"); +var getQueryResults = helper.getQueryResults2; +var assertQueryError = helper.assertQueryError2; +var isEqual = helper.isEqual; +var db = require("org/arangodb").db; +var _ = require("underscore"); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test suite +//////////////////////////////////////////////////////////////////////////////// + +function optimizerRuleTestSuite () { + var ruleName = "interchange-adjacent-enumerations"; + + // various choices to control the optimizer: + var paramNone = { optimizer: { rules: [ "-all" ] } }; + var paramEnabled = { optimizer: { rules: [ "-all", "+" + ruleName ] } }; + var paramDisabled = { optimizer: { rules: [ "+all", "-" + ruleName ] } }; + + var collection = null; + var collectionName = "UnitTestsAhuacatlOptimizer"; + + return { + +//////////////////////////////////////////////////////////////////////////////// +/// @brief set up +//////////////////////////////////////////////////////////////////////////////// + + setUp : function () { + db._drop(collectionName); + collection = db._create(collectionName); + + for (var i = 0; i < 10; ++i) { + collection.save({ value: i }); + } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief tear down +//////////////////////////////////////////////////////////////////////////////// + + tearDown : function () { + db._drop(collectionName); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test that rule has no effect when explicitly disabled +//////////////////////////////////////////////////////////////////////////////// + + testRuleDisabled : function () { + var queries = [ + "FOR i IN " + collectionName + " FOR j IN " + collectionName + " RETURN 1", + "FOR j IN " + collectionName + " FILTER j.i == 1 FOR i IN " + collectionName + " RETURN j" + ]; + + var opts = _.clone(paramNone); + opts.allPlans = true; + opts.verbosePlans = true; + + queries.forEach(function(query) { + var result = AQL_EXPLAIN(query, { }, opts); + result.plans.forEach(function(plan) { + assertEqual([ ], plan.rules); + }); + }); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test that rule has no effect +//////////////////////////////////////////////////////////////////////////////// + + testRuleNoEffect : function () { + var queries = [ + "FOR i IN 1..10 RETURN i", + "FOR i IN " + collectionName + " RETURN i", + "FOR i IN " + collectionName + " FILTER i == 1 FOR j IN " + collectionName + " RETURN i", + "FOR i IN " + collectionName + " LIMIT 1 FOR j IN " + collectionName + " RETURN i", + "FOR i IN " + collectionName + " RETURN (FOR j IN " + collectionName + " RETURN j)" + ]; + + var opts = _.clone(paramEnabled); + opts.allPlans = true; + opts.verbosePlans = true; + + queries.forEach(function(query) { + var result = AQL_EXPLAIN(query, { }, opts); + result.plans.forEach(function(plan) { + assertTrue(plan.rules.indexOf(ruleName) === -1, query); + }); + }); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test that rule has an effect +//////////////////////////////////////////////////////////////////////////////// + + testRuleHasEffect : function () { + var queries = [ + [ "FOR i IN " + collectionName + " FOR j IN " + collectionName + " RETURN i", 1 ], + [ "FOR i IN 1..10 FOR j IN " + collectionName + " FOR k IN " + collectionName + " RETURN i", 1 ], + [ "FOR i IN " + collectionName + " FOR j IN " + collectionName + " FOR k IN " + collectionName + " RETURN i", 5 ], + [ "FOR i IN " + collectionName + " FOR j IN " + collectionName + " FOR k IN " + collectionName + " FOR l IN " + collectionName + " RETURN i", 23 ], + [ "FOR x IN (FOR i IN " + collectionName + " FOR j IN " + collectionName + " RETURN i) RETURN x", 1 ], + [ "FOR x IN (FOR i IN " + collectionName + " FOR j IN " + collectionName + " FOR k IN " + collectionName + " RETURN i) RETURN x", 5 ], + [ "FOR x IN (FOR i IN " + collectionName + " FOR j IN " + collectionName + " FOR k IN " + collectionName + " RETURN i) FOR y IN (FOR i IN " + collectionName + " FOR j IN " + collectionName + " RETURN i) RETURN x", 11 ] + ]; + + var opts = _.clone(paramEnabled); + opts.allPlans = true; + opts.verbosePlans = true; + + queries.forEach(function(query) { + var withRule = 0; + var withoutRule = 0; + + var result = AQL_EXPLAIN(query[0], { }, opts); + result.plans.forEach(function(plan) { + if (plan.rules.indexOf(ruleName) === -1) { + withoutRule++; + } + else { + withRule++; + } + }); + + // there should still be the original plan + assertEqual(1, withoutRule, query[0]); + + // put there should also be permuted plans + assertEqual(query[1], withRule, query[0]); + }); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test results +//////////////////////////////////////////////////////////////////////////////// + + testResults : function () { + var queries = [ + [ "FOR i IN " + collectionName + " FOR j IN " + collectionName + " SORT i.value, j.value FILTER i.value == j.value RETURN i.value", [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ], + [ "FOR j IN " + collectionName + " FOR i IN " + collectionName + " SORT i.value, j.value FILTER i.value == j.value RETURN i.value", [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ], + [ "FOR x IN (FOR i IN " + collectionName + " FOR j IN " + collectionName + " RETURN { i: i.value, j: j.value }) FILTER x.i == x.j SORT x.i RETURN x.i", [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ] + ]; + + var opts = _.clone(paramEnabled); + opts.allPlans = true; + opts.verbosePlans = true; + + queries.forEach(function(query) { + var planDisabled = AQL_EXPLAIN(query[0], { }, paramDisabled); + var plansEnabled = AQL_EXPLAIN(query[0], { }, opts); + var resultDisabled = AQL_EXECUTE(query[0], { }, paramDisabled).json; + + assertTrue(planDisabled.plan.rules.indexOf(ruleName) === -1, query[0]); + assertEqual(resultDisabled, query[1]); + + assertTrue(plansEnabled.plans.length > 1); + + // iterate over all plans + var withRule = 0; + plansEnabled.plans.forEach(function(plan) { + var resultEnabled = AQL_EXECUTEJSON(plan).json; + assertTrue(isEqual(resultDisabled, resultEnabled), query[0]); + if (plan.rules.indexOf(ruleName) !== -1) { + withRule++; + } + assertEqual(resultEnabled, query[1]); + }); + + assertTrue(withRule > 0); + + }); + } + + }; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief executes the test suite +//////////////////////////////////////////////////////////////////////////////// + +jsunity.run(optimizerRuleTestSuite); + +return jsunity.done(); + +// Local Variables: +// mode: outline-minor +// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)" +// End: