Rhizome Java API: insert/update empty bundle

This commit is contained in:
Andrew Bettison 2014-07-10 21:19:42 +09:30
parent a87133d4d3
commit e35bf77938
4 changed files with 69 additions and 8 deletions

View File

@ -580,11 +580,13 @@ static int restful_rhizome_insert_end(struct http_request *hr)
rhizome_manifest_set_filesize(r->manifest, r->u.insert.write.file_length); rhizome_manifest_set_filesize(r->manifest, r->u.insert.write.file_length);
// fall through // fall through
case RHIZOME_PAYLOAD_STATUS_STORED: case RHIZOME_PAYLOAD_STATUS_STORED:
assert(r->manifest->filesize != RHIZOME_SIZE_UNSET);
// TODO: check that stored hash matches received payload's hash // TODO: check that stored hash matches received payload's hash
// fall through // fall through
case RHIZOME_PAYLOAD_STATUS_EMPTY: case RHIZOME_PAYLOAD_STATUS_EMPTY:
status_valid = 1; status_valid = 1;
assert(r->manifest->filesize != RHIZOME_SIZE_UNSET); if (r->manifest->filesize == RHIZOME_SIZE_UNSET)
rhizome_manifest_set_filesize(r->manifest, 0);
if (r->u.insert.payload_size == r->manifest->filesize) if (r->u.insert.payload_size == r->manifest->filesize)
break; break;
// fall through // fall through

View File

