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 */
......@@ -177,7 +177,8 @@ var JIO =
},
'localStorage': null, // where the browser stores data
'queueID': 1,
'storageTypeObject': {} // ex: {'type':'local','creator': fun ...}
'storageTypeObject': {}, // ex: {'type':'local','creator': fun ...}
'max_wait_time': 10000
},
// end jio globals
////////////////////////////////////////////////////////////////////////////
......@@ -764,9 +765,12 @@ var JIO =
// Change the job status to wait for time.
// 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.waitingFor = {'time':Date.now() +
(priv.job.tries*priv.job.tries*1000)};
priv.job.waitingFor = {'time':Date.now() + time};
};
//// 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 */
......@@ -505,6 +505,17 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
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 () {
// Checks the availability of the [job.userName].
// if the name already exists in a storage, it is not available.
......@@ -524,14 +535,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
that.done(isavailable);
}
};
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 ) ;
}
priv.execJobsFromStorageArray(callback);
};
that.saveDocument = function () {
// Save a single document in several storages.
......@@ -544,29 +548,22 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.fileContent: the document content.
// TODO
var newjob = {}, res = {'status':'done'}, i = 'id',
var newjob = {}, res = {'status':'done'}, i = 'id', done = false,
callback = function (result) {
priv.returnsValuesArray.push(result);
if (result.status === 'fail') {
res.status = 'fail';
}
if (priv.returnsValuesArray.length === priv.length) {
// if this is the last callback
if (res.status === 'fail') {
that.fail('Unable to save all files.',0);
if (!done) {
if (result.status !== 'fail') {
that.done ();
done = true;
} else {
that.done();
if (priv.returnsValuesArray.length ===
priv.length) {
that.fail ('Unable to save any file.',0);
}
}
}
};
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 ) ;
}
priv.execJobsFromStorageArray(callback);
};
that.loadDocument = function () {
......@@ -586,60 +583,22 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// TODO
var newjob = {}, aredifferent = false, doc = {}, i = 'id',
done = false,
res = {'status':'done'}, callback = function (result) {
priv.returnsValuesArray.push(result);
if (result.status === 'fail') {
res.status = 'fail';
} else {
// check if the file are different
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);
if (!done) {
if (result.status !== 'fail') {
that.done (result.document);
done = true;
} else {
if (!aredifferent) {
that.done(doc);
} else {
// TODO the files are different! Give options
// to know what do we do now!
// console.warn ('The files are different.');
that.done(doc);
if (priv.returnsValuesArray.length ===
priv.length) {
that.fail ('Unable to load any file.',0);
}
}
}
};
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 ) ;
}
priv.execJobsFromStorageArray(callback);
};
that.getDocumentList = function () {
......@@ -670,14 +629,7 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
}
}
};
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 ) ;
}
priv.execJobsFromStorageArray(callback);
};
that.removeDocument = function () {
......@@ -690,29 +642,22 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.applicant.ID: the applicant id.
// TODO
var newjob = {}, res = {'status':'done'}, i = 'key',
var newjob = {}, res = {'status':'done'}, i = 'key', done = false,
callback = function (result) {
priv.returnsValuesArray.push(result);
if (result.status === 'fail') {
res.status = 'fail';
}
if (priv.returnsValuesArray.length === priv.length) {
// if this is the last callback
if (res.status === 'fail') {
that.fail('Unable remove all files.',0);
if (!done) {
if (result.status !== 'fail') {
that.done ();
done = true;
} else {
that.done();
if (priv.returnsValuesArray.length ===
priv.length) {
that.fail ('Unable to remove any file.',0);
}
}
}
};
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 ) ;
}
priv.execJobsFromStorageArray(callback);
};
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 */
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 */
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 () {
{'type':'dummyall3tries','userName':'2'}]},
{'ID':'jiotests'});
mytest('DummyStorageAllOK,3tries: load 2 different files',{
'fileName':'file','fileContent':'content2',
'lastModified':17000,
'fileName':'file','fileContent':'content',
'lastModified':15000,
'creationDate':10000});
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