1
0
Fork 0

added test for cluster helper functions

This commit is contained in:
Jan Steemann 2014-01-03 16:04:40 +01:00
parent 486bdc2d41
commit a7d9b3f578
3 changed files with 153 additions and 4 deletions

View File

@ -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)

View File

@ -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) {

148
js/server/tests/cluster.js Normal file
View File

@ -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: