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

Jiotests modified according to ReplicateStorage + grunt tests ok.

parent d93b826b
/*! JIO - v0.1.0 - 2012-05-21 /*! JIO - v0.1.0 - 2012-05-22
* Copyright (c) 2012 Nexedi; Licensed */ * Copyright (c) 2012 Nexedi; Licensed */
...@@ -177,7 +177,8 @@ var JIO = ...@@ -177,7 +177,8 @@ var JIO =
}, },
'localStorage': null, // where the browser stores data 'localStorage': null, // where the browser stores data
'queueID': 1, 'queueID': 1,
'storageTypeObject': {} // ex: {'type':'local','creator': fun ...} 'storageTypeObject': {}, // ex: {'type':'local','creator': fun ...}
'max_wait_time': 10000
}, },
// end jio globals // end jio globals
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
...@@ -764,9 +765,12 @@ var JIO = ...@@ -764,9 +765,12 @@ var JIO =
// Change the job status to wait for time. // Change the job status to wait for time.
// The listener will invoke this job later. // The listener will invoke this job later.
var time = (priv.job.tries*priv.job.tries*1000);
if (time > jioGlobalObj.max_wait_time) {
time = jioGlobalObj.max_wait_time;
}
priv.job.status = 'wait'; priv.job.status = 'wait';
priv.job.waitingFor = {'time':Date.now() + priv.job.waitingFor = {'time':Date.now() + time};
(priv.job.tries*priv.job.tries*1000)};
}; };
//// end Private Methods //// end Private Methods
......
This diff is collapsed.
/*! JIO Storage - v0.1.0 - 2012-05-21 /*! JIO Storage - v0.1.0 - 2012-05-22
* Copyright (c) 2012 Nexedi; Licensed */ * Copyright (c) 2012 Nexedi; Licensed */
...@@ -505,6 +505,17 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -505,6 +505,17 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
that.setMaxTries (1); that.setMaxTries (1);
priv.execJobsFromStorageArray = function (callback) {
var newjob = {}, i;
for (i = 0; i < priv.storageArray.length; i += 1) {
newjob = that.cloneJob();
newjob.maxtries = priv.maxtries;
newjob.storage = priv.storageArray[i];
newjob.callback = callback;
that.addJob ( newjob ) ;
}
};
that.checkNameAvailability = function () { that.checkNameAvailability = function () {
// Checks the availability of the [job.userName]. // Checks the availability of the [job.userName].
// if the name already exists in a storage, it is not available. // if the name already exists in a storage, it is not available.
...@@ -524,14 +535,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -524,14 +535,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
that.done(isavailable); that.done(isavailable);
} }
}; };
priv.execJobsFromStorageArray(callback);
for (i = 0; i < priv.storageArray.length; i += 1) {
newjob = that.cloneJob();
newjob.maxtries = priv.maxtries;
newjob.storage = priv.storageArray[i];
newjob.callback = callback;
that.addJob ( newjob ) ;
}
}; };
that.saveDocument = function () { that.saveDocument = function () {
// Save a single document in several storages. // Save a single document in several storages.
...@@ -544,29 +548,22 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -544,29 +548,22 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.fileContent: the document content. // this.job.fileContent: the document content.
// TODO // TODO
var newjob = {}, res = {'status':'done'}, i = 'id', var newjob = {}, res = {'status':'done'}, i = 'id', done = false,
callback = function (result) { callback = function (result) {
priv.returnsValuesArray.push(result); priv.returnsValuesArray.push(result);
if (result.status === 'fail') { if (!done) {
res.status = 'fail'; if (result.status !== 'fail') {
} that.done ();
if (priv.returnsValuesArray.length === priv.length) { done = true;
// if this is the last callback
if (res.status === 'fail') {
that.fail('Unable to save all files.',0);
} else { } else {
that.done(); if (priv.returnsValuesArray.length ===
priv.length) {
that.fail ('Unable to save any file.',0);
}
} }
} }
}; };
priv.execJobsFromStorageArray(callback);
for (i = 0; i < priv.storageArray.length; i += 1) {
newjob = that.cloneJob();
newjob.maxtries = priv.maxtries;
newjob.storage = priv.storageArray[i];
newjob.callback = callback;
that.addJob ( newjob ) ;
}
}; };
that.loadDocument = function () { that.loadDocument = function () {
...@@ -586,60 +583,22 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -586,60 +583,22 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// TODO // TODO
var newjob = {}, aredifferent = false, doc = {}, i = 'id', var newjob = {}, aredifferent = false, doc = {}, i = 'id',
done = false,
res = {'status':'done'}, callback = function (result) { res = {'status':'done'}, callback = function (result) {
priv.returnsValuesArray.push(result); priv.returnsValuesArray.push(result);
if (result.status === 'fail') { if (!done) {
res.status = 'fail'; if (result.status !== 'fail') {
} else { that.done (result.document);
// check if the file are different done = true;
if (!doc.fileContent && !doc.creationDate &&
!doc.lastModified) {
// if it is the first document loaded
doc = $.extend({},result.document);
} else {
if (doc.fileContent !==
result.document.fileContent) {
// if the document is different from the
// previous one
aredifferent = true;
}
if (doc.creationDate >
result.document.creationDate) {
// get older creation date
doc.creationDate = result.document.creationDate;
}
if (doc.lastModified <
result.document.lastModified) {
// get newer last modified
doc.fileContent = result.document.fileContent;
doc.lastModified = result.document.lastModified;
}
}
}
if (priv.returnsValuesArray.length === priv.length) {
// if this is the last callback
if (res.status === 'fail') {
that.fail('Unable to load all files.',0);
} else { } else {
if (!aredifferent) { if (priv.returnsValuesArray.length ===
that.done(doc); priv.length) {
} else { that.fail ('Unable to load any file.',0);
// TODO the files are different! Give options
// to know what do we do now!
// console.warn ('The files are different.');
that.done(doc);
} }
} }
} }
}; };
priv.execJobsFromStorageArray(callback);
for (i = 0; i < priv.storageArray.length; i += 1) {
newjob = that.cloneJob();
newjob.maxtries = priv.maxtries;
newjob.storage = priv.storageArray[i];
newjob.callback = callback;
that.addJob ( newjob ) ;
}
}; };
that.getDocumentList = function () { that.getDocumentList = function () {
...@@ -670,14 +629,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -670,14 +629,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
} }
} }
}; };
priv.execJobsFromStorageArray(callback);
for (i = 0; i < priv.storageArray.length; i += 1) {
newjob = that.cloneJob();
newjob.maxtries = priv.maxtries;
newjob.storage = priv.storageArray[i];
newjob.callback = callback;
that.addJob ( newjob ) ;
}
}; };
that.removeDocument = function () { that.removeDocument = function () {
...@@ -690,29 +642,22 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -690,29 +642,22 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.applicant.ID: the applicant id. // this.job.applicant.ID: the applicant id.
// TODO // TODO
var newjob = {}, res = {'status':'done'}, i = 'key', var newjob = {}, res = {'status':'done'}, i = 'key', done = false,
callback = function (result) { callback = function (result) {
priv.returnsValuesArray.push(result); priv.returnsValuesArray.push(result);
if (result.status === 'fail') { if (!done) {
res.status = 'fail'; if (result.status !== 'fail') {
} that.done ();
if (priv.returnsValuesArray.length === priv.length) { done = true;
// if this is the last callback
if (res.status === 'fail') {
that.fail('Unable remove all files.',0);
} else { } else {
that.done(); if (priv.returnsValuesArray.length ===
priv.length) {
that.fail ('Unable to remove any file.',0);
}
} }
} }
}; };
priv.execJobsFromStorageArray(callback);
for (i = 0; i < priv.storageArray.length; i += 1) {
newjob = that.cloneJob();
newjob.maxtries = priv.maxtries;
newjob.storage = priv.storageArray[i];
newjob.callback = callback;
that.addJob ( newjob ) ;
}
}; };
return that; return that;
}; };
......
This diff is collapsed.
/*! Local Or Cookie Storage - v0.1.0 - 2012-05-21 /*! Local Or Cookie Storage - v0.1.0 - 2012-05-22
* Copyright (c) 2012 Nexedi; Licensed */ * Copyright (c) 2012 Nexedi; Licensed */
var LocalOrCookieStorage = var LocalOrCookieStorage =
......
/*! Local Or Cookie Storage - v0.1.0 - 2012-05-21 /*! Local Or Cookie Storage - v0.1.0 - 2012-05-22
* Copyright (c) 2012 Nexedi; Licensed */ * Copyright (c) 2012 Nexedi; Licensed */
var LocalOrCookieStorage=function(){var a=function(){var a=function(){};a.prototype={getItem:function(a){return JSON.parse(localStorage.getItem(a))},setItem:function(a,b){if(a)return localStorage.setItem(a,JSON.stringify(b))},getAll:function(){return localStorage},deleteItem:function(a){a&&delete localStorage[a]}};var b=function(){};b.prototype={getItem:function(a){var b=document.cookie.split(";"),c;for(c=0;c<b.length;c+=1){var d=b[c].substr(0,b[c].indexOf("=")),e=b[c].substr(b[c].indexOf("=")+1);d=d.replace(/^\s+|\s+$/g,"");if(d===a)return unescape(e)}return null},setItem:function(a,b){return b!==undefined?(document.cookie=a+"="+JSON.stringify(b)+";domain="+window.location.hostname+";path="+window.location.pathname,!0):!1},getAll:function(){var a={},b,c=document.cookie.split(":");for(b=0;b<c.length;b+=1){var d=c[b].substr(0,c[b].indexOf("=")),e=c[b].substr(c[b].indexOf("=")+1);d=d.replace(/^\s+|\s+$/g,""),a[d]=unescape(e)}return a},deleteItem:function(a){document.cookie=a+"=null;domain="+window.location.hostname+";path="+window.location.pathname+";expires=Thu, 01-Jan-1970 00:00:01 GMT"}};try{return localStorage.getItem?new a:new b}catch(c){return new b}};return window.requirejs?(define("LocalOrCookieStorage",[],a),undefined):a()}(); var LocalOrCookieStorage=function(){var a=function(){var a=function(){};a.prototype={getItem:function(a){return JSON.parse(localStorage.getItem(a))},setItem:function(a,b){if(a)return localStorage.setItem(a,JSON.stringify(b))},getAll:function(){return localStorage},deleteItem:function(a){a&&delete localStorage[a]}};var b=function(){};b.prototype={getItem:function(a){var b=document.cookie.split(";"),c;for(c=0;c<b.length;c+=1){var d=b[c].substr(0,b[c].indexOf("=")),e=b[c].substr(b[c].indexOf("=")+1);d=d.replace(/^\s+|\s+$/g,"");if(d===a)return unescape(e)}return null},setItem:function(a,b){return b!==undefined?(document.cookie=a+"="+JSON.stringify(b)+";domain="+window.location.hostname+";path="+window.location.pathname,!0):!1},getAll:function(){var a={},b,c=document.cookie.split(":");for(b=0;b<c.length;b+=1){var d=c[b].substr(0,c[b].indexOf("=")),e=c[b].substr(c[b].indexOf("=")+1);d=d.replace(/^\s+|\s+$/g,""),a[d]=unescape(e)}return a},deleteItem:function(a){document.cookie=a+"=null;domain="+window.location.hostname+";path="+window.location.pathname+";expires=Thu, 01-Jan-1970 00:00:01 GMT"}};try{return localStorage.getItem?new a:new b}catch(c){return new b}};return window.requirejs?(define("LocalOrCookieStorage",[],a),undefined):a()}();
\ No newline at end of file
...@@ -737,8 +737,8 @@ test ('Document load', function () { ...@@ -737,8 +737,8 @@ test ('Document load', function () {
{'type':'dummyall3tries','userName':'2'}]}, {'type':'dummyall3tries','userName':'2'}]},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('DummyStorageAllOK,3tries: load 2 different files',{ mytest('DummyStorageAllOK,3tries: load 2 different files',{
'fileName':'file','fileContent':'content2', 'fileName':'file','fileContent':'content',
'lastModified':17000, 'lastModified':15000,
'creationDate':10000}); 'creationDate':10000});
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