Commit ab2e0b8d authored by Romain Courteaud's avatar Romain Courteaud

WIP report replicate

parent 7460251a
......@@ -35,21 +35,31 @@
LOG_UNRESOLVED_CONFLICT = 1,
LOG_UNEXPECTED_LOCAL_ATTACHMENT = 2,
LOG_UNEXPECTED_REMOTE_ATTACHMENT = 3,
LOG_UNRESOLVED_ATTACHMENT_CONFLICT = 11,
// 100 - 199 solving conflict
LOG_FORCE_PUT_REMOTE = 100,
LOG_FORCE_POST_REMOTE = 101,
LOG_FORCE_DELETE_REMOTE = 103,
LOG_FORCE_PUT_REMOTE_ATTACHMENT = 110,
LOG_FORCE_DELETE_REMOTE_ATTACHMENT = 113,
LOG_FORCE_PUT_LOCAL = 150,
LOG_FORCE_POST_LOCAL = 151,
LOG_FORCE_DELETE_LOCAL = 153,
LOG_FORCE_PUT_LOCAL_ATTACHMENT = 160,
LOG_FORCE_DELETE_LOCAL_ATTACHMENT = 163,
// 200 - 299 pushing change
LOG_PUT_REMOTE = 200,
LOG_POST_REMOTE = 201,
LOG_DELETE_REMOTE = 203,
LOG_PUT_REMOTE_ATTACHMENT = 210,
LOG_DELETE_REMOTE_ATTACHMENT = 213,
LOG_PUT_LOCAL = 250,
LOG_POST_LOCAL = 251,
LOG_DELETE_LOCAL = 253,
LOG_FALSE_CONFLICT = 299,
LOG_PUT_LOCAL_ATTACHMENT = 260,
LOG_DELETE_LOCAL_ATTACHMENT = 263,
LOG_FALSE_CONFLICT = 298,
LOG_FALSE_CONFLICT_ATTACHMENT = 299,
// 300 - 399 nothing to do
LOG_SKIP_LOCAL_CREATION = 300,
LOG_SKIP_LOCAL_MODIFICATION = 301,
......@@ -57,8 +67,16 @@
LOG_SKIP_REMOTE_CREATION = 350,
LOG_SKIP_REMOTE_MODIFICATION = 351,
LOG_SKIP_REMOTE_DELETION = 353,
LOG_SKIP_CONFLICT = 398,
LOG_NO_CHANGE = 399;
LOG_SKIP_LOCAL_ATTACHMENT_CREATION = 310,
LOG_SKIP_LOCAL_ATTACHMENT_MODIFICATION = 311,
LOG_SKIP_LOCAL_ATTACHMENT_DELETION = 313,
LOG_SKIP_REMOTE_ATTACHMENT_CREATION = 360,
LOG_SKIP_REMOTE_ATTACHMENT_MODIFICATION = 361,
LOG_SKIP_REMOTE_ATTACHMENT_DELETION = 363,
LOG_SKIP_CONFLICT = 396,
LOG_SKIP_CONFLICT_ATTACHMENT = 397,
LOG_NO_CHANGE = 398,
LOG_NO_CHANGE_ATTACHMENT = 399;
function ReplicateReport() {
this._list = [];
......@@ -74,26 +92,46 @@
LOG_UNRESOLVED_CONFLICT: LOG_UNRESOLVED_CONFLICT,
LOG_UNEXPECTED_LOCAL_ATTACHMENT: LOG_UNEXPECTED_LOCAL_ATTACHMENT,
LOG_UNEXPECTED_REMOTE_ATTACHMENT: LOG_UNEXPECTED_REMOTE_ATTACHMENT,
LOG_UNRESOLVED_ATTACHMENT_CONFLICT: LOG_UNRESOLVED_ATTACHMENT_CONFLICT,
LOG_FORCE_PUT_REMOTE: LOG_FORCE_PUT_REMOTE,
LOG_FORCE_POST_REMOTE: LOG_FORCE_POST_REMOTE,
LOG_FORCE_DELETE_REMOTE: LOG_FORCE_DELETE_REMOTE,
LOG_FORCE_PUT_LOCAL: LOG_FORCE_PUT_LOCAL,
LOG_FORCE_POST_LOCAL: LOG_FORCE_POST_LOCAL,
LOG_FORCE_DELETE_LOCAL: LOG_FORCE_DELETE_LOCAL,
LOG_FORCE_PUT_REMOTE_ATTACHMENT: LOG_FORCE_PUT_REMOTE_ATTACHMENT,
LOG_FORCE_DELETE_REMOTE_ATTACHMENT: LOG_FORCE_DELETE_REMOTE_ATTACHMENT,
LOG_FORCE_PUT_LOCAL_ATTACHMENT: LOG_FORCE_PUT_LOCAL_ATTACHMENT,
LOG_FORCE_DELETE_LOCAL_ATTACHMENT: LOG_FORCE_DELETE_LOCAL_ATTACHMENT,
LOG_PUT_REMOTE: LOG_PUT_REMOTE,
LOG_POST_REMOTE: LOG_POST_REMOTE,
LOG_DELETE_REMOTE: LOG_DELETE_REMOTE,
LOG_PUT_REMOTE_ATTACHMENT: LOG_PUT_REMOTE_ATTACHMENT,
LOG_DELETE_REMOTE_ATTACHMENT: LOG_DELETE_REMOTE_ATTACHMENT,
LOG_PUT_LOCAL: LOG_PUT_LOCAL,
LOG_DELETE_LOCAL: LOG_DELETE_LOCAL,
LOG_PUT_LOCAL_ATTACHMENT: LOG_PUT_LOCAL_ATTACHMENT,
LOG_DELETE_LOCAL_ATTACHMENT: LOG_DELETE_LOCAL_ATTACHMENT,
LOG_FALSE_CONFLICT: LOG_FALSE_CONFLICT,
LOG_FALSE_CONFLICT_ATTACHMENT: LOG_FALSE_CONFLICT_ATTACHMENT,
LOG_SKIP_LOCAL_CREATION: LOG_SKIP_LOCAL_CREATION,
LOG_SKIP_LOCAL_MODIFICATION: LOG_SKIP_LOCAL_MODIFICATION,
LOG_SKIP_LOCAL_DELETION: LOG_SKIP_LOCAL_DELETION,
LOG_SKIP_REMOTE_CREATION: LOG_SKIP_REMOTE_CREATION,
LOG_SKIP_REMOTE_MODIFICATION: LOG_SKIP_REMOTE_MODIFICATION,
LOG_SKIP_REMOTE_DELETION: LOG_SKIP_REMOTE_DELETION,
LOG_SKIP_LOCAL_ATTACHMENT_CREATION: LOG_SKIP_LOCAL_ATTACHMENT_CREATION,
LOG_SKIP_LOCAL_ATTACHMENT_MODIFICATION:
LOG_SKIP_LOCAL_ATTACHMENT_MODIFICATION,
LOG_SKIP_LOCAL_ATTACHMENT_DELETION: LOG_SKIP_LOCAL_ATTACHMENT_DELETION,
LOG_SKIP_REMOTE_ATTACHMENT_CREATION: LOG_SKIP_REMOTE_ATTACHMENT_CREATION,
LOG_SKIP_REMOTE_ATTACHMENT_MODIFICATION:
LOG_SKIP_REMOTE_ATTACHMENT_MODIFICATION,
LOG_SKIP_REMOTE_ATTACHMENT_DELETION: LOG_SKIP_REMOTE_ATTACHMENT_DELETION,
LOG_SKIP_CONFLICT: LOG_SKIP_CONFLICT,
LOG_SKIP_CONFLICT_ATTACHMENT: LOG_SKIP_CONFLICT_ATTACHMENT,
LOG_NO_CHANGE: LOG_NO_CHANGE,
LOG_NO_CHANGE_ATTACHMENT: LOG_NO_CHANGE_ATTACHMENT,
log: function (id, type, extra) {
if (type === undefined) {
......@@ -112,6 +150,23 @@
}
},
logAttachment: function (id, name, type, extra) {
if (type === undefined) {
if (extra === undefined) {
extra = 'Unknown type: ' + type;
}
type = LOG_UNEXPECTED_ERROR;
}
if (extra === undefined) {
this._list.push([type, id, name]);
} else {
this._list.push([type, id, name, extra]);
}
if (type < 100) {
this.has_error = true;
}
},
toString: function () {
return this._list.toString();
}
......@@ -363,7 +418,16 @@
function propagateAttachmentDeletion(context,
destination,
id, name) {
id, name,
conflict, from_local, report) {
if (conflict) {
report.logAttachment(id, name, from_local ?
LOG_FORCE_DELETE_REMOTE_ATTACHMENT :
LOG_FORCE_DELETE_LOCAL_ATTACHMENT);
} else {
report.logAttachment(id, name, from_local ? LOG_DELETE_REMOTE_ATTACHMENT :
LOG_DELETE_LOCAL_ATTACHMENT);
}
return destination.removeAttachment(id, name)
.push(function () {
return context._signature_sub_storage.removeAttachment(id, name);
......@@ -372,7 +436,16 @@
function propagateAttachmentModification(context,
destination,
blob, hash, id, name) {
blob, hash, id, name,
from_local, is_conflict, report) {
if (is_conflict) {
report.logAttachment(id, name, from_local ?
LOG_FORCE_PUT_REMOTE_ATTACHMENT :
LOG_FORCE_PUT_LOCAL_ATTACHMENT);
} else {
report.logAttachment(id, name, from_local ? LOG_PUT_REMOTE_ATTACHMENT :
LOG_PUT_LOCAL_ATTACHMENT);
}
return destination.putAttachment(id, name, blob)
.push(function () {
return context._signature_sub_storage.putAttachment(id, name,
......@@ -387,7 +460,7 @@
status_hash, local_hash, blob,
source, destination, id, name,
conflict_force, conflict_revert,
conflict_ignore) {
conflict_ignore, from_local, report) {
// No need to check twice
skip_attachment_dict[name] = null;
var remote_blob;
......@@ -411,6 +484,7 @@
.push(function (remote_hash) {
if (local_hash === remote_hash) {
// Same modifications on both side
report.logAttachment(id, name, LOG_FALSE_CONFLICT_ATTACHMENT);
if (local_hash === null) {
// Deleted on both side, drop signature
return context._signature_sub_storage.removeAttachment(id, name);
......@@ -428,15 +502,21 @@
// Deleted locally
return propagateAttachmentDeletion(context,
destination,
id, name);
id, name,
(remote_hash !== status_hash),
from_local, report);
}
return propagateAttachmentModification(context,
destination, blob,
local_hash, id, name);
local_hash, id, name,
from_local,
(remote_hash !== status_hash),
report);
}
// Conflict cases
if (conflict_ignore === true) {
report.logAttachment(id, name, LOG_SKIP_CONFLICT_ATTACHMENT);
return;
}
......@@ -445,7 +525,9 @@
if (remote_hash === null) {
// Deleted remotely
return propagateAttachmentDeletion(context,
source, id, name);
source, id, name,
(local_hash !== status_hash),
!from_local, report);
}
return propagateAttachmentModification(
context,
......@@ -453,7 +535,10 @@
remote_blob,
remote_hash,
id,
name
name,
!from_local,
(local_hash !== status_hash),
report
);
}
......@@ -462,12 +547,14 @@
// Copy remote modification remotely
return propagateAttachmentModification(context,
destination, blob,
local_hash, id, name);
local_hash, id, name, from_local,
false,
report);
}
throw new jIO.util.jIOError("Conflict on '" + id +
"' with attachment '" +
name + "'",
409);
report.logAttachment(id, name, LOG_UNRESOLVED_ATTACHMENT_CONFLICT);
})
.push(undefined, function (error) {
report.logAttachment(id, name, LOG_UNEXPECTED_ERROR, error);
});
}
......@@ -478,7 +565,9 @@
conflict_force,
conflict_revert,
conflict_ignore,
is_creation, is_modification) {
is_creation, is_modification,
from_local,
report) {
var blob,
status_hash;
queue
......@@ -513,14 +602,20 @@
var array_buffer = evt.target.result,
local_hash = generateHashFromArrayBuffer(array_buffer);
if (local_hash !== status_hash) {
return checkAndPropagateAttachment(context,
skip_attachment_dict,
status_hash, local_hash, blob,
source, destination, id, name,
conflict_force, conflict_revert,
conflict_ignore);
if (local_hash === status_hash) {
if (!from_local) {
report.logAttachment(id, name, LOG_NO_CHANGE_ATTACHMENT);
}
return;
}
return checkAndPropagateAttachment(context,
skip_attachment_dict,
status_hash, local_hash, blob,
source, destination, id, name,
conflict_force, conflict_revert,
conflict_ignore,
from_local,
report);
});
}
......@@ -528,7 +623,7 @@
skip_attachment_dict,
destination, id, name, source,
conflict_force, conflict_revert,
conflict_ignore) {
conflict_ignore, from_local, report) {
var status_hash;
queue
.push(function () {
......@@ -542,16 +637,17 @@
status_hash, null, null,
source, destination, id, name,
conflict_force, conflict_revert,
conflict_ignore);
conflict_ignore, from_local, report);
});
}
function pushDocumentAttachment(context,
skip_attachment_dict, id, source,
destination, signature_allAttachments,
options) {
report, options) {
var local_dict = {},
signature_dict = {};
signature_dict = {},
from_local = options.from_local;
return source.allAttachments(id)
.push(undefined, function (error) {
if ((error instanceof jIO.util.jIOError) &&
......@@ -596,7 +692,19 @@
options.conflict_revert,
options.conflict_ignore,
is_creation,
is_modification]);
is_modification,
from_local,
report]);
} else {
if (signature_dict.hasOwnProperty(key)) {
report.logAttachment(id, key, from_local ?
LOG_SKIP_LOCAL_ATTACHMENT_MODIFICATION :
LOG_SKIP_REMOTE_ATTACHMENT_MODIFICATION);
} else {
report.logAttachment(id, key, from_local ?
LOG_SKIP_LOCAL_ATTACHMENT_CREATION :
LOG_SKIP_REMOTE_ATTACHMENT_CREATION);
}
}
}
}
......@@ -609,10 +717,10 @@
})
.push(function () {
var key, argument_list = [];
if (options.check_deletion === true) {
for (key in signature_dict) {
if (signature_dict.hasOwnProperty(key)) {
if (!local_dict.hasOwnProperty(key)) {
for (key in signature_dict) {
if (signature_dict.hasOwnProperty(key)) {
if (!local_dict.hasOwnProperty(key)) {
if (options.check_deletion === true) {
argument_list.push([undefined,
context,
skip_attachment_dict,
......@@ -620,17 +728,23 @@
source,
options.conflict_force,
options.conflict_revert,
options.conflict_ignore]);
options.conflict_ignore,
from_local,
report]);
} else {
report.logAttachment(id, key, from_local ?
LOG_SKIP_LOCAL_ATTACHMENT_DELETION :
LOG_SKIP_REMOTE_ATTACHMENT_DELETION);
}
}
}
return dispatchQueue(
context,
checkAttachmentLocalDeletion,
argument_list,
context._parallel_operation_attachment_amount
);
}
return dispatchQueue(
context,
checkAttachmentLocalDeletion,
argument_list,
context._parallel_operation_attachment_amount
);
});
}
......@@ -673,7 +787,7 @@
function repairFastDocumentAttachment(context, id,
signature_hash,
signature_attachment_hash,
signature_from_local) {
signature_from_local, report) {
if (signature_hash === signature_attachment_hash) {
// No replication to do
return;
......@@ -738,7 +852,8 @@
source,
destination,
context._signature_sub_storage,
signature_hash
signature_hash,
report
]);
}
}
......@@ -753,7 +868,8 @@
undefined,
id,
key,
context._signature_sub_storage
context._signature_sub_storage,
report
]);
}
}
......@@ -769,7 +885,8 @@
undefined,
id,
key,
destination
destination,
report
]);
}
}
......@@ -801,7 +918,7 @@
});
}
function repairDocumentAttachment(context, id, signature_hash_key,
function repairDocumentAttachment(context, id, report, signature_hash_key,
signature_hash,
signature_attachment_hash,
signature_from_local) {
......@@ -809,7 +926,7 @@
return repairFastDocumentAttachment(context, id,
signature_hash,
signature_attachment_hash,
signature_from_local);
signature_from_local, report);
}
var skip_attachment_dict = {};
......@@ -843,6 +960,7 @@
context._local_sub_storage,
context._remote_sub_storage,
signature_allAttachments,
report,
{
conflict_force: (context._conflict_handling ===
CONFLICT_KEEP_LOCAL),
......@@ -853,7 +971,8 @@
check_modification:
context._check_local_attachment_modification,
check_creation: context._check_local_attachment_creation,
check_deletion: context._check_local_attachment_deletion
check_deletion: context._check_local_attachment_deletion,
from_local: true
}
)
.push(function () {
......@@ -873,6 +992,7 @@
context._remote_sub_storage,
context._local_sub_storage,
signature_allAttachments,
report,
{
use_revert_post: context._use_remote_post,
conflict_force: (context._conflict_handling ===
......@@ -884,7 +1004,8 @@
check_modification:
context._check_remote_attachment_modification,
check_creation: context._check_remote_attachment_creation,
check_deletion: context._check_remote_attachment_deletion
check_deletion: context._check_remote_attachment_deletion,
from_local: false
}
);
}
......@@ -1028,7 +1149,7 @@
return context._signature_sub_storage.remove(id);
});
} else {
result = repairDocumentAttachment(context, id)
result = repairDocumentAttachment(context, id, report)
.push(function () {
return destination.allAttachments(id);
})
......@@ -1189,8 +1310,6 @@
create_new_document:
(status_hash !== null)});
}
doc = doc || local_hash;
remote_doc = remote_doc || remote_hash;
report.log(id, LOG_UNRESOLVED_CONFLICT);
})
.push(undefined, function (error) {
......@@ -1409,11 +1528,11 @@
});
}
function repairDocument(queue, context, id, signature_hash_key,
function repairDocument(queue, context, id, report, signature_hash_key,
signature_hash, signature_attachment_hash,
signature_from_local) {
queue.push(function () {
return repairDocumentAttachment(context, id, signature_hash_key,
return repairDocumentAttachment(context, id, report, signature_hash_key,
signature_hash,
signature_attachment_hash,
signature_from_local);
......@@ -1566,9 +1685,10 @@
// is deleted but not pushed to the other storage
if (!skip_deleted_document_dict.hasOwnProperty(row.id)) {
local_argument_list.push(
[undefined, context, row.id, context._signature_hash_key,
[undefined, context, row.id, report,
context._signature_hash_key,
row.value.hash, row.value.attachment_hash,
row.value.from_local]
row.value.from_local, report]
);
}
}
......
......@@ -102,7 +102,7 @@
test("local attachment creation", function () {
stop();
expect(2);
expect(3);
var id,
context = this,
......@@ -116,7 +116,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_PUT_REMOTE, id],
[report.LOG_PUT_REMOTE_ATTACHMENT, id, 'foo']
]);
return context.jio.__storage._remote_sub_storage.getAttachment(
id,
"foo",
......@@ -134,6 +138,7 @@
});
})
.fail(function (error) {
console.warn(error);
ok(false, error);
})
.always(function () {
......@@ -144,7 +149,7 @@
test("local attachment creation, local document creation not checked",
function () {
stop();
expect(6);
expect(7);
var id,
context = this,
......@@ -176,7 +181,10 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_SKIP_LOCAL_CREATION, id]
]);
return context.jio.__storage._remote_sub_storage.getAttachment(
id,
"foo",
......@@ -211,7 +219,7 @@
test("local attachment creation not checked", function () {
stop();
expect(6);
expect(7);
var id,
context = this,
......@@ -220,6 +228,7 @@
this.jio = jIO.createJIO({
type: "replicate",
check_local_attachment_creation: false,
check_local_attachment_modification: true,
local_sub_storage: {
type: "uuid",
sub_storage: {
......@@ -242,7 +251,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_PUT_REMOTE, id],
[report.LOG_SKIP_LOCAL_ATTACHMENT_CREATION, id, 'foo']
]);
return context.jio.__storage._remote_sub_storage.getAttachment(
id,
"foo",
......@@ -278,12 +291,13 @@
test("local attachment creation, local document creation and use remote post",
function () {
stop();
expect(4);
expect(5);
var id,
context = this,
post_id,
blob = new Blob([big_string]);
blob = new Blob([big_string]),
report;
this.jio = jIO.createJIO({
type: "replicate",
......@@ -312,12 +326,17 @@
return context.jio.repair();
})
// Another document should have been created
.then(function () {
.then(function (result) {
report = result;
return context.jio.__storage._remote_sub_storage.allDocs();
})
.then(function (result) {
equal(result.data.total_rows, 1);
post_id = result.data.rows[0].id;
deepEqual(report._list, [
[report.LOG_POST_REMOTE, id],
[report.LOG_PUT_REMOTE_ATTACHMENT, post_id, 'foo']
]);
return context.jio.getAttachment(
post_id,
"foo",
......@@ -352,7 +371,7 @@
test("remote attachment creation", function () {
stop();
expect(2);
expect(3);
var id,
context = this,
......@@ -367,7 +386,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_PUT_LOCAL, id],
[report.LOG_PUT_LOCAL_ATTACHMENT, id, 'foo']
]);
return context.jio.getAttachment(
id,
"foo",
......@@ -395,7 +418,7 @@
test("remote attachment creation, remote document creation not checked",
function () {
stop();
expect(6);
expect(7);
var id,
context = this,
......@@ -428,7 +451,10 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_SKIP_REMOTE_CREATION, id],
]);
return context.jio.getAttachment(
id,
"foo",
......@@ -464,7 +490,7 @@
test("remote attachment creation not checked", function () {
stop();
expect(6);
expect(7);
var id,
context = this,
......@@ -473,6 +499,7 @@
this.jio = jIO.createJIO({
type: "replicate",
check_remote_attachment_creation: false,
check_remote_attachment_modification: true,
local_sub_storage: {
type: "uuid",
sub_storage: {
......@@ -496,7 +523,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_PUT_LOCAL, id],
[report.LOG_SKIP_REMOTE_ATTACHMENT_CREATION, id, 'foo']
]);
return context.jio.getAttachment(
id,
"foo",
......@@ -531,7 +562,7 @@
test("local and remote attachment creations", function () {
stop();
expect(5);
expect(3);
var context = this,
id = 'foobar',
......@@ -556,10 +587,11 @@
.then(function () {
ok(false);
})
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Conflict on 'foobar' with attachment 'conflict'");
equal(error.status_code, 409);
.fail(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_UNRESOLVED_ATTACHMENT_CONFLICT, id, 'conflict']
]);
})
.then(function () {
return context.jio.__storage._signature_sub_storage.getAttachment(
......@@ -579,7 +611,7 @@
test("local and remote attachment creations: keep local", function () {
stop();
expect(3);
expect(4);
var context = this,
id = 'foobar',
......@@ -620,7 +652,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_FORCE_PUT_REMOTE_ATTACHMENT, id, 'conflict']
]);
return context.jio.getAttachment(
id,
"conflict",
......@@ -656,7 +692,7 @@
test("local and remote attachment creations: keep local, " +
"local not matching allAttachments", function () {
stop();
expect(3);
expect(4);
var context = this,
id = 'foobar',
......@@ -709,7 +745,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_FORCE_PUT_REMOTE_ATTACHMENT, id, 'conflict']
]);
return context.jio.getAttachment(
id,
"conflict",
......@@ -745,7 +785,7 @@
test("local and remote attachment creations: keep local, " +
"remote not matching allAttachments", function () {
stop();
expect(3);
expect(4);
var context = this,
id = 'foobar',
......@@ -789,7 +829,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_FORCE_PUT_REMOTE_ATTACHMENT, id, 'conflict']
]);
return context.jio.getAttachment(
id,
"conflict",
......@@ -824,7 +868,7 @@
test("local and remote attachment creations: keep remote", function () {
stop();
expect(3);
expect(4);
var context = this,
id = 'foobar',
......@@ -865,7 +909,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_FORCE_PUT_LOCAL_ATTACHMENT, id, 'conflict']
]);
return context.jio.getAttachment(
id,
"conflict",
......@@ -901,7 +949,7 @@
test("local and remote attachment creations: keep remote, " +
"local not matching allAttachments", function () {
stop();
expect(3);
expect(4);
var context = this,
id = 'foobar',
......@@ -954,7 +1002,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_FORCE_PUT_LOCAL_ATTACHMENT, id, 'conflict']
]);
return context.jio.getAttachment(
id,
"conflict",
......@@ -990,7 +1042,7 @@
test("local and remote attachment creations: keep remote, " +
"remote not matching allAttachments", function () {
stop();
expect(3);
expect(4);
var context = this,
id = 'foobar',
......@@ -1034,7 +1086,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_FORCE_PUT_LOCAL_ATTACHMENT, id, 'conflict']
]);
return context.jio.getAttachment(
id,
"conflict",
......@@ -1069,7 +1125,7 @@
test("local and remote attachment creations: continue", function () {
stop();
expect(4);
expect(5);
var context = this,
id = 'foobar',
......@@ -1110,7 +1166,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_SKIP_CONFLICT_ATTACHMENT, id, 'conflict']
]);
return context.jio.getAttachment(
id,
"conflict",
......@@ -1145,7 +1205,7 @@
test("local and remote same attachment creations", function () {
stop();
expect(3);
expect(4);
var context = this,
id = 'foobar',
......@@ -1167,7 +1227,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_FALSE_CONFLICT_ATTACHMENT, id, 'conflict']
]);
return context.jio.getAttachment(
id,
"conflict",
......@@ -1202,7 +1266,7 @@
test("no attachment modification", function () {
stop();
expect(3);
expect(4);
var context = this,
id = 'foobar',
......@@ -1221,7 +1285,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_NO_CHANGE_ATTACHMENT, id, 'conflict']
]);
return context.jio.getAttachment(
id,
"conflict",
......@@ -1256,7 +1324,7 @@
test("local attachment modification", function () {
stop();
expect(3);
expect(4);
var context = this,
id = 'foobar',
......@@ -1279,7 +1347,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_PUT_REMOTE_ATTACHMENT, id, 'conflict']
]);
return context.jio.getAttachment(
id,
"conflict",
......@@ -1314,7 +1386,7 @@
test("local attachment modification not checked", function () {
stop();
expect(3);
expect(4);
var context = this,
id = 'foobar',
......@@ -1355,7 +1427,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_SKIP_LOCAL_ATTACHMENT_MODIFICATION, id, 'conflict']
]);
return context.jio.getAttachment(
id,
"conflict",
......@@ -1390,7 +1466,7 @@
test("remote attachment modification", function () {
stop();
expect(3);
expect(4);
var context = this,
id = 'foobar',
......@@ -1414,7 +1490,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_PUT_LOCAL_ATTACHMENT, id, 'conflict']
]);
return context.jio.getAttachment(
id,
"conflict",
......@@ -1449,7 +1529,7 @@
test("remote attachment modification not checked", function () {
stop();
expect(3);
expect(4);
var context = this,
id = 'foobar',
......@@ -1459,7 +1539,9 @@
this.jio = jIO.createJIO({
type: "replicate",
check_local_attachment_creation: true,
check_local_attachment_modification: true,
check_remote_attachment_modification: false,
check_remote_attachment_creation: true,
local_sub_storage: {
type: "uuid",
sub_storage: {
......@@ -1491,7 +1573,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_SKIP_REMOTE_ATTACHMENT_MODIFICATION, id, 'conflict']
]);
return context.jio.getAttachment(
id,
"conflict",
......@@ -1526,7 +1612,7 @@
test("local and remote attachment modifications", function () {
stop();
expect(6);
expect(4);
var context = this,
id = 'foobar',
......@@ -1557,11 +1643,11 @@
.then(function () {
ok(false);
})
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Conflict on 'foobar' " +
"with attachment 'conflict'");
equal(error.status_code, 409);
.fail(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_UNRESOLVED_ATTACHMENT_CONFLICT, id, 'conflict']
]);
})
.then(function () {
return context.jio.getAttachment(
......@@ -1598,7 +1684,7 @@
test("local and remote attachment modifications: keep local", function () {
stop();
expect(3);
expect(4);
var context = this,
id = 'foobar',
......@@ -1647,7 +1733,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_FORCE_PUT_REMOTE_ATTACHMENT, id, 'conflict']
]);
return context.jio.getAttachment(
id,
"conflict",
......@@ -1682,7 +1772,7 @@
test("local and remote attachment modifications: keep remote", function () {
stop();
expect(3);
expect(4);
var context = this,
id = 'foobar',
......@@ -1731,7 +1821,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_FORCE_PUT_LOCAL_ATTACHMENT, id, 'conflict']
]);
return context.jio.getAttachment(
id,
"conflict",
......@@ -1766,7 +1860,7 @@
test("local and remote attachment modifications: continue", function () {
stop();
expect(3);
expect(4);
var context = this,
id = 'foobar',
......@@ -1815,7 +1909,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_SKIP_CONFLICT_ATTACHMENT, id, 'conflict']
]);
return context.jio.getAttachment(
id,
"conflict",
......@@ -1850,7 +1948,7 @@
test("local and remote attachment same modifications", function () {
stop();
expect(3);
expect(4);
var context = this,
id = 'foobar',
......@@ -1877,7 +1975,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_FALSE_CONFLICT_ATTACHMENT, id, 'conflict']
]);
return context.jio.getAttachment(
id,
"conflict",
......@@ -1912,7 +2014,7 @@
test("local attachment deletion", function () {
stop();
expect(9);
expect(10);
var id,
context = this,
......@@ -1932,7 +2034,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_DELETE_REMOTE_ATTACHMENT, id, 'foo']
]);
return context.jio.getAttachment(
id,
"foo",
......@@ -1978,7 +2084,7 @@
test("local attachment deletion not checked", function () {
stop();
expect(5);
expect(6);
var id,
context = this,
......@@ -2020,7 +2126,12 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_SKIP_LOCAL_ATTACHMENT_DELETION, id, 'foo'],
[report.LOG_NO_CHANGE_ATTACHMENT, id, 'foo']
]);
return context.jio.getAttachment(
id,
"foo",
......@@ -2057,7 +2168,7 @@
test("remote attachment deletion", function () {
stop();
expect(9);
expect(10);
var id,
context = this,
......@@ -2078,7 +2189,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_DELETE_LOCAL_ATTACHMENT, id, 'foo']
]);
return context.jio.getAttachment(
id,
"foo",
......@@ -2124,7 +2239,7 @@
test("remote attachment deletion not checked", function () {
stop();
expect(5);
expect(6);
var id,
context = this,
......@@ -2167,7 +2282,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_SKIP_REMOTE_ATTACHMENT_DELETION, id, 'foo']
]);
return context.jio.__storage._remote_sub_storage.getAttachment(
id,
"foo",
......@@ -2204,7 +2323,7 @@
test("local and remote attachment deletions", function () {
stop();
expect(9);
expect(10);
var id,
context = this,
......@@ -2228,7 +2347,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_FALSE_CONFLICT_ATTACHMENT, id, 'foo']
]);
return context.jio.getAttachment(
id,
"foo",
......@@ -2273,7 +2396,7 @@
test("local deletion and remote modifications", function () {
stop();
expect(3);
expect(4);
var id,
context = this,
......@@ -2298,7 +2421,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_FORCE_PUT_LOCAL_ATTACHMENT, id, 'foo']
]);
return context.jio.getAttachment(
id,
"foo",
......@@ -2333,7 +2460,7 @@
test("local deletion and remote modifications: keep local", function () {
stop();
expect(9);
expect(10);
var id,
context = this,
......@@ -2381,7 +2508,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_FORCE_DELETE_REMOTE_ATTACHMENT, id, 'foo']
]);
return context.jio.getAttachment(
id,
"foo",
......@@ -2427,7 +2558,7 @@
test("local deletion and remote modifications: keep local, dont check local",
function () {
stop();
expect(9);
expect(10);
var id,
context = this,
......@@ -2475,7 +2606,12 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_SKIP_LOCAL_ATTACHMENT_DELETION, id, 'foo'],
[report.LOG_FORCE_DELETE_REMOTE_ATTACHMENT, id, 'foo']
]);
return context.jio.getAttachment(
id,
"foo",
......@@ -2520,7 +2656,7 @@
test("local deletion and remote modifications: keep remote", function () {
stop();
expect(3);
expect(4);
var id,
context = this,
......@@ -2568,7 +2704,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_FORCE_PUT_LOCAL_ATTACHMENT, id, 'foo']
]);
return context.jio.getAttachment(
id,
"foo",
......@@ -2603,7 +2743,7 @@
test("local deletion and remote modifications: ignore", function () {
stop();
expect(5);
expect(6);
var id,
context = this,
......@@ -2651,7 +2791,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_SKIP_CONFLICT_ATTACHMENT, id, 'foo']
]);
return context.jio.getAttachment(
id,
"foo",
......@@ -2688,7 +2832,7 @@
test("local modifications and remote deletion", function () {
stop();
expect(3);
expect(4);
var id,
context = this,
......@@ -2713,7 +2857,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_PUT_REMOTE_ATTACHMENT, id, 'foo']
]);
return context.jio.getAttachment(
id,
"foo",
......@@ -2748,7 +2896,7 @@
test("local modifications and remote deletion: keep remote", function () {
stop();
expect(9);
expect(10);
var id,
context = this,
......@@ -2795,7 +2943,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_FORCE_DELETE_LOCAL_ATTACHMENT, id, 'foo']
]);
return context.jio.getAttachment(
id,
"foo",
......@@ -2840,7 +2992,7 @@
test("local modifications and remote deletion: keep local", function () {
stop();
expect(3);
expect(4);
var id,
context = this,
......@@ -2887,7 +3039,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_FORCE_PUT_REMOTE_ATTACHMENT, id, 'foo']
]);
return context.jio.getAttachment(
id,
"foo",
......@@ -2922,7 +3078,7 @@
test("local modif and remote del: keep remote, not check modif", function () {
stop();
expect(9);
expect(10);
var id,
context = this,
......@@ -2969,7 +3125,12 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_SKIP_LOCAL_ATTACHMENT_MODIFICATION, id, 'foo'],
[report.LOG_FORCE_DELETE_LOCAL_ATTACHMENT, id, 'foo']
]);
return context.jio.getAttachment(
id,
"foo",
......@@ -3014,7 +3175,7 @@
test("local modifications and remote deletion: ignore", function () {
stop();
expect(5);
expect(6);
var id,
context = this,
......@@ -3061,7 +3222,11 @@
.then(function () {
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_NO_CHANGE, id],
[report.LOG_SKIP_CONFLICT_ATTACHMENT, id, 'foo']
]);
return context.jio.getAttachment(
id,
"foo",
......@@ -3688,7 +3853,7 @@
test("attachment skipped when local document deletion skipped", function () {
stop();
expect(18);
expect(19);
var id,
context = this,
......@@ -3745,7 +3910,11 @@
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_SKIP_LOCAL_DELETION, id],
[report.LOG_NO_CHANGE, id]
]);
ok(true, 'second repair success');
// local document still deleted
......@@ -3862,7 +4031,7 @@
test("attachment skipped when remot document deletion skipped", function () {
stop();
expect(18);
expect(19);
var id,
context = this,
......@@ -3916,7 +4085,10 @@
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_SKIP_REMOTE_DELETION, id]
]);
ok(true, 'second repair success');
// remote document still deleted
......@@ -4033,7 +4205,7 @@
test("att sig deleted when local doc del resolved", function () {
stop();
expect(16);
expect(17);
var id,
context = this,
......@@ -4091,7 +4263,13 @@
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_FORCE_PUT_LOCAL, id],
[report.LOG_PUT_LOCAL_ATTACHMENT, id, 'foo'],
[report.LOG_PUT_LOCAL_ATTACHMENT, id, 'foomod'],
[report.LOG_PUT_LOCAL_ATTACHMENT, id, 'foocre']
]);
ok(true, 'second repair success');
// local document recreated
......@@ -4206,7 +4384,7 @@
test("att sig deleted when remot doc del resolved", function () {
stop();
expect(16);
expect(17);
var id,
context = this,
......@@ -4260,7 +4438,13 @@
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_FORCE_PUT_REMOTE, id],
[report.LOG_PUT_REMOTE_ATTACHMENT, id, 'foo'],
[report.LOG_PUT_REMOTE_ATTACHMENT, id, 'foomod'],
[report.LOG_PUT_REMOTE_ATTACHMENT, id, 'foocre']
]);
ok(true, 'second repair success');
// remote document recreated
......@@ -4375,7 +4559,7 @@
test("att sig deleted when local not checked doc del resolved", function () {
stop();
expect(16);
expect(17);
var id,
context = this,
......@@ -4434,7 +4618,14 @@
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_SKIP_LOCAL_DELETION, id],
[report.LOG_FORCE_PUT_LOCAL, id],
[report.LOG_PUT_LOCAL_ATTACHMENT, id, 'foo'],
[report.LOG_PUT_LOCAL_ATTACHMENT, id, 'foomod'],
[report.LOG_PUT_LOCAL_ATTACHMENT, id, 'foocre']
]);
ok(true, 'second repair success');
// local document recreated
......@@ -4549,7 +4740,7 @@
test("att sig deleted when remot doc not checked del resolved", function () {
stop();
expect(16);
expect(17);
var id,
context = this,
......@@ -4604,7 +4795,13 @@
return context.jio.repair();
})
.then(function () {
.then(function (report) {
deepEqual(report._list, [
[report.LOG_FORCE_PUT_REMOTE, id],
[report.LOG_PUT_REMOTE_ATTACHMENT, id, 'foo'],
[report.LOG_PUT_REMOTE_ATTACHMENT, id, 'foomod'],
[report.LOG_PUT_REMOTE_ATTACHMENT, id, 'foocre']
]);
ok(true, 'second repair success');
// remote document recreated
......
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