1
0
Fork 0

Merge branch 'mjmh' of https://github.com/triAGENS/ArangoDB into mjmh

This commit is contained in:
Jan Steemann 2014-06-16 17:09:58 +02:00
commit 02d1cf3ea4
4 changed files with 493 additions and 1 deletions

View File

@ -31,6 +31,7 @@ unittests-brief: \
unittests-config \
unittests-recovery \
unittests-boost \
unittests-shell-client-readonly\
unittests-shell-server \
unittests-shell-server-ahuacatl \
unittests-http-server \
@ -406,6 +407,7 @@ SHELL_COMMON = \
################################################################################
SHELL_SERVER_ONLY = \
@top_srcdir@/js/server/tests/shell-readonly.js \
@top_srcdir@/js/server/tests/shell-sharding-helpers.js \
@top_srcdir@/js/server/tests/shell-compaction-noncluster.js \
@top_srcdir@/js/server/tests/shell-tasks.js \
@ -548,6 +550,37 @@ unittests-shell-server-ahuacatl:
################################################################################
### @brief SHELL CLIENT TESTS
################################################################################
UNITTESTS_READONLY = $(addprefix --javascript.unit-tests ,@top_srcdir@/js/client/tests/shell-changeMode.js)
UNITTESTS_NO_READONLY = $(addprefix --javascript.unit-tests ,@top_srcdir@/js/client/tests/shell-noChangeMode.js)
.PHONY: unittests-shell-client-readonly
unittests-shell-client-readonly:
$(MAKE) start-server PID=$(PID) SERVER_START="--server.endpoint unix://$(VOCDIR)/arango.sock --server.disable-authentication true" PROTO=unix
@echo
@echo "================================================================================"
@echo "<< SHELL CLIENT READONLY >>"
@echo "================================================================================"
@echo
$(VALGRIND) @builddir@/bin/arangosh $(CLIENT_OPT) --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock $(UNITTESTS_READONLY) || test "x$(FORCE)" == "x1"
sleep 2
kill `cat $(PIDFILE)`
while test -f $(PIDFILE); do sleep 1; done
@if [ "$(VALGRIND)" != "" ]; then sleep 60; fi
@rm -rf "$(VOCDIR)"
@echo
$(MAKE) start-server PID=$(PID) SERVER_START="--server.endpoint tcp://$(VOCHOST):$(VOCPORT) --server.disable-authentication true" PROTO=http
$(VALGRIND) @builddir@/bin/arangosh $(CLIENT_OPT) --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint tcp://$(VOCHOST):$(VOCPORT) $(UNITTESTS_NO_READONLY) || test "x$(FORCE)" == "x1"
sleep 2
kill `cat $(PIDFILE)`
while test -f $(PIDFILE); do sleep 1; done
@if [ "$(VALGRIND)" != "" ]; then sleep 60; fi
@rm -rf "$(VOCDIR)"
@echo
SHELL_CLIENT_ONLY = \
@top_srcdir@/js/client/tests/shell-endpoints.js \
@ -557,7 +590,6 @@ SHELL_CLIENT_ONLY = \
SHELL_CLIENT = $(SHELL_COMMON) $(SHELL_CLIENT_ONLY)
.PHONY: unittests-shell-client
UNITTESTS_CLIENT = $(addprefix --javascript.unit-tests ,$(SHELL_CLIENT))
unittests-shell-client:

View File

@ -0,0 +1,91 @@
/*jslint indent: 2, maxlen: 120, vars: true, white: true, plusplus: true, nonpropdel: true, nomen: true, sloppy: true */
/*global require, assertEqual, assertNotEqual,
print, print_plain, COMPARE_STRING, NORMALIZE_STRING,
help, start_pager, stop_pager, start_pretty_print, stop_pretty_print, start_color_print, stop_color_print */
////////////////////////////////////////////////////////////////////////////////
/// @brief tests for client-specific functionality
///
/// @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 Esteban Lombeyda
/// @author Copyright 2014, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
var jsunity = require("jsunity");
var db = require("org/arangodb").db;
////////////////////////////////////////////////////////////////////////////////
/// @brief test suite
////////////////////////////////////////////////////////////////////////////////
function changeOperationModePositiveCaseTestSuite () {
return {
////////////////////////////////////////////////////////////////////////////////
/// @brief set up
////////////////////////////////////////////////////////////////////////////////
setUp : function () {
},
////////////////////////////////////////////////////////////////////////////////
/// @brief tear down
////////////////////////////////////////////////////////////////////////////////
tearDown : function () {
},
////////////////////////////////////////////////////////////////////////////////
/// @brief tests if the change of the operation mode of the arango server
/// can be done.
/// Note: this test needs an arango server with endpoint unix:...
/// See target unittests-shell-client-readonly
////////////////////////////////////////////////////////////////////////////////
testChangeMode : function () {
var result =
db._executeTransaction({collections: {},
action: function () {
var db = require('internal').db;
var result = db._changeMode('ReadOnly');
return result;
}
});
assertTrue(result);
}
};
}
////////////////////////////////////////////////////////////////////////////////
/// @brief executes the test suite
////////////////////////////////////////////////////////////////////////////////
jsunity.run(changeOperationModePositiveCaseTestSuite);
return jsunity.done();
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)"
// End:

View File

@ -0,0 +1,96 @@
/*jslint indent: 2, maxlen: 120, vars: true, white: true, plusplus: true, nonpropdel: true, nomen: true, sloppy: true */
/*global require, assertEqual, assertNotEqual,
print, print_plain, COMPARE_STRING, NORMALIZE_STRING,
help, start_pager, stop_pager, start_pretty_print, stop_pretty_print, start_color_print, stop_color_print */
////////////////////////////////////////////////////////////////////////////////
/// @brief tests for client-specific functionality
///
/// @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 Esteban Lombeyda
/// @author Copyright 2014, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
var jsunity = require("jsunity");
var arangodb = require("org/arangodb");
var db = arangodb.db;
////////////////////////////////////////////////////////////////////////////////
/// @brief test suite
////////////////////////////////////////////////////////////////////////////////
function changeOperationModeNegativeCaseTestSuite () {
return {
////////////////////////////////////////////////////////////////////////////////
/// @brief set up
////////////////////////////////////////////////////////////////////////////////
setUp : function () {
},
////////////////////////////////////////////////////////////////////////////////
/// @brief tear down
////////////////////////////////////////////////////////////////////////////////
tearDown : function () {
},
////////////////////////////////////////////////////////////////////////////////
/// @brief tests if the change of the operation mode of the arango server
/// can be done.
/// Note: this test needs an arango server with endpoint unix:...
/// See target unittests-shell-client-readonly
////////////////////////////////////////////////////////////////////////////////
testTryChangeMode : function () {
var modified = true;
try {
db._executeTransaction({collections: {},
action: function () {
var db = require('internal').db;
var result = db._changeMode('ReadOnly');
return result;
}
});} catch(e) {
assertEqual(arangodb.errors.ERROR_FORBIDDEN.code, e.errorNum);
modified = false;
}
assertFalse(modified);
}
};
}
////////////////////////////////////////////////////////////////////////////////
/// @brief executes the test suite
////////////////////////////////////////////////////////////////////////////////
jsunity.run(changeOperationModeNegativeCaseTestSuite);
return jsunity.done();
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)"
// End:

View File

