Commit d03d08f1 authored by Vincent Bechu's avatar Vincent Bechu

replicatestorage: add use_bulk option and tests

parent 1ecc04a5
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
}); });
this._use_remote_post = spec.use_remote_post || false; this._use_remote_post = spec.use_remote_post || false;
this._use_bulk_get = spec.use_bulk !== undefined ? spec.use_bulk : true;
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)
...@@ -479,7 +480,8 @@ ...@@ -479,7 +480,8 @@
// Keep it like this until the bulk API is stabilized // Keep it like this until the bulk API is stabilized
var use_bulk_get = false; var use_bulk_get = false;
try { try {
use_bulk_get = context._remote_sub_storage.hasCapacity("bulk"); use_bulk_get = context._remote_sub_storage.hasCapacity("bulk")
&& context._use_bulk_get;
} catch (error) { } catch (error) {
if (!((error instanceof jIO.util.jIOError) && if (!((error instanceof jIO.util.jIOError) &&
(error.status_code === 501))) { (error.status_code === 501))) {
......
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
equal(jio.__storage._check_remote_creation, true); equal(jio.__storage._check_remote_creation, true);
equal(jio.__storage._check_remote_deletion, true); equal(jio.__storage._check_remote_deletion, true);
equal(jio.__storage._check_remote_modification, true); equal(jio.__storage._check_remote_modification, true);
equal(jio.__storage._use_bulk_get, true);
equal(jio.__storage._signature_hash, equal(jio.__storage._signature_hash,
"_replicate_7209dfbcaff00f6637f939fdd71fa896793ed385"); "_replicate_7209dfbcaff00f6637f939fdd71fa896793ed385");
...@@ -87,7 +88,8 @@ ...@@ -87,7 +88,8 @@
check_local_modification: false, check_local_modification: false,
check_remote_creation: false, check_remote_creation: false,
check_remote_deletion: false, check_remote_deletion: false,
check_remote_modification: false check_remote_modification: false,
use_bulk: false
}); });
deepEqual( deepEqual(
...@@ -102,6 +104,7 @@ ...@@ -102,6 +104,7 @@
equal(jio.__storage._check_remote_creation, false); equal(jio.__storage._check_remote_creation, false);
equal(jio.__storage._check_remote_deletion, false); equal(jio.__storage._check_remote_deletion, false);
equal(jio.__storage._check_remote_modification, false); equal(jio.__storage._check_remote_modification, false);
equal(jio.__storage._use_bulk_get, false);
equal(jio.__storage._signature_hash, equal(jio.__storage._signature_hash,
"_replicate_11881e431308c0ec8c0e6430be98db380e1b92f8"); "_replicate_11881e431308c0ec8c0e6430be98db380e1b92f8");
...@@ -2627,4 +2630,176 @@ ...@@ -2627,4 +2630,176 @@
}); });
}); });
test("remote document creation with bulk off", function () {
stop();
expect(2);
var id,
post_id = "123456789",
context = this;
function Storage200Bulk(spec) {
this._sub_storage = jIO.createJIO(spec.sub_storage);
}
Storage200Bulk.prototype.get = function () {
return this._sub_storage.get.apply(this._sub_storage, arguments);
};
Storage200Bulk.prototype.bulk = function () {
throw new Error("Bulk called");
};
Storage200Bulk.prototype.post = function (param) {
return this.put(post_id, param);
};
Storage200Bulk.prototype.put = function () {
return this._sub_storage.put.apply(this._sub_storage, arguments);
};
Storage200Bulk.prototype.hasCapacity = function () {
return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments);
};
Storage200Bulk.prototype.buildQuery = function () {
return this._sub_storage.buildQuery.apply(this._sub_storage, arguments);
};
jIO.addStorage(
'replicatestorage200nobulk',
Storage200Bulk
);
this.jio = jIO.createJIO({
type: "replicate",
local_sub_storage: {
type: "memory"
},
remote_sub_storage: {
type: "replicatestorage200nobulk",
sub_storage: {
type: "memory"
}
},
use_bulk: false
});
context.jio.__storage._remote_sub_storage.post({"title": "bar"})
.then(function (result) {
id = result;
return context.jio.repair();
})
.then(function () {
return context.jio.get(id);
})
.then(function (result) {
deepEqual(result, {
title: "bar"
});
})
.then(function () {
return context.jio.__storage._signature_sub_storage.get(id);
})
.then(function (result) {
deepEqual(result, {
hash: "6799f3ea80e325b89f19589282a343c376c1f1af"
});
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("remote document modification with bulk off", function () {
stop();
expect(3);
var id,
post_id = "123456789",
context = this;
function Storage200Bulk(spec) {
this._sub_storage = jIO.createJIO(spec.sub_storage);
}
Storage200Bulk.prototype.get = function () {
return this._sub_storage.get.apply(this._sub_storage, arguments);
};
Storage200Bulk.prototype.bulk = function () {
throw new Error("bulk called");
};
Storage200Bulk.prototype.post = function (param) {
return this.put(post_id, param);
};
Storage200Bulk.prototype.put = function () {
return this._sub_storage.put.apply(this._sub_storage, arguments);
};
Storage200Bulk.prototype.hasCapacity = function () {
return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments);
};
Storage200Bulk.prototype.buildQuery = function () {
return this._sub_storage.buildQuery.apply(this._sub_storage, arguments);
};
jIO.addStorage(
'replicatestorage200nobulkremotemodification',
Storage200Bulk
);
this.jio = jIO.createJIO({
type: "replicate",
local_sub_storage: {
type: "memory"
},
remote_sub_storage: {
type: "replicatestorage200nobulkremotemodification",
sub_storage: {
type: "memory"
}
},
use_bulk: false
});
context.jio.__storage._remote_sub_storage.post({"title": "bar"})
.then(function (result) {
id = result;
return context.jio.repair();
})
.then(function () {
return context.jio.get(id);
})
.then(function (result) {
deepEqual(result, {
title: "bar"
});
})
.then(function () {
return context.jio.__storage._signature_sub_storage.get(id);
})
.then(function (result) {
deepEqual(result, {
hash: "6799f3ea80e325b89f19589282a343c376c1f1af"
});
})
.then(function () {
return context.jio.__storage._remote_sub_storage.put(
id,
{"title": "foo"}
);
})
.then(function (result) {
id = result;
return context.jio.repair();
})
.then(function () {
return context.jio.get(id);
})
.then(function (result) {
deepEqual(result, {
title: "foo"
});
})
.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