From 27149ee75520caf6062de66c2f409b12139f8b45 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Fri, 7 Nov 2014 15:13:55 +0100 Subject: [PATCH 1/3] documentation updates, config file updates --- CHANGELOG | 10 ++ .../Books/Users/Installing/Upgrading.mdpp | 4 +- Documentation/Books/Users/README.mdpp | 37 ++--- .../Books/Users/Upgrading/Upgrading23.mdpp | 151 +----------------- .../Users/Upgrading/UpgradingChanges23.mdpp | 31 ++++ etc/arangodb/arango-dfdb.conf.in | 1 + etc/arangodb/arangod.conf.in | 7 +- etc/relative/arango-dfdb.conf | 1 + etc/relative/arangod-coordinator.conf | 3 +- etc/relative/arangod-dbserver.conf | 3 +- etc/relative/arangod.conf | 3 +- etc/relative/dispatcher.conf | 1 + 12 files changed, 76 insertions(+), 176 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 94dc82ad54..d2665c981b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -78,6 +78,16 @@ v2.3.0-beta1 (2014-11-01) specified, the number of V8 contexts created will be equal to the number of server threads. Thus no change in configuration is required to keep the old behavior. + + However, the default configuration files shipped with ArangoDB have been changed. + The number of server threads has been increased in the configuration files, and + the number of V8 contexts is now explicitly set in the configuration files (to + the same value as the number of server threads was set to in 2.2). + + If you are using the default config files or merge them with your local config files, + please review if the higher default number of server threads is okay in your + environment. Additionally you should verify that the number of V8 contexts + created (as specified in option `--javascript.v8-contexts`) is okay. * removed index type "bitarray" diff --git a/Documentation/Books/Users/Installing/Upgrading.mdpp b/Documentation/Books/Users/Installing/Upgrading.mdpp index a6320406d8..ff693038c8 100644 --- a/Documentation/Books/Users/Installing/Upgrading.mdpp +++ b/Documentation/Books/Users/Installing/Upgrading.mdpp @@ -4,7 +4,7 @@ To upgrade an existing ArangoDB database to a newer version of ArangoDB (e.g. 1.2 to 1.3, or 2.0 to 2.1), the following method is recommended: -* Check the *CHANGELOG* for API or other changes in the new version of ArangoDB and make sure your applications can deal with them +* Check the *CHANGELOG* and the [list of incompatible changes](../Upgrading/UpgradingChanges23.html) for API or other changes in the new version of ArangoDB and make sure your applications can deal with them * Stop the "old" arangod service or binary * Copy the entire "old" data directory to a safe place (that is, a backup) * Install the new version of ArangoDB and start the server with the *--upgrade* option once. This might write to the logfile of ArangoDB, so you may want to check the logs for any issues before going on. @@ -16,4 +16,4 @@ If anything goes wrong during or shortly after the upgrade: * Revert to the "old" arangod binary and restore the "old" data directory * Start the "old" version again -It is not supported to use datafiles created or modified by a newer version of ArangoDB with an older ArangoDB version. For example, it is unsupported and is likely to cause problems when using 1.4 datafiles with an ArangoDB 1.3 instance. +It is not supported to use datafiles created or modified by a newer version of ArangoDB with an older ArangoDB version. For example, it is unsupported and is likely to cause problems when using 2.3 datafiles with an ArangoDB 2.2 instance. diff --git a/Documentation/Books/Users/README.mdpp b/Documentation/Books/Users/README.mdpp index 99374c5594..b59153f7ef 100644 --- a/Documentation/Books/Users/README.mdpp +++ b/Documentation/Books/Users/README.mdpp @@ -2,33 +2,30 @@ Welcome to the ArangoDB documentation! -The documentation introduces ArangoDB for you as an user, developer and administrator and describes all of his functions in detail. +The documentation introduces ArangoDB for you as an user, developer and administrator and describes all of its functions in detail. -ArangoDB is a multi-purpose open-source database with a flexible data -model for documents, graphs and key-values. You can easily build high -performance applications using a convenient -[SQL-like query language](../Aql/README.md) or [JavaScript](../Foxx/README.md) extensions. +ArangoDB is a multi-purpose, open-source database with flexible data models for documents, graphs, and key-values. Build high performance applications using a convenient SQL-like query language or JavaScript extensions. Use ACID transactions if you require them. Scale horizontally and vertically with a few mouse clicks. -The database server [_arangod_](../FirstSteps/Arangod.md) stores all documents and serves them -using a REST interface. There are [drivers](https://www.arangodb.com/drivers) for all major languages like -Ruby, Python, PHP, JavaScript, and Perl. In the following sections we -will use the JavaScript shell to communicate with the database and -demonstrate some of ArangoDB's features using JavaScript. +Key features include: -Some of the features and programs of ArangoDB are: - -- A powerful query language -- Open Source -- A database daemon -- An ArangoDB shell -- Flexible data modeling -- And many more! +* **Schema-free schemata** let you combine the space efficiency of MySQL with the performance power of NoSQL +* Use ArangoDB as an **application server** and fuse your application and database together for maximal throughput +* JavaScript for all: **no language zoo**, you can use one language from your browser to your back-end +* ArangoDB is **multi-threaded** - exploit the power of all your cores +* **Flexible data modelling**: model your data as combination of key-value pairs, documents or graphs - perfect for social relations +* Free **index choice**: use the correct index for your problem, be it a skip list or a fulltext search +* Configurable **durability**: let the application decide if it needs more durability or more performance +* No-nonsense storage: ArangoDB uses all of the power of **modern storage hardware**, like SSD and large caches +* **Powerful query language** (AQL) to retrieve and modify data +* **Transactions**: run queries on multiple documents or collections with optional transactional consistency and isolation +* **Replication** and **Sharding**: set up the database in a master-slave configuration or spread bigger datasets across multiple servers +* It is **open source** (Apache Licence 2.0) In this documentation you can inform yourself about all the functions, features and programs ArangoDB provides for you. -If you want to test the shell go [here](https://www.arangodb.com/shtutorial). +If you want to test the shell go [here](https://www.arangodb.com/shtutorial/). -If you want to play with our query language, go to our [AQL Tutorial](https://www.arangodb.com/shtutorial). +If you want to play with our query language, go to our [AQL Tutorial](https://www.arangodb.com/aqltutorial/). !SUBSECTION Community diff --git a/Documentation/Books/Users/Upgrading/Upgrading23.mdpp b/Documentation/Books/Users/Upgrading/Upgrading23.mdpp index 3a1ec3fd69..46bda552df 100644 --- a/Documentation/Books/Users/Upgrading/Upgrading23.mdpp +++ b/Documentation/Books/Users/Upgrading/Upgrading23.mdpp @@ -1,7 +1,8 @@ !CHAPTER Upgrading to ArangoDB 2.3 Please read the following sections if you upgrade from a previous version to -ArangoDB 2.3. +ArangoDB 2.3. Please be sure that you have checked the list of [changes in 2.3](../Upgrading/UpgradingChanges23.html) +before upgrading. Please note first that a database directory used with ArangoDB 2.3 cannot be used with earlier versions (e.g. ArangoDB 2.2) any @@ -113,151 +114,3 @@ above in the graphical front end. You have to replace `"root"` with a user name and `""` with a password that is valid for authentication with the cluster. - -!SECTION AQL: Changed behavior - -!SUBSECTION AQL queries throw less exceptions - -ArangoDB 2.3 contains a completely rewritten AQL query optimizer and execution -engine. This means that AQL queries will be executed with a different engine than -in ArangoDB 2.2 and earlier. Parts of AQL queries might be executed in different -order than before because the AQL optimizer has more freedom to move things -around in a query. - -In previous versions of ArangoDB, AQL queries aborted with an exception in many -situations and threw a runtime exception. Exceptions were thrown when trying to -find a value using the `IN` operator in a non-list element, when trying to use -non-boolean values with the logical operands `&&` or `||` or `!`, when using non-numeric -values in arithmetic operations, when passing wrong parameters into functions etc. - -In ArangoDB 2.3 this has been changed in many cases to make AQL more user-friendly -and to allow the optimization to perform much more query optimizations. - -Here is a summary of changes: -- when a non-list value is used on the right-hand side of the `IN` operator, the - result will be `false` in ArangoDB 2.3, and no exception will be thrown. -- the boolean operators `&&` and `||` do not throw in ArangoDB 2.3 if any of the - operands is not a boolean value. Instead, they will perform an implicit cast of - the values to booleans. Their result will be as follows: - - `lhs && rhs` will return `lhs` if it is `false` or would be `false` when converted - into a boolean. If `lhs` is `true` or would be `true` when converted to a boolean, - `rhs` will be returned. - - `lhs || rhs` will return 'lhs` if it is `true` or would be `true` when converted - into a boolean. If `lhs` is `false` or would be `false` when converted to a boolean, - `rhs` will be returned. - - `! value` will return the negated value of `value` converted into a boolean -- the arithmetic operators (`+`, `-`, `*`, `/`, `%`) can be applied to any value and - will not throw exceptions when applied to non-numeric values. Instead, any value used - in these operators will be casted to a numeric value implicitly. If no numeric result - can be produced by an arithmetic operator, it will return `null` in ArangoDB 2.3. This - is also true for division by zero. -- passing arguments of invalid types into AQL functions does not throw a runtime - exception in most cases, but may produce runtime warnings. Built-in AQL functions that - receive invalid arguments will then return `null`. - - -!SUBSECTION Changed return values in ArangoQueryCursor.getExtra() - -The return value of `ArangoQueryCursor.getExtra()` has been changed in ArangoDB 2.3. -It now contains a `stats` attribute with statistics about the query previously executed. -It also contains a `warnings` attribute with warnings that happened during query -execution. - -The new return value format looks like this: - -``` -arangosh> stmt = db._createStatement("FOR i IN mycollection RETURN i"); stmt.execute().getExtra() -{ - "stats" : { - "writesExecuted" : 0, - "writesIgnored" : 0, - "scannedFull" : 2600, - "scannedIndex" : 0 - }, - "warnings" : [ ] -} - -arangosh> stmt = db._createStatement("FOR i IN xx REMOVE i IN xx"); stmt.execute().getExtra() -{ - "stats" : { - "writesExecuted" : 2600, - "writesIgnored" : 0, - "scannedFull" : 2600, - "scannedIndex" : 0 - }, - "warnings" : [ ] -} -``` - -In ArangoDB 2.2, the return value of `ArangoQueryCursor.getExtra()` was empty for read-only -queries and contained two queries for data-modification queries: - -``` -arangosh> stmt = db._createStatement("FOR i IN mycollection RETURN i"); stmt.execute().getExtra() -{ -} - -arangosh> stmt = db._createStatement("FOR i IN mycollection REMOVE i IN mycollection"); stmt.execute().getExtra() -{ - "operations" : { - "executed" : 2600, - "ignored" : 0 - } -} -``` - -!SUBSECTION Changed return values in ArangoStatement.explain() - -The return value of `ArangoStatement.explain()` has been changed in ArangoDB 2.3. - -In ArangoDB 2.3, the full execution plan for an AQL query is returned alongside all -applied optimizer rules, optimization warnings etc. It is also possible to have the -optimizer return all execution plans. This required a new data structure. - -Client programs that use `ArangoStatement.explain()` or the HTTP REST API method -`POST /_api/explain` may need to be adjusted to use the new return format. - - -The return value of `ArangoStatement.parse()` has been extended in ArangoDB 2.3. -In addition to the existing attributes, ArangoDB 2.3 will also return an `ast` attribute -containing the abstract syntax tree of the statement. This extra attribute can -safely be ignored by client programs. - - -!SUBSECTION New AQL keywords - -The following keywords have been added to AQL in ArangoDB 2.3: - -- *NOT* -- *AND* -- *OR* - -Unquoted usage of these keywords for attribute names in AQL queries will likely -fail in ArangoDB 2.3. If any such attribute name needs to be used in a query, it -should be enclosed in backticks to indicate the usage of a literal attribute -name. - - -!SECTION Removed features - -!SUBSECTION Bitarray indexes - -Bitarray indexes were only half-way documented and integrated in previous versions -of ArangoDB so their benefit was limited. The support for bitarray indexes has -thus been removed in ArangoDB 2.3. It is not possible to create indexes of type -"bitarray" with ArangoDB 2.3. - -When a collection is openend that contains a bitarray index definition created -with a previous version of ArangoDB, ArangoDB will ignore it and log the following -warning: - - index type 'bitarray' is not supported in this version of ArangoDB and is ignored - -Future versions of ArangoDB may automatically remove such index definitions so the -warnings will eventually disappear. - - -!SUBSECTION Other removed features - -The HTTP API method at `POST /_admin/modules/flush` has been removed. - diff --git a/Documentation/Books/Users/Upgrading/UpgradingChanges23.mdpp b/Documentation/Books/Users/Upgrading/UpgradingChanges23.mdpp index 7d4744fa04..910a05cf64 100644 --- a/Documentation/Books/Users/Upgrading/UpgradingChanges23.mdpp +++ b/Documentation/Books/Users/Upgrading/UpgradingChanges23.mdpp @@ -4,6 +4,37 @@ It is recommended to check the following list of incompatible changes **before** upgrading to ArangoDB 2.3, and adjust any client programs if necessary. +!SECTION Default configuration file changes + +With ArangoDB 2.3, the number of server threads can be configured independently of +the number of V8 contexts. The configuration option `--javascript.v8-contexts` was +added to arangod to provide better control over the number of V8 contexts created +in arangod. + +Previously, the number of V8 contexts arangod created at startup was equal +to the number of server threads (as specified by option `--server.threads`). + +In some situations it may be more sensible to create different amounts of threads +and V8 contexts. This is because each V8 contexts created will consume memory +and requires CPU resources for periodic garbage collection. Contrary, server +threads do not have such high memory or CPU footprint. + +If the option `--javascript.v8-contexts` is not specified, the number of V8 +contexts created at startup will remain equal to the number of server threads. +Thus no change in configuration is required to keep the same behavior as in +previous ArangoDB versions. + +However, the default configuration files shipped with ArangoDB have been changed. +The number of server threads has been increased in the configuration files, and +the number of V8 contexts is now explicitly set in the configuration files (to +the same value as the number of server threads was set to in 2.2). + +If you are using the default config files or merge them with your local config files, +please review if the higher default number of server threads is okay in your +environment. Additionally you should verify that the number of V8 contexts +created (as specified in option `--javascript.v8-contexts`) is okay. + + !SECTION AQL !SUBSECTION AQL queries throw less exceptions diff --git a/etc/arangodb/arango-dfdb.conf.in b/etc/arangodb/arango-dfdb.conf.in index 197ceac1c8..67917016b2 100644 --- a/etc/arangodb/arango-dfdb.conf.in +++ b/etc/arangodb/arango-dfdb.conf.in @@ -15,6 +15,7 @@ threads = 1 startup-directory = @PKGDATADIR@/js app-path = @LOCALSTATEDIR@/lib/arangodb-apps script = @PKGDATADIR@/js/server/arango-dfdb.js +v8-contexts = 1 [log] level = info diff --git a/etc/arangodb/arangod.conf.in b/etc/arangodb/arangod.conf.in index a0e360f65a..89eb83104b 100644 --- a/etc/arangodb/arangod.conf.in +++ b/etc/arangodb/arangod.conf.in @@ -34,8 +34,8 @@ endpoint = tcp://0.0.0.0:8529 # disable authentication for the admin frontend disable-authentication = yes -# number of worker threads for V8 -threads = 5 +# number of server threads +threads = 10 # the user and group are normally set in the start script # uid = arangodb @@ -49,6 +49,9 @@ startup-directory = @PKGDATADIR@/js app-path = @LOCALSTATEDIR@/lib/arangodb-apps # app-path = @HOMEDRIVE@/@HOMEPATH@/arangodb/apps +# number of worker threads for V8 +v8-contexts = 5 + [log] level = info severity = human diff --git a/etc/relative/arango-dfdb.conf b/etc/relative/arango-dfdb.conf index 9a97889763..69f8e9ef9f 100644 --- a/etc/relative/arango-dfdb.conf +++ b/etc/relative/arango-dfdb.conf @@ -14,6 +14,7 @@ threads = 1 startup-directory = ./js app-path = ./js/apps script = ./js/server/arango-dfdb.js +v8-contexts = 1 [ruby] modules-path = ./mr diff --git a/etc/relative/arangod-coordinator.conf b/etc/relative/arangod-coordinator.conf index 275e64c6d4..db23dfdbfb 100644 --- a/etc/relative/arangod-coordinator.conf +++ b/etc/relative/arangod-coordinator.conf @@ -5,7 +5,7 @@ [server] disable-authentication = true endpoint = tcp://localhost:8529 -threads = 5 +threads = 10 keyfile = UnitTests/server.pem # reuse-address = false @@ -16,6 +16,7 @@ threads = 3 startup-directory = ./js app-path = ./js/apps frontend-development = false +v8-contexts = 5 [ruby] action-directory = ./mr/actions/system diff --git a/etc/relative/arangod-dbserver.conf b/etc/relative/arangod-dbserver.conf index 275e64c6d4..db23dfdbfb 100644 --- a/etc/relative/arangod-dbserver.conf +++ b/etc/relative/arangod-dbserver.conf @@ -5,7 +5,7 @@ [server] disable-authentication = true endpoint = tcp://localhost:8529 -threads = 5 +threads = 10 keyfile = UnitTests/server.pem # reuse-address = false @@ -16,6 +16,7 @@ threads = 3 startup-directory = ./js app-path = ./js/apps frontend-development = false +v8-contexts = 5 [ruby] action-directory = ./mr/actions/system diff --git a/etc/relative/arangod.conf b/etc/relative/arangod.conf index b2fa46d57e..b4038cc82f 100644 --- a/etc/relative/arangod.conf +++ b/etc/relative/arangod.conf @@ -5,7 +5,7 @@ [server] disable-authentication = true endpoint = tcp://localhost:8529 -threads = 5 +threads = 10 # reuse-address = false [scheduler] @@ -15,6 +15,7 @@ threads = 3 startup-directory = ./js app-path = ./js/apps frontend-development = false +v8-contexts = 5 [ruby] action-directory = ./mr/actions/system diff --git a/etc/relative/dispatcher.conf b/etc/relative/dispatcher.conf index e16c904f10..2f2bdc8317 100644 --- a/etc/relative/dispatcher.conf +++ b/etc/relative/dispatcher.conf @@ -15,6 +15,7 @@ threads = 3 startup-directory = ./js app-path = ./js/apps frontend-development = false +v8-contexts = 4 [ruby] action-directory = ./mr/actions/system From af257d45cda3eb05ef916285f43885fedf5f4198 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Fri, 7 Nov 2014 15:28:40 +0100 Subject: [PATCH 2/3] removed debug output --- js/apps/system/aardvark/aardvark.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/apps/system/aardvark/aardvark.js b/js/apps/system/aardvark/aardvark.js index fca0da4914..9535b8bf69 100644 --- a/js/apps/system/aardvark/aardvark.js +++ b/js/apps/system/aardvark/aardvark.js @@ -424,7 +424,6 @@ controller.get("/query/result/download/:query", function(req, res) { var internal = require("internal"); query = internal.base64Decode(query); -internal.print(query); try { parsedQuery = JSON.parse(query); } From f72554d01e70439353e11c614078f63b2522c781 Mon Sep 17 00:00:00 2001 From: scottashton Date: Fri, 7 Nov 2014 15:55:41 +0100 Subject: [PATCH 3/3] added tests for aql functions within-rectangle and is-in-polygon --- js/server/tests/aql-is-in-polygon.js | 97 ++++++++++++++++ js/server/tests/aql-within-rectangle.js | 147 ++++++++++++++++++++++++ 2 files changed, 244 insertions(+) create mode 100644 js/server/tests/aql-is-in-polygon.js create mode 100644 js/server/tests/aql-within-rectangle.js diff --git a/js/server/tests/aql-is-in-polygon.js b/js/server/tests/aql-is-in-polygon.js new file mode 100644 index 0000000000..729527d47b --- /dev/null +++ b/js/server/tests/aql-is-in-polygon.js @@ -0,0 +1,97 @@ +/*jshint strict: false, maxlen: 500 */ +/*global require, AQL_EXECUTE, assertTrue */ + +//////////////////////////////////////////////////////////////////////////////// +/// @brief tests for optimizer rules +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2010-2014 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 Florian Bartels +/// @author Copyright 2014, triAGENS GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +var jsunity = require("jsunity"); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test suite +//////////////////////////////////////////////////////////////////////////////// + +function isInPolygonSuite () { + + return { + +//////////////////////////////////////////////////////////////////////////////// +/// @brief set up +//////////////////////////////////////////////////////////////////////////////// + + setUp : function () { + + + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief tear down +//////////////////////////////////////////////////////////////////////////////// + + tearDown : function () { + + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test WITHIN_RECTANGLE as result +//////////////////////////////////////////////////////////////////////////////// + + testIsInPolygonSuiteAsResult : function () { + assertTrue(AQL_EXECUTE("RETURN IS_IN_POLYGON ([[ 0, 0 ], [ 0, 10 ], [ 10, 10 ], [ 10, 0 ] ], 10, 9)").json[0]); + } + /* + testIsNotInPolygonSuiteAsResult : function () { + assertFalse(AQL_EXECUTE("RETURN IS_IN_POLYGON ([[ 0, 0 ], [ 0, 10 ], [ 10, 10 ], [ 10, 0 ] ], 10, 11)").json[0]); + }, + + testIsInPolygonSuiteWithListParameter : function () { + assertTrue(AQL_EXECUTE("RETURN IS_IN_POLYGON ([[ 0, 0 ], [ 0, 10 ], [ 10, 10 ], [ 11, 0 ] ], [ 11, 0 ])").json[0]); + }, + + testIsInPolygonSuiteWithListParameterWithReverseParameterOrder : function () { + assertFalse(AQL_EXECUTE("RETURN IS_IN_POLYGON ([[ 0, 0 ], [ 0, 10 ], [ 10, 10 ], [ 11, 0 ] ], [ 0, 11 ], false)").json[0]); + }, + + testIsInPolygonSuiteWithSinglePointPolygon : function () { + assertTrue(AQL_EXECUTE("RETURN IS_IN_POLYGON ([[ 0, 0 ]], [ 0, 0 ])").json[0]); + }*/ + + + }; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief executes the test suite +//////////////////////////////////////////////////////////////////////////////// + +jsunity.run(isInPolygonSuite); + +return jsunity.done(); + +// Local Variables: +// mode: outline-minor +// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)" +// End: diff --git a/js/server/tests/aql-within-rectangle.js b/js/server/tests/aql-within-rectangle.js new file mode 100644 index 0000000000..3355588592 --- /dev/null +++ b/js/server/tests/aql-within-rectangle.js @@ -0,0 +1,147 @@ +/*jshint strict: false, maxlen: 500 */ +/*global require, assertEqual, AQL_EXECUTE, assertTrue, fail */ + +//////////////////////////////////////////////////////////////////////////////// +/// @brief tests for optimizer rules +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2010-2014 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 Florian Bartels +/// @author Copyright 2014, triAGENS GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +var jsunity = require("jsunity"); +var internal = require("internal"); +var errors = internal.errors; +var db = require("org/arangodb").db, indexId; + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test suite +//////////////////////////////////////////////////////////////////////////////// + +function withinRectangleSuite () { + + return { + +//////////////////////////////////////////////////////////////////////////////// +/// @brief set up +//////////////////////////////////////////////////////////////////////////////// + + setUp : function () { + + var i, j ; + db._create("geo"); + indexId = db.geo.ensureGeoIndex("lat", "lon"); + + for (i = -40; i < 40; ++i) { + for (j = -40; j < 40; ++j) { + db.geo.save({ lat: i, lon: j }); + } + } + + db._create("geo2"); + indexId = db.geo2.ensureGeoIndex("pos"); + + for (i = -40; i < 40; ++i) { + for (j = -40; j < 40; ++j) { + db.geo2.save({ pos : [i, j] }); + } + } + + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief tear down +//////////////////////////////////////////////////////////////////////////////// + + tearDown : function () { + db._drop("geo"); + db._drop("geo2"); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test WITHIN_RECTANGLE as result +//////////////////////////////////////////////////////////////////////////////// + + testWithinRectangleAsResult : function () { + var actual =AQL_EXECUTE("RETURN WITHIN_RECTANGLE(geo, -1, -1, 1, 1)").json[0]; + assertEqual(actual.length , 9); + }, + + testWithinRectangleAsResultForSingleDocument : function () { + var actual =AQL_EXECUTE("RETURN WITHIN_RECTANGLE(geo, -0.8, -1.2, -1.2, -0.8)").json[0]; + assertEqual(actual.length , 1); + }, + + testWithinRectangleAsResultForMissingDocument : function () { + var actual =AQL_EXECUTE("RETURN WITHIN_RECTANGLE(geo, -41, -41, -41, -41)").json[0]; + assertEqual(actual.length , 0); + }, + + testWithinRectangleAsResultForUnknownCollection : function () { + try { + AQL_EXECUTE("RETURN WITHIN_RECTANGLE(unknown, -41, -41, -41, -41)"); + fail(); + } catch (e) { + assertTrue(e.errorNum === errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code); + } + }, + + testWithinRectangleAsResultForCollectionWithoutGeoIndex : function () { + try { + AQL_EXECUTE("RETURN WITHIN_RECTANGLE(_graphs, -41, -41, -41, -41)"); + fail(); + } catch (e) { + assertTrue(e.errorNum === errors.ERROR_QUERY_GEO_INDEX_MISSING.code); + } + + }, + + testWithinRectangleAsResultWithPositionBasedGeoIndex : function () { + var actual =AQL_EXECUTE("RETURN WITHIN_RECTANGLE(geo2, -1, -1, 1, 1)").json[0]; + assertEqual(actual.length , 9); + }, + + testWithinRectangleAsResultForSingleDocumentWithPositionBasedGeoIndex : function () { + var actual =AQL_EXECUTE("RETURN WITHIN_RECTANGLE(geo2, -0.8, -1.2, -1.2, -0.8)").json[0]; + assertEqual(actual.length , 1); + }, + + testWithinRectangleAsResultForMissingDocumentWithPositionBasedGeoIndex : function () { + var actual =AQL_EXECUTE("RETURN WITHIN_RECTANGLE(geo2, -41, -41, -41, -41)").json[0]; + assertEqual(actual.length , 0); + } + + }; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief executes the test suite +//////////////////////////////////////////////////////////////////////////////// + +jsunity.run(withinRectangleSuite); + +return jsunity.done(); + +// Local Variables: +// mode: outline-minor +// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)" +// End: