Commit 9273600e authored by Romain Courteaud's avatar Romain Courteaud

Add repair method.

This (slow) method will be used to stabilised a storage (launch synchronisation process for example).
parent 3fb5fcf5
......@@ -443,6 +443,20 @@
};
declareMethod(JioProxyStorage, "allAttachments", checkId);
declareMethod(JioProxyStorage, "repair");
JioProxyStorage.prototype.repair = function () {
var context = this,
argument_list = arguments;
return new RSVP.Queue()
.push(function () {
var storage_method = context.__storage.repair;
if (storage_method !== undefined) {
return context.__storage.repair.apply(context.__storage,
argument_list);
}
});
};
/////////////////////////////////////////////////////////////////
// Storage builder
......
......@@ -83,6 +83,10 @@
});
};
DocumentStorage.prototype.repair = function () {
return this._sub_storage.repair.apply(this._sub_storage, arguments);
};
DocumentStorage.prototype.hasCapacity = function (capacity) {
return (capacity === "list");
};
......
......@@ -242,6 +242,10 @@
return this._sub_storage.removeAttachment(ROOT, id);
};
FileSystemBridgeStorage.prototype.repair = function () {
return this._sub_storage.repair.apply(this._sub_storage, arguments);
};
jIO.addStorage('drivetojiomapping', FileSystemBridgeStorage);
}(jIO, RSVP, Blob));
......@@ -39,6 +39,9 @@
return this._sub_storage.removeAttachment.apply(this._sub_storage,
arguments);
};
QueryStorage.prototype.repair = function () {
return this._sub_storage.repair.apply(this._sub_storage, arguments);
};
QueryStorage.prototype.hasCapacity = function (name) {
if (name === "list") {
......
......@@ -199,6 +199,18 @@
return false;
};
UnionStorage.prototype.repair = function () {
var i,
promise_list = [];
for (i = 0; i < this._storage_list.length; i += 1) {
promise_list.push(this._storage_list[i].repair.apply(
this._storage_list[i],
arguments
));
}
return RSVP.all(promise_list);
};
jIO.addStorage('union', UnionStorage);
}(jIO, RSVP));
......@@ -50,6 +50,9 @@
return this._sub_storage.removeAttachment.apply(this._sub_storage,
arguments);
};
UUIDStorage.prototype.repair = function () {
return this._sub_storage.repair.apply(this._sub_storage, arguments);
};
UUIDStorage.prototype.hasCapacity = function (name) {
return this._sub_storage.hasCapacity(name);
};
......
......@@ -478,4 +478,38 @@
});
});
/////////////////////////////////////////////////////////////////
// documentStorage.repair
/////////////////////////////////////////////////////////////////
module("documentStorage.repair");
test("repair called substorage repair", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "document",
document_id: "foo",
sub_storage: {
type: "documentstorage200"
}
}),
expected_options = {foo: "bar"};
Storage200.prototype.repair = function (options) {
deepEqual(options, expected_options, "repair 200 called");
return "OK";
};
jio.repair(expected_options)
.then(function (result) {
equal(result, "OK");
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
}(jIO, QUnit, Blob, btoa));
......@@ -1053,4 +1053,37 @@
});
});
/////////////////////////////////////////////////////////////////
// driveToJioMapping.repair
/////////////////////////////////////////////////////////////////
module("driveToJioMapping.repair");
test("repair called substorage repair", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "drivetojiomapping",
sub_storage: {
type: "drivetojiomapping200"
}
}),
expected_options = {foo: "bar"};
Storage200.prototype.repair = function (options) {
deepEqual(options, expected_options, "repair 200 called");
return "OK";
};
jio.repair(expected_options)
.then(function (result) {
equal(result, "OK");
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
}(jIO, QUnit, Blob));
......@@ -820,4 +820,37 @@
});
});
/////////////////////////////////////////////////////////////////
// queryStorage.repair
/////////////////////////////////////////////////////////////////
module("queryStorage.repair");
test("repair called substorage repair", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "query",
sub_storage: {
type: "querystorage200"
}
}),
expected_options = {foo: "bar"};
Storage200.prototype.repair = function (options) {
deepEqual(options, expected_options, "repair 200 called");
return "OK";
};
jio.repair(expected_options)
.then(function (result) {
equal(result, "OK");
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
}(jIO, QUnit, Blob));
......@@ -61,6 +61,10 @@
}
}];
};
Storage200.prototype.repair = function (options) {
deepEqual(options, {foo: "bar"}, "repair 200 called");
return "OK";
};
jIO.addStorage('unionstorage200', Storage200);
function Storage200v2() {
......@@ -90,6 +94,7 @@
}
Storage500.prototype.get = generateError;
Storage500.prototype.post = generateError;
Storage500.prototype.repair = generateError;
jIO.addStorage('unionstorage500', Storage500);
/////////////////////////////////////////////////////////////////
......@@ -850,5 +855,60 @@
});
});
/////////////////////////////////////////////////////////////////
// unionStorage.repair
/////////////////////////////////////////////////////////////////
module("unionStorage.repair");
test("repair called substorage repair", function () {
stop();
expect(3);
var jio = jIO.createJIO({
type: "union",
storage_list: [{
type: "unionstorage200"
}, {
type: "unionstorage200"
}]
});
jio.repair({foo: "bar"})
.then(function (result) {
deepEqual(result, ["OK", "OK"]);
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("repair fails in one substorage fails", function () {
stop();
expect(5);
var jio = jIO.createJIO({
type: "union",
storage_list: [{
type: "unionstorage200"
}, {
type: "unionstorage500"
}]
});
jio.repair({foo: "bar"})
.fail(function (error) {
ok(error instanceof Error);
equal(error.message, "manually triggered error");
equal(error.status_code, undefined);
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
}(jIO, QUnit));
......@@ -398,4 +398,37 @@
});
});
/////////////////////////////////////////////////////////////////
// uuidStorage.repair
/////////////////////////////////////////////////////////////////
module("uuidStorage.repair");
test("repair called substorage repair", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "uuid",
sub_storage: {
type: "uuidstorage200"
}
}),
expected_options = {foo: "bar"};
Storage200.prototype.repair = function (options) {
deepEqual(options, expected_options, "repair 200 called");
return "OK";
};
jio.repair(expected_options)
.then(function (result) {
equal(result, "OK");
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
}(jIO, QUnit, Blob));
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