From a7d9b3f5783838f2a39c92c14c65ae8510b778ef Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Fri, 3 Jan 2014 16:04:40 +0100 Subject: [PATCH] added test for cluster helper functions --- UnitTests/Makefile.unittests | 3 +- js/server/modules/org/arangodb/cluster.js | 6 +- js/server/tests/cluster.js | 148 ++++++++++++++++++++++ 3 files changed, 153 insertions(+), 4 deletions(-) create mode 100644 js/server/tests/cluster.js diff --git a/UnitTests/Makefile.unittests b/UnitTests/Makefile.unittests index bdfdee4396..62f676733c 100755 --- a/UnitTests/Makefile.unittests +++ b/UnitTests/Makefile.unittests @@ -410,7 +410,8 @@ SHELL_SERVER_ONLY = \ if ENABLE_CLUSTER SHELL_SERVER_ONLY += \ - @top_srcdir@/js/server/tests/agency.js + @top_srcdir@/js/server/tests/agency.js \ + @top_srcdir@/js/server/tests/cluster.js endif SHELL_SERVER = $(SHELL_COMMON) $(SHELL_SERVER_ONLY) diff --git a/js/server/modules/org/arangodb/cluster.js b/js/server/modules/org/arangodb/cluster.js index 777fab11be..6e4ced8e58 100644 --- a/js/server/modules/org/arangodb/cluster.js +++ b/js/server/modules/org/arangodb/cluster.js @@ -37,7 +37,7 @@ var isCoordinator = function () { return false; } - return ArangoServerState.isCoordinator(); + return (new ArangoServerState).isCoordinator(); }; var role = function () { @@ -45,7 +45,7 @@ var role = function () { return undefined; } - return ArangoServerState.role(); + return (new ArangoServerState).role(); }; var status = function () { @@ -53,7 +53,7 @@ var status = function () { return undefined; } - return ArangoServerState.status(); + return (new ArangoServerState).status(); }; var isCoordinatorRequest = function (req) { diff --git a/js/server/tests/cluster.js b/js/server/tests/cluster.js new file mode 100644 index 0000000000..c3e50cebfa --- /dev/null +++ b/js/server/tests/cluster.js @@ -0,0 +1,148 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief test the cluster helper functions +/// +/// @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 2013, triAGENS GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +var cluster = require("org/arangodb/cluster"); +var jsunity = require("jsunity"); + +// ----------------------------------------------------------------------------- +// --SECTION-- cluster +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test suite: cluster enabled +//////////////////////////////////////////////////////////////////////////////// + +function ClusterEnabledSuite () { + return { + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test isCluster +//////////////////////////////////////////////////////////////////////////////// + + testIsCluster : function () { + assertTrue(cluster.isCluster()); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test role +//////////////////////////////////////////////////////////////////////////////// + + testRole : function () { + assertTrue(cluster.role() !== undefined); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test status +//////////////////////////////////////////////////////////////////////////////// + + testStatus : function () { + assertTrue(cluster.status() !== undefined); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test isCoordinatorRequest +//////////////////////////////////////////////////////////////////////////////// + + testIsCoordinatorRequest : function () { + assertFalse(cluster.isCoordinatorRequest(null)); + assertFalse(cluster.isCoordinatorRequest(undefined)); + assertFalse(cluster.isCoordinatorRequest({ })); + assertFalse(cluster.isCoordinatorRequest({ headers: { } })); + assertFalse(cluster.isCoordinatorRequest({ headers: { test: "" } })); + assertTrue(cluster.isCoordinatorRequest({ headers: { "x-arango-coordinator": "abc" } })); + } + }; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test suite: cluster disabled +//////////////////////////////////////////////////////////////////////////////// + +function ClusterDisabledSuite () { + return { + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test isCluster +//////////////////////////////////////////////////////////////////////////////// + + testIsCluster : function () { + assertFalse(cluster.isCluster()); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test role +//////////////////////////////////////////////////////////////////////////////// + + testRole : function () { + assertTrue(cluster.role() === undefined); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test status +//////////////////////////////////////////////////////////////////////////////// + + testStatus : function () { + assertTrue(cluster.status() === undefined); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test isCoordinatorRequest +//////////////////////////////////////////////////////////////////////////////// + + testIsCoordinatorRequest : function () { + assertFalse(cluster.isCoordinatorRequest(null)); + assertFalse(cluster.isCoordinatorRequest(undefined)); + assertFalse(cluster.isCoordinatorRequest({ })); + assertFalse(cluster.isCoordinatorRequest({ headers: { } })); + assertFalse(cluster.isCoordinatorRequest({ headers: { test: "" } })); + assertTrue(cluster.isCoordinatorRequest({ headers: { "x-arango-coordinator": "abc" } })); + } + }; +} + +// ----------------------------------------------------------------------------- +// --SECTION-- main +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief executes the test suites +//////////////////////////////////////////////////////////////////////////////// + +if (cluster.isCluster()) { + jsunity.run(ClusterEnabledSuite); +} +else { + jsunity.run(ClusterDisabledSuite); +} + +return jsunity.done(); + +// Local Variables: +// mode: outline-minor +// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)" +// End: +