Commit b5fb51e6 authored by Romain Courteaud's avatar Romain Courteaud Committed by Vincent Bechu

ReplicateStorage: more tests for parallel parameters

parent 2f903beb
...@@ -4334,84 +4334,312 @@ ...@@ -4334,84 +4334,312 @@
}); });
}); });
test("use 2 queue in parallel", function () { test("use 1 parallel operation", function () {
stop(); stop();
expect(1); expect(16);
var context = this, var context = this,
start_sync = [], order_number = 0,
sync_pause; expected_order_list = [
'start get 0',
'stop get 0',
'start put 0',
'stop put 0',
'start get 1',
'stop get 1',
'start put 1',
'stop put 1',
'start get 2',
'stop get 2',
'start put 2',
'stop put 2',
'start get 3',
'stop get 3',
'start put 3',
'stop put 3'
];
function assertExecutionOrder(text) {
equal(text, expected_order_list[order_number],
expected_order_list[order_number]);
order_number += 1;
}
function Storage2711() { function StorageOneParallelOperation() {
this._sub_storage = jIO.createJIO({type: "memory"}); this._sub_storage = jIO.createJIO({type: "memory"});
return this; return this;
} }
Storage2711.prototype.put = function (id, doc) { StorageOneParallelOperation.prototype.put = function (id, doc) {
this._sub_storage.put(id, doc); assertExecutionOrder('start put ' + id);
return id; var storage = this;
return storage._sub_storage.put(id, doc)
.push(function (result) {
assertExecutionOrder('stop put ' + id);
return result;
});
}; };
Storage2711.prototype.get = function (id) {
StorageOneParallelOperation.prototype.get = function (id) {
assertExecutionOrder('start get ' + id);
var storage = this; var storage = this;
start_sync[id] = true; return storage._sub_storage.get(id)
return ((id === "0") ? RSVP.delay(500) : RSVP.delay(100)) .push(undefined, function (error) {
.then(function () { assertExecutionOrder('stop get ' + id);
throw error;
});
};
StorageOneParallelOperation.prototype.buildQuery = function () {
return this._sub_storage.buildQuery.apply(this._sub_storage, arguments);
};
StorageOneParallelOperation.prototype.hasCapacity = function () {
return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments);
};
jIO.addStorage(
'one_parallel',
StorageOneParallelOperation
);
this.jio = jIO.createJIO({
type: "replicate",
local_sub_storage: {
type: "memory"
},
remote_sub_storage: {
type: "one_parallel"
}
});
return RSVP.all([
context.jio.put("0", {"title": "foo"}),
context.jio.put("1", {"title": "foo1"}),
context.jio.put("2", {"title": "foo2"}),
context.jio.put("3", {"title": "foo3"})
])
.then(function () {
return context.jio.repair();
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("use 2 parallel operations", function () {
stop();
expect(16);
var context = this,
order_number = 0,
expected_order_list = [
'start get 0',
'start get 1',
'stop get 1',
'start put 1',
'stop put 1',
'start get 2',
'stop get 2',
'start put 2',
'stop get 0',
'start put 0',
'stop put 0',
'start get 3',
'stop get 3',
'start put 3',
'stop put 3',
'stop put 2'
],
defer0,
defer2;
function assertExecutionOrder(text) {
equal(text, expected_order_list[order_number],
expected_order_list[order_number]);
order_number += 1;
}
function StorageTwoParallelOperation() {
this._sub_storage = jIO.createJIO({type: "memory"});
return this;
}
StorageTwoParallelOperation.prototype.put = function (id, doc) {
var storage = this;
assertExecutionOrder('start put ' + id);
return new RSVP.Queue()
.push(function () {
if (id === "2") { if (id === "2") {
sync_pause = start_sync.toString(); defer0.resolve();
defer2 = RSVP.defer();
return defer2.promise;
} }
start_sync[id] = false; })
.push(function () {
return storage._sub_storage.put(id, doc);
})
.push(function (result) {
if (id === "3") {
defer2.resolve();
}
assertExecutionOrder('stop put ' + id);
return result;
});
};
StorageTwoParallelOperation.prototype.get = function (id) {
var storage = this;
assertExecutionOrder('start get ' + id);
return new RSVP.Queue()
.push(function () {
if (id === "0") {
defer0 = RSVP.defer();
return defer0.promise;
}
})
.push(function () {
return storage._sub_storage.get(id); return storage._sub_storage.get(id);
})
.push(undefined, function (error) {
assertExecutionOrder('stop get ' + id);
throw error;
}); });
}; };
Storage2711.prototype.buildQuery = function () { StorageTwoParallelOperation.prototype.buildQuery = function () {
return this._sub_storage.buildQuery.apply(this._sub_storage, arguments); return this._sub_storage.buildQuery.apply(this._sub_storage, arguments);
}; };
Storage2711.prototype.bulk = function () { StorageTwoParallelOperation.prototype.hasCapacity = function () {
return this._sub_storage.bulk.apply(this._sub_storage, arguments);
};
Storage2711.prototype.hasCapacity = function () {
return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments); return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments);
}; };
jIO.addStorage( jIO.addStorage(
'parallel', 'two_parallel',
Storage2711 StorageTwoParallelOperation
); );
this.jio = jIO.createJIO({ this.jio = jIO.createJIO({
type: "replicate", type: "replicate",
conflict_handling: 1,
check_local_creation: true,
check_local_modification: true,
parallel_operation_amount: 2, parallel_operation_amount: 2,
local_sub_storage: { local_sub_storage: {
type: "uuid", type: "memory"
sub_storage: {
type: "memory"
}
}, },
remote_sub_storage: { remote_sub_storage: {
type: "parallel" type: "two_parallel"
} }
}); });
return context.jio.put("0", {"title": "foo"}) return RSVP.all([
.push(function () { context.jio.put("0", {"title": "foo"}),
return context.jio.put("1", {"title": "foo1"}); context.jio.put("1", {"title": "foo1"}),
}) context.jio.put("2", {"title": "foo2"}),
.push(function () { context.jio.put("3", {"title": "foo3"})
return context.jio.put("2", {"title": "foo2"}); ])
}) .then(function () {
.push(function () {
return context.jio.put("3", {"title": "foo3"});
})
.push(function () {
return context.jio.repair(); return context.jio.repair();
}) })
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("use 4 parallel operations", function () {
stop();
expect(16);
var context = this,
order_number = 0,
expected_order_list = [
'start get 0',
'start get 1',
'start get 2',
'start get 3',
'stop get 0',
'stop get 1',
'stop get 2',
'stop get 3',
'start put 0',
'start put 1',
'start put 2',
'start put 3',
'stop put 0',
'stop put 1',
'stop put 2',
'stop put 3'
];
function assertExecutionOrder(text) {
equal(text, expected_order_list[order_number],
expected_order_list[order_number]);
order_number += 1;
}
function StorageFourParallelOperation() {
this._sub_storage = jIO.createJIO({type: "memory"});
return this;
}
StorageFourParallelOperation.prototype.put = function (id, doc) {
assertExecutionOrder('start put ' + id);
var storage = this;
return storage._sub_storage.put(id, doc)
.push(function (result) {
assertExecutionOrder('stop put ' + id);
return result;
});
};
StorageFourParallelOperation.prototype.get = function (id) {
assertExecutionOrder('start get ' + id);
var storage = this;
return storage._sub_storage.get(id)
.push(undefined, function (error) {
assertExecutionOrder('stop get ' + id);
throw error;
});
};
StorageFourParallelOperation.prototype.buildQuery = function () {
return this._sub_storage.buildQuery.apply(this._sub_storage, arguments);
};
StorageFourParallelOperation.prototype.hasCapacity = function () {
return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments);
};
jIO.addStorage(
'four_parallel',
StorageFourParallelOperation
);
this.jio = jIO.createJIO({
type: "replicate",
parallel_operation_amount: 4,
local_sub_storage: {
type: "memory"
},
remote_sub_storage: {
type: "four_parallel"
}
});
return RSVP.all([
context.jio.put("0", {"title": "foo"}),
context.jio.put("1", {"title": "foo1"}),
context.jio.put("2", {"title": "foo2"}),
context.jio.put("3", {"title": "foo3"})
])
.then(function () { .then(function () {
equal(sync_pause, "true,false,true", "rigth order"); return context.jio.repair();
}) })
.fail(function (error) { .fail(function (error) {
ok(false, error); ok(false, error);
...@@ -7503,108 +7731,514 @@ ...@@ -7503,108 +7731,514 @@
}); });
}); });
test("use 2 queue in parallel", function () { test("use 1 parallel operation", function () {
stop(); stop();
expect(1); expect(40);
var context = this, var context = this,
start_sync = [], order_number = 0,
sync_pause; expected_order_list = [
'start get 0',
'stop get 0',
'start put 0',
'stop put 0',
'start get 1',
'stop get 1',
'start put 1',
'stop put 1',
'start getAttachment 00',
'stop getAttachment 00',
'start putAttachment 00',
'stop putAttachment 00',
'start getAttachment 01',
'stop getAttachment 01',
'start putAttachment 01',
'stop putAttachment 01',
'start getAttachment 02',
'stop getAttachment 02',
'start putAttachment 02',
'stop putAttachment 02',
'start getAttachment 03',
'stop getAttachment 03',
'start putAttachment 03',
'stop putAttachment 03',
'start getAttachment 10',
'stop getAttachment 10',
'start putAttachment 10',
'stop putAttachment 10',
'start getAttachment 11',
'stop getAttachment 11',
'start putAttachment 11',
'stop putAttachment 11',
'start getAttachment 12',
'stop getAttachment 12',
'start putAttachment 12',
'stop putAttachment 12',
'start getAttachment 13',
'stop getAttachment 13',
'start putAttachment 13',
'stop putAttachment 13'
];
function assertExecutionOrder(text) {
equal(text, expected_order_list[order_number],
expected_order_list[order_number]);
order_number += 1;
}
function Storage2713() { function StorageOneParallelOperation() {
this._sub_storage = jIO.createJIO({type: "memory"}); this._sub_storage = jIO.createJIO({type: "memory"});
return this; return this;
} }
Storage2713.prototype.put = function (id, doc) { StorageOneParallelOperation.prototype.put = function (id, doc) {
this._sub_storage.put(id, doc); assertExecutionOrder('start put ' + id);
return id; var storage = this;
return storage._sub_storage.put(id, doc)
.push(function (result) {
assertExecutionOrder('stop put ' + id);
return result;
});
}; };
Storage2713.prototype.get = function (id) {
console.log("get", id); StorageOneParallelOperation.prototype.get = function (id) {
return this._sub_storage.get(id); assertExecutionOrder('start get ' + id);
var storage = this;
return storage._sub_storage.get(id)
.push(undefined, function (error) {
assertExecutionOrder('stop get ' + id);
throw error;
});
}; };
Storage2713.prototype.getAttachment = function () {
var storage = this, StorageOneParallelOperation.prototype.getAttachment = function (id, name) {
argument_list = arguments, assertExecutionOrder('start getAttachment ' + name);
id = argument_list[1]; var storage = this;
start_sync[id] = true; return storage._sub_storage.getAttachment(id, name)
return ((id === "0") ? RSVP.delay(500) : RSVP.delay(100)) .push(undefined, function (error) {
.then(function () { assertExecutionOrder('stop getAttachment ' + name);
if (id === "2") { throw error;
sync_pause = start_sync.toString();
}
start_sync[id] = false;
return storage._sub_storage.getAttachment.apply(
storage._sub_storage,
argument_list
);
}); });
}; };
Storage2713.prototype.putAttachment = function () {
return this._sub_storage.putAttachment.apply(this._sub_storage, StorageOneParallelOperation.prototype.putAttachment = function (id, name,
arguments); blob) {
assertExecutionOrder('start putAttachment ' + name);
var storage = this;
return storage._sub_storage.putAttachment(id, name, blob)
.push(function (result) {
assertExecutionOrder('stop putAttachment ' + name);
return result;
});
}; };
Storage2713.prototype.removeAttachment = function () {
return this._sub_storage.removeAttachment.apply(this._sub_storage, StorageOneParallelOperation.prototype.buildQuery = function () {
arguments); return this._sub_storage.buildQuery.apply(this._sub_storage, arguments);
}; };
Storage2713.prototype.allAttachments = function () { StorageOneParallelOperation.prototype.allAttachments = function () {
return this._sub_storage.allAttachments.apply(this._sub_storage, return this._sub_storage.allAttachments.apply(this._sub_storage,
arguments); arguments);
}; };
Storage2713.prototype.buildQuery = function () {
return this._sub_storage.buildQuery.apply(this._sub_storage, arguments); StorageOneParallelOperation.prototype.hasCapacity = function () {
return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments);
}; };
Storage2713.prototype.bulk = function () { jIO.addStorage(
return this._sub_storage.bulk.apply(this._sub_storage, arguments); 'one_parallel_attachment',
StorageOneParallelOperation
);
this.jio = jIO.createJIO({
type: "replicate",
check_local_attachment_creation: true,
local_sub_storage: {
type: "memory"
},
remote_sub_storage: {
type: "one_parallel_attachment"
}
});
return RSVP.all([
context.jio.put("0", {}),
context.jio.put("1", {})
])
.then(function () {
return RSVP.all([
context.jio.putAttachment("0", "00", new Blob(["0"])),
context.jio.putAttachment("0", "01", new Blob(["1"])),
context.jio.putAttachment("0", "02", new Blob(["2"])),
context.jio.putAttachment("0", "03", new Blob(["3"])),
context.jio.putAttachment("1", "10", new Blob(["0"])),
context.jio.putAttachment("1", "11", new Blob(["1"])),
context.jio.putAttachment("1", "12", new Blob(["2"])),
context.jio.putAttachment("1", "13", new Blob(["3"]))
]);
})
.then(function () {
return context.jio.repair();
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("use 2 parallel operation", function () {
stop();
expect(40);
var context = this,
order_number = 0,
expected_order_list = [
'start get 0',
'stop get 0',
'start put 0',
'stop put 0',
'start get 1',
'stop get 1',
'start put 1',
'stop put 1',
'start getAttachment 00',
'start getAttachment 01',
'stop getAttachment 01',
'start putAttachment 01',
'stop putAttachment 01',
'start getAttachment 02',
'stop getAttachment 02',
'start putAttachment 02',
'stop getAttachment 00',
'start putAttachment 00',
'stop putAttachment 00',
'start getAttachment 03',
'stop getAttachment 03',
'start putAttachment 03',
'stop putAttachment 03',
'stop putAttachment 02',
'start getAttachment 10',
'start getAttachment 11',
'stop getAttachment 11',
'start putAttachment 11',
'stop putAttachment 11',
'start getAttachment 12',
'stop getAttachment 12',
'start putAttachment 12',
'stop getAttachment 10',
'start putAttachment 10',
'stop putAttachment 10',
'start getAttachment 13',
'stop getAttachment 13',
'start putAttachment 13',
'stop putAttachment 13',
'stop putAttachment 12'
],
defer0,
defer2;
function assertExecutionOrder(text) {
equal(text, expected_order_list[order_number],
expected_order_list[order_number]);
order_number += 1;
}
function StorageTwoParallelOperation() {
this._sub_storage = jIO.createJIO({type: "memory"});
return this;
}
StorageTwoParallelOperation.prototype.put = function (id, doc) {
assertExecutionOrder('start put ' + id);
var storage = this;
return storage._sub_storage.put(id, doc)
.push(function (result) {
assertExecutionOrder('stop put ' + id);
return result;
});
};
StorageTwoParallelOperation.prototype.get = function (id) {
assertExecutionOrder('start get ' + id);
var storage = this;
return storage._sub_storage.get(id)
.push(undefined, function (error) {
assertExecutionOrder('stop get ' + id);
throw error;
});
}; };
Storage2713.prototype.hasCapacity = function () {
StorageTwoParallelOperation.prototype.getAttachment = function (id,
name) {
assertExecutionOrder('start getAttachment ' + name);
var storage = this;
return new RSVP.Queue()
.push(function () {
if (name[1] === "0") {
defer0 = RSVP.defer();
return defer0.promise;
}
})
.push(function () {
return storage._sub_storage.getAttachment(id, name);
})
.push(undefined, function (error) {
assertExecutionOrder('stop getAttachment ' + name);
throw error;
});
};
StorageTwoParallelOperation.prototype.putAttachment = function (id, name,
blob) {
assertExecutionOrder('start putAttachment ' + name);
var storage = this;
return new RSVP.Queue()
.push(function () {
if (name[1] === "2") {
defer0.resolve();
defer2 = RSVP.defer();
return defer2.promise;
}
})
.push(function () {
return storage._sub_storage.putAttachment(id, name, blob);
})
.push(function (result) {
if (name[1] === "3") {
defer2.resolve();
}
assertExecutionOrder('stop putAttachment ' + name);
return result;
});
};
StorageTwoParallelOperation.prototype.buildQuery = function () {
return this._sub_storage.buildQuery.apply(this._sub_storage, arguments);
};
StorageTwoParallelOperation.prototype.allAttachments = function () {
return this._sub_storage.allAttachments.apply(this._sub_storage,
arguments);
};
StorageTwoParallelOperation.prototype.hasCapacity = function () {
return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments); return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments);
}; };
jIO.addStorage( jIO.addStorage(
'parallel_attachment', 'two_parallel_attachment',
Storage2713 StorageTwoParallelOperation
); );
this.jio = jIO.createJIO({ this.jio = jIO.createJIO({
type: "replicate", type: "replicate",
conflict_handling: 1,
check_local_attachment_creation: true, check_local_attachment_creation: true,
check_local_attachment_modification: true,
parallel_operation_attachment_amount: 2, parallel_operation_attachment_amount: 2,
local_sub_storage: { local_sub_storage: {
type: "uuid", type: "memory"
sub_storage: {
type: "memory"
}
}, },
remote_sub_storage: { remote_sub_storage: {
type: "parallel_attachment" type: "two_parallel_attachment"
} }
}); });
return context.jio.put("foo", {}) return RSVP.all([
.push(function () { context.jio.put("0", {}),
return context.jio.putAttachment("foo", "0", new Blob(["0"])); context.jio.put("1", {})
}) ])
.push(function () { .then(function () {
return context.jio.putAttachment("foo", "1", new Blob(["1"])); return RSVP.all([
context.jio.putAttachment("0", "00", new Blob(["0"])),
context.jio.putAttachment("0", "01", new Blob(["1"])),
context.jio.putAttachment("0", "02", new Blob(["2"])),
context.jio.putAttachment("0", "03", new Blob(["3"])),
context.jio.putAttachment("1", "10", new Blob(["0"])),
context.jio.putAttachment("1", "11", new Blob(["1"])),
context.jio.putAttachment("1", "12", new Blob(["2"])),
context.jio.putAttachment("1", "13", new Blob(["3"]))
]);
}) })
.push(function () { .then(function () {
return context.jio.putAttachment("foo", "2", new Blob(["2"])); return context.jio.repair();
}) })
.push(function () { .fail(function (error) {
return context.jio.putAttachment("foo", "3", new Blob(["3"])); ok(false, error);
}) })
.push(function () { .always(function () {
return context.jio.repair(); start();
});
});
test("use 4 parallel operation", function () {
stop();
expect(40);
var context = this,
order_number = 0,
expected_order_list = [
'start get 0',
'stop get 0',
'start put 0',
'stop put 0',
'start get 1',
'stop get 1',
'start put 1',
'stop put 1',
'start getAttachment 00',
'stop getAttachment 00',
'start putAttachment 00',
'start getAttachment 01',
'stop getAttachment 01',
'start putAttachment 01',
'start getAttachment 02',
'stop getAttachment 02',
'start putAttachment 02',
'start getAttachment 03',
'stop getAttachment 03',
'start putAttachment 03',
'stop putAttachment 00',
'stop putAttachment 01',
'stop putAttachment 02',
'stop putAttachment 03',
'start getAttachment 10',
'stop getAttachment 10',
'start putAttachment 10',
'start getAttachment 11',
'stop getAttachment 11',
'start putAttachment 11',
'start getAttachment 12',
'stop getAttachment 12',
'start putAttachment 12',
'start getAttachment 13',
'stop getAttachment 13',
'start putAttachment 13',
'stop putAttachment 10',
'stop putAttachment 11',
'stop putAttachment 12',
'stop putAttachment 13'
];
function assertExecutionOrder(text) {
equal(text, expected_order_list[order_number],
expected_order_list[order_number]);
order_number += 1;
}
function StorageFourParallelOperation() {
this._sub_storage = jIO.createJIO({type: "memory"});
return this;
}
StorageFourParallelOperation.prototype.put = function (id, doc) {
assertExecutionOrder('start put ' + id);
var storage = this;
return storage._sub_storage.put(id, doc)
.push(function (result) {
assertExecutionOrder('stop put ' + id);
return result;
});
};
StorageFourParallelOperation.prototype.get = function (id) {
assertExecutionOrder('start get ' + id);
var storage = this;
return storage._sub_storage.get(id)
.push(undefined, function (error) {
assertExecutionOrder('stop get ' + id);
throw error;
});
};
StorageFourParallelOperation.prototype.getAttachment = function (id,
name) {
assertExecutionOrder('start getAttachment ' + name);
var storage = this;
return storage._sub_storage.getAttachment(id, name)
.push(undefined, function (error) {
assertExecutionOrder('stop getAttachment ' + name);
throw error;
});
};
StorageFourParallelOperation.prototype.putAttachment = function (id, name,
blob) {
assertExecutionOrder('start putAttachment ' + name);
var storage = this;
return storage._sub_storage.putAttachment(id, name, blob)
.push(function (result) {
assertExecutionOrder('stop putAttachment ' + name);
return result;
});
};
StorageFourParallelOperation.prototype.buildQuery = function () {
return this._sub_storage.buildQuery.apply(this._sub_storage, arguments);
};
StorageFourParallelOperation.prototype.allAttachments = function () {
return this._sub_storage.allAttachments.apply(this._sub_storage,
arguments);
};
StorageFourParallelOperation.prototype.hasCapacity = function () {
return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments);
};
jIO.addStorage(
'four_parallel_attachment',
StorageFourParallelOperation
);
this.jio = jIO.createJIO({
type: "replicate",
check_local_attachment_creation: true,
parallel_operation_attachment_amount: 4,
local_sub_storage: {
type: "memory"
},
remote_sub_storage: {
type: "four_parallel_attachment"
}
});
return RSVP.all([
context.jio.put("0", {}),
context.jio.put("1", {})
])
.then(function () {
return RSVP.all([
context.jio.putAttachment("0", "00", new Blob(["0"])),
context.jio.putAttachment("0", "01", new Blob(["1"])),
context.jio.putAttachment("0", "02", new Blob(["2"])),
context.jio.putAttachment("0", "03", new Blob(["3"])),
context.jio.putAttachment("1", "10", new Blob(["0"])),
context.jio.putAttachment("1", "11", new Blob(["1"])),
context.jio.putAttachment("1", "12", new Blob(["2"])),
context.jio.putAttachment("1", "13", new Blob(["3"]))
]);
}) })
.then(function () { .then(function () {
equal(sync_pause, "true,false,true", "rigth order"); return context.jio.repair();
}) })
.fail(function (error) { .fail(function (error) {
ok(false, error); ok(false, error);
......
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