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

Replicate Storage complete.

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