Commit 08c3aa1d authored by Tristan Cavelier's avatar Tristan Cavelier

Update IndexStorage and Jio tests

parent 2722fe85
This diff is collapsed.
...@@ -1031,34 +1031,36 @@ test ('Document load', function () { ...@@ -1031,34 +1031,36 @@ test ('Document load', function () {
o.jio = JIO.newJio({type:'indexed',storage:{type:'dummyall3tries'}}); o.jio = JIO.newJio({type:'indexed',storage:{type:'dummyall3tries'}});
// loading must take long time with dummyall3tries // loading must take long time with dummyall3tries
o.f = this.spy(); o.f = this.spy();
o.jio.loadDocument('memo',{max_retry:3,success:o.f,error:o.f, o.jio.get('memo',{max_retry:3,metadata_only:true},o.f);
metadata_only:true});
o.clock.tick(1000); o.clock.tick(1000);
ok(!o.f.called,'Callback must not be called'); ok(!o.f.called,'Callback must not be called');
// wait long time too retreive list // wait long time too retreive list
o.clock.tick(10000); o.clock.tick(1000);
// now we can test if the document metadata are loaded faster. // now we can test if the document metadata are loaded faster.
o.doc = {name:'memo',last_modified:25000,creation_date:20000}; o.doc = {_id:'memo',_last_modified:25000,_creation_date:20000};
o.f2 = function (result) { o.f2 = function (err,val) {
deepEqual (result,o.doc,'Document metadata retrieved'); deepEqual (err||val,o.doc,'Document metadata retrieved');
}; };
this.spy(o,'f2'); this.spy(o,'f2');
o.jio.loadDocument('memo',{max_retry:3,success:o.f2,error:o.f2, o.jio.get('memo',{max_retry:3,metadata_only:true},o.f2);
metadata_only:true});
o.clock.tick(1000); o.clock.tick(1000);
if (!o.f2.calledOnce) { if (!o.f2.calledOnce) {
ok (false, 'no response / too much results'); if (o.f2.called) {
ok (false, 'too much results');
} else {
ok (false, 'no response');
}
} }
// test a simple document loading // test a simple document loading
o.doc2 = {name:'file',last_modified:17000, o.doc2 = {_id:'file',_last_modified:17000,
creation_date:11000,content:'content2'}; _creation_date:11000,content:'content file'};
o.f3 = function (result) { o.f3 = function (err,val) {
deepEqual (result,o.doc2,'Simple document loading'); deepEqual (err||val,o.doc2,'Simple document loading');
}; };
this.spy(o,'f3'); this.spy(o,'f3');
o.jio.loadDocument('file',{max_retry:3,success:o.f3,error:o.f3}); o.jio.get('file',{max_retry:3},o.f3);
o.clock.tick(2000); o.clock.tick(2000);
if (!o.f3.calledOnce) { if (!o.f3.calledOnce) {
ok (false, 'no response / too much results'); ok (false, 'no response / too much results');
...@@ -1072,17 +1074,15 @@ test ('Document save', function () { ...@@ -1072,17 +1074,15 @@ test ('Document save', function () {
o.jio = JIO.newJio({type:'indexed', o.jio = JIO.newJio({type:'indexed',
storage:{type:'dummyall3tries', storage:{type:'dummyall3tries',
username:'indexsave'}}); username:'indexsave'}});
o.f = function (result) { o.f = function (err,val) {
if (!result) { if (err) {
result = 'done'; err = err.status;
} else {
result = 'fail';
} }
deepEqual (result,'done','document save'); deepEqual (err || val,{ok:true,id:'file'},'document save');
}; };
this.spy(o,'f'); this.spy(o,'f');
o.jio.saveDocument('file','content',{max_retry:3,success:o.f,error:o.f}); o.jio.put({_id:'file',content:'content'},{max_retry:3},o.f);
o.clock.tick(10000); o.clock.tick(2000);
if (!o.f.calledOnce){ if (!o.f.calledOnce){
ok (false, 'no response / too much results'); ok (false, 'no response / too much results');
} }
...@@ -1095,21 +1095,24 @@ test ('Get document list', function () { ...@@ -1095,21 +1095,24 @@ test ('Get document list', function () {
o.jio = JIO.newJio({type:'indexed', o.jio = JIO.newJio({type:'indexed',
storage:{type:'dummyall3tries', storage:{type:'dummyall3tries',
username:'indexgetlist'}}); username:'indexgetlist'}});
o.doc1 = {name:'file',last_modified:15000,creation_date:10000}; o.doc1 = {id:'file',key:'file',value:{
o.doc2 = {name:'memo',last_modified:25000,creation_date:20000}; _last_modified:15000,_creation_date:10000}};
o.doc2 = {id:'memo',key:'memo',value:{
_last_modified:25000,_creation_date:20000}};
// getting list must take long time with dummyall3tries // getting list must take long time with dummyall3tries
o.f = this.spy(); o.f = this.spy();
o.jio.getDocumentList('.',{max_retry:3,onResponse:o.f}); o.jio.allDocs({max_retry:3},o.f);
o.clock.tick(1000); o.clock.tick(1000);
ok(!o.f.called,'Callback must not be called'); ok(!o.f.called,'Callback must not be called');
// wail long time too retreive list // wail long time too retreive list
o.clock.tick(10000); o.clock.tick(1000);
// now we can test if the document list is loaded faster // now we can test if the document list is loaded faster
o.f2 = function (result) { o.f2 = function (err,val) {
deepEqual (result,[o.doc1,o.doc2],'get document list'); deepEqual (err || objectifyDocumentArray(val.rows),
objectifyDocumentArray([o.doc1,o.doc2]),'get document list');
}; };
this.spy(o,'f2'); this.spy(o,'f2');
o.jio.getDocumentList('.',{max_retry:3,success:o.f2,error:o.f2}); o.jio.allDocs({max_retry:3},o.f2);
o.clock.tick(1000) o.clock.tick(1000)
if (!o.f2.calledOnce) { if (!o.f2.calledOnce) {
ok (false, 'no response / too much results'); ok (false, 'no response / too much results');
...@@ -1119,23 +1122,27 @@ test ('Get document list', function () { ...@@ -1119,23 +1122,27 @@ test ('Get document list', function () {
test ('Remove document', function () { test ('Remove document', function () {
var o = {}; o.clock = this.sandbox.useFakeTimers(); var o = {}; o.clock = this.sandbox.useFakeTimers();
o.clock.tick(base_tick); o.clock.tick(base_tick);
o.jio = JIO.newJio({type:'indexed', o.secondstorage = {type:'dummyall3tries',username:'indexremove'}
storage:{type:'dummyall3tries', o.storage_file_object_name = 'jio/indexed_file_object/'+
username:'indexremove'}}); JSON.stringify (o.secondstorage);
o.f = function (result) {
if (!result) { o.jio = JIO.newJio({type:'indexed',storage:o.secondstorage});
result = 'done'; o.f = function (err,val) {
} else { if (err) {
result = 'fail'; err = err.status;
} }
deepEqual (result,'done','document remove'); deepEqual (err || val,{ok:true,id:'file'},'document remove');
}; };
this.spy(o,'f'); this.spy(o,'f');
o.jio.removeDocument('file',{max_retry:3,success:o.f,error:o.f}); o.jio.remove({_id:'file'},{max_retry:3},o.f);
o.clock.tick(10000); o.clock.tick(2000);
if (!o.f.calledOnce){ if (!o.f.calledOnce){
ok (false, 'no response / too much results'); ok (false, 'no response / too much results');
} }
o.tmp = LocalOrCookieStorage.getItem(o.storage_file_object_name) || {};
ok (!o.tmp.file,'File does not exists anymore');
o.jio.stop(); o.jio.stop();
}); });
......
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