Commit f2943ed8 authored by Tristan Cavelier's avatar Tristan Cavelier

replicaterevisionstorage upgraded + tests

parent 5a50c92f
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
module(jIO); module(jIO);
}(['jio'], function (jIO) { }(['jio'], function (jIO) {
"use strict"; "use strict";
jIO.addStorageType('replicaterevision', function (spec) { jIO.addStorage('replicaterevision', function (spec) {
var that = this, priv = {}; var that = this, priv = {};
spec = spec || {}; spec = spec || {};
...@@ -217,16 +217,9 @@ ...@@ -217,16 +217,9 @@
command.success(); command.success();
} }
if (!param._id) { if (!param._id) {
return callback({ return callback({"status": 501});
"status": 501
});
} }
priv.check( priv.check(command, param, option, callback);
command,
param,
option,
callback
);
}; };
/** /**
...@@ -264,8 +257,18 @@ ...@@ -264,8 +257,18 @@
callback = callback || priv.emptyFunction; callback = callback || priv.emptyFunction;
option = option || {}; option = option || {};
functions.begin = function () { functions.begin = function () {
// }; // // XXX make revision storage check and repair
// functions.repairAllSubStorages = function () { // // to enable check/repair sub storage from this storage
// // by calling this function just below
// //functions.repairAllSubStorages();
// // else we assume that sub storages are good
// functions.getAllDocuments(functions.newParam(
// doc,
// option,
// repair
// ));
// };
// functions.repairAllSubStorages = function () {
var i; var i;
for (i = 0; i < priv.storage_list.length; i += 1) { for (i = 0; i < priv.storage_list.length; i += 1) {
priv.send( priv.send(
...@@ -315,8 +318,8 @@ ...@@ -315,8 +318,8 @@
// 1: [responseB, [2]] // 1: [responseB, [2]]
], ],
"attachments": { "attachments": {
// attachmentA : {_id: attachmentA, _revs_info, _mimetype: ..} // attachmentA : {_id: attachmentA, _revs_info, _content_type: ..}
// attachmentB : {_id: attachmentB, _revs_info, _mimetype: ..} // attachmentB : {_id: attachmentB, _revs_info, _content_type: ..}
} }
}, },
"conflicts": { "conflicts": {
...@@ -333,9 +336,9 @@ ...@@ -333,9 +336,9 @@
var i, metadata, cloned_option; var i, metadata, cloned_option;
metadata = priv.clone(param.doc); metadata = priv.clone(param.doc);
cloned_option = priv.clone(param.option); cloned_option = priv.clone(param.option);
option.conflicts = true; cloned_option.conflicts = true;
option.revs = true; cloned_option.revs = true;
option.revs_info = true; cloned_option.revs_info = true;
for (i = 0; i < priv.storage_list.length; i += 1) { for (i = 0; i < priv.storage_list.length; i += 1) {
// if the document is not loaded // if the document is not loaded
priv.send(command, "get", i, priv.send(command, "get", i,
...@@ -356,7 +359,7 @@ ...@@ -356,7 +359,7 @@
// get document failed, exit // get document failed, exit
param.deal_result_state = "error"; param.deal_result_state = "error";
callback({ callback({
"status": "conflict", "status": 409,
"message": "An error occured on the sub storage", "message": "An error occured on the sub storage",
"reason": err.reason "reason": err.reason
}, undefined); }, undefined);
...@@ -378,6 +381,7 @@ ...@@ -378,6 +381,7 @@
// this is now the last response // this is now the last response
functions.makeResponsesStats(param.responses); functions.makeResponsesStats(param.responses);
//console.log(JSON.parse(JSON.stringify(param.responses)));
if (param.responses.stats_items.length === 1) { if (param.responses.stats_items.length === 1) {
// the responses are equals! // the responses are equals!
response_object.ok = true; response_object.ok = true;
...@@ -394,7 +398,7 @@ ...@@ -394,7 +398,7 @@
if (param.repair === false) { if (param.repair === false) {
// do not repair // do not repair
callback({ callback({
"status": "conflict", "status": 409,
"message": "Some documents are different in the sub storages", "message": "Some documents are different in the sub storages",
"reason": "Storage contents differ" "reason": "Storage contents differ"
}, undefined); }, undefined);
...@@ -460,7 +464,7 @@ ...@@ -460,7 +464,7 @@
/*jslint unparam: true */ /*jslint unparam: true */
if (err) { if (err) {
callback({ callback({
"status": "conflict", "status": 409,
"message": "Unable to retreive attachments", "message": "Unable to retreive attachments",
"reason": err.reason "reason": err.reason
}, undefined); }, undefined);
...@@ -513,7 +517,7 @@ ...@@ -513,7 +517,7 @@
if (new_doc._attachments.hasOwnProperty(i)) { if (new_doc._attachments.hasOwnProperty(i)) {
attachment_to_put.push({ attachment_to_put.push({
"_id": i, "_id": i,
"_mimetype": new_doc._attachments[i].content_type, "_content_type": new_doc._attachments[i].content_type,
"_revs_info": new_doc._revs_info "_revs_info": new_doc._revs_info
}); });
} }
...@@ -555,9 +559,7 @@ ...@@ -555,9 +559,7 @@
var i, attachment; var i, attachment;
if (err) { if (err) {
return callback({ return callback({
"status": 40, "status": 409,
"statusText": "Check Failed",
"error": "check_failed",
"message": "Unable to copy attachments", "message": "Unable to copy attachments",
"reason": err.reason "reason": err.reason
}, undefined); }, undefined);
...@@ -566,7 +568,7 @@ ...@@ -566,7 +568,7 @@
attachment = { attachment = {
"_id": param.doc._id, "_id": param.doc._id,
"_attachment": attachment_to_put[i]._id, "_attachment": attachment_to_put[i]._id,
"_mimetype": attachment_to_put[i]._mimetype, "_content_type": attachment_to_put[i]._content_type,
"_revs_info": attachment_to_put[i]._revs_info, "_revs_info": attachment_to_put[i]._revs_info,
// "_revs_info": param.responses.list[index]._revs_info, // "_revs_info": param.responses.list[index]._revs_info,
"_data": param.responses.attachments[attachment_to_put[i]._id] "_data": param.responses.attachments[attachment_to_put[i]._id]
...@@ -640,7 +642,7 @@ ...@@ -640,7 +642,7 @@
* @param {object} command The JIO command * @param {object} command The JIO command
*/ */
that.post = function (command, metadata, option) { that.post = function (command, metadata, option) {
that.genericRequest(command, "put", metadata, option); that.genericRequest(command, "post", metadata, option);
}; };
/** /**
...@@ -649,7 +651,7 @@ ...@@ -649,7 +651,7 @@
* @param {object} command The JIO command * @param {object} command The JIO command
*/ */
that.put = function (command, metadata, option) { that.put = function (command, metadata, option) {
that.genericRequest(command, "post", metadata, option); that.genericRequest(command, "put", metadata, option);
}; };
/** /**
...@@ -696,7 +698,5 @@ ...@@ -696,7 +698,5 @@
that.removeAttachment = function (command, param, option) { that.removeAttachment = function (command, param, option) {
that.genericRequest(command, "removeAttachment", param, option); that.genericRequest(command, "removeAttachment", param, option);
}; };
return that;
}); });
})); }));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment