Commit 68750128 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

Replicate Storage: Add ignore error options

parent 2d988363
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
*/ */
/*jslint nomen: true*/ /*jslint nomen: true*/
/*global jIO, RSVP, Rusha*/ /*global jIO, RSVP, Rusha, console*/
(function (jIO, RSVP, Rusha, stringify) { (function (jIO, RSVP, Rusha, stringify) {
"use strict"; "use strict";
...@@ -58,6 +58,9 @@ ...@@ -58,6 +58,9 @@
this._use_remote_post = spec.use_remote_post || false; this._use_remote_post = spec.use_remote_post || false;
this._ignore_document_replication_error =
spec.ignore_document_replication_error || false;
this._conflict_handling = spec.conflict_handling || 0; this._conflict_handling = spec.conflict_handling || 0;
// 0: no resolution (ie, throw an Error) // 0: no resolution (ie, throw an Error)
// 1: keep the local state // 1: keep the local state
...@@ -224,6 +227,7 @@ ...@@ -224,6 +227,7 @@
throw error; throw error;
}); });
}); });
} }
function checkSignatureDifference(queue, source, destination, id, function checkSignatureDifference(queue, source, destination, id,
...@@ -302,6 +306,16 @@ ...@@ -302,6 +306,16 @@
throw error; throw error;
}); });
} }
})
.push(undefined, function (error) {
if (options.ignore_document_replication_error) {
// XXX This should be logged
console.log("Ignored error for " + id);
console.log(error);
skip_document_dict[id] = null;
return;
}
throw error;
}); });
} }
...@@ -470,7 +484,9 @@ ...@@ -470,7 +484,9 @@
CONFLICT_KEEP_REMOTE)), CONFLICT_KEEP_REMOTE)),
check_modification: context._check_local_modification, check_modification: context._check_local_modification,
check_creation: context._check_local_creation, check_creation: context._check_local_creation,
check_deletion: context._check_local_deletion check_deletion: context._check_local_deletion,
ignore_document_replication_error:
context._ignore_document_replication_error
}); });
} }
}) })
...@@ -498,7 +514,9 @@ ...@@ -498,7 +514,9 @@
CONFLICT_CONTINUE), CONFLICT_CONTINUE),
check_modification: context._check_remote_modification, check_modification: context._check_remote_modification,
check_creation: context._check_remote_creation, check_creation: context._check_remote_creation,
check_deletion: context._check_remote_deletion check_deletion: context._check_remote_deletion,
ignore_document_replication_error:
context._ignore_document_replication_error
}); });
} }
}); });
......
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
deepEqual(jio.__storage._query_options, {}); deepEqual(jio.__storage._query_options, {});
equal(jio.__storage._use_remote_post, false); equal(jio.__storage._use_remote_post, false);
equal(jio.__storage._ignore_document_replication_error, false);
equal(jio.__storage._conflict_handling, 0); equal(jio.__storage._conflict_handling, 0);
equal(jio.__storage._check_local_creation, true); equal(jio.__storage._check_local_creation, true);
equal(jio.__storage._check_local_deletion, true); equal(jio.__storage._check_local_deletion, true);
...@@ -89,6 +90,7 @@ ...@@ -89,6 +90,7 @@
}, },
query: {query: 'portal_type: "Foo"', limit: [0, 1234567890]}, query: {query: 'portal_type: "Foo"', limit: [0, 1234567890]},
use_remote_post: true, use_remote_post: true,
ignore_document_replication_error: true,
conflict_handling: 3, conflict_handling: 3,
check_local_creation: false, check_local_creation: false,
check_local_deletion: false, check_local_deletion: false,
...@@ -103,6 +105,7 @@ ...@@ -103,6 +105,7 @@
{query: 'portal_type: "Foo"', limit: [0, 1234567890]} {query: 'portal_type: "Foo"', limit: [0, 1234567890]}
); );
equal(jio.__storage._use_remote_post, true); equal(jio.__storage._use_remote_post, true);
equal(jio.__storage._ignore_document_replication_error, true);
equal(jio.__storage._conflict_handling, 3); equal(jio.__storage._conflict_handling, 3);
equal(jio.__storage._check_local_creation, false); equal(jio.__storage._check_local_creation, false);
equal(jio.__storage._check_local_deletion, false); equal(jio.__storage._check_local_deletion, false);
...@@ -2637,4 +2640,121 @@ ...@@ -2637,4 +2640,121 @@
}); });
}); });
test("do not ignore document replication error", function () {
stop();
expect(1);
function Storage200PutError() {
this._sub_storage = jIO.createJIO({type: "memory"});
}
Storage200PutError.prototype.put = function () {
throw new jIO.util.jIOError(
"Forbidden: cannot modify document",
403
);
};
Storage200PutError.prototype.get = function () {
return this._sub_storage.get.apply(this._sub_storage, arguments);
};
Storage200PutError.prototype.post = function () {
throw new jIO.util.jIOError(
"Forbidden: cannot modify document",
403
);
};
Storage200PutError.prototype.hasCapacity = function () {
return true;
};
Storage200PutError.prototype.buildQuery = function () {
return this._sub_storage.buildQuery.apply(this._sub_storage, arguments);
};
jIO.addStorage(
'replicatestorage200puterror',
Storage200PutError
);
var jio = jIO.createJIO({
type: "replicate",
local_sub_storage: {
type: "memory"
},
remote_sub_storage: {
type: "replicatestorage200puterror"
}
});
jio.put("error", {title: "bar"})
.then(function () {
return jio.repair();
})
.then(function () {
ok(false, "Error should be raised by substorage");
})
.fail(function () {
ok(true, "Error raised by substorage");
})
.always(function () {
start();
});
});
test("ignore document replication error", function () {
stop();
expect(1);
function Storage500PutError() {
this._sub_storage = jIO.createJIO({type: "memory"});
}
Storage500PutError.prototype.put = function () {
throw new jIO.util.jIOError(
"Forbidden: cannot modify document",
403
);
};
Storage500PutError.prototype.get = function () {
return this._sub_storage.get.apply(this._sub_storage, arguments);
};
Storage500PutError.prototype.post = function () {
throw new jIO.util.jIOError(
"Forbidden: cannot modify document",
403
);
};
Storage500PutError.prototype.hasCapacity = function () {
return true;
};
Storage500PutError.prototype.buildQuery = function () {
return this._sub_storage.buildQuery.apply(this._sub_storage, arguments);
};
jIO.addStorage(
'replicatestorage500puterror',
Storage500PutError
);
var jio = jIO.createJIO({
type: "replicate",
ignore_document_replication_error: true,
local_sub_storage: {
type: "memory"
},
remote_sub_storage: {
type: "replicatestorage500puterror"
}
});
jio.put("error", {title: "bar"})
.then(function () {
return jio.repair();
})
.then(function () {
ok(true, "Error is not be raised by substorage");
})
.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