Commit 1b04d350 authored by Hardik Juneja's avatar Hardik Juneja Committed by Hardik Juneja

Add hasCapacityMethod Function and fix related tests

parent a7ee771f
...@@ -447,7 +447,7 @@ ...@@ -447,7 +447,7 @@
ERP5Storage.prototype.hasCapacity = function (name) { ERP5Storage.prototype.hasCapacity = function (name) {
return ((name === "list") || (name === "query") || return ((name === "list") || (name === "query") ||
(name === "select") || (name === "limit") || (name === "select") || (name === "limit") ||
(name === "sort")); (name === "sort")) || (name === "allow_bulk");
}; };
function isSingleLocalRoles(parsed_query) { function isSingleLocalRoles(parsed_query) {
......
...@@ -479,7 +479,7 @@ ...@@ -479,7 +479,7 @@
// Keep it like this until the bulk API is stabilized // Keep it like this until the bulk API is stabilized
var use_bulk_get = false; var use_bulk_get = false;
try { try {
use_bulk_get = context._remote_sub_storage.hasCapacity("bulk"); use_bulk_get = context._remote_sub_storage.hasCapacity("allow_bulk");
} catch (error) { } catch (error) {
if (!((error instanceof jIO.util.jIOError) && if (!((error instanceof jIO.util.jIOError) &&
(error.status_code === 501))) { (error.status_code === 501))) {
......
...@@ -2486,7 +2486,10 @@ ...@@ -2486,7 +2486,10 @@
Storage200Bulk.prototype.put = function () { Storage200Bulk.prototype.put = function () {
return this._sub_storage.put.apply(this._sub_storage, arguments); return this._sub_storage.put.apply(this._sub_storage, arguments);
}; };
Storage200Bulk.prototype.hasCapacity = function () { Storage200Bulk.prototype.hasCapacity = function (name) {
if (name === "allow_bulk") {
return true;
}
return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments); return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments);
}; };
Storage200Bulk.prototype.buildQuery = function () { Storage200Bulk.prototype.buildQuery = function () {
...@@ -2566,7 +2569,10 @@ ...@@ -2566,7 +2569,10 @@
Storage200Bulk.prototype.put = function () { Storage200Bulk.prototype.put = function () {
return this._sub_storage.put.apply(this._sub_storage, arguments); return this._sub_storage.put.apply(this._sub_storage, arguments);
}; };
Storage200Bulk.prototype.hasCapacity = function () { Storage200Bulk.prototype.hasCapacity = function (name) {
if (name === "allow_bulk") {
return true;
}
return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments); return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments);
}; };
Storage200Bulk.prototype.buildQuery = function () { Storage200Bulk.prototype.buildQuery = function () {
...@@ -2637,4 +2643,114 @@ ...@@ -2637,4 +2643,114 @@
}); });
}); });
test("Donot bulk if substorage don't implement it", function () {
stop();
expect(2);
var id,
post_id = "123456789",
context = this;
function SubStorage200Bulk() {
return;
}
function Storage200Bulk(spec) {
this._sub_storage = jIO.createJIO(spec.sub_storage);
}
Storage200Bulk.prototype.bulk = function (args) {
deepEqual(args, [{
method: "get",
parameter_list: [post_id]
}]);
return this._sub_storage.bulk(args);
};
Storage200Bulk.prototype.get = function () {
return this._sub_storage.get.apply(this._sub_storage, arguments);
};
Storage200Bulk.prototype.post = function (param) {
return this.put(post_id, param);
};
Storage200Bulk.prototype.put = function () {
return this._sub_storage.put.apply(this._sub_storage, arguments);
};
Storage200Bulk.prototype.hasCapacity = function () {
return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments);
};
Storage200Bulk.prototype.buildQuery = function () {
return this._sub_storage.buildQuery.apply(this._sub_storage, arguments);
};
jIO.addStorage(
'replicatestorage200nobulk',
Storage200Bulk
);
SubStorage200Bulk.prototype.get = function () {
return {title: "bar"};
};
SubStorage200Bulk.prototype.post = function (param) {
return this.put(post_id, param);
};
SubStorage200Bulk.prototype.put = function () {
return post_id;
};
SubStorage200Bulk.prototype.hasCapacity = function (name) {
if (name === "allow_bulk") {
return false;
}
return true;
};
SubStorage200Bulk.prototype.buildQuery = function () {
return [{id: "123456789", value: {"title": "bar"}}];
};
jIO.addStorage(
'replicatesubstorage200nobulk',
SubStorage200Bulk
);
this.jio = jIO.createJIO({
type: "replicate",
local_sub_storage: {
type: "memory"
},
remote_sub_storage: {
type: "replicatestorage200nobulk",
sub_storage: {
type: "replicatesubstorage200nobulk"
}
}
});
context.jio.__storage._remote_sub_storage.post({"title": "bar"})
.then(function (result) {
id = result;
return context.jio.repair();
})
.then(function () {
return context.jio.get(id);
})
.then(function (result) {
deepEqual(result, {
title: "bar"
});
})
.then(function () {
return context.jio.__storage._signature_sub_storage.get(id);
})
.then(function (result) {
deepEqual(result, {
hash: "6799f3ea80e325b89f19589282a343c376c1f1af"
});
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
}(jIO, QUnit)); }(jIO, QUnit));
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