@ -679,14 +679,18 @@ enum rhizome_payload_status rhizome_finish_write(struct rhizome_write *write)
{ {
enum rhizome_payload_status status = RHIZOME_PAYLOAD_STATUS_NEW; enum rhizome_payload_status status = RHIZOME_PAYLOAD_STATUS_NEW;
// Once the whole file has been processed, we should finally know its. // Once the whole file has been processed, we should finally know its length
if (write->file_length == RHIZOME_SIZE_UNSET) { if (write->file_length == RHIZOME_SIZE_UNSET) {
if (config.debug.rhizome_store) if (config.debug.rhizome_store)
DEBUGF("Wrote %"PRIu64" bytes, set file_length", write->file_offset); DEBUGF("Wrote %"PRIu64" bytes, set file_length", write->file_offset);
write->file_length = write->file_offset; write->file_length = write->file_offset;
status = store_make_space(write->file_length, NULL); if (write->file_length == 0)
if (status!=RHIZOME_PAYLOAD_STATUS_NEW) status = RHIZOME_PAYLOAD_STATUS_EMPTY;
goto failure; else {
status = store_make_space(write->file_length, NULL);
if (status != RHIZOME_PAYLOAD_STATUS_NEW)
goto failure;
}
} }
// flush out any remaining buffered pieces to disk // flush out any remaining buffered pieces to disk
@ -709,7 +713,7 @@ enum rhizome_payload_status rhizome_finish_write(struct rhizome_write *write)
} }
assert(write->file_offset == write->file_length); assert(write->file_offset == write->file_length);
if (write->file_length==0){ if (write->file_length == 0) {
// whoops, no payload, don't store anything // whoops, no payload, don't store anything
if (config.debug.rhizome_store) if (config.debug.rhizome_store)
DEBUGF("Ignoring empty write"); DEBUGF("Ignoring empty write");

View File

@ -393,4 +393,59 @@ test_RhizomeInsertAnon() {
assert_rhizome_list --fromhere=0 --manifest=ifile2.manifest file2 assert_rhizome_list --fromhere=0 --manifest=ifile2.manifest file2
} }
doc_RhizomeInsertEmptyNew="Java API update existing Rhizome bundle to empty"
setup_RhizomeInsertEmptyNew() {
setup
>empty
assert [ ! -s empty ]
}
test_RhizomeInsertEmptyNew() {
executeJavaOk org.servalproject.test.Rhizome rhizome-insert '' '' empty empty.manifest "lucky"
tfw_cat --stdout --stderr -v empty.manifest
extract_manifest_id BID empty.manifest
assertStdoutGrep '^_status=NEW$'
assertStdoutGrep "^id=$BID\$"
assertStdoutGrep "^filesize=0\$"
assertStdoutGrep --matches=0 "^filehash="
assertStderrGrep --matches=1 "^bundle_status_code=NEW$CR\$"
assertStderrGrep --matches=1 --ignore-case "^bundle_status_message=.*bundle new to store.*$CR\$"
assertStderrGrep --matches=1 "^payload_status_code=EMPTY$CR\$"
assertStderrGrep --matches=1 --ignore-case "^payload_status_message=.*payload empty.*$CR\$"
executeOk_servald rhizome list
assert_rhizome_list empty
executeOk_servald rhizome extract bundle "$BID" xempty.manifest xempty
assert [ ! -e xempty ]
assert diff xempty.manifest empty.manifest
}
doc_RhizomeInsertEmptyUpdate="Java API insert new empty Rhizome bundle"
setup_RhizomeInsertEmptyUpdate() {
setup
create_file file1 1001
executeOk_servald rhizome add file "$SIDA1" file1 file1.manifest
extract_stdout_manifestid BID
extract_stdout_BK BK
>empty
assert [ ! -s empty ]
echo "id=$BID" >iempty.manifest
echo "BK=$BK" >>iempty.manifest
}
test_RhizomeInsertEmptyUpdate() {
executeJavaOk org.servalproject.test.Rhizome rhizome-insert '' iempty.manifest empty empty.manifest
tfw_cat --stdout --stderr -v empty.manifest
assertStdoutGrep '^_status=NEW$'
assertStdoutGrep "^id=$BID\$"
assertStdoutGrep "^filesize=0\$"
assertStdoutGrep --matches=0 "^filehash="
assertStderrGrep --matches=1 "^bundle_status_code=NEW$CR\$"
assertStderrGrep --matches=1 --ignore-case "^bundle_status_message=.*bundle new to store.*$CR\$"
assertStderrGrep --matches=1 "^payload_status_code=EMPTY$CR\$"
assertStderrGrep --matches=1 --ignore-case "^payload_status_message=.*payload empty.*$CR\$"
executeOk_servald rhizome list
assert_rhizome_list empty
executeOk_servald rhizome extract bundle "$BID" xempty.manifest xempty
assert [ ! -e xempty ]
assert diff xempty.manifest empty.manifest
}
runTests "$@" runTests "$@"

View File

@ -650,8 +650,8 @@ test_RhizomeInsertEmpty() {
assertStdoutIs 201 assertStdoutIs 201
assertGrep --matches=1 --ignore-case http.header "^Serval-Rhizome-Result-Bundle-Status-Code: 0$CR\$" assertGrep --matches=1 --ignore-case http.header "^Serval-Rhizome-Result-Bundle-Status-Code: 0$CR\$"
assertGrep --matches=1 --ignore-case http.header "^Serval-Rhizome-Result-Bundle-Status-Message: .*bundle new to store.*$CR\$" assertGrep --matches=1 --ignore-case http.header "^Serval-Rhizome-Result-Bundle-Status-Message: .*bundle new to store.*$CR\$"
assertGrep --matches=1 --ignore-case http.header "^Serval-Rhizome-Result-Payload-Status-Code: 1$CR\$" assertGrep --matches=1 --ignore-case http.header "^Serval-Rhizome-Result-Payload-Status-Code: 0$CR\$"
assertGrep --matches=1 --ignore-case http.header "^Serval-Rhizome-Result-Payload-Status-Message: .*payload new to store.*$CR\$" assertGrep --matches=1 --ignore-case http.header "^Serval-Rhizome-Result-Payload-Status-Message: .*payload empty.*$CR\$"
extract_manifest_id BID empty.manifest extract_manifest_id BID empty.manifest
executeOk_servald rhizome list executeOk_servald rhizome list
assert_rhizome_list empty assert_rhizome_list empty