From 6834d1e3f8c27e46ba8caca99edabf8a9ba4a5b9 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Sat, 5 May 2012 23:42:27 +0200 Subject: [PATCH] added cap doc --- .../api-index-create-new-cap-constraint | 14 +++ RestServer/api-index.dox | 5 +- RestServer/index-cap.dox | 6 +- RestServer/indexes.dox | 3 +- RestServer/shell-index.dox | 6 +- RestServer/simple-queries.dox | 5 - UnitTests/HttpInterface/api-index-spec.rb | 95 +++++++++++++++++++ js/actions/system/api-index.js | 9 +- js/client/js-client.h | 24 +++++ 9 files changed, 147 insertions(+), 20 deletions(-) create mode 100644 Doxygen/Examples.AvocadoDB/api-index-create-new-cap-constraint diff --git a/Doxygen/Examples.AvocadoDB/api-index-create-new-cap-constraint b/Doxygen/Examples.AvocadoDB/api-index-create-new-cap-constraint new file mode 100644 index 0000000000..3eb418a891 --- /dev/null +++ b/Doxygen/Examples.AvocadoDB/api-index-create-new-cap-constraint @@ -0,0 +1,14 @@ +> curl --data @- -X POST --dump - http://localhost:8529/_api/index?collection=1786279 +{ "type" : "cap", "size" : 10 } + +HTTP/1.1 201 Created +content-type: application/json + +{ + "size": 10, + "code": 201, + "id": "1786279/2769319", + "type": "cap", + "isNewlyCreated": true, + "error": false +} diff --git a/RestServer/api-index.dox b/RestServer/api-index.dox index f1926720e6..65e6e587f7 100644 --- a/RestServer/api-index.dox +++ b/RestServer/api-index.dox @@ -54,10 +54,7 @@ /// This is an introduction to AvocadoDB's Http interface for indexes in /// general. There are special section for /// -/// - @ref IndexGeo -/// - @ref IndexSkiplist -/// - @ref IndexHash -/// - @ref IndexPrioQueue +/// @copydoc IndexesTOC /// ///
/// @copydoc HttpIndexTOC diff --git a/RestServer/index-cap.dox b/RestServer/index-cap.dox index 0168071e48..4743faf679 100644 --- a/RestServer/index-cap.dox +++ b/RestServer/index-cap.dox @@ -31,7 +31,7 @@ ///
    ///
  1. @ref IndexCapHttp ///
      -///
    1. @ref IndexCapHttpEnsureCap "POST /_api/index"
    2. +///
    3. @ref IndexCapHttpEnsureCapConstraint "POST /_api/index"
    4. ///
    ///
  2. ///
  3. @ref IndexCapShell @@ -59,13 +59,13 @@ /// @section IndexCapHttp Accessing Cap Constraints via Http //////////////////////////////////////////////////////////// /// -/// @anchor IndexCapHttpEnsureCap +/// @anchor IndexCapHttpEnsureCapConstraint /// @copydetails JSF_POST_api_index_cap /// /// @section IndexCapShell Accessing Cap Constraints from the Shell /////////////////////////////////////////////////////////////////// /// -/// @anchor IndexCapShellEnsureGeoIndex +/// @anchor IndexCapShellEnsureCapConstraint /// @copydetails JS_EnsureCapConstraintVocbaseCol //////////////////////////////////////////////////////////////////////////////// diff --git a/RestServer/indexes.dox b/RestServer/indexes.dox index af01048587..2f91b86268 100644 --- a/RestServer/indexes.dox +++ b/RestServer/indexes.dox @@ -29,6 +29,7 @@ /// @page IndexesTOC /// ///
      +///
    1. @ref IndexCap
    2. ///
    3. @ref IndexGeo
    4. ///
    5. @ref IndexHash
    6. ///
    7. @ref IndexSkiplist
    8. @@ -38,7 +39,7 @@ //////////////////////////////////////////////////////////////////////////////// /// @page Indexes Indexes /// -/// This is an introduction to AvocadoDB's geo indexes. +/// This is an introduction to AvocadoDB's various indexes. /// ///
      /// @copydoc IndexesTOC diff --git a/RestServer/shell-index.dox b/RestServer/shell-index.dox index d1669ae493..455afe407e 100644 --- a/RestServer/shell-index.dox +++ b/RestServer/shell-index.dox @@ -63,11 +63,7 @@ /// This is an introduction to AvocadoDB's interface for indexs in general. /// There are special sections for /// -/// - @ref IndexGeo -/// - @ref IndexSkiplist -/// - @ref IndexHash -/// - @ref IndexPrioQueue -/// - @ref IndexCap +/// @copydoc IndexesTOC /// ///
      /// @copydoc ShellIndexTOC diff --git a/RestServer/simple-queries.dox b/RestServer/simple-queries.dox index 9ef9d28c66..36c12c5c0a 100644 --- a/RestServer/simple-queries.dox +++ b/RestServer/simple-queries.dox @@ -61,7 +61,6 @@ ///
        ///
      1. @ref SimpleQueryHasNext "@FA{query}.hasNext()"
      2. ///
      3. @ref SimpleQueryNext "@FA{query}.next()"
      4. -///
      5. @ref SimpleQueryNextRef "@FA{query}.nextRef()"
      6. ///
      /// ///
    @@ -175,10 +174,6 @@ /// /// @anchor SimpleQueryNext /// @copydetails JSF_SimpleQuery_prototype_next -///
    -/// -/// @anchor SimpleQueryNextRef -/// @copydetails JSF_SimpleQuery_prototype_nextRef //////////////////////////////////////////////////////////////////////////////// // Local Variables: diff --git a/UnitTests/HttpInterface/api-index-spec.rb b/UnitTests/HttpInterface/api-index-spec.rb index 5be5251f26..baedbb7e1b 100644 --- a/UnitTests/HttpInterface/api-index-spec.rb +++ b/UnitTests/HttpInterface/api-index-spec.rb @@ -47,6 +47,101 @@ describe AvocadoDB do end end +################################################################################ +## creating a cap constraint +################################################################################ + + context "creating cap constraints:" do + before do + @cn = "UnitTestsCollectionIndexes" + AvocadoDB.drop_collection(@cn) + @cid = AvocadoDB.create_collection(@cn) + end + + after do + AvocadoDB.drop_collection(@cn) + end + + it "returns either 201 for new or 200 for old indexes" do + cmd = api + "?collection=#{@cid}" + body = "{ \"type\" : \"cap\", \"size\" : 10 }" + doc = AvocadoDB.log_post("#{prefix}-create-new-cap-constraint", cmd, :body => body) + + doc.code.should eq(201) + doc.headers['content-type'].should eq("application/json") + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(201) + doc.parsed_response['id'].should_not eq(0) + doc.parsed_response['type'].should eq("cap") + doc.parsed_response['isNewlyCreated'].should eq(true) + + doc = AvocadoDB.log_post("#{prefix}-create-old-cap-constraint", cmd, :body => body) + + doc.code.should eq(200) + doc.headers['content-type'].should eq("application/json") + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['id'].should_not eq(0) + doc.parsed_response['type'].should eq("cap") + doc.parsed_response['isNewlyCreated'].should eq(false) + end + end + +################################################################################ +## creating a cap constraint and unloading +################################################################################ + + context "cap constraints after unload/load:" do + before do + @cn = "UnitTestsCollectionIndexes" + AvocadoDB.drop_collection(@cn) + @cid = AvocadoDB.create_collection(@cn) + end + + after do + AvocadoDB.drop_collection(@cn) + end + + it "survives unload" do + cmd = api + "?collection=#{@cid}" + body = "{ \"type\" : \"cap\", \"size\" : 10 }" + doc = AvocadoDB.post(cmd, :body => body) + + doc.code.should eq(201) + doc.headers['content-type'].should eq("application/json") + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(201) + doc.parsed_response['id'].should_not eq(0) + + iid = doc.parsed_response['id'] + + cmd = "/_api/collection/#{@cid}/unload" + doc = AvocadoDB.put(cmd) + + doc.code.should eq(200) + + cmd = "/_api/collection/#{@cid}" + doc = AvocadoDB.get(cmd) + doc.code.should eq(200) + + while doc.parsed_response['status'] != 2 + doc = AvocadoDB.get(cmd) + doc.code.should eq(200) + end + + cmd = api + "/#{iid}" + doc = AvocadoDB.get(cmd) + + doc.code.should eq(200) + doc.headers['content-type'].should eq("application/json") + doc.parsed_response['error'].should eq(false) + doc.parsed_response['code'].should eq(200) + doc.parsed_response['id'].should eq(iid) + doc.parsed_response['type'].should eq("cap") + doc.parsed_response['size'].should eq(10) + end + end + ################################################################################ ## creating a geo index ################################################################################ diff --git a/js/actions/system/api-index.js b/js/actions/system/api-index.js index 63f4b1f566..8d7b3a494f 100644 --- a/js/actions/system/api-index.js +++ b/js/actions/system/api-index.js @@ -175,7 +175,7 @@ function GET_api_index (req, res) { /// /// Creating a cap collection /// -/// @verbinclude api-index-create-cap-constraint +/// @verbinclude api-index-create-new-cap-constraint //////////////////////////////////////////////////////////////////////////////// function POST_api_index_cap (req, res, collection, body) { @@ -188,7 +188,12 @@ function POST_api_index_cap (req, res, collection, body) { var size = body.size; var index = collection.ensureCapConstraint(size); - actions.resultOk(req, res, actions.HTTP_OK, index); + if (index.isNewlyCreated) { + actions.resultOk(req, res, actions.HTTP_CREATED, index); + } + else { + actions.resultOk(req, res, actions.HTTP_OK, index); + } } catch (err) { actions.resultException(req, res, err); diff --git a/js/client/js-client.h b/js/client/js-client.h index f5913396d9..2917be3a10 100644 --- a/js/client/js-client.h +++ b/js/client/js-client.h @@ -1123,6 +1123,14 @@ static string JS_client_client = "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" + "/// @brief returns all documents\n" + "////////////////////////////////////////////////////////////////////////////////\n" + "\n" + "AvocadoCollection.prototype.toArray = function () {\n" + " return this.all().toArray();\n" + "}\n" + "\n" + "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief returns all indexes\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" @@ -1211,6 +1219,22 @@ static string JS_client_client = "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" + "/// @brief adds a cap constraint\n" + "////////////////////////////////////////////////////////////////////////////////\n" + "\n" + "AvocadoCollection.prototype.ensureCapConstraint = function (size) {\n" + " var body;\n" + "\n" + " body = { type : \"cap\", size : size };\n" + "\n" + " var requestResult = this._database._connection.POST(\"/_api/index?collection=\" + encodeURIComponent(this._id), JSON.stringify(body));\n" + "\n" + " TRI_CheckRequestResult(requestResult);\n" + "\n" + " return requestResult;\n" + "}\n" + "\n" + "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief adds an geo index\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n"