Commit e7f70409 authored by Aurel's avatar Aurel Committed by Cédric Le Ninivin

replicate : when getting a conflict, always use put method on creation

/reviewed-on !28
parent e0f00ad7
...@@ -235,7 +235,7 @@ ...@@ -235,7 +235,7 @@
} }
if (options.conflict_force === true) { if (options.conflict_force === true) {
return propagateModification(source, destination, doc, local_hash, return propagateModification(source, destination, doc, local_hash,
id, options); id);
} }
// Already exists on destination // Already exists on destination
throw new jIO.util.jIOError("Conflict on '" + id + "': " + throw new jIO.util.jIOError("Conflict on '" + id + "': " +
......
...@@ -939,6 +939,71 @@ ...@@ -939,6 +939,71 @@
}); });
}); });
test("local and remote document creations: keep local, remote post",
function () {
stop();
expect(3);
var context = this;
this.jio = jIO.createJIO({
type: "replicate",
use_remote_post: 1,
local_sub_storage: {
type: "uuid",
sub_storage: {
type: "memory"
}
},
remote_sub_storage: {
type: "uuid",
sub_storage: {
type: "memory"
}
},
conflict_handling: 1
});
RSVP.all([
context.jio.put("conflict", {"title": "foo"}),
context.jio.__storage._remote_sub_storage.put("conflict",
{"title": "bar"})
])
.then(function () {
return context.jio.repair();
})
.then(function () {
return context.jio.__storage._signature_sub_storage.get("conflict");
})
.then(function (result) {
deepEqual(result, {
hash: "5ea9013447539ad65de308cbd75b5826a2ae30e5"
});
})
.then(function () {
return context.jio.get("conflict");
})
.then(function (result) {
deepEqual(result, {
title: "foo"
});
})
.then(function () {
return context.jio.__storage._remote_sub_storage.get("conflict");
})
.then(function (result) {
deepEqual(result, {
title: "foo"
});
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("local and remote document creations: keep remote", function () { test("local and remote document creations: keep remote", function () {
stop(); stop();
expect(3); expect(3);
...@@ -1002,6 +1067,71 @@ ...@@ -1002,6 +1067,71 @@
}); });
}); });
test("local and remote document creations: keep remote, remote post",
function () {
stop();
expect(3);
var context = this;
this.jio = jIO.createJIO({
type: "replicate",
use_remote_post: 1,
local_sub_storage: {
type: "uuid",
sub_storage: {
type: "memory"
}
},
remote_sub_storage: {
type: "uuid",
sub_storage: {
type: "memory"
}
},
conflict_handling: 2
});
RSVP.all([
context.jio.put("conflict", {"title": "foo"}),
context.jio.__storage._remote_sub_storage.put("conflict",
{"title": "bar"})
])
.then(function () {
return context.jio.repair();
})
.then(function () {
return context.jio.__storage._signature_sub_storage.get("conflict");
})
.then(function (result) {
deepEqual(result, {
hash: "6799f3ea80e325b89f19589282a343c376c1f1af"
});
})
.then(function () {
return context.jio.get("conflict");
})
.then(function (result) {
deepEqual(result, {
title: "bar"
});
})
.then(function () {
return context.jio.__storage._remote_sub_storage.get("conflict");
})
.then(function (result) {
deepEqual(result, {
title: "bar"
});
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("local and remote document creations: continue", function () { test("local and remote document creations: continue", function () {
stop(); stop();
expect(4); expect(4);
...@@ -1065,6 +1195,71 @@ ...@@ -1065,6 +1195,71 @@
}); });
}); });
test("local and remote document creations: continue, remote post",
function () {
stop();
expect(4);
var context = this;
this.jio = jIO.createJIO({
type: "replicate",
use_remote_post: 1,
local_sub_storage: {
type: "uuid",
sub_storage: {
type: "memory"
}
},
remote_sub_storage: {
type: "uuid",
sub_storage: {
type: "memory"
}
},
conflict_handling: 3
});
RSVP.all([
context.jio.put("conflict", {"title": "foo"}),
context.jio.__storage._remote_sub_storage.put("conflict",
{"title": "bar"})
])
.then(function () {
return context.jio.repair();
})
.then(function () {
return context.jio.__storage._signature_sub_storage.get("conflict");
})
.fail(function (error) {
ok(error instanceof jIO.util.jIOError);
// equal(error.message, "Cannot find document: conflict");
equal(error.status_code, 404);
})
.then(function () {
return context.jio.get("conflict");
})
.then(function (result) {
deepEqual(result, {
title: "foo"
});
})
.then(function () {
return context.jio.__storage._remote_sub_storage.get("conflict");
})
.then(function (result) {
deepEqual(result, {
title: "bar"
});
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("local and remote same document creations", function () { test("local and remote same document creations", function () {
stop(); stop();
expect(1); expect(1);
......
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