Commit b076d049 authored by Vincent Bechu's avatar Vincent Bechu

mappingstorage: add bulk, repair and tests

parent 89139428
...@@ -273,12 +273,36 @@ ...@@ -273,12 +273,36 @@
return this._sub_storage.repair.apply(this._sub_storage, arguments); return this._sub_storage.repair.apply(this._sub_storage, arguments);
}; };
MappingStorage.prototype.bulk = function () { MappingStorage.prototype.bulk = function (id_list) {
var i, that = this, mapped_result = []; var i,
return this._sub_storage.bulk.apply(arguments) that = this,
mapped_result = [],
promise_list = id_list.map(function (parameter) {
return getSubStorageId(that, parameter.parameter_list[0])
.push(function (id) {
if (parameter.method === "put") {
return {
"method": parameter.method,
"parameter_list": [
id,
unmapDocument(parameter.parameter_list[1])
]
};
}
return {"method": parameter.method, "parameter_list": [id]};
});
});
return new RSVP.Queue()
.push(function () {
return RSVP.all(promise_list);
})
.push(function (id_list_mapped) {
return that._sub_storage.bulk(id_list_mapped);
})
.push(function (result) { .push(function (result) {
for (i = 0; i < result.length; i += 1) { for (i = 0; i < result.length; i += 1) {
mapped_result.push(mapDocument(that, result[i]), false); mapped_result.push(mapDocument(that, result[i], false));
} }
return mapped_result; return mapped_result;
}); });
......
...@@ -827,7 +827,7 @@ ...@@ -827,7 +827,7 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// mappingStorage.bulk // mappingStorage.bulk
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
/* module("mappingstorage.bulk"); module("mappingstorage.bulk");
test("bulk with map_all_property", function () { test("bulk with map_all_property", function () {
stop(); stop();
expect(2); expect(2);
...@@ -837,7 +837,7 @@ ...@@ -837,7 +837,7 @@
sub_storage: { sub_storage: {
type: "mappingstorage2713" type: "mappingstorage2713"
}, },
map_all_doc: true, map_all_property: true,
mapping_dict: { mapping_dict: {
"title": {"equal": "otherTitle"}, "title": {"equal": "otherTitle"},
"id": {"equal": "otherId"} "id": {"equal": "otherId"}
...@@ -848,8 +848,28 @@ ...@@ -848,8 +848,28 @@
return true; return true;
}; };
Storage2713.prototype.bulk = function () { Storage2713.prototype.buildQuery = function (option) {
deepEqual(arguments, ["some", "arguments"], "bulk 2713 called"); if (option.query === 'otherId: "id1"') {
return [{id: "foo"}];
}
if (option.query === 'otherId: "id2"') {
return [{id: "bar"}];
}
throw new Error("invalid option:" + option.toString());
};
Storage2713.prototype.bulk = function (args) {
deepEqual(
args,
[{
method: "get",
parameter_list: ["foo"]
}, {
method: "get",
parameter_list: ["bar"]
}],
"bulk 2713 called"
);
return [ return [
{ {
"otherId": "foo", "otherId": "foo",
...@@ -863,7 +883,13 @@ ...@@ -863,7 +883,13 @@
]; ];
}; };
jio.bulk("some", "arguments") jio.bulk([{
method: "get",
parameter_list: ["id1"]
}, {
method: "get",
parameter_list: ["id2"]
}])
.push(function (result) { .push(function (result) {
deepEqual( deepEqual(
result, result,
...@@ -882,7 +908,7 @@ ...@@ -882,7 +908,7 @@
.always(function () { .always(function () {
start(); start();
}); });
});*/ });
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// mappingStorage.repair // mappingStorage.repair
......
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