@ -0,0 +1,273 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief tests for routing
///
/// @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 Esteban Lombeyda
/// @author Copyright 2014, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
var internal = require("internal");
var jsunity = require("jsunity");
var arangodb = require("org/arangodb");
// -----------------------------------------------------------------------------
// --SECTION-- test suite
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief single tests when server is running in ReadOnly mode
////////////////////////////////////////////////////////////////////////////////
function dropDatabaseTestSuite () {
var db;
return {
////////////////////////////////////////////////////////////////////////////////
/// @brief set up
////////////////////////////////////////////////////////////////////////////////
setUp : function () {
db = require("internal").db;
db._changeMode("Normal");
db._createDatabase("testDB");
db._changeMode("ReadOnly");
},
tearDown : function () {
try {
db._changeMode("Normal");
db._dropDatabase("testDB");
} catch (e) {
}
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test: creation of a data base in read only modes should faill
////////////////////////////////////////////////////////////////////////////////
testCreateDatabase: function () {
var not_modified = false;
try {
db._createDatabase("xxxDB");
}catch (e) {
not_modified = true;
assertEqual(arangodb.ERROR_ARANGO_READ_ONLY, e.errorNum);
}
assertTrue(not_modified);
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test: droping of a data base in read only mode should be posible
////////////////////////////////////////////////////////////////////////////////
testDropDatabase: function () {
var modified = false;
try {
db._dropDatabase("testDB");
modified = true;
}catch (e) {
not_modified = false;
}
assertTrue(modified);
},
};
}
////////////////////////////////////////////////////////////////////////////////
/// @brief single tests when server is running in ReadOnly mode
////////////////////////////////////////////////////////////////////////////////
function readOnlyDatabaseSuite () {
var db;
var collection;
return {
////////////////////////////////////////////////////////////////////////////////
/// @brief set up
////////////////////////////////////////////////////////////////////////////////
setUp : function () {
db = require("internal").db;
collection = db._createDocumentCollection("testCol");
collection.save({_key: "testDocKey", a: 2 });
db._changeMode("ReadOnly");
},
tearDown : function () {
try {
db._changeMode("Normal");
collection.drop("testCol");
} catch (e) {
print(e);
}
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test: simple routing (prefix)
////////////////////////////////////////////////////////////////////////////////
testCreateDocumentCollection: function () {
var not_modified = false;
try {
db._createDocumentCollection("abcDC");
}catch (e) {
not_modified = true;
assertEqual(arangodb.ERROR_ARANGO_READ_ONLY, e.errorNum);
}
assertTrue(not_modified);
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test: simple routing (parameter)
////////////////////////////////////////////////////////////////////////////////
testDropCollection: function () {
var not_modified = false;
try {
db._createDocumentCollection("xxxDC");
not_modified = true;
}catch (e) {
}
assertFalse(not_modified);
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test: simple routing (optional)
////////////////////////////////////////////////////////////////////////////////
testInsertDocument: function () {
var modified = false;
try {
collection.save({a:1, b:2});
modified = true;
}catch (e) {
assertEqual(arangodb.ERROR_ARANGO_READ_ONLY, e.errorNum);
}
assertFalse(modified);
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test: simple routing (optional)
////////////////////////////////////////////////////////////////////////////////
testUpdateDocument: function () {
var modified = false;
try {
collection.update("testDocKey", {name: "testing", a: 3});
modified = true;
}catch (e) {
assertEqual(arangodb.ERROR_ARANGO_READ_ONLY, e.errorNum);
}
assertFalse(modified);
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test: simple routing (prefix vs non-prefix)
////////////////////////////////////////////////////////////////////////////////
testRemoveDocument: function () {
var modified = false;
try {
var removed = collection.remove("testDocKey");
assertFalse(removed);
modified = true;
}catch (e) {
assertEqual(arangodb.ERROR_ARANGO_READ_ONLY, e.errorNum);
}
assertFalse(modified);
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test: content string
////////////////////////////////////////////////////////////////////////////////
testCreateBitArrayIndex: function () {
var modified = false;
try {
collection.ensureBitarray("a", [1,2,3,4]);
modified = true;
}catch (e) {
assertEqual(arangodb.ERROR_ARANGO_READ_ONLY, e.errorNum);
}
assertFalse(modified);
},
testCreateHashIndex: function () {
var modified = false;
try {
collection.ensureIndex({ type: "hash", fields: [ "name" ], unique: true });
modified = true;
}catch (e) {
assertEqual(arangodb.ERROR_ARANGO_READ_ONLY, e.errorNum);
}
assertFalse(modified);
},
testCreateGeoIndex: function () {
var modified = false;
try {
collection.ensureIndex({ type: "geo1", fields: [ "x" ], unique: true });
modified = true;
}catch (e) {
assertEqual(arangodb.ERROR_ARANGO_READ_ONLY, e.errorNum);
}
assertFalse(modified);
},
testCreateGeo2Index: function () {
var modified = false;
try {
collection.ensureIndex({ type: "geo2", fields: [ "x", "y" ], unique: true });
modified = true;
}catch (e) {
assertEqual(arangodb.ERROR_ARANGO_READ_ONLY, e.errorNum);
}
assertFalse(modified);
},
testCreateSkipListIndex: function () {
var modified = false;
try {
collection.ensureIndex({ type: "skiplist", fields: [ "x" ]});
modified = true;
}catch (e) {
assertEqual(arangodb.ERROR_ARANGO_READ_ONLY, e.errorNum);
}
assertFalse(modified);
},
};
}
// -----------------------------------------------------------------------------
// --SECTION-- main
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief executes the test suites
////////////////////////////////////////////////////////////////////////////////
jsunity.run(dropDatabaseTestSuite);
jsunity.run(readOnlyDatabaseSuite);
return jsunity.done();
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------
// Local Variables:
// mode: outline-minor
// outline-regexp: "\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @\\}\\)"
// End: