1
0
Fork 0

added cap doc

This commit is contained in:
Frank Celler 2012-05-05 23:42:27 +02:00
parent 6e6b68b1fc
commit 6834d1e3f8
9 changed files with 147 additions and 20 deletions

View File

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

View File

@ -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
///
/// <hr>
/// @copydoc HttpIndexTOC

View File

@ -31,7 +31,7 @@
/// <ol>
/// <li>@ref IndexCapHttp
/// <ol>
/// <li>@ref IndexCapHttpEnsureCap "POST /_api/index"</li>
/// <li>@ref IndexCapHttpEnsureCapConstraint "POST /_api/index"</li>
/// </ol>
/// </li>
/// <li>@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
////////////////////////////////////////////////////////////////////////////////

View File

@ -29,6 +29,7 @@
/// @page IndexesTOC
///
/// <ol>
/// <li>@ref IndexCap</li>
/// <li>@ref IndexGeo</li>
/// <li>@ref IndexHash</li>
/// <li>@ref IndexSkiplist</li>
@ -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.
///
/// <hr>
/// @copydoc IndexesTOC

View File

@ -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
///
/// <hr>
/// @copydoc ShellIndexTOC

View File

@ -61,7 +61,6 @@
/// <ol>
/// <li>@ref SimpleQueryHasNext "@FA{query}.hasNext()"</li>
/// <li>@ref SimpleQueryNext "@FA{query}.next()"</li>
/// <li>@ref SimpleQueryNextRef "@FA{query}.nextRef()"</li>
/// </ol>
/// </li>
/// </ol>
@ -175,10 +174,6 @@
///
/// @anchor SimpleQueryNext
/// @copydetails JSF_SimpleQuery_prototype_next
/// <hr>
///
/// @anchor SimpleQueryNextRef
/// @copydetails JSF_SimpleQuery_prototype_nextRef
////////////////////////////////////////////////////////////////////////////////
// Local Variables:

View File

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

View File

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

View File

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