1
0
Fork 0

fix for wrong cid

This commit is contained in:
Frank Celler 2012-03-26 17:17:57 +02:00
parent be33a5c44f
commit fd1ab94663
6 changed files with 50 additions and 38 deletions

View File

@ -432,7 +432,7 @@ int RestVocbaseBaseHandler::useCollection (string const& name, bool create) {
generateError(HttpResponse::BAD, generateError(HttpResponse::BAD,
TRI_ERROR_HTTP_CORRUPTED_JSON, TRI_ERROR_HTTP_CORRUPTED_JSON,
"collection identifier is empty"); "collection identifier is empty");
return false; return TRI_set_errno(TRI_ERROR_HTTP_CORRUPTED_JSON);
} }
// try to find the collection // try to find the collection
@ -451,7 +451,14 @@ int RestVocbaseBaseHandler::useCollection (string const& name, bool create) {
} }
// and use the collection // and use the collection
return TRI_UseCollectionVocBase(_vocbase, const_cast<TRI_vocbase_col_s*>(_collection)); int res = TRI_UseCollectionVocBase(_vocbase, const_cast<TRI_vocbase_col_s*>(_collection));
if (res == TRI_ERROR_NO_ERROR) {
_documentCollection = _collection->_collection;
assert(_documentCollection != 0);
}
return res;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -4,16 +4,17 @@ require './avocadodb.rb'
describe AvocadoDB do describe AvocadoDB do
prefix = "rest_create-document" prefix = "rest_create-document"
context "creating a document in a collection" do context "creating a document:" do
################################################################################ ################################################################################
## error handling ## error handling
################################################################################ ################################################################################
context "error handling" do context "error handling:" do
it "returns an error if url contains a suffix" do it "returns an error if url contains a suffix" do
cmd = "/document/123456" cmd = "/document/123456"
doc = AvocadoDB.post(cmd) body = "{}"
doc = AvocadoDB.post(cmd, :body => body)
doc.code.should eq(400) doc.code.should eq(400)
doc.parsed_response['error'].should eq(true) doc.parsed_response['error'].should eq(true)
@ -21,12 +22,13 @@ describe AvocadoDB do
doc.parsed_response['code'].should eq(400) doc.parsed_response['code'].should eq(400)
doc.headers['content-type'].should eq("application/json; charset=utf-8") doc.headers['content-type'].should eq("application/json; charset=utf-8")
AvocadoDB.log(:method => :post, :url => cmd, :result => doc, :output => "#{prefix}-superfluous-suffix") AvocadoDB.log(:method => :post, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-superfluous-suffix")
end end
it "returns an error if collection idenifier is missing" do it "returns an error if collection idenifier is missing" do
cmd = "/document" cmd = "/document"
doc = AvocadoDB.post(cmd) body = "{}"
doc = AvocadoDB.post(cmd, :body => body)
doc.code.should eq(400) doc.code.should eq(400)
doc.parsed_response['error'].should eq(true) doc.parsed_response['error'].should eq(true)
@ -34,12 +36,13 @@ describe AvocadoDB do
doc.parsed_response['code'].should eq(400) doc.parsed_response['code'].should eq(400)
doc.headers['content-type'].should eq("application/json; charset=utf-8") doc.headers['content-type'].should eq("application/json; charset=utf-8")
AvocadoDB.log(:method => :post, :url => cmd, :result => doc, :output => "#{prefix}-missing-cid") AvocadoDB.log(:method => :post, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-missing-cid")
end end
it "returns an error if the collection identifier is unknown" do it "returns an error if the collection identifier is unknown" do
cmd = "/document?collection=123456" cmd = "/document?collection=123456"
doc = AvocadoDB.post(cmd) body = "{}"
doc = AvocadoDB.post(cmd, :body => body)
doc.code.should eq(404) doc.code.should eq(404)
doc.parsed_response['error'].should eq(true) doc.parsed_response['error'].should eq(true)
@ -47,12 +50,13 @@ describe AvocadoDB do
doc.parsed_response['code'].should eq(404) doc.parsed_response['code'].should eq(404)
doc.headers['content-type'].should eq("application/json; charset=utf-8") doc.headers['content-type'].should eq("application/json; charset=utf-8")
AvocadoDB.log(:method => :post, :url => cmd, :result => doc, :output => "#{prefix}-unknown-cid") AvocadoDB.log(:method => :post, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-unknown-cid")
end end
it "returns an error if the collection name is unknown" do it "returns an error if the collection name is unknown" do
cmd = "/document?collection=unknown_collection" cmd = "/document?collection=unknown_collection"
doc = AvocadoDB.post(cmd) body = "{}"
doc = AvocadoDB.post(cmd, :body => body)
doc.code.should eq(404) doc.code.should eq(404)
doc.parsed_response['error'].should eq(true) doc.parsed_response['error'].should eq(true)
@ -60,7 +64,7 @@ describe AvocadoDB do
doc.parsed_response['code'].should eq(404) doc.parsed_response['code'].should eq(404)
doc.headers['content-type'].should eq("application/json; charset=utf-8") doc.headers['content-type'].should eq("application/json; charset=utf-8")
AvocadoDB.log(:method => :post, :url => cmd, :result => doc, :output => "#{prefix}-unknown-name") AvocadoDB.log(:method => :post, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-unknown-name")
end end
it "returns an error if the JSON body is corrupted" do it "returns an error if the JSON body is corrupted" do
@ -92,7 +96,7 @@ describe AvocadoDB do
## known collection identifier, waitForSync = true ## known collection identifier, waitForSync = true
################################################################################ ################################################################################
context "known collection identifier, waitForSync = true" do context "known collection identifier, waitForSync = true:" do
before do before do
@cn = "UnitTestsCollectionBasics" @cn = "UnitTestsCollectionBasics"
@cid = AvocadoDB.create_collection(@cn) @cid = AvocadoDB.create_collection(@cn)
@ -142,7 +146,7 @@ describe AvocadoDB do
## known collection identifier, waitForSync = false ## known collection identifier, waitForSync = false
################################################################################ ################################################################################
context "known collection identifier, waitForSync = false" do context "known collection identifier, waitForSync = false:" do
before do before do
@cn = "UnitTestsCollectionUnsynced" @cn = "UnitTestsCollectionUnsynced"
@cid = AvocadoDB.create_collection(@cn, false) @cid = AvocadoDB.create_collection(@cn, false)
@ -192,7 +196,7 @@ describe AvocadoDB do
## known collection name ## known collection name
################################################################################ ################################################################################
context "known collection name" do context "known collection name:" do
before do before do
@cn = "UnitTestsCollectionBasics" @cn = "UnitTestsCollectionBasics"
@cid = AvocadoDB.create_collection(@cn) @cid = AvocadoDB.create_collection(@cn)
@ -242,7 +246,7 @@ describe AvocadoDB do
## unknown collection name ## unknown collection name
################################################################################ ################################################################################
context "unknown collection name" do context "unknown collection name:" do
before do before do
@cn = "UnitTestsCollectionNamed#{Time.now.to_i}" @cn = "UnitTestsCollectionNamed#{Time.now.to_i}"
end end

View File

@ -4,13 +4,13 @@ require './avocadodb.rb'
describe AvocadoDB do describe AvocadoDB do
prefix = "rest_delete-document" prefix = "rest_delete-document"
context "delete a document in a collection" do context "delete a document:" do
################################################################################ ################################################################################
## error handling ## error handling
################################################################################ ################################################################################
context "error handling" do context "error handling:" do
before do before do
@cn = "UnitTestsCollectionBasics" @cn = "UnitTestsCollectionBasics"
@cid = AvocadoDB.create_collection(@cn) @cid = AvocadoDB.create_collection(@cn)
@ -119,7 +119,7 @@ describe AvocadoDB do
## deleting documents ## deleting documents
################################################################################ ################################################################################
context "deleting documents" do context "deleting documents:" do
before do before do
@cn = "UnitTestsCollectionBasics" @cn = "UnitTestsCollectionBasics"
@cid = AvocadoDB.create_collection(@cn) @cid = AvocadoDB.create_collection(@cn)

View File

@ -4,13 +4,13 @@ require './avocadodb.rb'
describe AvocadoDB do describe AvocadoDB do
prefix = "rest_read-document" prefix = "rest_read-document"
context "reading a document in a collection" do context "reading a document:" do
################################################################################ ################################################################################
## error handling ## error handling
################################################################################ ################################################################################
context "error handling" do context "error handling:" do
before do before do
@cn = "UnitTestsCollectionBasics" @cn = "UnitTestsCollectionBasics"
@cid = AvocadoDB.create_collection(@cn) @cid = AvocadoDB.create_collection(@cn)
@ -79,7 +79,7 @@ describe AvocadoDB do
## reading documents ## reading documents
################################################################################ ################################################################################
context "reading documents" do context "reading a document:" do
before do before do
@cn = "UnitTestsCollectionBasics" @cn = "UnitTestsCollectionBasics"
@cid = AvocadoDB.create_collection(@cn) @cid = AvocadoDB.create_collection(@cn)
@ -252,7 +252,7 @@ describe AvocadoDB do
## reading all documents ## reading all documents
################################################################################ ################################################################################
context "reading all documents" do context "reading all documents:" do
before do before do
@cn = "UnitTestsCollectionAll" @cn = "UnitTestsCollectionAll"
@cid = AvocadoDB.create_collection(@cn) @cid = AvocadoDB.create_collection(@cn)
@ -354,7 +354,7 @@ describe AvocadoDB do
## checking document ## checking document
################################################################################ ################################################################################
context "checking a document" do context "checking a document:" do
before do before do
@cn = "UnitTestsCollectionBasics" @cn = "UnitTestsCollectionBasics"
@cid = AvocadoDB.create_collection(@cn) @cid = AvocadoDB.create_collection(@cn)

View File

@ -4,13 +4,13 @@ require './avocadodb.rb'
describe AvocadoDB do describe AvocadoDB do
prefix = "rest_update-document" prefix = "rest_update-document"
context "update a document in a collection" do context "update a document:" do
################################################################################ ################################################################################
## error handling ## error handling
################################################################################ ################################################################################
context "error handling" do context "error handling:" do
before do before do
@cn = "UnitTestsCollectionBasics" @cn = "UnitTestsCollectionBasics"
@cid = AvocadoDB.create_collection(@cn) @cid = AvocadoDB.create_collection(@cn)
@ -22,7 +22,8 @@ describe AvocadoDB do
it "returns an error if document handle is missing" do it "returns an error if document handle is missing" do
cmd = "/document" cmd = "/document"
doc = AvocadoDB.put(cmd) body = "{}"
doc = AvocadoDB.put(cmd, :body => body)
doc.code.should eq(400) doc.code.should eq(400)
doc.parsed_response['error'].should eq(true) doc.parsed_response['error'].should eq(true)
@ -30,14 +31,15 @@ describe AvocadoDB do
doc.parsed_response['code'].should eq(400) doc.parsed_response['code'].should eq(400)
doc.headers['content-type'].should eq("application/json; charset=utf-8") doc.headers['content-type'].should eq("application/json; charset=utf-8")
AvocadoDB.log(:method => :post, :url => cmd, :result => doc, :output => "#{prefix}-missing-handle") AvocadoDB.log(:method => :post, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-missing-handle")
AvocadoDB.size_collection(@cid).should eq(0) AvocadoDB.size_collection(@cid).should eq(0)
end end
it "returns an error if document handle is corrupted" do it "returns an error if document handle is corrupted" do
cmd = "/document/123456" cmd = "/document/123456"
doc = AvocadoDB.put(cmd) body = "{}"
doc = AvocadoDB.put(cmd, :body => body)
doc.code.should eq(400) doc.code.should eq(400)
doc.parsed_response['error'].should eq(true) doc.parsed_response['error'].should eq(true)
@ -45,14 +47,15 @@ describe AvocadoDB do
doc.parsed_response['code'].should eq(400) doc.parsed_response['code'].should eq(400)
doc.headers['content-type'].should eq("application/json; charset=utf-8") doc.headers['content-type'].should eq("application/json; charset=utf-8")
AvocadoDB.log(:method => :get, :url => cmd, :result => doc, :output => "#{prefix}-bad-handle") AvocadoDB.log(:method => :get, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-bad-handle")
AvocadoDB.size_collection(@cid).should eq(0) AvocadoDB.size_collection(@cid).should eq(0)
end end
it "returns an error if document handle is corrupted" do it "returns an error if document handle is corrupted" do
cmd = "/document//123456" cmd = "/document//123456"
doc = AvocadoDB.put(cmd) body = "{}"
doc = AvocadoDB.put(cmd, :body => body)
doc.code.should eq(400) doc.code.should eq(400)
doc.parsed_response['error'].should eq(true) doc.parsed_response['error'].should eq(true)
@ -60,14 +63,15 @@ describe AvocadoDB do
doc.parsed_response['code'].should eq(400) doc.parsed_response['code'].should eq(400)
doc.headers['content-type'].should eq("application/json; charset=utf-8") doc.headers['content-type'].should eq("application/json; charset=utf-8")
AvocadoDB.log(:method => :get, :url => cmd, :result => doc, :output => "#{prefix}-bad-handle2") AvocadoDB.log(:method => :get, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-bad-handle2")
AvocadoDB.size_collection(@cid).should eq(0) AvocadoDB.size_collection(@cid).should eq(0)
end end
it "returns an error if collection identifier is unknown" do it "returns an error if collection identifier is unknown" do
cmd = "/document/123456/234567" cmd = "/document/123456/234567"
doc = AvocadoDB.put(cmd) body = "{}"
doc = AvocadoDB.put(cmd, :body => body)
doc.code.should eq(404) doc.code.should eq(404)
doc.parsed_response['error'].should eq(true) doc.parsed_response['error'].should eq(true)
@ -75,7 +79,7 @@ describe AvocadoDB do
doc.parsed_response['code'].should eq(404) doc.parsed_response['code'].should eq(404)
doc.headers['content-type'].should eq("application/json; charset=utf-8") doc.headers['content-type'].should eq("application/json; charset=utf-8")
AvocadoDB.log(:method => :get, :url => cmd, :result => doc, :output => "#{prefix}-unknown-cid") AvocadoDB.log(:method => :get, :url => cmd, :body => body, :result => doc, :output => "#{prefix}-unknown-cid")
AvocadoDB.size_collection(@cid).should eq(0) AvocadoDB.size_collection(@cid).should eq(0)
end end
@ -130,7 +134,7 @@ describe AvocadoDB do
## updating documents ## updating documents
################################################################################ ################################################################################
context "updating documents" do context "updating document:" do
before do before do
@cn = "UnitTestsCollectionBasics" @cn = "UnitTestsCollectionBasics"
@cid = AvocadoDB.create_collection(@cn) @cid = AvocadoDB.create_collection(@cn)

View File

@ -343,9 +343,6 @@ TRI_collection_t* TRI_CreateCollection (TRI_collection_t* collection,
char* tmp2; char* tmp2;
int res; int res;
// generate a collection identifier
parameter->_cid = TRI_NewTickVocBase();
// sanity check // sanity check
if (sizeof(TRI_df_header_marker_t) + sizeof(TRI_df_footer_marker_t) > parameter->_maximalSize) { if (sizeof(TRI_df_header_marker_t) + sizeof(TRI_df_footer_marker_t) > parameter->_maximalSize) {
TRI_set_errno(TRI_ERROR_AVOCADO_DATAFILE_FULL); TRI_set_errno(TRI_ERROR_AVOCADO_DATAFILE_FULL);