Commit b149e374 authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

Replicate Storage complete.

parent a4b6f558
(function(){
//// clear jio localstorage //// clear jio localstorage
for (var k in LocalOrCookieStorage.getAll()) { for (var k in LocalOrCookieStorage.getAll()) {
var splitk = k.split('/'); var splitk = k.split('/');
...@@ -355,8 +356,8 @@ test ('Get document list', function () { ...@@ -355,8 +356,8 @@ test ('Get document list', function () {
mytest = function (value){ mytest = function (value){
o.f = function (result) { o.f = function (result) {
var objectifyDocumentArray = function (array) { var objectifyDocumentArray = function (array) {
var obj = {}, k; var obj = {};
for (k in array) {obj[array[k].fileName] = array[k];} for (var k in array) {obj[array[k].fileName] = array[k];}
return obj; return obj;
}; };
deepEqual (objectifyDocumentArray(result.list), deepEqual (objectifyDocumentArray(result.list),
...@@ -690,6 +691,7 @@ test ('Check name availability', function () { ...@@ -690,6 +691,7 @@ test ('Check name availability', function () {
test ('Document load', function () { test ('Document load', function () {
// Test if ReplicateStorage can load several documents. // Test if ReplicateStorage can load several documents.
// TODO finish it
var o = {}; var clock = this.sandbox.useFakeTimers(); var t = this; var o = {}; var clock = this.sandbox.useFakeTimers(); var t = this;
var mytest = function (message,doc) { var mytest = function (message,doc) {
...@@ -724,6 +726,7 @@ test ('Document load', function () { ...@@ -724,6 +726,7 @@ test ('Document load', function () {
test ('Document save', function () { test ('Document save', function () {
// Test if ReplicateStorage can save several documents. // Test if ReplicateStorage can save several documents.
// TODO finish it
var o = {}, clock = this.sandbox.useFakeTimers(), t = this, var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (message,value) { mytest = function (message,value) {
...@@ -745,7 +748,8 @@ test ('Document save', function () { ...@@ -745,7 +748,8 @@ test ('Document save', function () {
}); });
test ('Get Document List', function () { test ('Get Document List', function () {
// Test if ReplicateStorage can save several documents. // Test if ReplicateStorage can get several list.
// TODO finish it
var o = {}, clock = this.sandbox.useFakeTimers(), t = this, var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (message,value) { mytest = function (message,value) {
...@@ -759,8 +763,7 @@ test ('Get Document List', function () { ...@@ -759,8 +763,7 @@ test ('Get Document List', function () {
objectifyDocumentArray(value),'getting list'); objectifyDocumentArray(value),'getting list');
}; };
t.spy(o,'f'); t.spy(o,'f');
o.jio.saveDocument({'fileName':'file','fileContent':'content', o.jio.getDocumentList({'callback':o.f,'maxtries':3});
'callback':o.f,'maxtries':3});
clock.tick(100000); clock.tick(100000);
if (!o.f.calledOnce) if (!o.f.calledOnce)
ok(false, 'no response / too much results'); ok(false, 'no response / too much results');
...@@ -769,10 +772,41 @@ test ('Get Document List', function () { ...@@ -769,10 +772,41 @@ test ('Get Document List', function () {
{'type':'dummyallok','userName':'1'}, {'type':'dummyallok','userName':'1'},
{'type':'dummyall3tries','userName':'2'}]}, {'type':'dummyall3tries','userName':'2'}]},
{'ID':'jiotests'}); {'ID':'jiotests'});
o.doc1 = {'fileName':'memo','fileContent':'test', o.doc1 = {'fileName':'file',
'lastModified':15000,'creationDate':10000}; 'lastModified':15000,'creationDate':10000};
o.doc1 = {'fileName':'memo','fileContent':'test', o.doc2 = {'fileName':'memo',
'lastModified':25000,'creationDate':20000}; 'lastModified':25000,'creationDate':20000};
mytest('DummyStorageAllOK,3tries: get document list .',[o.doc1,o.doc2]); mytest('DummyStorageAllOK,3tries: get document list .',[o.doc1,o.doc2]);
o.jio.stop(); o.jio.stop();
}); });
test ('Remove document', function () {
// Test if ReplicateStorage can remove several documents.
// TODO finish it
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (message,value) {
o.f = function (result) {
var objectifyDocumentArray = function (array) {
var obj = {}, k;
for (k in array) {obj[array[k].fileName] = array[k];}
return obj;
};
deepEqual (objectifyDocumentArray(result.list),
objectifyDocumentArray(value),'getting list');
};
t.spy(o,'f');
o.jio.removeDocument({'fileName':'file','callback':o.f,'maxtries':3});
clock.tick(100000);
if (!o.f.calledOnce)
ok(false, 'no response / too much results');
};
o.jio=JIO.createNew({'type':'replicate','userName':'Dummy','storageArray':[
{'type':'dummyallok','userName':'1'},
{'type':'dummyall3tries','userName':'2'}]},
{'ID':'jiotests'});
mytest('DummyStorageAllOK,3tries: remove document .',true);
o.jio.stop();
});
})();
...@@ -197,8 +197,8 @@ ...@@ -197,8 +197,8 @@
}, },
getNewQueueID = function () { getNewQueueID = function () {
// Returns a new queueID // Returns a new queueID
var localStor = jioGlobalObj.localStorage.getAll(), k = 'key', var localStor = jioGlobalObj.localStorage.getAll(), id = 0, k = 'key',
splitk = ['splitedkey'], id = 0; splitk = ['splitedkey'];
for (k in localStor) { for (k in localStor) {
splitk = k.split('/'); splitk = k.split('/');
if (splitk[0] === 'jio' && if (splitk[0] === 'jio' &&
...@@ -352,7 +352,7 @@ ...@@ -352,7 +352,7 @@
// job : the job object // job : the job object
var res = {'newone':true,'elimArray':[],'waitArray':[], var res = {'newone':true,'elimArray':[],'waitArray':[],
'removeArray':[]}, basestorage = null, id=0; 'removeArray':[]}, basestorage = null, id = 'id';
//// browsing current jobs //// browsing current jobs
for (id in this.jobObject) { for (id in this.jobObject) {
...@@ -433,7 +433,7 @@ ...@@ -433,7 +433,7 @@
// options.where : remove values where options.where(job) === true // options.where : remove values where options.where(job) === true
var settings = $.extend ({'where':function (job) {return true;}}, var settings = $.extend ({'where':function (job) {return true;}},
options),k='key',andwhere,found=false; options),andwhere,found=false,k='key';
//// modify the job list //// modify the job list
if (settings.job) { if (settings.job) {
...@@ -460,7 +460,7 @@ ...@@ -460,7 +460,7 @@
resetAll: function () { resetAll: function () {
// Reset all job to 'initial'. // Reset all job to 'initial'.
// TODO manage jobs ! All jobs are not 'initial'. // TODO manage jobs ! All jobs are not 'initial'.
var id = 'id'; var id = 'id';
for (id in this.jobObject) { for (id in this.jobObject) {
this.jobObject[id].status = 'initial'; this.jobObject[id].status = 'initial';
...@@ -471,9 +471,10 @@ ...@@ -471,9 +471,10 @@
invokeAll: function () { invokeAll: function () {
// Do all jobs in the queue. // Do all jobs in the queue.
var i = 'id', j = 'ind', ok = false; var i = 'id', ok;
//// do All jobs //// do All jobs
for (i in this.jobObject) { for (i in this.jobObject) {
ok = false;
if (this.jobObject[i].status === 'initial') { if (this.jobObject[i].status === 'initial') {
// if status initial // if status initial
// invoke new job // invoke new job
...@@ -484,7 +485,7 @@ ...@@ -484,7 +485,7 @@
if (this.jobObject[i].waitingFor.jobIdArray) { if (this.jobObject[i].waitingFor.jobIdArray) {
// wait job // wait job
// browsing job id array // browsing job id array
for (j in this.jobObject[i].waitingFor.jobIdArray) { for (var j in this.jobObject[i].waitingFor.jobIdArray) {
if (this.jobObject[this.jobObject[i]. if (this.jobObject[this.jobObject[i].
waitingFor.jobIdArray[j]]) { waitingFor.jobIdArray[j]]) {
// if a job is still exist, don't invoke // if a job is still exist, don't invoke
......
...@@ -49,11 +49,11 @@ ...@@ -49,11 +49,11 @@
// wait a little in order to simulate asynchronous operation // wait a little in order to simulate asynchronous operation
setTimeout(function () { setTimeout(function () {
var localStorageObject = null, k = 'key', splitk = ['splitedkey']; var localStorageObject = null;
localStorageObject = jioGlobalObj.localStorage.getAll(); localStorageObject = jioGlobalObj.localStorage.getAll();
for (k in localStorageObject) { for (var k in localStorageObject) {
splitk = k.split('/'); var splitk = k.split('/');
if (splitk[0] === 'jio' && if (splitk[0] === 'jio' &&
splitk[1] === 'local' && splitk[1] === 'local' &&
splitk[2] === that.getUserName()) { splitk[2] === that.getUserName()) {
...@@ -141,8 +141,8 @@ ...@@ -141,8 +141,8 @@
// 'lastModified':date,'creationDate':date} // 'lastModified':date,'creationDate':date}
setTimeout(function () { setTimeout(function () {
var list = [], localStor = null, k = 'key', var list = [], localStorageObject = null, k = 'key',
splitk = ['splitedkey']; splitk = ['splitedkey'], fileObject = {};
localStorageObject = jioGlobalObj.localStorage.getAll(); localStorageObject = jioGlobalObj.localStorage.getAll();
for (k in localStorageObject) { for (k in localStorageObject) {
...@@ -511,8 +511,8 @@ ...@@ -511,8 +511,8 @@
// this.job.storage.storageArray: An Array of storages. // this.job.storage.storageArray: An Array of storages.
// TODO // TODO
var newjob = {}, isavailable = true, var newjob = {}, isavailable = true, i = 'id',
res = {'status':'done'}, i = 'ind'; res = {'status':'done'};
for (i in priv.storageArray) { for (i in priv.storageArray) {
newjob = that.cloneJob(); newjob = that.cloneJob();
...@@ -543,9 +543,8 @@ ...@@ -543,9 +543,8 @@
// this.job.fileContent: the document content. // this.job.fileContent: the document content.
// TODO // TODO
var newjob = {}, var newjob = {}, res = {'status':'done'}, i = 'id';
res = {'status':'done'}, i = 'ind';
for (i in priv.storageArray) { for (i in priv.storageArray) {
newjob = that.cloneJob(); newjob = that.cloneJob();
newjob.maxtries = priv.maxtries; newjob.maxtries = priv.maxtries;
...@@ -584,10 +583,9 @@ ...@@ -584,10 +583,9 @@
// 'creationDate':date,'lastModified':date} // 'creationDate':date,'lastModified':date}
// TODO // TODO
var newjob = {}, aredifferent = false, doc = {}, var newjob = {}, aredifferent = false, doc = {}, i = 'id',
res = {'status':'done'}, i = 'ind'; res = {'status':'done'};
doc.fileName = that.getFileName();
for (i in priv.storageArray) { for (i in priv.storageArray) {
newjob = that.cloneJob(); newjob = that.cloneJob();
newjob.maxtries = priv.maxtries; newjob.maxtries = priv.maxtries;
...@@ -655,8 +653,7 @@ ...@@ -655,8 +653,7 @@
// 'lastModified':date,'creationDate':date} // 'lastModified':date,'creationDate':date}
// TODO // TODO
var newjob = {}, var newjob = {}, res = {'status':'done'}, i = 'id';
res = {'status':'done'}, i = 'ind';
for (i in priv.storageArray) { for (i in priv.storageArray) {
newjob = that.cloneJob(); newjob = that.cloneJob();
...@@ -690,9 +687,8 @@ ...@@ -690,9 +687,8 @@
// this.job.applicant.ID: the applicant id. // this.job.applicant.ID: the applicant id.
// TODO // TODO
var newjob = {}, var newjob = {}, res = {'status':'done'}, i = 'key';
res = {'status':'done'}, i = 'ind';
for (i in priv.storageArray) { for (i in priv.storageArray) {
newjob = that.cloneJob(); newjob = that.cloneJob();
newjob.maxtries = priv.maxtries; newjob.maxtries = priv.maxtries;
...@@ -712,7 +708,8 @@ ...@@ -712,7 +708,8 @@
} }
}; };
that.addJob ( newjob ) ; that.addJob ( newjob ) ;
} }; }
};
return that; return that;
}; };
// end ReplicateStorage // end ReplicateStorage
......
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