Commit 48388898 authored by Vincent Bechu's avatar Vincent Bechu

mappingstorage: add bulk, repair and tests

parent 4e69547a
......@@ -273,12 +273,36 @@
return this._sub_storage.repair.apply(this._sub_storage, arguments);
};
MappingStorage.prototype.bulk = function () {
var i, that = this, mapped_result = [];
return this._sub_storage.bulk.apply(arguments)
MappingStorage.prototype.bulk = function (id_list) {
var i,
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) {
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;
});
......
......@@ -827,7 +827,7 @@
/////////////////////////////////////////////////////////////////
// mappingStorage.bulk
/////////////////////////////////////////////////////////////////
/* module("mappingstorage.bulk");
module("mappingstorage.bulk");
test("bulk with map_all_property", function () {
stop();
expect(2);
......@@ -837,7 +837,7 @@
sub_storage: {
type: "mappingstorage2713"
},
map_all_doc: true,
map_all_property: true,
mapping_dict: {
"title": {"equal": "otherTitle"},
"id": {"equal": "otherId"}
......@@ -848,8 +848,28 @@
return true;
};
Storage2713.prototype.bulk = function () {
deepEqual(arguments, ["some", "arguments"], "bulk 2713 called");
Storage2713.prototype.buildQuery = function (option) {
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 [
{
"otherId": "foo",
......@@ -863,7 +883,13 @@
];
};
jio.bulk("some", "arguments")
jio.bulk([{
method: "get",
parameter_list: ["id1"]
}, {
method: "get",
parameter_list: ["id2"]
}])
.push(function (result) {
deepEqual(
result,
......@@ -882,7 +908,7 @@
.always(function () {
start();
});
});*/
});
/////////////////////////////////////////////////////////////////
// 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