From cb016351e867c02f4c51c660ba6f6ee651d41f2b Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Wed, 11 Apr 2012 15:41:00 +0200 Subject: [PATCH] documentation and minor fixes --- .../shell_collection-properties | 2 + .../shell_collection-properties-change | 2 + .../Examples.Durham/shell_create-collection | 4 + .../shell_create-collection-properties | 4 + .../Examples.Durham/shell_read-collection-all | 4 + .../Examples.Durham/shell_read-collection-id | 2 +- .../shell_read-collection-name | 2 +- .../shell_read-collection-short-cut | 2 + Makefile.files | 1 + RestServer/ref-manual.dox | 11 +- RestServer/rest-document.dox | 12 +- RestServer/shell-collection.dox | 20 ++ V8/v8-line-editor.cpp | 2 +- V8/v8-vocbase.cpp | 73 ++++- VocBase/collection.c | 2 +- VocBase/vocbase.c | 18 ++ js/actions/system/api-collection.js | 92 +++--- js/actions/system/api-index.js | 4 +- js/actions/system/api-system.js | 33 +- js/common/modules/jsunity.js | 1 + js/server/tests/shell-collection.js | 291 ++++++++++++++++++ .../{shell-documents.js => shell-document.js} | 16 +- 22 files changed, 501 insertions(+), 97 deletions(-) create mode 100644 Doxygen/Examples.Durham/shell_collection-properties create mode 100644 Doxygen/Examples.Durham/shell_collection-properties-change create mode 100644 Doxygen/Examples.Durham/shell_create-collection create mode 100644 Doxygen/Examples.Durham/shell_create-collection-properties create mode 100644 Doxygen/Examples.Durham/shell_read-collection-all create mode 100644 Doxygen/Examples.Durham/shell_read-collection-short-cut create mode 100644 js/server/tests/shell-collection.js rename js/server/tests/{shell-documents.js => shell-document.js} (97%) diff --git a/Doxygen/Examples.Durham/shell_collection-properties b/Doxygen/Examples.Durham/shell_collection-properties new file mode 100644 index 0000000000..98b1f89a21 --- /dev/null +++ b/Doxygen/Examples.Durham/shell_collection-properties @@ -0,0 +1,2 @@ +avocado> db.examples.properties() +{ "waitForSync" : false, "journalSize" : 33554432 } diff --git a/Doxygen/Examples.Durham/shell_collection-properties-change b/Doxygen/Examples.Durham/shell_collection-properties-change new file mode 100644 index 0000000000..4a1455deec --- /dev/null +++ b/Doxygen/Examples.Durham/shell_collection-properties-change @@ -0,0 +1,2 @@ +avocado> db.examples.properties({ waitForSync : false }) +{ "waitForSync" : false, "journalSize" : 33554432 } diff --git a/Doxygen/Examples.Durham/shell_create-collection b/Doxygen/Examples.Durham/shell_create-collection new file mode 100644 index 0000000000..d7f48abc1a --- /dev/null +++ b/Doxygen/Examples.Durham/shell_create-collection @@ -0,0 +1,4 @@ +avocado> c = db._create("cars"); +[AvocadoCollection 111137, "cars" (status loaded)] +avocado> c.properties() +{ "waitForSync" : false, "journalSize" : 33554432 } diff --git a/Doxygen/Examples.Durham/shell_create-collection-properties b/Doxygen/Examples.Durham/shell_create-collection-properties new file mode 100644 index 0000000000..7bb815d830 --- /dev/null +++ b/Doxygen/Examples.Durham/shell_create-collection-properties @@ -0,0 +1,4 @@ +avocado> c = db._create("cars", { waitForSync : true, journalSize : 1024 * 1204 }); +[AvocadoCollection 96384, "cars" (status loaded)] +avocado> c.properties() +{ "waitForSync" : true, "journalSize" : 1232896 } diff --git a/Doxygen/Examples.Durham/shell_read-collection-all b/Doxygen/Examples.Durham/shell_read-collection-all new file mode 100644 index 0000000000..b67bf2c18f --- /dev/null +++ b/Doxygen/Examples.Durham/shell_read-collection-all @@ -0,0 +1,4 @@ +avocado> db.examples.load(); +avocado> var d = db.demo; +avocado> db._collections(); +[[AvocadoCollection 96393, "examples" (status loaded)], [AvocadoCollection 1407113, "demo" (status new born)]] diff --git a/Doxygen/Examples.Durham/shell_read-collection-id b/Doxygen/Examples.Durham/shell_read-collection-id index 216ba5b9fc..97094293ef 100644 --- a/Doxygen/Examples.Durham/shell_read-collection-id +++ b/Doxygen/Examples.Durham/shell_read-collection-id @@ -1,2 +1,2 @@ -avocado> db._collection(145387) +avocado> db._collection(145387); [AvocadoCollection 145387, "demo" (status loaded)] diff --git a/Doxygen/Examples.Durham/shell_read-collection-name b/Doxygen/Examples.Durham/shell_read-collection-name index a1bbcf7dd6..81715dee32 100644 --- a/Doxygen/Examples.Durham/shell_read-collection-name +++ b/Doxygen/Examples.Durham/shell_read-collection-name @@ -1,2 +1,2 @@ -avocado> db._collection("demo") +avocado> db._collection("demo"); [AvocadoCollection 145387, "demo" (status loaded)] diff --git a/Doxygen/Examples.Durham/shell_read-collection-short-cut b/Doxygen/Examples.Durham/shell_read-collection-short-cut new file mode 100644 index 0000000000..feb6ee01fa --- /dev/null +++ b/Doxygen/Examples.Durham/shell_read-collection-short-cut @@ -0,0 +1,2 @@ +avocado> db.examples; +[AvocadoCollection 110371, "examples" (status new born)] diff --git a/Makefile.files b/Makefile.files index 8f0e00b297..ca2b5c5064 100644 --- a/Makefile.files +++ b/Makefile.files @@ -313,6 +313,7 @@ WIKI = \ HttpCollection \ HttpIndex \ HttpInterface \ + HttpSystem \ IndexGeo \ IndexHash \ IndexSkiplist \ diff --git a/RestServer/ref-manual.dox b/RestServer/ref-manual.dox index e894415c02..cc8604b828 100644 --- a/RestServer/ref-manual.dox +++ b/RestServer/ref-manual.dox @@ -44,11 +44,6 @@ ///
  • @ref Indexes /// @copydetails IndexesTOC ///
  • -///
  • Shell Commands -///
      -///
    1. @ref ShellDocument
    2. -///
    -///
  • ///
  • @ref OTWP ///
      ///
    1. @ref RestDocument
    2. @@ -58,6 +53,12 @@ ///
    3. @ref HttpSystem
    4. ///
    ///
  • +///
  • Shell Commands +///
      +///
    1. @ref ShellDocument
    2. +///
    3. @ref ShellCollection
    4. +///
    +///
  • /// //////////////////////////////////////////////////////////////////////////////// diff --git a/RestServer/rest-document.dox b/RestServer/rest-document.dox index 444c8643d5..b1c4bce6f7 100644 --- a/RestServer/rest-document.dox +++ b/RestServer/rest-document.dox @@ -41,12 +41,12 @@ /// @page RestDocumentCallsTOC /// ///
      -///
    1. @ref RestDocumentRead "GET /document/@FA{document-handle}"
    2. -///
    3. @ref RestDocumentCreate "POST /document?collection=@FA{collection-identifier}"
    4. -///
    5. @ref RestDocumentUpdate "PUT /document/@FA{document-handle}"
    6. -///
    7. @ref RestDocumentDelete "DELETE /document/@FA{document-handle}"
    8. -///
    9. @ref RestDocumentHead "HEAD /document/@FA{document-handle}"
    10. -///
    11. @ref RestDocumentReadAll "GET /document?collection=@FA{collection-identifier}"
    12. +///
    13. @ref RestDocumentRead "GET /document/document-handle"
    14. +///
    15. @ref RestDocumentCreate "POST /document?collection=collection-identifier"
    16. +///
    17. @ref RestDocumentUpdate "PUT /document/document-handle"
    18. +///
    19. @ref RestDocumentDelete "DELETE /document/document-handle"
    20. +///
    21. @ref RestDocumentHead "HEAD /document/document-handle"
    22. +///
    23. @ref RestDocumentReadAll "GET /document?collection=collection-identifier"
    24. ///
    //////////////////////////////////////////////////////////////////////////////// diff --git a/RestServer/shell-collection.dox b/RestServer/shell-collection.dox index a722c0e1a5..a64be65fac 100644 --- a/RestServer/shell-collection.dox +++ b/RestServer/shell-collection.dox @@ -42,6 +42,10 @@ /// ///
      ///
    1. @ref ShellCollectionRead "db._collection(collection-identifier)"
    2. +///
    3. @ref ShellCollectionCreate "db._create(collection-name, properties)"
    4. +///
    5. @ref ShellCollectionReadAll "db._collections()"
    6. +///
    7. @ref ShellCollectionReadShortCut "db.collection-name"
    8. +///
    9. @ref ShellCollectionProperties "collection.properties()"
    10. ///
    //////////////////////////////////////////////////////////////////////////////// @@ -106,6 +110,22 @@ /// @copydetails JS_CollectionVocBase ///
    /// +/// @anchor ShellCollectionCreate +/// @copydetails JS_CreateVocBase +///
    +/// +/// @anchor ShellCollectionReadAll +/// @copydetails JS_CollectionsVocBase +///
    +/// +/// @anchor ShellCollectionReadShortCut +/// @copydetails MapGetVocBase +///
    +/// +/// @anchor ShellCollectionProperties +/// @copydetails JS_PropertiesVocbaseCol +///
    +/// //////////////////////////////////////////////////////////////////////////////// // Local Variables: diff --git a/V8/v8-line-editor.cpp b/V8/v8-line-editor.cpp index 935769b8ef..6d45c2f828 100644 --- a/V8/v8-line-editor.cpp +++ b/V8/v8-line-editor.cpp @@ -159,7 +159,7 @@ static char* CompletionGenerator (char const* text, int state) { v8::String::Utf8Value str(v); char const* s = *str; - if (s != 0) { + if (s != 0 && *s) { string suffix = (current->Get(v)->IsFunction()) ? "()" : ""; string name = path + s + suffix; diff --git a/V8/v8-vocbase.cpp b/V8/v8-vocbase.cpp index b07ca6e810..4e3677d09f 100644 --- a/V8/v8-vocbase.cpp +++ b/V8/v8-vocbase.cpp @@ -4378,21 +4378,28 @@ static v8::Handle JS_NameVocbaseCol (v8::Arguments const& argv) { /// /// - @LIT{waitForSync}: If @LIT{true} creating a document will only return /// after the data was synced to disk. +/// /// - @LIT{journalSize} : The size of the journal in bytes. /// -/// @FUN{properties(@FA{properties-array})} +/// @FUN{properties(@FA{properties})} /// -/// Changes the collection properties. +/// Changes the collection properties. @FA{properties} must be a object with +/// one or more of the following attribute(s): +/// +/// - @LIT{waitForSync}: If @LIT{true} creating a document will only return +/// after the data was synced to disk. +/// +/// Note that it is not possible to change the journal size after creation. /// /// @EXAMPLES /// /// Read all properties /// -/// @verbinclude admin1 +/// @verbinclude shell_collection-properties /// /// Change a property /// -/// @verbinclude admin2 +/// @verbinclude shell_collection-properties-change //////////////////////////////////////////////////////////////////////////////// static v8::Handle JS_PropertiesVocbaseCol (v8::Arguments const& argv) { @@ -4827,6 +4834,16 @@ static v8::Handle JS_SaveEdgesCol (v8::Arguments const& argv) { //////////////////////////////////////////////////////////////////////////////// /// @brief selects a collection from the vocbase +/// +/// @FUN{db.@FA{collection-name}} +/// +/// Returns the collection with the given @FA{collection-name}. If no such +/// collection exists, create a collection named @FA{collection-name} with the +/// default properties. +/// +/// @EXAMPLES +/// +/// @verbinclude shell_read-collection-short-cut //////////////////////////////////////////////////////////////////////////////// static v8::Handle MapGetVocBase (v8::Local name, @@ -4843,7 +4860,7 @@ static v8::Handle MapGetVocBase (v8::Local name, string key = TRI_ObjectToString(name); if (key == "") { - return scope.Close(v8::ThrowException(v8::String::New("name must not be empty"))); + return scope.Close(v8::ThrowException(CreateErrorObject(TRI_ERROR_AVOCADO_ILLEGAL_NAME, "name must not be empty"))); } if ( key == "toString" @@ -4947,6 +4964,14 @@ static v8::Handle JS_CollectionVocBase (v8::Arguments const& argv) { //////////////////////////////////////////////////////////////////////////////// /// @brief returns all collections +/// +/// @FUN{db._collections()} +/// +/// Returns all collections of the given database. +/// +/// @EXAMPLES +/// +/// @verbinclude shell_read-collection-all //////////////////////////////////////////////////////////////////////////////// static v8::Handle JS_CollectionsVocBase (v8::Arguments const& argv) { @@ -5004,6 +5029,34 @@ static v8::Handle JS_CompletionsVocBase (v8::Arguments const& argv) { //////////////////////////////////////////////////////////////////////////////// /// @brief creates a new collection +/// +/// @FUN{db._create(@FA{collection-name})} +/// +/// Creates a new collection named @FA{collection-name}. If the collection name +/// already exists, than an error is thrown. The default value for +/// @LIT{waitForSync} is @LIT{false}. +/// +/// @FUN{db._create(@FA{collection-name}, @FA{properties})} +/// +/// @FA{properties} must be an object, with the following attribues: +/// +/// - @LIT{waitForSync} (optional, default @LIT{false}): If @LIT{true} creating +/// a document will only return after the data was synced to disk. +/// +/// - @LIT{journalSize} (optional, default is a @ref CommandLineAvocado +/// "configuration parameter"): The maximal size of +/// a journal or datafile. Note that this also limits the maximal +/// size of a single object. Must be at least 1MB. +/// +/// @EXAMPLES +/// +/// With defaults: +/// +/// @verbinclude shell_create-collection +/// +/// With properties: +/// +/// @verbinclude shell_create-collection-properties //////////////////////////////////////////////////////////////////////////////// static v8::Handle JS_CreateVocBase (v8::Arguments const& argv) { @@ -5019,7 +5072,7 @@ static v8::Handle JS_CreateVocBase (v8::Arguments const& argv) { if (argv.Length() < 1) { return scope.Close(v8::ThrowException( CreateErrorObject(TRI_ERROR_BAD_PARAMETER, - "usage: _create(, )"))); + "usage: _create(, )"))); } // extract the name @@ -5030,7 +5083,7 @@ static v8::Handle JS_CreateVocBase (v8::Arguments const& argv) { if (2 <= argv.Length()) { if (! argv[1]->IsObject()) { - return scope.Close(v8::ThrowException(CreateErrorObject(TRI_ERROR_BAD_PARAMETER, " must be an object"))); + return scope.Close(v8::ThrowException(CreateErrorObject(TRI_ERROR_BAD_PARAMETER, " must be an object"))); } v8::Handle p = argv[1]->ToObject(); @@ -5043,7 +5096,7 @@ static v8::Handle JS_CreateVocBase (v8::Arguments const& argv) { if (s < TRI_JOURNAL_MINIMAL_SIZE) { return scope.Close(v8::ThrowException( CreateErrorObject(TRI_ERROR_BAD_PARAMETER, - ".journalSize too small"))); + ".journalSize too small"))); } TRI_InitParameterCollection(¶meter, name.c_str(), (TRI_voc_size_t) s); @@ -5228,7 +5281,7 @@ static v8::Handle MapGetEdges (v8::Local name, string key = TRI_ObjectToString(name); if (key == "") { - return scope.Close(v8::ThrowException(v8::String::New("name must not be empty"))); + return scope.Close(v8::ThrowException(CreateErrorObject(TRI_ERROR_AVOCADO_ILLEGAL_NAME, "name must not be empty"))); } if ( key == "toString" @@ -5362,7 +5415,7 @@ static v8::Handle MapGetShapedJson (v8::Local name, string key = TRI_ObjectToString(name); if (key == "") { - return scope.Close(v8::ThrowException(v8::String::New("name must not be empty"))); + return scope.Close(v8::ThrowException(CreateErrorObject(TRI_ERROR_AVOCADO_ILLEGAL_NAME, "name must not be empty"))); } if (key[0] == '_') { diff --git a/VocBase/collection.c b/VocBase/collection.c index 18cfa5cd7a..6a6eb1fe35 100644 --- a/VocBase/collection.c +++ b/VocBase/collection.c @@ -366,7 +366,7 @@ void TRI_InitParameterCollection (TRI_col_parameter_t* parameter, parameter->_type = TRI_COL_TYPE_SIMPLE_DOCUMENT; - parameter->_waitForSync = true; + parameter->_waitForSync = false; parameter->_maximalSize = (maximalSize / PageSize) * PageSize; diff --git a/VocBase/vocbase.c b/VocBase/vocbase.c index f756f26f8f..1e4bfbdaea 100644 --- a/VocBase/vocbase.c +++ b/VocBase/vocbase.c @@ -590,6 +590,13 @@ static TRI_vocbase_col_t* BearCollectionVocBase (TRI_vocbase_t* vocbase, char co // create a new one // ............................................................................. + if (*name == '\0') { + TRI_WRITE_UNLOCK_COLLECTIONS_VOCBASE(vocbase); + + TRI_set_errno(TRI_ERROR_AVOCADO_ILLEGAL_NAME); + return NULL; + } + // check that the name does not contain any strange characters wrong = TRI_IsAllowedCollectionName(name); @@ -1233,6 +1240,13 @@ TRI_vocbase_col_t* TRI_CreateCollectionVocBase (TRI_vocbase_t* vocbase, TRI_col_ return NULL; } + if (*name == '\0') { + TRI_WRITE_UNLOCK_COLLECTIONS_VOCBASE(vocbase); + + TRI_set_errno(TRI_ERROR_AVOCADO_ILLEGAL_NAME); + return NULL; + } + // check that the name does not contain any strange characters wrong = TRI_IsAllowedCollectionName(name); @@ -1482,6 +1496,10 @@ int TRI_RenameCollectionVocBase (TRI_vocbase_t* vocbase, TRI_vocbase_col_t* coll } // check name conventions + if (*newName == '\0') { + return TRI_set_errno(TRI_ERROR_AVOCADO_ILLEGAL_NAME); + } + wrong = TRI_IsAllowedCollectionName(newName); if (wrong != 0) { diff --git a/js/actions/system/api-collection.js b/js/actions/system/api-collection.js index c81ce556d2..7b35d40967 100644 --- a/js/actions/system/api-collection.js +++ b/js/actions/system/api-collection.js @@ -104,15 +104,16 @@ function CollectionRepresentation (collection, showProperties, showCount, showFi /// Creates an new collection with a given name. The request must contain an /// object with the following attributes. /// -/// @LIT{name}: The name of the collection. +/// - @LIT{name}: The name of the collection. /// -/// @LIT{waitForSync} (optional, default: false): If @LIT{true} then the data -/// is synchronised to disk before returning from a create or update of an -/// document. +/// - @LIT{waitForSync} (optional, default: false): If @LIT{true} then +/// the data is synchronised to disk before returning from a create or +/// update of an document. /// -/// @LIT{journalSize} (optional, default 32MB): The maximal size of a -/// journal or datafile. Note that this also limits the maximal size -/// of a single object. Must be at least 1MB. +/// - @LIT{journalSize} (optional, default is a @ref +/// CommandLineAvocado "configuration parameter"): The maximal size of +/// a journal or datafile. Note that this also limits the maximal +/// size of a single object. Must be at least 1MB. /// /// @EXAMPLES /// @@ -211,17 +212,16 @@ function GET_api_collections (req, res) { /// The result is an objects describing the collection with the following /// attributes: /// -/// @LIT{id}: The identifier of the collection. +/// - @LIT{id}: The identifier of the collection. /// -/// @LIT{name}: The name of the collection. +/// - @LIT{name}: The name of the collection. /// -/// @LIT{status}: The status of the collection as number. -/// -/// - 1: new born collection -/// - 2: unloaded -/// - 3: loaded -/// - 4: in the process of being unloaded -/// - 5: deleted +/// - @LIT{status}: The status of the collection as number. +/// - 1: new born collection +/// - 2: unloaded +/// - 3: loaded +/// - 4: in the process of being unloaded +/// - 5: deleted /// /// Every other status indicates a corrupted collection. /// @@ -242,10 +242,10 @@ function GET_api_collections (req, res) { /// @LIT{waitForSync} and the @LIT{journalSize} properties. This is /// achieved by forcing a load of the underlying collection. /// -/// @LIT{waitForSync}: If @LIT{true} then creating or changing a document will -/// wait until the data has been synchronised to disk. +/// - @LIT{waitForSync}: If @LIT{true} then creating or changing a +/// document will wait until the data has been synchronised to disk. /// -/// @LIT{journalSize}: The maximal size of a journal / datafile. +/// - @LIT{journalSize}: The maximal size of a journal / datafile. /// /// @REST{GET /_api/collection/@FA{collection-identifier}/count} //////////////////////////////////////////////////////////////// @@ -253,7 +253,7 @@ function GET_api_collections (req, res) { /// In addition to the above, the result also contains the number of documents. /// Note that this will always load the collection into memory. /// -/// @LIT{count}: The number of documents inside the collection. +/// - @LIT{count}: The number of documents inside the collection. /// /// @REST{GET /_api/collection/@FA{collection-identifier}/figures} ////////////////////////////////////////////////////////////////// @@ -262,21 +262,21 @@ function GET_api_collections (req, res) { /// and additional statistical information about the collection. Note that this /// will always load the collection into memory. /// -/// @LIT{count}: The number of documents inside the collection. +/// - @LIT{count}: The number of documents inside the collection. /// -/// @LIT{figures.alive.count}: The number of living documents. +/// - @LIT{figures.alive.count}: The number of living documents. /// -/// @LIT{figures.alive.size}: The total size in bytes used by all living -/// documents. +/// - @LIT{figures.alive.size}: The total size in bytes used by all +/// living documents. /// -/// @LIT{figures.dead.count}: The number of dead documents. +/// - @LIT{figures.dead.count}: The number of dead documents. /// -/// @LIT{figures.dead.size}: The total size in bytes used by all dead -/// documents. +/// - @LIT{figures.dead.size}: The total size in bytes used by all +/// dead documents. /// -/// @LIT{figures.datafile.count}: The number of active datafiles. +/// - @LIT{figures.datafile.count}: The number of active datafiles. /// -/// @LIT{journalSize}: The maximal size of the journal in bytes. +/// - @LIT{journalSize}: The maximal size of the journal in bytes. /// /// @EXAMPLES ///////////// @@ -393,13 +393,13 @@ function GET_api_collection (req, res) { /// /// Loads a collection into memory. On success an object with the following /// -/// @LIT{id}: The identifier of the collection. +/// - @LIT{id}: The identifier of the collection. /// -/// @LIT{name}: The name of the collection. +/// - @LIT{name}: The name of the collection. /// -/// @LIT{count}: The number of documents inside the collection. +/// - @LIT{count}: The number of documents inside the collection. /// -/// @LIT{status}: The status of the collection as number. +/// - @LIT{status}: The status of the collection as number. /// /// If the @FA{collection-identifier} is missing, then a @LIT{HTTP 400} is /// returned. If the @FA{collection-identifier} is unknown, then a @LIT{HTTP @@ -434,11 +434,11 @@ function PUT_api_collection_load (req, res, collection) { /// You can use the collection afterwards; in which case it will be loaded into /// memory, again. On success an object with the following /// -/// @LIT{id}: The identifier of the collection. +/// - @LIT{id}: The identifier of the collection. /// -/// @LIT{name}: The name of the collection. +/// - @LIT{name}: The name of the collection. /// -/// @LIT{status}: The status of the collection as number. +/// - @LIT{status}: The status of the collection as number. /// /// If the @FA{collection-identifier} is missing, then a @LIT{HTTP 400} is /// returned. If the @FA{collection-identifier} is unknown, then a @LIT{HTTP @@ -498,16 +498,16 @@ function PUT_api_collection_truncate (req, res, collection) { /// Changes the properties of a collection. Expects an object with the /// attribute(s) /// -/// @LIT{waitForSync}: If @LIT{true} then creating or changing a document will -/// wait until the data has been synchronised to disk. +/// - @LIT{waitForSync}: If @LIT{true} then creating or changing a +/// document will wait until the data has been synchronised to disk. /// /// If returns an object with the attributes /// -/// @LIT{id}: The identifier of the collection. +/// - @LIT{id}: The identifier of the collection. /// -/// @LIT{name}: The name of the collection. +/// - @LIT{name}: The name of the collection. /// -/// @LIT{waitForSync}: The new value. +/// - @LIT{waitForSync}: The new value. /// /// @EXAMPLES /// @@ -544,13 +544,13 @@ function PUT_api_collection_properties (req, res, collection) { /// /// Renames a collection. Expects an object with the attribute(s) /// -/// @LIT{name}: The new name. +/// - @LIT{name}: The new name. /// /// If returns an object with the attributes /// -/// @LIT{id}: The identifier of the collection. +/// - @LIT{id}: The identifier of the collection. /// -/// @LIT{name}: The new name of the collection. +/// - @LIT{name}: The new name of the collection. /// /// @EXAMPLES /// @@ -644,9 +644,9 @@ function PUT_api_collection (req, res) { /// If the collection was successfully deleted then, an object is returned with /// the following attributes: /// -/// @LIT{error}: @LIT{false} +/// - @LIT{error}: @LIT{false} /// -/// @LIT{id}: The identifier of the deleted collection. +/// - @LIT{id}: The identifier of the deleted collection. /// /// If the @FA{collection-identifier} is missing, then a @LIT{HTTP 400} is /// returned. If the @FA{collection-identifier} is unknown, then a @LIT{HTTP diff --git a/js/actions/system/api-index.js b/js/actions/system/api-index.js index afb0907689..a36006415e 100644 --- a/js/actions/system/api-index.js +++ b/js/actions/system/api-index.js @@ -101,9 +101,9 @@ function GET_api_indexes (req, res) { /// The result is an objects describing the index with the following /// attributes: /// -/// @LIT{id}: The identifier of the collection. +/// - @LIT{id}: The identifier of the collection. /// -/// @LIT{type}: The type of the collection. +/// - @LIT{type}: The type of the collection. /// /// All other attributes are type-dependent. /// diff --git a/js/actions/system/api-system.js b/js/actions/system/api-system.js index 72353534bb..1b3164a69f 100644 --- a/js/actions/system/api-system.js +++ b/js/actions/system/api-system.js @@ -44,28 +44,29 @@ var actions = require("actions"); /// /// The call returns an object with the following attributes: /// -/// @LIT{system.userTime}: Amount of time that this process has been scheduled -/// in user mode, measured in clock ticks divided by sysconf(_SC_CLK_TCK) aka -/// seconds. +/// - @LIT{system.userTime}: Amount of time that this process has been +/// scheduled in user mode, measured in clock ticks divided by +/// sysconf(_SC_CLK_TCK) aka seconds. /// -/// @LIT{system.systemTime}: mount of time that this process has been scheduled -/// in kernel mode, measured in clock ticks divided by sysconf(_SC_CLK_TCK) aka -/// seconds. +/// - @LIT{system.systemTime}: mount of time that this process has +/// been scheduled in kernel mode, measured in clock ticks divided by +/// sysconf(_SC_CLK_TCK) aka seconds. /// -/// @LIT{system.numberOfThreads}: Number of threads in this process. +/// - @LIT{system.numberOfThreads}: Number of threads in this process. /// -/// @LIT{system.residentSize}: Resident Set Size: number of pages the process -/// has in real memory. This is just the pages which count toward text, data, -/// or stack space. This does not include pages which have not been -/// demand-loaded in, or which are swapped out. +/// - @LIT{system.residentSize}: Resident Set Size: number of pages +/// the process has in real memory. This is just the pages which +/// count toward text, data, or stack space. This does not include +/// pages which have not been demand-loaded in, or which are swapped +/// out. /// -/// @LIT{system.virtualSize}: Virtual memory size in bytes. +/// - @LIT{system.virtualSize}: Virtual memory size in bytes. /// -/// @LIT{system.minorPageFaults}: The number of minor faults the process has -/// made which have not required loading a memory page from disk. +/// - @LIT{system.minorPageFaults}: The number of minor faults the process has +/// made which have not required loading a memory page from disk. /// -/// @LIT{system.majorPageFaults}: The number of major faults the process has -/// made which have required loading a memory page from disk. +/// - @LIT{system.majorPageFaults}: The number of major faults the process has +/// made which have required loading a memory page from disk. //////////////////////////////////////////////////////////////////////////////// actions.defineHttp({ diff --git a/js/common/modules/jsunity.js b/js/common/modules/jsunity.js index 79026473c4..2a63d40942 100644 --- a/js/common/modules/jsunity.js +++ b/js/common/modules/jsunity.js @@ -425,6 +425,7 @@ function RunCommandLineTests () { } catch (err) { print("cannot run test file '" + file + "': " + err); + print(err.stack); result = false; } } diff --git a/js/server/tests/shell-collection.js b/js/server/tests/shell-collection.js new file mode 100644 index 0000000000..f9e5f1b1ed --- /dev/null +++ b/js/server/tests/shell-collection.js @@ -0,0 +1,291 @@ +//////////////////////////////////////////////////////////////////////////////// +/// @brief test the collection interface +/// +/// @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 Dr. Frank Celler +/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +var jsunity = require("jsunity"); + +// ----------------------------------------------------------------------------- +// --SECTION-- collection methods +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test suite: error handling +//////////////////////////////////////////////////////////////////////////////// + +function collectionSuiteErrorHandling () { + var ERRORS = require("internal").errors; + + return { + +//////////////////////////////////////////////////////////////////////////////// +/// @brief bad name (underscore) +//////////////////////////////////////////////////////////////////////////////// + + testErrorHandlingBadNameUnderscore : function () { + try { + db._create("_illegal"); + } + catch (err) { + assertEqual(ERRORS.ERROR_AVOCADO_ILLEGAL_NAME.code, err.errorNum); + } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief bad name (empty) +//////////////////////////////////////////////////////////////////////////////// + + testErrorHandlingBadNameEmpty : function () { + try { + db._create(""); + } + catch (err) { + assertEqual(ERRORS.ERROR_AVOCADO_ILLEGAL_NAME.code, err.errorNum); + } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief bad name (number) +//////////////////////////////////////////////////////////////////////////////// + + testErrorHandlingBadNameNumber : function () { + try { + db._create("12345"); + } + catch (err) { + assertEqual(ERRORS.ERROR_AVOCADO_ILLEGAL_NAME.code, err.errorNum); + } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief bad name (underscore) (short-cut) +//////////////////////////////////////////////////////////////////////////////// + + testErrorHandlingBadNameUnderscoreShortCut : function () { + try { + db["_illegal"]; + } + catch (err) { + assertEqual(ERRORS.ERROR_AVOCADO_ILLEGAL_NAME.code, err.errorNum); + } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief bad name (empty) (short-cut) +//////////////////////////////////////////////////////////////////////////////// + + testErrorHandlingBadNameEmptyShortCut : function () { + try { + db[""]; + } + catch (err) { + assertEqual(ERRORS.ERROR_AVOCADO_ILLEGAL_NAME.code, err.errorNum); + } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief bad name (number) (short-cut) +//////////////////////////////////////////////////////////////////////////////// + + testErrorHandlingBadNameNumberShortCut : function () { + try { + db["12345"]; + } + catch (err) { + assertEqual(ERRORS.ERROR_AVOCADO_ILLEGAL_NAME.code, err.errorNum); + } + } + }; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test suite: collection +//////////////////////////////////////////////////////////////////////////////// + +function collectionSuite () { + var ERRORS = require("internal").errors; + + return { + +//////////////////////////////////////////////////////////////////////////////// +/// @brief read by name +//////////////////////////////////////////////////////////////////////////////// + + testReadingByName : function () { + var cn = "example"; + + db._drop(cn); + var c1 = db._create(cn); + + assertTypeOf("number", c1._id); + assertEqual(cn, c1.name()); + assertTypeOf("number", c1.status()); + + var c2 = db._collection(cn); + + assertEqual(c1._id, c2._id); + assertEqual(c1.name(), c2.name()); + assertEqual(c1.status(), c2.status()); + + db._drop(cn); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief read by identifier +//////////////////////////////////////////////////////////////////////////////// + + testReadingByIdentifier : function () { + var cn = "example"; + + db._drop(cn); + var c1 = db._create(cn); + + assertTypeOf("number", c1._id); + assertEqual(cn, c1.name()); + assertTypeOf("number", c1.status()); + + var c2 = db._collection(c1._id); + + assertEqual(c1._id, c2._id); + assertEqual(c1.name(), c2.name()); + assertEqual(c1.status(), c2.status()); + + db._drop(cn); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief read by name (short-cut) +//////////////////////////////////////////////////////////////////////////////// + + testReadingByNameShortCut : function () { + var cn = "example"; + + db._drop(cn); + var c1 = db._create(cn); + + assertTypeOf("number", c1._id); + assertEqual(cn, c1.name()); + assertTypeOf("number", c1.status()); + + var c2 = db[cn]; + + assertEqual(c1._id, c2._id); + assertEqual(c1.name(), c2.name()); + assertEqual(c1.status(), c2.status()); + + db._drop(cn); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief read all +//////////////////////////////////////////////////////////////////////////////// + + testReadingAll : function () { + var cn = "example"; + + db._drop(cn); + var c1 = db._create(cn); + + assertTypeOf("number", c1._id); + assertEqual(cn, c1.name()); + assertTypeOf("number", c1.status()); + + var l = db._collections(); + + assertNotEqual(0, l.length); + + db._drop(cn); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief creating with defaults +//////////////////////////////////////////////////////////////////////////////// + + testCreatingDefaults : function () { + var cn = "example"; + + db._drop(cn); + var c1 = db._create(cn); + + assertTypeOf("number", c1._id); + assertEqual(cn, c1.name()); + assertTypeOf("number", c1.status()); + + var p = c1.properties(); + + assertEqual(false, p.waitForSync); + + db._drop(cn); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief creating with properties +//////////////////////////////////////////////////////////////////////////////// + + testCreatingProperties : function () { + var cn = "example"; + + db._drop(cn); + var c1 = db._create(cn, { waitForSync : true, journalSize : 1024 * 1024 }); + + assertTypeOf("number", c1._id); + assertEqual(cn, c1.name()); + assertTypeOf("number", c1.status()); + + var p = c1.properties(); + + assertEqual(true, p.waitForSync); + + if (p.journalSize < 1024 * 1024) { + fail(); + } + + if (1024 * 1025 < p.journalSize) { + fail(); + } + + db._drop(cn); + }, + }; +} + +// ----------------------------------------------------------------------------- +// --SECTION-- main +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief executes the test suites +//////////////////////////////////////////////////////////////////////////////// + +jsunity.run(collectionSuiteErrorHandling); +jsunity.run(collectionSuite); + +return jsunity.done(); + +// Local Variables: +// mode: outline-minor +// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)" +// End: + diff --git a/js/server/tests/shell-documents.js b/js/server/tests/shell-document.js similarity index 97% rename from js/server/tests/shell-documents.js rename to js/server/tests/shell-document.js index a3f055958e..feaadfbad2 100644 --- a/js/server/tests/shell-documents.js +++ b/js/server/tests/shell-document.js @@ -35,7 +35,7 @@ var jsunity = require("jsunity"); /// @brief test suite: error handling //////////////////////////////////////////////////////////////////////////////// -function readCollectionDocumentSuiteErrorHandling () { +function collectionDocumentSuiteErrorHandling () { var cn = "UnitTestsCollectionBasics"; var ERRORS = require("internal").errors; var collection = null; @@ -107,7 +107,7 @@ function readCollectionDocumentSuiteErrorHandling () { /// @brief test suite: normal operations //////////////////////////////////////////////////////////////////////////////// -function readCollectionDocumentSuiteReadDocument () { +function collectionDocumentSuiteReadDocument () { var cn = "UnitTestsCollectionBasics"; var ERRORS = require("internal").errors; var collection = null; @@ -274,7 +274,7 @@ function readCollectionDocumentSuiteReadDocument () { /// @brief test suite: error handling //////////////////////////////////////////////////////////////////////////////// -function readDocumentSuiteErrorHandling () { +function documentSuiteErrorHandling () { var cn = "UnitTestsCollectionBasics"; var ERRORS = require("internal").errors; @@ -318,7 +318,7 @@ function readDocumentSuiteErrorHandling () { /// @brief test suite: normal operations //////////////////////////////////////////////////////////////////////////////// -function readDocumentSuiteReadDocument () { +function documentSuiteReadDocument () { var cn = "UnitTestsCollectionBasics"; var ERRORS = require("internal").errors; var collection = null; @@ -474,11 +474,11 @@ function readDocumentSuiteReadDocument () { /// @brief executes the test suites //////////////////////////////////////////////////////////////////////////////// -jsunity.run(readCollectionDocumentSuiteErrorHandling); -jsunity.run(readCollectionDocumentSuiteReadDocument); +jsunity.run(collectionDocumentSuiteErrorHandling); +jsunity.run(collectionDocumentSuiteReadDocument); -jsunity.run(readDocumentSuiteErrorHandling); -jsunity.run(readDocumentSuiteReadDocument); +jsunity.run(documentSuiteErrorHandling); +jsunity.run(documentSuiteReadDocument); return jsunity.done();