Commit 979fca4a authored by Tristan Cavelier's avatar Tristan Cavelier

Jio can now restore older jio instance.

parent 3d2ae5e9
...@@ -15,12 +15,12 @@ module.exports = function(grunt) { ...@@ -15,12 +15,12 @@ module.exports = function(grunt) {
dist: { dist: {
src: ['<banner:meta.banner>', src: ['<banner:meta.banner>',
// Wrapper top // Wrapper top
'<file_strip_banner:../../src/<%= pkg.name %>/wrapper.top.js>', '<file_strip_banner:../../src/<%= pkg.name %>/intro.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/exceptions.js>', '<file_strip_banner:../../src/<%= pkg.name %>/exceptions.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/storages/storage.js>', '<file_strip_banner:../../src/<%= pkg.name %>/storages/storage.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/storages/storageHandler.js>', '<file_strip_banner:../../src/<%= pkg.name %>/storages/storageHandler.js>',
// Jio wrapper top // Jio wrapper top
'<file_strip_banner:../../src/<%= pkg.name %>/jio.top.js>', '<file_strip_banner:../../src/<%= pkg.name %>/jio.intro.js>',
// Jio Classes // Jio Classes
'<file_strip_banner:../../src/<%= pkg.name %>/commands/command.js>', '<file_strip_banner:../../src/<%= pkg.name %>/commands/command.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/commands/getDocumentList.js>', '<file_strip_banner:../../src/<%= pkg.name %>/commands/getDocumentList.js>',
...@@ -42,10 +42,10 @@ module.exports = function(grunt) { ...@@ -42,10 +42,10 @@ module.exports = function(grunt) {
'<file_strip_banner:../../src/<%= pkg.name %>/jobs/jobManager.js>', '<file_strip_banner:../../src/<%= pkg.name %>/jobs/jobManager.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/jobs/jobRules.js>', '<file_strip_banner:../../src/<%= pkg.name %>/jobs/jobRules.js>',
// Jio wrappor bottem // Jio wrappor bottem
'<file_strip_banner:../../src/<%= pkg.name %>/jio.bottom.js>', '<file_strip_banner:../../src/<%= pkg.name %>/jio.outro.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/jioNamespace.js>', '<file_strip_banner:../../src/<%= pkg.name %>/jioNamespace.js>',
// Wrapper bottom // Wrapper bottom
'<file_strip_banner:../../src/<%= pkg.name %>/wrapper.bottom.js>'], '<file_strip_banner:../../src/<%= pkg.name %>/outro.js>'],
dest: '../../lib/jio/<%= pkg.name %>.js' dest: '../../lib/jio/<%= pkg.name %>.js'
} }
}, },
...@@ -87,10 +87,7 @@ module.exports = function(grunt) { ...@@ -87,10 +87,7 @@ module.exports = function(grunt) {
browser: true browser: true
}, },
globals: { globals: {
jQuery: true,
sjcl:true,
LocalOrCookieStorage: true, LocalOrCookieStorage: true,
Base64: true,
console: true, console: true,
unescape: true, unescape: true,
// Needed to avoid "not defined error" with requireJs // Needed to avoid "not defined error" with requireJs
...@@ -112,6 +109,6 @@ module.exports = function(grunt) { ...@@ -112,6 +109,6 @@ module.exports = function(grunt) {
}); });
// Default task. // Default task.
grunt.registerTask('default', 'concat min lint qunit'); grunt.registerTask('default', 'concat lint min qunit');
}; };
...@@ -14,7 +14,9 @@ module.exports = function(grunt) { ...@@ -14,7 +14,9 @@ module.exports = function(grunt) {
concat: { concat: {
dist: { dist: {
src: ['<banner:meta.banner>', src: ['<banner:meta.banner>',
'<file_strip_banner:../../src/<%= pkg.name %>.js>'], '<file_strip_banner:../../src/<%= pkg.name %>/intro.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/localStorage.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/outro.js>'],
dest: '../../lib/jio/<%= pkg.name %>.js' dest: '../../lib/jio/<%= pkg.name %>.js'
} }
}, },
...@@ -28,7 +30,7 @@ module.exports = function(grunt) { ...@@ -28,7 +30,7 @@ module.exports = function(grunt) {
files: [] files: []
}, },
lint: { lint: {
files: ['grunt.js','../../src/<%= pkg.name %>.js'] files: ['grunt.js','../../lib/jio/<%= pkg.name %>.js']
}, },
watch: { watch: {
files: '<config:lint.files>', files: '<config:lint.files>',
...@@ -53,7 +55,7 @@ module.exports = function(grunt) { ...@@ -53,7 +55,7 @@ module.exports = function(grunt) {
sjcl: true, sjcl: true,
LocalOrCookieStorage: true, LocalOrCookieStorage: true,
Base64: true, Base64: true,
JIO: true, jio: true,
console: true, console: true,
unescape: true, unescape: true,
// Needed to avoid "not defined error" with requireJs // Needed to avoid "not defined error" with requireJs
...@@ -75,6 +77,6 @@ module.exports = function(grunt) { ...@@ -75,6 +77,6 @@ module.exports = function(grunt) {
}); });
// Default task. // Default task.
grunt.registerTask('default', 'lint concat min'); grunt.registerTask('default', 'concat lint min');
}; };
...@@ -2,11 +2,9 @@ ...@@ -2,11 +2,9 @@
for node in `ls -1` ; do for node in `ls -1` ; do
if [ -d "$node" ] ; then if [ -d "$node" ] ; then
cd "$node"
printf "\n\033[1m\033[36mgrunt --force -> %s\033[0m\n" "$node" printf "\n\033[1m\033[36mmake -C %s\033[0m\n" "$node"
grunt --force make -C "$node"
cd ..
fi fi
done done
/*! JIO - v0.1.0 - 2012-06-12 /*! JIO - v0.1.0 - 2012-06-13
* Copyright (c) 2012 Nexedi; Licensed */ * Copyright (c) 2012 Nexedi; Licensed */
var jio = (function () { var jio = (function () {
...@@ -91,6 +91,7 @@ var storage = function(spec, my) { ...@@ -91,6 +91,7 @@ var storage = function(spec, my) {
* @param {object} command The command * @param {object} command The command
*/ */
that.execute = function(command) { that.execute = function(command) {
that.validate(command);
command.executeOn(that); command.executeOn(that);
}; };
...@@ -104,6 +105,10 @@ var storage = function(spec, my) { ...@@ -104,6 +105,10 @@ var storage = function(spec, my) {
}; };
that.validate = function(command) { that.validate = function(command) {
var mess = that.validateState();
if (mess) {
throw invalidStorage({storage:that,message:mess});
}
command.validate(that); command.validate(that);
}; };
...@@ -129,6 +134,10 @@ var storage = function(spec, my) { ...@@ -129,6 +134,10 @@ var storage = function(spec, my) {
that.saveDocument(); that.saveDocument();
}; };
that.validateState = function() {
return '';
};
return that; return that;
}; };
...@@ -146,24 +155,22 @@ var storageHandler = function(spec, my) { ...@@ -146,24 +155,22 @@ var storageHandler = function(spec, my) {
* Override this function. * Override this function.
* @method beforeExecute * @method beforeExecute
* @param {object} command The command. * @param {object} command The command.
* @param {object} option Some options.
*/ */
that.beforeExecute = function(command,option) {}; that.beforeExecute = function(command) {};
/** /**
* Execute the command according to this storage. * Execute the command according to this storage.
* @method execute * @method execute
* @param {object} command The command. * @param {object} command The command.
* @param {object} option Some options.
*/ */
that.execute = function(command,option) { that.execute = function(command) {
var i; var i;
that.validate(command); that.validate(command);
that.beforeExecute(command,option); that.beforeExecute(command);
for(i = 0; i < priv.storage_a.length; i++) { for(i = 0; i < priv.storage_a.length; i++) {
priv.storage_a[i].execute(command); priv.storage_a[i].execute(command);
} }
that.afterExecute(command,option); that.afterExecute(command);
}; };
/** /**
...@@ -171,10 +178,9 @@ var storageHandler = function(spec, my) { ...@@ -171,10 +178,9 @@ var storageHandler = function(spec, my) {
* Override this function. * Override this function.
* @method afterExecute * @method afterExecute
* @param {object} command The command. * @param {object} command The command.
* @param {object} option Some options.
*/ */
that.afterExecute = function(command,option) { that.afterExecute = function(command) {
that.done(); command.done();
}; };
/** /**
...@@ -298,7 +304,6 @@ var command = function(spec, my) { ...@@ -298,7 +304,6 @@ var command = function(spec, my) {
}; };
that.done = function(return_value) { that.done = function(return_value) {
console.log ('done');
priv.done(return_value); priv.done(return_value);
priv.respond({status:doneStatus(),value:return_value}); priv.respond({status:doneStatus(),value:return_value});
priv.end(); priv.end();
...@@ -308,7 +313,6 @@ var command = function(spec, my) { ...@@ -308,7 +313,6 @@ var command = function(spec, my) {
if (priv.option.max_retry === 0 || priv.tried < priv.option.max_retry) { if (priv.option.max_retry === 0 || priv.tried < priv.option.max_retry) {
priv.retry(); priv.retry();
} else { } else {
console.log ('fail');
priv.fail(return_error); priv.fail(return_error);
priv.respond({status:failStatus(),error:return_error}); priv.respond({status:failStatus(),error:return_error});
priv.end(); priv.end();
...@@ -337,6 +341,10 @@ var command = function(spec, my) { ...@@ -337,6 +341,10 @@ var command = function(spec, my) {
option:priv.option}; option:priv.option};
}; };
that.canBeRestored = function() {
return true;
};
return that; return that;
}; };
...@@ -354,6 +362,10 @@ var getDocumentList = function(spec, my) { ...@@ -354,6 +362,10 @@ var getDocumentList = function(spec, my) {
storage.getDocumentList(that); storage.getDocumentList(that);
}; };
that.canBeRestored = function() {
return false;
};
return that; return that;
}; };
...@@ -371,6 +383,10 @@ var loadDocument = function(spec, my) { ...@@ -371,6 +383,10 @@ var loadDocument = function(spec, my) {
storage.loadDocument(that); storage.loadDocument(that);
}; };
that.canBeRestored = function() {
return false;
};
return that; return that;
}; };
...@@ -396,14 +412,15 @@ var saveDocument = function(spec, my) { ...@@ -396,14 +412,15 @@ var saveDocument = function(spec, my) {
spec = spec || {}; spec = spec || {};
my = my || {}; my = my || {};
// Attributes // // Attributes //
var content = spec.content; var priv = {};
priv.content = spec.content;
// Methods // // Methods //
that.getLabel = function() { that.getLabel = function() {
return 'saveDocument'; return 'saveDocument';
}; };
that.getContent = function() { that.getContent = function() {
return content; return priv.content;
}; };
/** /**
...@@ -412,7 +429,7 @@ var saveDocument = function(spec, my) { ...@@ -412,7 +429,7 @@ var saveDocument = function(spec, my) {
*/ */
var super_validate = that.validate; var super_validate = that.validate;
that.validate = function(handler) { that.validate = function(handler) {
if (typeof content !== 'string') { if (typeof priv.content !== 'string') {
throw invalidCommandState({command:that,message:'No data to save'}); throw invalidCommandState({command:that,message:'No data to save'});
} }
super_validate(handler); super_validate(handler);
...@@ -422,6 +439,13 @@ var saveDocument = function(spec, my) { ...@@ -422,6 +439,13 @@ var saveDocument = function(spec, my) {
storage.saveDocument(that); storage.saveDocument(that);
}; };
var super_serialized = that.serialized;
that.serialized = function() {
var o = super_serialized();
o.content = priv.content;
return o;
};
return that; return that;
}; };
...@@ -568,7 +592,6 @@ var waitStatus = function(spec, my) { ...@@ -568,7 +592,6 @@ var waitStatus = function(spec, my) {
that.canStart = function() { that.canStart = function() {
priv.refreshJobIdArray(); priv.refreshJobIdArray();
console.log (priv.job_id_a);
return (priv.job_id_a.length === 0 && Date.now() >= priv.threshold); return (priv.job_id_a.length === 0 && Date.now() >= priv.threshold);
}; };
that.canRestart = function() { that.canRestart = function() {
...@@ -708,7 +731,6 @@ var job = function(spec, my) { ...@@ -708,7 +731,6 @@ var job = function(spec, my) {
* @param {object} job The other job. * @param {object} job The other job.
*/ */
that.update = function(job) { that.update = function(job) {
console.log ('updating');
priv.command.setMaxRetry(-1); priv.command.setMaxRetry(-1);
priv.command.fail({status:0,statusText:'Replaced', priv.command.fail({status:0,statusText:'Replaced',
message:'Job has been replaced by another one.'}); message:'Job has been replaced by another one.'});
...@@ -821,6 +843,8 @@ var activityUpdater = (function(spec, my) { ...@@ -821,6 +843,8 @@ var activityUpdater = (function(spec, my) {
}; };
return that; return that;
}()); }());
var announcer = (function(spec, my) { var announcer = (function(spec, my) {
var that = {}; var that = {};
spec = spec || {}; spec = spec || {};
...@@ -965,6 +989,7 @@ var jobManager = (function(spec, my) { ...@@ -965,6 +989,7 @@ var jobManager = (function(spec, my) {
if (jio_date < Date.now() - 10000) { if (jio_date < Date.now() - 10000) {
priv.restoreOldJobFromJioId(id); priv.restoreOldJobFromJioId(id);
priv.removeOldJioId(id); priv.removeOldJioId(id);
priv.removeJobArrayFromJioId(id);
} }
}; };
...@@ -972,9 +997,12 @@ var jobManager = (function(spec, my) { ...@@ -972,9 +997,12 @@ var jobManager = (function(spec, my) {
var i, jio_job_array; var i, jio_job_array;
jio_job_array = LocalOrCookieStorage.getItem('jio/job_array/'+id)||[]; jio_job_array = LocalOrCookieStorage.getItem('jio/job_array/'+id)||[];
for (i = 0; i < jio_job_array.length; i+= 1) { for (i = 0; i < jio_job_array.length; i+= 1) {
var command_o = command(jio_job_array[i].command);
if (command_o.canBeRestored()) {
that.addJob ( job( that.addJob ( job(
{storage:jioNamespace.storage(jio_job_array[i]), {storage:jioNamespace.storage(jio_job_array[i].storage),
command:command(jio_job_array[i].command)})); command:command_o}));
}
} }
}; };
...@@ -987,6 +1015,11 @@ var jobManager = (function(spec, my) { ...@@ -987,6 +1015,11 @@ var jobManager = (function(spec, my) {
} }
} }
LocalOrCookieStorage.setItem('jio/id_array',new_a); LocalOrCookieStorage.setItem('jio/id_array',new_a);
LocalOrCookieStorage.deleteItem('jio/id/'+id);
};
priv.removeJobArrayFromJioId = function(id) {
LocalOrCookieStorage.deleteItem('jio/job_array/'+id);
}; };
/** /**
...@@ -1011,11 +1044,9 @@ var jobManager = (function(spec, my) { ...@@ -1011,11 +1044,9 @@ var jobManager = (function(spec, my) {
var i; var i;
for (i = 0; i < priv.job_a.length; i+= 1) { for (i = 0; i < priv.job_a.length; i+= 1) {
if (priv.job_a[i].getId() === id) { if (priv.job_a[i].getId() === id) {
console.log ('found');
return true; return true;
} }
} }
console.log ('not found');
return false; return false;
}; };
...@@ -1047,11 +1078,9 @@ var jobManager = (function(spec, my) { ...@@ -1047,11 +1078,9 @@ var jobManager = (function(spec, my) {
return; return;
} }
} }
console.log ('managing '+JSON.stringify (result_a));
for (i = 0; i < result_a.length; i+= 1) { for (i = 0; i < result_a.length; i+= 1) {
switch (result_a[i].action) { switch (result_a[i].action) {
case 'eliminate': case 'eliminate':
console.log ('eliminating');
that.eliminate(result_a[i].job); that.eliminate(result_a[i].job);
break; break;
case 'update': case 'update':
...@@ -1059,7 +1088,6 @@ var jobManager = (function(spec, my) { ...@@ -1059,7 +1088,6 @@ var jobManager = (function(spec, my) {
priv.copyJobArrayToLocal(); priv.copyJobArrayToLocal();
return; return;
case 'wait': case 'wait':
console.log ('wait');
job.waitForJob(result_a[i].job); job.waitForJob(result_a[i].job);
break; break;
default: break; default: break;
...@@ -1074,7 +1102,6 @@ var jobManager = (function(spec, my) { ...@@ -1074,7 +1102,6 @@ var jobManager = (function(spec, my) {
for (i = 0; i < priv.job_a.length; i+= 1) { for (i = 0; i < priv.job_a.length; i+= 1) {
if (priv.job_a[i].getId() !== job.getId()) { if (priv.job_a[i].getId() !== job.getId()) {
tmp_a.push(priv.job_a[i]); tmp_a.push(priv.job_a[i]);
console.log ('add: '+priv.job_a[i].getId()+' -> it is not '+job.getId());
} }
} }
priv.job_a = tmp_a; priv.job_a = tmp_a;
...@@ -1224,30 +1251,22 @@ var jobRules = (function(spec, my) { ...@@ -1224,30 +1251,22 @@ var jobRules = (function(spec, my) {
j2label = job2.getCommand().getLabel(); j2label = job2.getCommand().getLabel();
j1status = (job1.getStatus().getLabel()==='on going'? j1status = (job1.getStatus().getLabel()==='on going'?
'on going':'not on going'); 'on going':'not on going');
try { if (priv.action[j1label] &&
console.log (j1label); priv.action[j1label][j1status] &&
console.log (j2label); priv.action[j1label][j1status][j2label]) {
console.log (j1status);
return priv.action[j1label][j1status][j2label](job1,job2); return priv.action[j1label][j1status][j2label](job1,job2);
} catch (e) {
if(e.name==='TypeError') {
return priv.default_action(job1,job2);
} else { } else {
throw e; return priv.default_action(job1,job2);
}
} }
}; };
priv.canCompare = function(job1,job2) { priv.canCompare = function(job1,job2) {
var job1label = job1.getCommand().getLabel(), var job1label = job1.getCommand().getLabel(),
job2label = job2.getCommand().getLabel(); job2label = job2.getCommand().getLabel();
try { if (priv.compare[job1label] &&
priv.compare[job2label]) {
return priv.compare[job1label][job2label](job1,job2); return priv.compare[job1label][job2label](job1,job2);
} catch(e) {
if (e.name==='TypeError') {
return priv.default_compare(job1,job2);
} else { } else {
throw e; return priv.default_compare(job1,job2);
}
} }
}; };
that.validateJobAccordingToJob = function(job1,job2) { that.validateJobAccordingToJob = function(job1,job2) {
...@@ -1267,14 +1286,16 @@ var jobRules = (function(spec, my) { ...@@ -1267,14 +1286,16 @@ var jobRules = (function(spec, my) {
// Attributes // // Attributes //
var priv = {}; var priv = {};
var jio_id_array_name = 'jio/id_array'; var jio_id_array_name = 'jio/id_array';
priv.id = 1; priv.id = null;
priv.storage = jioNamespace.storage(spec, that); priv.storage = jioNamespace.storage(spec);
// initialize // // initialize //
(function () { priv.init = function() {
// Initialize the jio id and add the new id to the list // Initialize the jio id and add the new id to the list
var i, if (priv.id === null) {
jio_id_a = LocalOrCookieStorage.getItem (jio_id_array_name) || []; var i, jio_id_a =
LocalOrCookieStorage.getItem (jio_id_array_name) || [];
priv.id = 1;
for (i = 0; i < jio_id_a.length; i+= 1) { for (i = 0; i < jio_id_a.length; i+= 1) {
if (jio_id_a[i] >= priv.id) { if (jio_id_a[i] >= priv.id) {
priv.id = jio_id_a[i] + 1; priv.id = jio_id_a[i] + 1;
...@@ -1282,22 +1303,26 @@ var jobRules = (function(spec, my) { ...@@ -1282,22 +1303,26 @@ var jobRules = (function(spec, my) {
} }
jio_id_a.push(priv.id); jio_id_a.push(priv.id);
LocalOrCookieStorage.setItem (jio_id_array_name,jio_id_a); LocalOrCookieStorage.setItem (jio_id_array_name,jio_id_a);
}());
(function (){
// Start Jio updater, and the jobManager
activityUpdater.setId(priv.id); activityUpdater.setId(priv.id);
activityUpdater.start();
jobManager.setId(priv.id); jobManager.setId(priv.id);
jobManager.start(); }
}()); };
// Methods // // Methods //
that.start = function() { that.start = function() {
priv.init();
activityUpdater.start();
jobManager.start(); jobManager.start();
}; };
that.stop = function() { that.stop = function() {
jobManager.stop(); jobManager.stop();
}; };
that.close = function() {
activityUpdater.stop();
jobManager.stop();
priv.id = null;
};
that.start();
/** /**
* Returns the jio id. * Returns the jio id.
...@@ -1446,11 +1471,12 @@ var jioNamespace = (function(spec, my) { ...@@ -1446,11 +1471,12 @@ var jioNamespace = (function(spec, my) {
* @method storage * @method storage
* @param {object} spec The specifications. * @param {object} spec The specifications.
* @param {object} my The protected object. * @param {object} my The protected object.
* @param {string} forcetype Force storage type
* @return {object} The storage object. * @return {object} The storage object.
*/ */
that.storage = function(spec, my) { that.storage = function(spec, my, forcetype) {
spec = spec || {}; spec = spec || {};
var type = spec.type || 'base'; var type = forcetype || spec.type || 'base';
if (!storage_type_o[type]) { if (!storage_type_o[type]) {
throw invalidStorageType({type:type, throw invalidStorageType({type:type,
message:'Storage does not exists.'}); message:'Storage does not exists.'});
......
/*! JIO - v0.1.0 - 2012-06-12 /*! JIO - v0.1.0 - 2012-06-13
* Copyright (c) 2012 Nexedi; Licensed */ * Copyright (c) 2012 Nexedi; Licensed */
var jio=function(){var a=function(a,b){var c={};return a=a||{},b=b||{},c.name="jioException",c.message=a.message||"Unknown Reason.",c.toString=function(){return c.name+": "+c.message},c},b=function(b,c){var d=a(b,c);b=b||{};var e=b.command;return d.name="invalidCommandState",d.toString=function(){return d.name+": "+e.getLabel()+", "+d.message},d},c=function(b,c){var d=a(b,c);b=b||{};var e=b.storage.getType();return d.name="invalidStorage",d.toString=function(){return d.name+": "+'Type "'+e+'", '+d.message},d},d=function(b,c){var d=a(b,c),e=b.type;return d.name="invalidStorageType",d.toString=function(){return d.name+": "+e+", "+d.message},d},e=function(b,c){var d=a(b,c);return d.name="jobNotReadyException",d},f=function(b,c){var d=a(b,c);return d.name="tooMuchTriesJobException",d},g=function(b,c){var d=a(b,c);return d.name="invalidJobException",d},h=function(a,b){var d={};a=a||{},b=b||{};var e={};return e.type=a.type||"",d.getType=function(){return e.type},d.setType=function(a){e.type=a},d.execute=function(a){a.executeOn(d)},d.isValid=function(){return!0},d.validate=function(a){a.validate(d)},d.serialized=function(){return{type:d.getType()}},d.saveDocument=function(a){throw c({storage:d,message:"Unknown storage."})},d.loadDocument=function(a){d.saveDocument()},d.removeDocument=function(a){d.saveDocument()},d.getDocumentList=function(a){d.saveDocument()},d},i=function(a,b){var c=h(a,b);a=a||{},b=b||{};var d={};return d.storage_a=a.storagelist||[],c.beforeExecute=function(a,b){},c.execute=function(a,b){var e;c.validate(a),c.beforeExecute(a,b);for(e=0;e<d.storage_a.length;e++)d.storage_a[e].execute(a);c.afterExecute(a,b)},c.afterExecute=function(a,b){c.done()},c.serialized=function(){return{type:d.type,storagelist:d.storagelist}},c},j=function(a,c){var d=function(a,c){var d={};a=a||{},c=c||{};var e={};return e.commandlist={saveDocument:l,loadDocument:i,removeDocument:j,getDocumentList:h},a.label&&e.commandlist[a.label]?(e.label=a.label,delete a.label,e.commandlist[e.label](a,c)):(e.path=a.path||"",e.tried=0,e.option=a.option||{},e.respond=e.option.onResponse||function(){},e.done=e.option.onDone||function(){},e.fail=e.option.onFail||function(){},e.retry=function(){d.setMaxRetry(-1),d.fail({status:0,statusText:"Fail Retry",message:"Impossible to retry."})},e.end=function(){},d.getLabel=function(){return"command"},d.getPath=function(){return e.path},d.getOption=function(a){return e.option[a]},d.validate=function(a){d.validateState()},d.getTried=function(){return e.tried},d.setMaxRetry=function(a){e.option.max_retry=a},d.execute=function(a){d.validate(a),e.tried++,a.execute(d)},d.executeOn=function(a){},d.validateState=function(){if(e.path==="")throw b({command:d,message:"Path is empty"})},d.done=function(a){console.log("done"),e.done(a),e.respond({status:n(),value:a}),e.end()},d.fail=function(a){e.option.max_retry===0||e.tried<e.option.max_retry?e.retry():(console.log("fail"),e.fail(a),e.respond({status:o(),error:a}),e.end())},d.onEndDo=function(a){e.end=a},d.onRetryDo=function(a){e.retry=a},d.serialized=function(){return{label:d.getLabel(),tried:e.tried,max_retry:e.max_retry,path:e.path,option:e.option}},d)},h=function(a,b){var c=d(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"getDocumentList"},c.executeOn=function(a){a.getDocumentList(c)},c},i=function(a,b){var c=d(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"loadDocument"},c.executeOn=function(a){a.loadDocument(c)},c},j=function(a,b){var c=d(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"removeDocument"},c.executeOn=function(a){a.removeDocument(c)},c},l=function(a,c){var e=d(a,c);a=a||{},c=c||{};var f=a.content;e.getLabel=function(){return"saveDocument"},e.getContent=function(){return f};var g=e.validate;return e.validate=function(a){if(typeof f!="string")throw b({command:e,message:"No data to save"});g(a)},e.executeOn=function(a){a.saveDocument(e)},e},m=function(a,b){var c={};return a=a||{},b=b||{},c.getLabel=function(){return"job status"},c.canStart=function(){},c.canRestart=function(){},c.serialized=function(){return{label:c.getLabel()}},c},n=function(a,b){var c=m(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"done"},c.canStart=function(){return!1},c.canRestart=function(){return!1},c},o=function(a,b){var c=m(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"fail"},c.canStart=function(){return!1},c.canRestart=function(){return!0},c},p=function(a,b){var c=m(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"initial"},c.canStart=function(){return!0},c.canRestart=function(){return!0},c},q=function(a,b){var c=m(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"on going"},c.canStart=function(){return!1},c.canRestart=function(){return!1},c},r=function(a,b){var c=m(a,b);a=a||{},b=b||{};var d={};return d.job_id_a=a.job_id_array||[],d.threshold=0,c.getLabel=function(){return"wait"},d.refreshJobIdArray=function(){var a=[],b;for(b=0;b<d.job_id_a.length;b+=1)x.jobIdExists(d.job_id_a[b])&&a.push(d.job_id_a[b]);d.job_id_a=a},c.waitForJob=function(a){var b;for(b=0;b<d.job_id_a.length;b+=1)if(d.job_id_a[b]===a.getId())return;d.job_id_a.push(a.getId())},c.dontWaitForJob=function(a){var b,c=[];for(b=0;b<d.job_id_a.length;b+=1)d.job_id_a[b]!==a.getId()&&c.push(d.job_id_a[b]);d.job_id_a=c},c.waitForTime=function(a){d.threshold=Date.now()+a},c.stopWaitForTime=function(){d.threshold=0},c.canStart=function(){return d.refreshJobIdArray(),console.log(d.job_id_a),d.job_id_a.length===0&&Date.now()>=d.threshold},c.canRestart=function(){return c.canStart()},c.serialized=function(){return{label:c.getLabel(),waitfortime:d.threshold,waitforjob:d.job_id_a}},c},s=function(a,b){var c={};a=a||{},b=b||{};var d={};return d.id=w.nextId(),d.command=a.command,d.storage=a.storage,d.status=p(),d.date=new Date,function(){if(!d.storage)throw g({job:c,message:"No storage set"});if(!d.command)throw g({job:c,message:"No command set"})}(),c.getCommand=function(){return d.command},c.getStatus=function(){return d.status},c.getId=function(){return d.id},c.getStorage=function(){return d.storage},c.getDate=function(){return d.date},c.isReady=function(){return d.tried===0?d.status.canStart():d.status.canRestart()},c.serialized=function(){return{id:d.id,date:d.date.getTime(),status:d.status.serialized(),command:d.command.serialized(),storage:d.storage.serialized()}},c.waitForJob=function(a){d.status.getLabel()!=="wait"&&(d.status=r()),d.status.waitForJob(a)},c.dontWaitFor=function(a){d.status.getLabel()==="wait"&&d.status.dontWaitForJob(a)},c.waitForTime=function(a){d.status.getLabel()!=="wait"&&(d.status=r()),d.status.waitForTime(a)},c.stopWaitForTime=function(){d.status.getLabel()==="wait"&&d.status.stopWaitForTime()},c.update=function(a){console.log("updating"),d.command.setMaxRetry(-1),d.command.fail({status:0,statusText:"Replaced",message:"Job has been replaced by another one."}),d.date=a.getDate(),d.command=a.getCommand(),d.status=a.getStatus()},c.execute=function(){if(d.max_retry!==0&&d.tried>=d.max_retry)throw f({job:c,message:"The job was invoked too much time."});if(!c.isReady())throw e({message:"Can not execute this job."});d.status=q(),d.command.onRetryDo(function(){var a=d.command.getTried();a=a*a*200,a>1e4&&(a=1e4),c.waitForTime(a)}),d.command.onEndDo(function(){x.terminateJob(c)}),d.command.execute(d.storage)},c},t=function(a,b){var c={};a=a||{},b=b||{};var d=[],e=a.name||"";return c.add=function(a){d.push(a)},c.remove=function(a){var b,c=[];for(b=0;b<d.length;b+=1)d[b]!==a&&c.push(d[b]);d=c},c.register=function(){v.register(c)},c.unregister=function(){v.unregister(c)},c.trigger=function(a){var b;for(b=0;b<d.length;b++)d[b].apply(null,a)},c},u=function(a,b){var c={};a=a||{},b=b||{};var d={};return d.id=a.id||0,d.interval=400,d.interval_id=null,d.touch=function(){LocalOrCookieStorage.setItem("jio/id/"+d.id,Date.now())},c.setId=function(a){d.id=a},c.setIntervalDelay=function(a){d.interval=a},c.getIntervalDelay=function(){return d.interval},c.start=function(){d.interval_id||(d.touch(),d.interval_id=setInterval(function(){d.touch()},d.interval))},c.stop=function(){d.interval_id!==null&&(clearInterval(d.interval_id),d.interval_id=null)},c}(),v=function(a,b){var c={};a=a||{},b=b||{};var d={};return c.register=function(a){d[a]||(d[a]=t())},c.unregister=function(a){d[a]&&delete d[a]},c.at=function(a){return d[a]},c.on=function(a,b){c.register(a),c.at(a).add(b)},c.trigger=function(a,b){c.at(a).trigger(b)},c}(),w=function(a,b){var c={};a=a||{},b=b||{};var d=0;return c.nextId=function(){return d=d+1,d},c}(),x=function(a,b){var c={};a=a||{},b=b||{};var e="jio/job_array",f={};return f.id=a.id,f.interval_id=null,f.interval=200,f.job_a=[],f.getJobArrayName=function(){return e+"/"+f.id},f.getJobArray=function(){return LocalOrCookieStorage.getItem(f.getJobArrayName())||[]},f.copyJobArrayToLocal=function(){var a=[],b;for(b=0;b<f.job_a.length;b+=1)a.push(f.job_a[b].serialized());LocalOrCookieStorage.setItem(f.getJobArrayName(),a)},f.removeJob=function(a){var b,c=[];for(b=0;b<f.job_a.length;b+=1)f.job_a[b]!==a&&c.push(f.job_a[b]);f.job_a=c,f.copyJobArrayToLocal()},c.setId=function(a){f.id=a},c.start=function(){var a;f.interval_id===null&&(f.interval_id=setInterval(function(){f.restoreOldJio();for(a=0;a<f.job_a.length;a+=1)c.execute(f.job_a[a])},f.interval))},c.stop=function(){f.interval_id!==null&&(clearInterval(f.interval_id),f.interval_id=null,f.job_a.length===0&&LocalOrCookieStorage.deleteItem(f.getJobArrayName()))},f.restoreOldJio=function(){var a,b;f.lastrestore=f.lastrestore||0;if(f.lastrestore>Date.now()-2e3)return;b=LocalOrCookieStorage.getItem("jio/id_array")||[];for(a=0;a<b.length;a+=1)f.restoreOldJioId(b[a]);f.lastrestore=Date.now()},f.restoreOldJioId=function(a){var b;b=LocalOrCookieStorage.getItem("jio/id/"+a)||0,b<Date.now()-1e4&&(f.restoreOldJobFromJioId(a),f.removeOldJioId(a))},f.restoreOldJobFromJioId=function(a){var b,e;e=LocalOrCookieStorage.getItem("jio/job_array/"+a)||[];for(b=0;b<e.length;b+=1)c.addJob(s({storage:k.storage(e[b]),command:d(e[b].command)}))},f.removeOldJioId=function(a){var b,c,d=[];c=LocalOrCookieStorage.getItem("jio/id_array")||[];for(b=0;b<c.length;b+=1)c[b]!==a&&d.push(c[b]);LocalOrCookieStorage.setItem("jio/id_array",d)},c.execute=function(a){try{a.execute()}catch(b){switch(b.name){case"jobNotReadyException":break;case"tooMuchTriesJobException":break;default:throw b}}f.copyJobArrayToLocal()},c.jobIdExists=function(a){var b;for(b=0;b<f.job_a.length;b+=1)if(f.job_a[b].getId()===a)return console.log("found"),!0;return console.log("not found"),!1},c.terminateJob=function(a){f.removeJob(a),f.copyJobArrayToLocal()},c.addJob=function(a){var b=c.validateJobAccordingToJobList(f.job_a,a);f.manage(a,b)},c.validateJobAccordingToJobList=function(a,b){var c,d=[];for(c=0;c<a.length;c+=1)d.push(y.validateJobAccordingToJob(a[c],b));return d},f.manage=function(a,b){var d;if(f.job_a.length!==b.length)throw new RangeError("Array out of bound");for(d=0;d<b.length;d+=1)if(b[d].action==="dont accept")return;console.log("managing "+JSON.stringify(b));for(d=0;d<b.length;d+=1)switch(b[d].action){case"eliminate":console.log("eliminating"),c.eliminate(b[d].job);break;case"update":b[d].job.update(a),f.copyJobArrayToLocal();return;case"wait":console.log("wait"),a.waitForJob(b[d].job);break;default:}f.job_a.push(a),f.copyJobArrayToLocal()},c.eliminate=function(a){var b,c=[];for(b=0;b<f.job_a.length;b+=1)f.job_a[b].getId()!==a.getId()&&(c.push(f.job_a[b]),console.log("add: "+f.job_a[b].getId()+" -> it is not "+a.getId()));f.job_a=c,f.copyJobArrayToLocal()},c}(),y=function(a,b){var c={},d={};return c.eliminate=function(){return"eliminate"},c.update=function(){return"update"},c.dontAccept=function(){return"dont accept"},c.wait=function(){return"wait"},c.none=function(){return"none"},d.compare={},d.default_compare=function(a,b){return a.getCommand().getPath()===b.getCommand().getPath()&&JSON.stringify(a.getStorage().serialized())===JSON.stringify(b.getStorage().serialized())},d.action={saveDocument:{"on going":{saveDocument:function(a,b){return a.getCommand().getContent()===b.getCommand().getContent()?c.dontAccept():c.wait()},loadDocument:c.wait,removeDocument:c.wait,getDocumentList:c.none},"not on going":{saveDocument:c.update,loadDocument:c.wait,removeDocument:c.eliminate,getDocumentList:c.none}},loadDocument:{"on going":{saveDocument:c.wait,loadDocument:c.dontAccept,removeDocument:c.wait,getDocumentList:c.none},"not on going":{saveDocument:c.wait,loadDocument:c.update,removeDocument:c.wait,getDocumentList:c.none}},removeDocument:{"on going":{saveDocument:c.wait,loadDocument:c.dontAccept,removeDocument:c.dontAccept,getDocumentList:c.none},"not on going":{saveDocument:c.eliminate,loadDocument:c.dontAccept,removeDocument:c.update,getDocumentList:c.none}},getDocumentList:{"on going":{saveDocument:c.none,loadDocument:c.none,removeDocument:c.none,getDocumentList:c.dontAccept},"not on going":{saveDocument:c.none,loadDocument:c.none,removeDocument:c.none,getDocumentList:c.update}}},d.default_action=c.none,d.getAction=function(a,b){var c,e,f;c=a.getCommand().getLabel(),e=b.getCommand().getLabel(),f=a.getStatus().getLabel()==="on going"?"on going":"not on going";try{return console.log(c),console.log(e),console.log(f),d.action[c][f][e](a,b)}catch(g){if(g.name==="TypeError")return d.default_action(a,b);throw g}},d.canCompare=function(a,b){var c=a.getCommand().getLabel(),e=b.getCommand().getLabel();try{return d.compare[c][e](a,b)}catch(f){if(f.name==="TypeError")return d.default_compare(a,b);throw f}},c.validateJobAccordingToJob=function(a,b){return d.canCompare(a,b)?{action:d.getAction(a,b),job:a}:{action:d.default_action(a,b),job:a}},c}(),z={};a=a||{},c=c||{};var A={},B="jio/id_array";return A.id=1,A.storage=k.storage(a,z),function(){var a,b=LocalOrCookieStorage.getItem(B)||[];for(a=0;a<b.length;a+=1)b[a]>=A.id&&(A.id=b[a]+1);b.push(A.id),LocalOrCookieStorage.setItem(B,b)}(),function(){u.setId(A.id),u.start(),x.setId(A.id),x.start()}(),z.start=function(){x.start()},z.stop=function(){x.stop()},z.getId=function(){return A.id},z.validateStorageDescription=function(a){return k.storage(a.type)(a).isValid()},z.saveDocument=function(a,b,c,d){c=c||{},c.onResponse=c.onResponse||function(){},c.onDone=c.onDone||function(){},c.onFail=c.onFail||function(){},c.max_retry=c.max_retry||0,x.addJob(s({storage:d?k.storage(d):A.storage,command:l({path:a,content:b,option:c})}))},z.loadDocument=function(a,b,c){b=b||{},b.onResponse=b.onResponse||function(){},b.onDone=b.onDone||function(){},b.onFail=b.onFail||function(){},b.max_retry=b.max_retry||0,b.metadata_only=b.metadata_only!==undefined?b.metadata_only:!1,x.addJob(s({storage:c?k.storage(c):A.storage,command:i({path:a,option:b})}))},z.removeDocument=function(a,b,c){b=b||{},b.onResponse=b.onResponse||function(){},b.onDone=b.onDone||function(){},b.onFail=b.onFail||function(){},b.max_retry=b.max_retry||0,x.addJob(s({storage:c?k.storage(c):A.storage,command:j({path:a,option:b})}))},z.getDocumentList=function(a,b,c){b=b||{},b.onResponse=b.onResponse||function(){},b.onDone=b.onDone||function(){},b.onFail=b.onFail||function(){},b.max_retry=b.max_retry||0,b.metadata_only=b.metadata_only!==undefined?b.metadata_only:!0,x.addJob(s({storage:c?k.storage(c):A.storage,command:h({path:a,option:b})}))},z},k=function(a,b){var c={};a=a||{},b=b||{};var e={base:h,handler:i};return c.storage=function(a,b){a=a||{};var c=a.type||"base";if(!e[c])throw d({type:c,message:"Storage does not exists."});return e[c](a,b)},c.newJio=function(a){var b=a;return typeof b=="string"&&(b=JSON.parse(b)),b=b||{type:"base"},j(a)},c.addStorageType=function(a,b){b=b||function(){return null};if(e[a])throw d({type:a,message:"Already known."});e[a]=b},c}();return k}(); var jio=function(){var a=function(a,b){var c={};return a=a||{},b=b||{},c.name="jioException",c.message=a.message||"Unknown Reason.",c.toString=function(){return c.name+": "+c.message},c},b=function(b,c){var d=a(b,c);b=b||{};var e=b.command;return d.name="invalidCommandState",d.toString=function(){return d.name+": "+e.getLabel()+", "+d.message},d},c=function(b,c){var d=a(b,c);b=b||{};var e=b.storage.getType();return d.name="invalidStorage",d.toString=function(){return d.name+": "+'Type "'+e+'", '+d.message},d},d=function(b,c){var d=a(b,c),e=b.type;return d.name="invalidStorageType",d.toString=function(){return d.name+": "+e+", "+d.message},d},e=function(b,c){var d=a(b,c);return d.name="jobNotReadyException",d},f=function(b,c){var d=a(b,c);return d.name="tooMuchTriesJobException",d},g=function(b,c){var d=a(b,c);return d.name="invalidJobException",d},h=function(a,b){var d={};a=a||{},b=b||{};var e={};return e.type=a.type||"",d.getType=function(){return e.type},d.setType=function(a){e.type=a},d.execute=function(a){d.validate(a),a.executeOn(d)},d.isValid=function(){return!0},d.validate=function(a){var b=d.validateState();if(b)throw c({storage:d,message:b});a.validate(d)},d.serialized=function(){return{type:d.getType()}},d.saveDocument=function(a){throw c({storage:d,message:"Unknown storage."})},d.loadDocument=function(a){d.saveDocument()},d.removeDocument=function(a){d.saveDocument()},d.getDocumentList=function(a){d.saveDocument()},d.validateState=function(){return""},d},i=function(a,b){var c=h(a,b);a=a||{},b=b||{};var d={};return d.storage_a=a.storagelist||[],c.beforeExecute=function(a){},c.execute=function(a){var b;c.validate(a),c.beforeExecute(a);for(b=0;b<d.storage_a.length;b++)d.storage_a[b].execute(a);c.afterExecute(a)},c.afterExecute=function(a){a.done()},c.serialized=function(){return{type:d.type,storagelist:d.storagelist}},c},j=function(a,c){var d=function(a,c){var d={};a=a||{},c=c||{};var e={};return e.commandlist={saveDocument:l,loadDocument:i,removeDocument:j,getDocumentList:h},a.label&&e.commandlist[a.label]?(e.label=a.label,delete a.label,e.commandlist[e.label](a,c)):(e.path=a.path||"",e.tried=0,e.option=a.option||{},e.respond=e.option.onResponse||function(){},e.done=e.option.onDone||function(){},e.fail=e.option.onFail||function(){},e.retry=function(){d.setMaxRetry(-1),d.fail({status:0,statusText:"Fail Retry",message:"Impossible to retry."})},e.end=function(){},d.getLabel=function(){return"command"},d.getPath=function(){return e.path},d.getOption=function(a){return e.option[a]},d.validate=function(a){d.validateState()},d.getTried=function(){return e.tried},d.setMaxRetry=function(a){e.option.max_retry=a},d.execute=function(a){d.validate(a),e.tried++,a.execute(d)},d.executeOn=function(a){},d.validateState=function(){if(e.path==="")throw b({command:d,message:"Path is empty"})},d.done=function(a){e.done(a),e.respond({status:n(),value:a}),e.end()},d.fail=function(a){e.option.max_retry===0||e.tried<e.option.max_retry?e.retry():(e.fail(a),e.respond({status:o(),error:a}),e.end())},d.onEndDo=function(a){e.end=a},d.onRetryDo=function(a){e.retry=a},d.serialized=function(){return{label:d.getLabel(),tried:e.tried,max_retry:e.max_retry,path:e.path,option:e.option}},d.canBeRestored=function(){return!0},d)},h=function(a,b){var c=d(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"getDocumentList"},c.executeOn=function(a){a.getDocumentList(c)},c.canBeRestored=function(){return!1},c},i=function(a,b){var c=d(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"loadDocument"},c.executeOn=function(a){a.loadDocument(c)},c.canBeRestored=function(){return!1},c},j=function(a,b){var c=d(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"removeDocument"},c.executeOn=function(a){a.removeDocument(c)},c},l=function(a,c){var e=d(a,c);a=a||{},c=c||{};var f={};f.content=a.content,e.getLabel=function(){return"saveDocument"},e.getContent=function(){return f.content};var g=e.validate;e.validate=function(a){if(typeof f.content!="string")throw b({command:e,message:"No data to save"});g(a)},e.executeOn=function(a){a.saveDocument(e)};var h=e.serialized;return e.serialized=function(){var a=h();return a.content=f.content,a},e},m=function(a,b){var c={};return a=a||{},b=b||{},c.getLabel=function(){return"job status"},c.canStart=function(){},c.canRestart=function(){},c.serialized=function(){return{label:c.getLabel()}},c},n=function(a,b){var c=m(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"done"},c.canStart=function(){return!1},c.canRestart=function(){return!1},c},o=function(a,b){var c=m(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"fail"},c.canStart=function(){return!1},c.canRestart=function(){return!0},c},p=function(a,b){var c=m(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"initial"},c.canStart=function(){return!0},c.canRestart=function(){return!0},c},q=function(a,b){var c=m(a,b);return a=a||{},b=b||{},c.getLabel=function(){return"on going"},c.canStart=function(){return!1},c.canRestart=function(){return!1},c},r=function(a,b){var c=m(a,b);a=a||{},b=b||{};var d={};return d.job_id_a=a.job_id_array||[],d.threshold=0,c.getLabel=function(){return"wait"},d.refreshJobIdArray=function(){var a=[],b;for(b=0;b<d.job_id_a.length;b+=1)x.jobIdExists(d.job_id_a[b])&&a.push(d.job_id_a[b]);d.job_id_a=a},c.waitForJob=function(a){var b;for(b=0;b<d.job_id_a.length;b+=1)if(d.job_id_a[b]===a.getId())return;d.job_id_a.push(a.getId())},c.dontWaitForJob=function(a){var b,c=[];for(b=0;b<d.job_id_a.length;b+=1)d.job_id_a[b]!==a.getId()&&c.push(d.job_id_a[b]);d.job_id_a=c},c.waitForTime=function(a){d.threshold=Date.now()+a},c.stopWaitForTime=function(){d.threshold=0},c.canStart=function(){return d.refreshJobIdArray(),d.job_id_a.length===0&&Date.now()>=d.threshold},c.canRestart=function(){return c.canStart()},c.serialized=function(){return{label:c.getLabel(),waitfortime:d.threshold,waitforjob:d.job_id_a}},c},s=function(a,b){var c={};a=a||{},b=b||{};var d={};return d.id=w.nextId(),d.command=a.command,d.storage=a.storage,d.status=p(),d.date=new Date,function(){if(!d.storage)throw g({job:c,message:"No storage set"});if(!d.command)throw g({job:c,message:"No command set"})}(),c.getCommand=function(){return d.command},c.getStatus=function(){return d.status},c.getId=function(){return d.id},c.getStorage=function(){return d.storage},c.getDate=function(){return d.date},c.isReady=function(){return d.tried===0?d.status.canStart():d.status.canRestart()},c.serialized=function(){return{id:d.id,date:d.date.getTime(),status:d.status.serialized(),command:d.command.serialized(),storage:d.storage.serialized()}},c.waitForJob=function(a){d.status.getLabel()!=="wait"&&(d.status=r()),d.status.waitForJob(a)},c.dontWaitFor=function(a){d.status.getLabel()==="wait"&&d.status.dontWaitForJob(a)},c.waitForTime=function(a){d.status.getLabel()!=="wait"&&(d.status=r()),d.status.waitForTime(a)},c.stopWaitForTime=function(){d.status.getLabel()==="wait"&&d.status.stopWaitForTime()},c.update=function(a){d.command.setMaxRetry(-1),d.command.fail({status:0,statusText:"Replaced",message:"Job has been replaced by another one."}),d.date=a.getDate(),d.command=a.getCommand(),d.status=a.getStatus()},c.execute=function(){if(d.max_retry!==0&&d.tried>=d.max_retry)throw f({job:c,message:"The job was invoked too much time."});if(!c.isReady())throw e({message:"Can not execute this job."});d.status=q(),d.command.onRetryDo(function(){var a=d.command.getTried();a=a*a*200,a>1e4&&(a=1e4),c.waitForTime(a)}),d.command.onEndDo(function(){x.terminateJob(c)}),d.command.execute(d.storage)},c},t=function(a,b){var c={};a=a||{},b=b||{};var d=[],e=a.name||"";return c.add=function(a){d.push(a)},c.remove=function(a){var b,c=[];for(b=0;b<d.length;b+=1)d[b]!==a&&c.push(d[b]);d=c},c.register=function(){v.register(c)},c.unregister=function(){v.unregister(c)},c.trigger=function(a){var b;for(b=0;b<d.length;b++)d[b].apply(null,a)},c},u=function(a,b){var c={};a=a||{},b=b||{};var d={};return d.id=a.id||0,d.interval=400,d.interval_id=null,d.touch=function(){LocalOrCookieStorage.setItem("jio/id/"+d.id,Date.now())},c.setId=function(a){d.id=a},c.setIntervalDelay=function(a){d.interval=a},c.getIntervalDelay=function(){return d.interval},c.start=function(){d.interval_id||(d.touch(),d.interval_id=setInterval(function(){d.touch()},d.interval))},c.stop=function(){d.interval_id!==null&&(clearInterval(d.interval_id),d.interval_id=null)},c}(),v=function(a,b){var c={};a=a||{},b=b||{};var d={};return c.register=function(a){d[a]||(d[a]=t())},c.unregister=function(a){d[a]&&delete d[a]},c.at=function(a){return d[a]},c.on=function(a,b){c.register(a),c.at(a).add(b)},c.trigger=function(a,b){c.at(a).trigger(b)},c}(),w=function(a,b){var c={};a=a||{},b=b||{};var d=0;return c.nextId=function(){return d=d+1,d},c}(),x=function(a,b){var c={};a=a||{},b=b||{};var e="jio/job_array",f={};return f.id=a.id,f.interval_id=null,f.interval=200,f.job_a=[],f.getJobArrayName=function(){return e+"/"+f.id},f.getJobArray=function(){return LocalOrCookieStorage.getItem(f.getJobArrayName())||[]},f.copyJobArrayToLocal=function(){var a=[],b;for(b=0;b<f.job_a.length;b+=1)a.push(f.job_a[b].serialized());LocalOrCookieStorage.setItem(f.getJobArrayName(),a)},f.removeJob=function(a){var b,c=[];for(b=0;b<f.job_a.length;b+=1)f.job_a[b]!==a&&c.push(f.job_a[b]);f.job_a=c,f.copyJobArrayToLocal()},c.setId=function(a){f.id=a},c.start=function(){var a;f.interval_id===null&&(f.interval_id=setInterval(function(){f.restoreOldJio();for(a=0;a<f.job_a.length;a+=1)c.execute(f.job_a[a])},f.interval))},c.stop=function(){f.interval_id!==null&&(clearInterval(f.interval_id),f.interval_id=null,f.job_a.length===0&&LocalOrCookieStorage.deleteItem(f.getJobArrayName()))},f.restoreOldJio=function(){var a,b;f.lastrestore=f.lastrestore||0;if(f.lastrestore>Date.now()-2e3)return;b=LocalOrCookieStorage.getItem("jio/id_array")||[];for(a=0;a<b.length;a+=1)f.restoreOldJioId(b[a]);f.lastrestore=Date.now()},f.restoreOldJioId=function(a){var b;b=LocalOrCookieStorage.getItem("jio/id/"+a)||0,b<Date.now()-1e4&&(f.restoreOldJobFromJioId(a),f.removeOldJioId(a),f.removeJobArrayFromJioId(a))},f.restoreOldJobFromJioId=function(a){var b,e;e=LocalOrCookieStorage.getItem("jio/job_array/"+a)||[];for(b=0;b<e.length;b+=1){var f=d(e[b].command);f.canBeRestored()&&c.addJob(s({storage:k.storage(e[b].storage),command:f}))}},f.removeOldJioId=function(a){var b,c,d=[];c=LocalOrCookieStorage.getItem("jio/id_array")||[];for(b=0;b<c.length;b+=1)c[b]!==a&&d.push(c[b]);LocalOrCookieStorage.setItem("jio/id_array",d),LocalOrCookieStorage.deleteItem("jio/id/"+a)},f.removeJobArrayFromJioId=function(a){LocalOrCookieStorage.deleteItem("jio/job_array/"+a)},c.execute=function(a){try{a.execute()}catch(b){switch(b.name){case"jobNotReadyException":break;case"tooMuchTriesJobException":break;default:throw b}}f.copyJobArrayToLocal()},c.jobIdExists=function(a){var b;for(b=0;b<f.job_a.length;b+=1)if(f.job_a[b].getId()===a)return!0;return!1},c.terminateJob=function(a){f.removeJob(a),f.copyJobArrayToLocal()},c.addJob=function(a){var b=c.validateJobAccordingToJobList(f.job_a,a);f.manage(a,b)},c.validateJobAccordingToJobList=function(a,b){var c,d=[];for(c=0;c<a.length;c+=1)d.push(y.validateJobAccordingToJob(a[c],b));return d},f.manage=function(a,b){var d;if(f.job_a.length!==b.length)throw new RangeError("Array out of bound");for(d=0;d<b.length;d+=1)if(b[d].action==="dont accept")return;for(d=0;d<b.length;d+=1)switch(b[d].action){case"eliminate":c.eliminate(b[d].job);break;case"update":b[d].job.update(a),f.copyJobArrayToLocal();return;case"wait":a.waitForJob(b[d].job);break;default:}f.job_a.push(a),f.copyJobArrayToLocal()},c.eliminate=function(a){var b,c=[];for(b=0;b<f.job_a.length;b+=1)f.job_a[b].getId()!==a.getId()&&c.push(f.job_a[b]);f.job_a=c,f.copyJobArrayToLocal()},c}(),y=function(a,b){var c={},d={};return c.eliminate=function(){return"eliminate"},c.update=function(){return"update"},c.dontAccept=function(){return"dont accept"},c.wait=function(){return"wait"},c.none=function(){return"none"},d.compare={},d.default_compare=function(a,b){return a.getCommand().getPath()===b.getCommand().getPath()&&JSON.stringify(a.getStorage().serialized())===JSON.stringify(b.getStorage().serialized())},d.action={saveDocument:{"on going":{saveDocument:function(a,b){return a.getCommand().getContent()===b.getCommand().getContent()?c.dontAccept():c.wait()},loadDocument:c.wait,removeDocument:c.wait,getDocumentList:c.none},"not on going":{saveDocument:c.update,loadDocument:c.wait,removeDocument:c.eliminate,getDocumentList:c.none}},loadDocument:{"on going":{saveDocument:c.wait,loadDocument:c.dontAccept,removeDocument:c.wait,getDocumentList:c.none},"not on going":{saveDocument:c.wait,loadDocument:c.update,removeDocument:c.wait,getDocumentList:c.none}},removeDocument:{"on going":{saveDocument:c.wait,loadDocument:c.dontAccept,removeDocument:c.dontAccept,getDocumentList:c.none},"not on going":{saveDocument:c.eliminate,loadDocument:c.dontAccept,removeDocument:c.update,getDocumentList:c.none}},getDocumentList:{"on going":{saveDocument:c.none,loadDocument:c.none,removeDocument:c.none,getDocumentList:c.dontAccept},"not on going":{saveDocument:c.none,loadDocument:c.none,removeDocument:c.none,getDocumentList:c.update}}},d.default_action=c.none,d.getAction=function(a,b){var c,e,f;return c=a.getCommand().getLabel(),e=b.getCommand().getLabel(),f=a.getStatus().getLabel()==="on going"?"on going":"not on going",d.action[c]&&d.action[c][f]&&d.action[c][f][e]?d.action[c][f][e](a,b):d.default_action(a,b)},d.canCompare=function(a,b){var c=a.getCommand().getLabel(),e=b.getCommand().getLabel();return d.compare[c]&&d.compare[e]?d.compare[c][e](a,b):d.default_compare(a,b)},c.validateJobAccordingToJob=function(a,b){return d.canCompare(a,b)?{action:d.getAction(a,b),job:a}:{action:d.default_action(a,b),job:a}},c}(),z={};a=a||{},c=c||{};var A={},B="jio/id_array";return A.id=null,A.storage=k.storage(a),A.init=function(){if(A.id===null){var a,b=LocalOrCookieStorage.getItem(B)||[];A.id=1;for(a=0;a<b.length;a+=1)b[a]>=A.id&&(A.id=b[a]+1);b.push(A.id),LocalOrCookieStorage.setItem(B,b),u.setId(A.id),x.setId(A.id)}},z.start=function(){A.init(),u.start(),x.start()},z.stop=function(){x.stop()},z.close=function(){u.stop(),x.stop(),A.id=null},z.start(),z.getId=function(){return A.id},z.validateStorageDescription=function(a){return k.storage(a.type)(a).isValid()},z.saveDocument=function(a,b,c,d){c=c||{},c.onResponse=c.onResponse||function(){},c.onDone=c.onDone||function(){},c.onFail=c.onFail||function(){},c.max_retry=c.max_retry||0,x.addJob(s({storage:d?k.storage(d):A.storage,command:l({path:a,content:b,option:c})}))},z.loadDocument=function(a,b,c){b=b||{},b.onResponse=b.onResponse||function(){},b.onDone=b.onDone||function(){},b.onFail=b.onFail||function(){},b.max_retry=b.max_retry||0,b.metadata_only=b.metadata_only!==undefined?b.metadata_only:!1,x.addJob(s({storage:c?k.storage(c):A.storage,command:i({path:a,option:b})}))},z.removeDocument=function(a,b,c){b=b||{},b.onResponse=b.onResponse||function(){},b.onDone=b.onDone||function(){},b.onFail=b.onFail||function(){},b.max_retry=b.max_retry||0,x.addJob(s({storage:c?k.storage(c):A.storage,command:j({path:a,option:b})}))},z.getDocumentList=function(a,b,c){b=b||{},b.onResponse=b.onResponse||function(){},b.onDone=b.onDone||function(){},b.onFail=b.onFail||function(){},b.max_retry=b.max_retry||0,b.metadata_only=b.metadata_only!==undefined?b.metadata_only:!0,x.addJob(s({storage:c?k.storage(c):A.storage,command:h({path:a,option:b})}))},z},k=function(a,b){var c={};a=a||{},b=b||{};var e={base:h,handler:i};return c.storage=function(a,b,c){a=a||{};var f=c||a.type||"base";if(!e[f])throw d({type:f,message:"Storage does not exists."});return e[f](a,b)},c.newJio=function(a){var b=a;return typeof b=="string"&&(b=JSON.parse(b)),b=b||{type:"base"},j(a)},c.addStorageType=function(a,b){b=b||function(){return null};if(e[a])throw d({type:a,message:"Already known."});e[a]=b},c}();return k}();
\ No newline at end of file \ No newline at end of file
...@@ -10,9 +10,7 @@ ...@@ -10,9 +10,7 @@
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Dummy Storage 1 : all ok // Dummy Storage 1 : all ok
var newDummyStorageAllOk = function ( spec, my ) { var newDummyStorageAllOk = function ( spec, my ) {
var that = Jio.storage( {type:'base'}, my ); var that = Jio.storage( spec, my, 'base' );
that.setType('dummyallok');
that.saveDocument = function (command) { that.saveDocument = function (command) {
// Tells us that the document is saved. // Tells us that the document is saved.
...@@ -74,7 +72,7 @@ ...@@ -74,7 +72,7 @@
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Dummy Storage 2 : all fail // Dummy Storage 2 : all fail
newDummyStorageAllFail = function ( spec, my ) { newDummyStorageAllFail = function ( spec, my ) {
var that = Jio.storage( {type:'base'}, my ); var that = Jio.storage( spec, my, 'base' );
that.setType('dummyallfail'); that.setType('dummyallfail');
...@@ -121,7 +119,7 @@ ...@@ -121,7 +119,7 @@
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Dummy Storage 3 : all not found // Dummy Storage 3 : all not found
newDummyStorageAllNotFound = function ( spec, my ) { newDummyStorageAllNotFound = function ( spec, my ) {
var that = Jio.storage( {type:'base'}, my ); var that = Jio.storage( spec, my, 'base' );
that.setType('dummyallnotfound'); that.setType('dummyallnotfound');
...@@ -167,7 +165,7 @@ ...@@ -167,7 +165,7 @@
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Dummy Storage 4 : all 3 tries // Dummy Storage 4 : all 3 tries
newDummyStorageAll3Tries = function ( spec, my ) { newDummyStorageAll3Tries = function ( spec, my ) {
var that = Jio.storage( {type:'base'}, my ), priv = {}; var that = Jio.storage( spec, my, 'base' ), priv = {};
that.setType('dummyall3tries'); that.setType('dummyall3tries');
......
auto: grunt
check-syntax: grunt
grunt:
make -C ../../grunt/*_gruntJIO
...@@ -36,3 +36,4 @@ var activityUpdater = (function(spec, my) { ...@@ -36,3 +36,4 @@ var activityUpdater = (function(spec, my) {
}; };
return that; return that;
}()); }());
...@@ -103,7 +103,6 @@ var command = function(spec, my) { ...@@ -103,7 +103,6 @@ var command = function(spec, my) {
}; };
that.done = function(return_value) { that.done = function(return_value) {
console.log ('done');
priv.done(return_value); priv.done(return_value);
priv.respond({status:doneStatus(),value:return_value}); priv.respond({status:doneStatus(),value:return_value});
priv.end(); priv.end();
...@@ -113,7 +112,6 @@ var command = function(spec, my) { ...@@ -113,7 +112,6 @@ var command = function(spec, my) {
if (priv.option.max_retry === 0 || priv.tried < priv.option.max_retry) { if (priv.option.max_retry === 0 || priv.tried < priv.option.max_retry) {
priv.retry(); priv.retry();
} else { } else {
console.log ('fail');
priv.fail(return_error); priv.fail(return_error);
priv.respond({status:failStatus(),error:return_error}); priv.respond({status:failStatus(),error:return_error});
priv.end(); priv.end();
...@@ -142,5 +140,9 @@ var command = function(spec, my) { ...@@ -142,5 +140,9 @@ var command = function(spec, my) {
option:priv.option}; option:priv.option};
}; };
that.canBeRestored = function() {
return true;
};
return that; return that;
}; };
...@@ -12,5 +12,9 @@ var getDocumentList = function(spec, my) { ...@@ -12,5 +12,9 @@ var getDocumentList = function(spec, my) {
storage.getDocumentList(that); storage.getDocumentList(that);
}; };
that.canBeRestored = function() {
return false;
};
return that; return that;
}; };
...@@ -12,5 +12,9 @@ var loadDocument = function(spec, my) { ...@@ -12,5 +12,9 @@ var loadDocument = function(spec, my) {
storage.loadDocument(that); storage.loadDocument(that);
}; };
that.canBeRestored = function() {
return false;
};
return that; return that;
}; };
...@@ -3,14 +3,15 @@ var saveDocument = function(spec, my) { ...@@ -3,14 +3,15 @@ var saveDocument = function(spec, my) {
spec = spec || {}; spec = spec || {};
my = my || {}; my = my || {};
// Attributes // // Attributes //
var content = spec.content; var priv = {};
priv.content = spec.content;
// Methods // // Methods //
that.getLabel = function() { that.getLabel = function() {
return 'saveDocument'; return 'saveDocument';
}; };
that.getContent = function() { that.getContent = function() {
return content; return priv.content;
}; };
/** /**
...@@ -19,7 +20,7 @@ var saveDocument = function(spec, my) { ...@@ -19,7 +20,7 @@ var saveDocument = function(spec, my) {
*/ */
var super_validate = that.validate; var super_validate = that.validate;
that.validate = function(handler) { that.validate = function(handler) {
if (typeof content !== 'string') { if (typeof priv.content !== 'string') {
throw invalidCommandState({command:that,message:'No data to save'}); throw invalidCommandState({command:that,message:'No data to save'});
} }
super_validate(handler); super_validate(handler);
...@@ -29,5 +30,12 @@ var saveDocument = function(spec, my) { ...@@ -29,5 +30,12 @@ var saveDocument = function(spec, my) {
storage.saveDocument(that); storage.saveDocument(that);
}; };
var super_serialized = that.serialized;
that.serialized = function() {
var o = super_serialized();
o.content = priv.content;
return o;
};
return that; return that;
}; };
...@@ -5,14 +5,16 @@ ...@@ -5,14 +5,16 @@
// Attributes // // Attributes //
var priv = {}; var priv = {};
var jio_id_array_name = 'jio/id_array'; var jio_id_array_name = 'jio/id_array';
priv.id = 1; priv.id = null;
priv.storage = jioNamespace.storage(spec, that); priv.storage = jioNamespace.storage(spec);
// initialize // // initialize //
(function () { priv.init = function() {
// Initialize the jio id and add the new id to the list // Initialize the jio id and add the new id to the list
var i, if (priv.id === null) {
jio_id_a = LocalOrCookieStorage.getItem (jio_id_array_name) || []; var i, jio_id_a =
LocalOrCookieStorage.getItem (jio_id_array_name) || [];
priv.id = 1;
for (i = 0; i < jio_id_a.length; i+= 1) { for (i = 0; i < jio_id_a.length; i+= 1) {
if (jio_id_a[i] >= priv.id) { if (jio_id_a[i] >= priv.id) {
priv.id = jio_id_a[i] + 1; priv.id = jio_id_a[i] + 1;
...@@ -20,22 +22,26 @@ ...@@ -20,22 +22,26 @@
} }
jio_id_a.push(priv.id); jio_id_a.push(priv.id);
LocalOrCookieStorage.setItem (jio_id_array_name,jio_id_a); LocalOrCookieStorage.setItem (jio_id_array_name,jio_id_a);
}());
(function (){
// Start Jio updater, and the jobManager
activityUpdater.setId(priv.id); activityUpdater.setId(priv.id);
activityUpdater.start();
jobManager.setId(priv.id); jobManager.setId(priv.id);
jobManager.start(); }
}()); };
// Methods // // Methods //
that.start = function() { that.start = function() {
priv.init();
activityUpdater.start();
jobManager.start(); jobManager.start();
}; };
that.stop = function() { that.stop = function() {
jobManager.stop(); jobManager.stop();
}; };
that.close = function() {
activityUpdater.stop();
jobManager.stop();
priv.id = null;
};
that.start();
/** /**
* Returns the jio id. * Returns the jio id.
......
...@@ -12,11 +12,12 @@ var jioNamespace = (function(spec, my) { ...@@ -12,11 +12,12 @@ var jioNamespace = (function(spec, my) {
* @method storage * @method storage
* @param {object} spec The specifications. * @param {object} spec The specifications.
* @param {object} my The protected object. * @param {object} my The protected object.
* @param {string} forcetype Force storage type
* @return {object} The storage object. * @return {object} The storage object.
*/ */
that.storage = function(spec, my) { that.storage = function(spec, my, forcetype) {
spec = spec || {}; spec = spec || {};
var type = spec.type || 'base'; var type = forcetype || spec.type || 'base';
if (!storage_type_o[type]) { if (!storage_type_o[type]) {
throw invalidStorageType({type:type, throw invalidStorageType({type:type,
message:'Storage does not exists.'}); message:'Storage does not exists.'});
......
...@@ -122,7 +122,6 @@ var job = function(spec, my) { ...@@ -122,7 +122,6 @@ var job = function(spec, my) {
* @param {object} job The other job. * @param {object} job The other job.
*/ */
that.update = function(job) { that.update = function(job) {
console.log ('updating');
priv.command.setMaxRetry(-1); priv.command.setMaxRetry(-1);
priv.command.fail({status:0,statusText:'Replaced', priv.command.fail({status:0,statusText:'Replaced',
message:'Job has been replaced by another one.'}); message:'Job has been replaced by another one.'});
......
...@@ -92,6 +92,7 @@ var jobManager = (function(spec, my) { ...@@ -92,6 +92,7 @@ var jobManager = (function(spec, my) {
if (jio_date < Date.now() - 10000) { if (jio_date < Date.now() - 10000) {
priv.restoreOldJobFromJioId(id); priv.restoreOldJobFromJioId(id);
priv.removeOldJioId(id); priv.removeOldJioId(id);
priv.removeJobArrayFromJioId(id);
} }
}; };
...@@ -99,9 +100,12 @@ var jobManager = (function(spec, my) { ...@@ -99,9 +100,12 @@ var jobManager = (function(spec, my) {
var i, jio_job_array; var i, jio_job_array;
jio_job_array = LocalOrCookieStorage.getItem('jio/job_array/'+id)||[]; jio_job_array = LocalOrCookieStorage.getItem('jio/job_array/'+id)||[];
for (i = 0; i < jio_job_array.length; i+= 1) { for (i = 0; i < jio_job_array.length; i+= 1) {
var command_o = command(jio_job_array[i].command);
if (command_o.canBeRestored()) {
that.addJob ( job( that.addJob ( job(
{storage:jioNamespace.storage(jio_job_array[i]), {storage:jioNamespace.storage(jio_job_array[i].storage),
command:command(jio_job_array[i].command)})); command:command_o}));
}
} }
}; };
...@@ -114,6 +118,11 @@ var jobManager = (function(spec, my) { ...@@ -114,6 +118,11 @@ var jobManager = (function(spec, my) {
} }
} }
LocalOrCookieStorage.setItem('jio/id_array',new_a); LocalOrCookieStorage.setItem('jio/id_array',new_a);
LocalOrCookieStorage.deleteItem('jio/id/'+id);
};
priv.removeJobArrayFromJioId = function(id) {
LocalOrCookieStorage.deleteItem('jio/job_array/'+id);
}; };
/** /**
...@@ -138,11 +147,9 @@ var jobManager = (function(spec, my) { ...@@ -138,11 +147,9 @@ var jobManager = (function(spec, my) {
var i; var i;
for (i = 0; i < priv.job_a.length; i+= 1) { for (i = 0; i < priv.job_a.length; i+= 1) {
if (priv.job_a[i].getId() === id) { if (priv.job_a[i].getId() === id) {
console.log ('found');
return true; return true;
} }
} }
console.log ('not found');
return false; return false;
}; };
...@@ -174,11 +181,9 @@ var jobManager = (function(spec, my) { ...@@ -174,11 +181,9 @@ var jobManager = (function(spec, my) {
return; return;
} }
} }
console.log ('managing '+JSON.stringify (result_a));
for (i = 0; i < result_a.length; i+= 1) { for (i = 0; i < result_a.length; i+= 1) {
switch (result_a[i].action) { switch (result_a[i].action) {
case 'eliminate': case 'eliminate':
console.log ('eliminating');
that.eliminate(result_a[i].job); that.eliminate(result_a[i].job);
break; break;
case 'update': case 'update':
...@@ -186,7 +191,6 @@ var jobManager = (function(spec, my) { ...@@ -186,7 +191,6 @@ var jobManager = (function(spec, my) {
priv.copyJobArrayToLocal(); priv.copyJobArrayToLocal();
return; return;
case 'wait': case 'wait':
console.log ('wait');
job.waitForJob(result_a[i].job); job.waitForJob(result_a[i].job);
break; break;
default: break; default: break;
...@@ -201,7 +205,6 @@ var jobManager = (function(spec, my) { ...@@ -201,7 +205,6 @@ var jobManager = (function(spec, my) {
for (i = 0; i < priv.job_a.length; i+= 1) { for (i = 0; i < priv.job_a.length; i+= 1) {
if (priv.job_a[i].getId() !== job.getId()) { if (priv.job_a[i].getId() !== job.getId()) {
tmp_a.push(priv.job_a[i]); tmp_a.push(priv.job_a[i]);
console.log ('add: '+priv.job_a[i].getId()+' -> it is not '+job.getId());
} }
} }
priv.job_a = tmp_a; priv.job_a = tmp_a;
......
...@@ -138,30 +138,22 @@ var jobRules = (function(spec, my) { ...@@ -138,30 +138,22 @@ var jobRules = (function(spec, my) {
j2label = job2.getCommand().getLabel(); j2label = job2.getCommand().getLabel();
j1status = (job1.getStatus().getLabel()==='on going'? j1status = (job1.getStatus().getLabel()==='on going'?
'on going':'not on going'); 'on going':'not on going');
try { if (priv.action[j1label] &&
console.log (j1label); priv.action[j1label][j1status] &&
console.log (j2label); priv.action[j1label][j1status][j2label]) {
console.log (j1status);
return priv.action[j1label][j1status][j2label](job1,job2); return priv.action[j1label][j1status][j2label](job1,job2);
} catch (e) {
if(e.name==='TypeError') {
return priv.default_action(job1,job2);
} else { } else {
throw e; return priv.default_action(job1,job2);
}
} }
}; };
priv.canCompare = function(job1,job2) { priv.canCompare = function(job1,job2) {
var job1label = job1.getCommand().getLabel(), var job1label = job1.getCommand().getLabel(),
job2label = job2.getCommand().getLabel(); job2label = job2.getCommand().getLabel();
try { if (priv.compare[job1label] &&
priv.compare[job2label]) {
return priv.compare[job1label][job2label](job1,job2); return priv.compare[job1label][job2label](job1,job2);
} catch(e) {
if (e.name==='TypeError') {
return priv.default_compare(job1,job2);
} else { } else {
throw e; return priv.default_compare(job1,job2);
}
} }
}; };
that.validateJobAccordingToJob = function(job1,job2) { that.validateJobAccordingToJob = function(job1,job2) {
......
...@@ -49,7 +49,6 @@ var waitStatus = function(spec, my) { ...@@ -49,7 +49,6 @@ var waitStatus = function(spec, my) {
that.canStart = function() { that.canStart = function() {
priv.refreshJobIdArray(); priv.refreshJobIdArray();
console.log (priv.job_id_a);
return (priv.job_id_a.length === 0 && Date.now() >= priv.threshold); return (priv.job_id_a.length === 0 && Date.now() >= priv.threshold);
}; };
that.canRestart = function() { that.canRestart = function() {
......
...@@ -21,6 +21,7 @@ var storage = function(spec, my) { ...@@ -21,6 +21,7 @@ var storage = function(spec, my) {
* @param {object} command The command * @param {object} command The command
*/ */
that.execute = function(command) { that.execute = function(command) {
that.validate(command);
command.executeOn(that); command.executeOn(that);
}; };
...@@ -34,6 +35,10 @@ var storage = function(spec, my) { ...@@ -34,6 +35,10 @@ var storage = function(spec, my) {
}; };
that.validate = function(command) { that.validate = function(command) {
var mess = that.validateState();
if (mess) {
throw invalidStorage({storage:that,message:mess});
}
command.validate(that); command.validate(that);
}; };
...@@ -59,5 +64,9 @@ var storage = function(spec, my) { ...@@ -59,5 +64,9 @@ var storage = function(spec, my) {
that.saveDocument(); that.saveDocument();
}; };
that.validateState = function() {
return '';
};
return that; return that;
}; };
...@@ -12,24 +12,22 @@ var storageHandler = function(spec, my) { ...@@ -12,24 +12,22 @@ var storageHandler = function(spec, my) {
* Override this function. * Override this function.
* @method beforeExecute * @method beforeExecute
* @param {object} command The command. * @param {object} command The command.
* @param {object} option Some options.
*/ */
that.beforeExecute = function(command,option) {}; that.beforeExecute = function(command) {};
/** /**
* Execute the command according to this storage. * Execute the command according to this storage.
* @method execute * @method execute
* @param {object} command The command. * @param {object} command The command.
* @param {object} option Some options.
*/ */
that.execute = function(command,option) { that.execute = function(command) {
var i; var i;
that.validate(command); that.validate(command);
that.beforeExecute(command,option); that.beforeExecute(command);
for(i = 0; i < priv.storage_a.length; i++) { for(i = 0; i < priv.storage_a.length; i++) {
priv.storage_a[i].execute(command); priv.storage_a[i].execute(command);
} }
that.afterExecute(command,option); that.afterExecute(command);
}; };
/** /**
...@@ -37,10 +35,9 @@ var storageHandler = function(spec, my) { ...@@ -37,10 +35,9 @@ var storageHandler = function(spec, my) {
* Override this function. * Override this function.
* @method afterExecute * @method afterExecute
* @param {object} command The command. * @param {object} command The command.
* @param {object} option Some options.
*/ */
that.afterExecute = function(command,option) { that.afterExecute = function(command) {
that.done(); command.done();
}; };
/** /**
......
...@@ -231,7 +231,6 @@ test ('Simple Job Elimination', function () { ...@@ -231,7 +231,6 @@ test ('Simple Job Elimination', function () {
'job creation'); 'job creation');
o.jio.removeDocument('file',{onResponse:o.f2,max_retry:1}); o.jio.removeDocument('file',{onResponse:o.f2,max_retry:1});
o.tmp = LocalOrCookieStorage.getItem('jio/job_array/'+id)[0]; o.tmp = LocalOrCookieStorage.getItem('jio/job_array/'+id)[0];
console.log (localStorage);
deepEqual(o.tmp.command.label,'removeDocument','job elimination'); deepEqual(o.tmp.command.label,'removeDocument','job elimination');
}); });
...@@ -274,23 +273,18 @@ test ('Simple Job Waiting', function () { ...@@ -274,23 +273,18 @@ test ('Simple Job Waiting', function () {
o.jio = JIO.newJio({type:'dummyallok',applicationname:'jiotests'}); o.jio = JIO.newJio({type:'dummyallok',applicationname:'jiotests'});
o.id = o.jio.getId(); o.id = o.jio.getId();
o.jio.saveDocument('file','content',{onResponse:o.f3,max_retry:1}); o.jio.saveDocument('file','content',{onResponse:o.f3,max_retry:1});
console.log (LocalOrCookieStorage.getItem ('jio/job_array/'+o.id));
o.clock.tick(200); o.clock.tick(200);
console.log (LocalOrCookieStorage.getItem ('jio/job_array/'+o.id));
o.jio.saveDocument('file','content1',{onResponse:o.f4,max_retry:1}); o.jio.saveDocument('file','content1',{onResponse:o.f4,max_retry:1});
console.log (LocalOrCookieStorage.getItem ('jio/job_array/'+o.id));
o.tmp0 = LocalOrCookieStorage.getItem('jio/job_array/'+o.id)[0]; o.tmp0 = LocalOrCookieStorage.getItem('jio/job_array/'+o.id)[0];
o.tmp1 = LocalOrCookieStorage.getItem('jio/job_array/'+o.id)[1]; o.tmp1 = LocalOrCookieStorage.getItem('jio/job_array/'+o.id)[1];
ok(o.tmp1 && o.tmp0.status.label === 'on going', ok(o.tmp1 && o.tmp0.status.label === 'on going',
'The second job must not overwrite the first on going one.'); 'The second job must not overwrite the first on going one.');
console.log (LocalOrCookieStorage.getItem ('jio/job_array/'+o.id));
ok(o.tmp1.status.label === 'wait' && ok(o.tmp1.status.label === 'wait' &&
o.tmp1.status.waitforjob && o.tmp1.status.waitforjob &&
JSON.stringify(o.tmp1.status.waitforjob) === JSON.stringify(o.tmp1.status.waitforjob) ===
JSON.stringify ([1]), JSON.stringify ([1]),
'The second job must be waiting for the first to end'); 'The second job must be waiting for the first to end');
o.clock.tick(1000); o.clock.tick(1000);
console.log (LocalOrCookieStorage.getItem ('jio/job_array/'+o.id));
ok(o.f3.calledOnce,'first request passed'); ok(o.f3.calledOnce,'first request passed');
ok(o.f4.calledOnce,'restore waiting job'); ok(o.f4.calledOnce,'restore waiting job');
o.jio.stop(); o.jio.stop();
...@@ -321,892 +315,867 @@ test ('Restore old Jio', function() { ...@@ -321,892 +315,867 @@ test ('Restore old Jio', function() {
o.f = function(result) { o.f = function(result) {
ok(false,'must never be called!'); ok(false,'must never be called!');
}; };
o.clock.tick(10000000); o.clock.tick(0);
this.spy(o,'f'); this.spy(o,'f');
o.jio = JIO.newJio({type:'dummyall3tries',applicationname:'jiotests'}); o.jio = JIO.newJio({type:'dummyall3tries',applicationname:'jiotests'});
o.id = o.jio.getId(); o.id = o.jio.getId();
o.jio.saveDocument('file','content',{onResponse:o.f,max_retry:3}); o.jio.saveDocument('file','content',{onResponse:o.f,max_retry:3});
o.clock.tick(1000); o.clock.tick(1000);
o.jio.stop(); o.jio.close();
o.jio = JIO.newJio({type:'dummyallok',applicationname:'jiotests'}); o.jio = JIO.newJio({type:'dummyallok',applicationname:'jiotests'});
o.clock.tick(10000); // 10 sec o.clock.tick(11000); // 10 sec
console.log (localStorage);
deepEqual(LocalOrCookieStorage.getItem('jio/job_array/'+o.id),null, deepEqual(LocalOrCookieStorage.getItem('jio/job_array/'+o.id),null,
'job array list must be empty'); 'job array list must be empty');
deepEqual(LocalOrCookieStorage.getItem('jio/job_array/'+o.jio.getId()),[], o.tmp1 = LocalOrCookieStorage.getItem('jio/job_array/'+o.jio.getId());
'ee'); if (o.tmp1.length > 0) {
deepEqual([o.tmp1[0].command.label,o.tmp1[0].command.path,
o.tmp1[0].command.content],
['saveDocument','file','content'],
'job is restored' + o.jio.getId());
} else {
ok (false, 'The recovered job must exists');
}
}); });
module ( 'Jio LocalStorage' ); module ( 'Jio LocalStorage' );
test ('Check name availability', function () {
// Test if LocalStorage can check the availabality of a name.
// We remove MrCheckName from local storage, and checking must return true.
// We now add MrCheckName to local storage, and checking must return false.
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (value){
o.f = function (result) {
deepEqual(result.return_value,value,'checking name availabality');};
t.spy(o,'f');
o.jio.checkNameAvailability(
{'user_name':'MrCheckName','onResponse': o.f,'max_tries':1});
clock.tick(510);
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
}
};
// new jio
o.jio = JIO.newJio({'type':'local','user_name':'noname'},
{"ID":'noid'});
// name must be available
removeFile ('MrCheckName','jiotests',{name:'file'});
mytest(true);
// name must be unavailable
addFile ('MrCheckName','jiotests',{name:'file'});
mytest(false);
o.jio.stop();
});
test ('Document save', function () { test ('Document save', function () {
// Test if LocalStorage can save documents. // Test if LocalStorage can save documents.
// We launch a saving to localstorage and we check if the file is // We launch a saving to localstorage and we check if the file is
// realy saved. Then save again and check if // realy saved. Then save again and check if
var o = {}, clock = this.sandbox.useFakeTimers(), t = this, var o = {}; o.clock = this.sandbox.useFakeTimers(); o.t = this;
mytest = function (message,value,lmcd){ o.spy = function(res,value,message) {
o.f = function (result) { o.f = function(result) {
deepEqual(result.status,value,message);}; if (res === 'status') {
t.spy(o,'f'); deepEqual (result.status.getLabel(),value,message);
o.jio.saveDocument(
{'name':'file','content':'content','onResponse': o.f,
'max_tries':1});
clock.tick(510);
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
} else { } else {
// check content deepEqual (result.value,value,message);
o.tmp = LocalOrCookieStorage.getItem (
'jio/local/MrSaveName/jiotests/file');
o.tmp.lmcd = lmcd(o.tmp.creation_date,o.tmp.last_modified);
delete o.tmp.last_modified;
delete o.tmp.creation_date;
deepEqual (o.tmp,{'name':'file','content':'content',
'lmcd':true},'check content');
}
};
o.jio = JIO.newJio({'type':'local','user_name':'MrSaveName'},
{"ID":'jiotests'});
LocalOrCookieStorage.deleteItem ('jio/local/MrSaveName/jiotests/file');
// save and check document existence
clock.tick(200);
// message, value, fun ( creationdate, lastmodified )
mytest('saving document','done',function(cd,lm){
return (cd === lm);
});
// re-save and check modification date
mytest('saving again','done',function(cd,lm){
return (cd < lm);
});
o.jio.stop();
});
test ('Document load', function () {
// Test if LocalStorage can load documents.
// We launch a loading from localstorage and we check if the file is
// realy loaded.
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
doc = {},
mytest = function (res,value){
o.f = function (result) {
deepEqual(result[res],value,'loading document');};
t.spy(o,'f');
o.jio.loadDocument(
{'name':'file','onResponse': o.f,'max_tries':1});
clock.tick(510);
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
} }
}; };
o.jio = JIO.newJio({'type':'local','user_name':'MrLoadName'}, o.t.spy(o,'f');
{"ID":'jiotests'});
// load a non existing file
LocalOrCookieStorage.deleteItem ('jio/local/MrLoadName/jiotests/file');
mytest ('status','fail');
// re-load file after saving it manually
doc = {'name':'file','content':'content',
'last_modified':1234,'creation_date':1000};
LocalOrCookieStorage.setItem (
'jio/local_file_name_array/MrLoadName/jiotests',['file']);
LocalOrCookieStorage.setItem ('jio/local/MrLoadName/jiotests/file',doc);
mytest ('return_value',doc);
o.jio.stop();
});
test ('Get document list', function () {
// Test if LocalStorage can get a list of documents.
// We create 2 documents inside localStorage to check them.
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
doc1 = {}, doc2 = {},
mytest = function (value){
o.f = function (result) {
deepEqual (objectifyDocumentArray(result.return_value),
objectifyDocumentArray(value),'getting list');
}; };
t.spy(o,'f'); o.tick = function (value, tick) {
o.jio.getDocumentList({'onResponse': o.f,'max_tries':1}); o.clock.tick(tick || 1000);
clock.tick(510);
if (!o.f.calledOnce) { if (!o.f.calledOnce) {
ok(false, 'no response / too much results'); ok(false, 'no response / too much results');
} }
}; o.tmp =
o.jio = JIO.newJio({'type':'local','user_name':'MrListName'}, LocalOrCookieStorage.getItem ('jio/local/MrSaveName/jiotests/file');
{"ID":'jiotests'}); if (o.tmp) {
doc1 = {'name':'file','content':'content', o.tmp.lmcd = (o.tmp.last_modified === o.tmp.creation_date);
'last_modified':1,'creation_date':0}; delete o.tmp.last_modified;
doc2 = {'name':'memo','content':'test', delete o.tmp.creation_date;
'last_modified':5,'creation_date':2}; deepEqual (o.tmp,{name:'file',content:'content',lmcd:value},
addFile ('MrListName','jiotests',doc1); 'check saved document');
addFile ('MrListName','jiotests',doc2);
delete doc1.content;
delete doc2.content;
mytest ([doc1,doc2]);
o.jio.stop();
});
test ('Document remove', function () {
// Test if LocalStorage can remove documents.
// We launch a remove from localstorage and we check if the file is
// realy removed.
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (){
o.f = function (result) {
deepEqual(result.status,'done','removing document');};
t.spy(o,'f');
o.jio.removeDocument(
{'name':'file','onResponse': o.f,'max_tries':1});
clock.tick(510);
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
} else { } else {
// check if the file is still there ok (false, 'document is not saved!');
o.tmp = LocalOrCookieStorage.getItem (
'jio/local/MrRemoveName/jiotests/file');
ok (!o.tmp, 'check no content');
}
};
o.jio = JIO.newJio({'type':'local','user_name':'MrRemoveName'},
{"ID":'jiotests'});
// test removing a file
LocalOrCookieStorage.setItem ('jio/local/MrRemoveName/jiotests/file',{});
mytest ();
o.jio.stop();
});
module ('Jio DAVStorage');
test ('Check name availability', function () {
// Test if DavStorage can check the availabality of a name.
var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (method,value,errno) {
var server = t.sandbox.useFakeServer();
server.respondWith ("PROPFIND",
"https://ca-davstorage:8080/dav/davcheck/",
[errno, {'Content-Type': 'text/xml' },
'']);
o.f = function (result) {
deepEqual(result[method],value,'checking name availability');};
t.spy(o,'f');
o.jio.checkNameAvailability({'user_name':'davcheck','onResponse':o.f,
'max_tries':1});
clock.tick(500);
server.respond();
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
} }
}; };
o.jio = JIO.newJio({'type':'dav','user_name':'davcheck', o.jio = JIO.newJio({type:'local',username:'MrSaveName',
'password':'checkpwd', applicationname:'jiotests'});
'url':'https://ca-davstorage:8080'}, // save and check document existence
{'ID':'jiotests'}); o.spy('status','done','saving document');
// 404 error, the name does not exist, name is available. o.jio.saveDocument('file','content',{onResponse:o.f,max_retry:1});
mytest ('return_value',true,404); o.tick(true);
// 200 error, responding ok, the name already exists, name is not available.
mytest ('return_value',false,200);
// 405 error, random error
mytest ('status','fail',405);
o.jio.stop();
});
test ('Document load', function () { o.spy('status','done','saving document');
// Test if DavStorage can load documents. o.jio.saveDocument('file','content',{onResponse:o.f,max_retry:1});
o.tick(false);
var davload = getXML('responsexml/davload'),
o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (message,doc,errprop,errget) {
var server = t.sandbox.useFakeServer();
server.respondWith (
"PROPFIND","https://ca-davstorage:8080/dav/davload/jiotests/file",
[errprop,{'Content-Type':'text/xml; charset="utf-8"'},
davload]);
server.respondWith (
"GET","https://ca-davstorage:8080/dav/davload/jiotests/file",
[errget,{},'content']);
o.f = function (result) {
deepEqual (result.return_value,doc,message);};
t.spy(o,'f');
o.jio.loadDocument({'name':'file','onResponse':o.f,'max_tries':1});
clock.tick(500);
server.respond();
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
}
};
o.jio = JIO.newJio({'type':'dav','user_name':'davload',
'password':'checkpwd',
'url':'https://ca-davstorage:8080'},
{'ID':'jiotests'});
// note: http errno:
// 200 OK
// 201 Created
// 204 No Content
// 207 Multi Status
// 403 Forbidden
// 404 Not Found
// load an inexistant document.
mytest ('load inexistant document',undefined,404,404);
// load a document.
mytest ('load document',{'name':'file','content':'content',
'last_modified':1335953199000,
'creation_date':1335953202000},207,200);
o.jio.stop();
});
test ('Document save', function () {
// Test if DavStorage can save documents.
var davsave = getXML('responsexml/davsave'),
o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (message,value,errnoput,errnoprop) {
var server = t.sandbox.useFakeServer();
server.respondWith (
// lastmodified = 7000, creationdate = 5000
"PROPFIND","https://ca-davstorage:8080/dav/davsave/jiotests/file",
[errnoprop,{'Content-Type':'text/xml; charset="utf-8"'},
davsave]);
server.respondWith (
"PUT",
"https://ca-davstorage:8080/dav/davsave/jiotests/file",
[errnoput, {'Content-Type':'x-www-form-urlencoded'},
'content']);
server.respondWith (
"GET","https://ca-davstorage:8080/dav/davsave/jiotests/file",
[errnoprop===207?200:errnoprop,{},'content']);
// server.respondWith ("MKCOL","https://ca-davstorage:8080/dav",
// [200,{},'']);
// server.respondWith ("MKCOL","https://ca-davstorage:8080/dav/davsave",
// [200,{},'']);
// server.respondWith ("MKCOL",
// "https://ca-davstorage:8080/dav/davsave/jiotests",
// [200,{},'']);
o.f = function (result) {
deepEqual (result.status,value,message);};
t.spy(o,'f');
o.jio.saveDocument({'name':'file','content':'content',
'onResponse':o.f,'max_tries':1});
clock.tick(500);
server.respond();
if (!o.f.calledOnce) {
ok(false, 'no response / too much results');
}
};
o.jio = JIO.newJio({'type':'dav','user_name':'davsave',
'password':'checkpwd',
'url':'https://ca-davstorage:8080'},
{'ID':'jiotests'});
// note: http errno:
// 200 OK
// 201 Created
// 204 No Content
// 207 Multi Status
// 403 Forbidden
// 404 Not Found
// // the path does not exist, we want to create it, and save the file.
// mytest('create path if not exists, and create document',
// true,201,404);
// the document does not exist, we want to create it
mytest('create document','done',201,404);
clock.tick(8000);
// the document already exists, we want to overwrite it
mytest('overwrite document','done',204,207);
o.jio.stop(); o.jio.stop();
}); });
test ('Get Document List', function () { // test ('Document load', function () {
// Test if DavStorage can get a list a document. // // Test if LocalStorage can load documents.
// // We launch a loading from localstorage and we check if the file is
var davlist = getXML('responsexml/davlist'), // // realy loaded.
o = {}, clock = this.sandbox.useFakeTimers(), t = this,
mytest = function (message,value,errnoprop) { // var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
var server = t.sandbox.useFakeServer(); // doc = {},
server.respondWith ( // mytest = function (res,value){
"PROPFIND",'https://ca-davstorage:8080/dav/davlist/jiotests/', // o.f = function (result) {
[errnoprop,{'Content-Type':'text/xml; charset="utf-8"'}, // deepEqual(result[res],value,'loading document');};
davlist]); // t.spy(o,'f');
o.f = function (result) { // o.jio.loadDocument(
if (result.status === 'fail') { // {'name':'file','onResponse': o.f,'max_tries':1});
deepEqual (result.return_value, value, message); // clock.tick(510);
} else { // if (!o.f.calledOnce) {
deepEqual (objectifyDocumentArray(result.return_value), // ok(false, 'no response / too much results');
objectifyDocumentArray(value),message); // }
} // };
}; // o.jio = JIO.newJio({'type':'local','user_name':'MrLoadName'},
t.spy(o,'f'); // {"ID":'jiotests'});
o.jio.getDocumentList({'onResponse':o.f,'max_tries':1}); // // load a non existing file
clock.tick(500); // LocalOrCookieStorage.deleteItem ('jio/local/MrLoadName/jiotests/file');
server.respond(); // mytest ('status','fail');
if (!o.f.calledOnce) {
ok(false, 'no response / too much results'); // // re-load file after saving it manually
} // doc = {'name':'file','content':'content',
}; // 'last_modified':1234,'creation_date':1000};
o.jio = JIO.newJio({'type':'dav','user_name':'davlist', // LocalOrCookieStorage.setItem (
'password':'checkpwd', // 'jio/local_file_name_array/MrLoadName/jiotests',['file']);
'url':'https://ca-davstorage:8080'}, // LocalOrCookieStorage.setItem ('jio/local/MrLoadName/jiotests/file',doc);
{'ID':'jiotests'}); // mytest ('return_value',doc);
mytest('fail to get list',undefined,404);
mytest('getting list',[{'name':'file','creation_date':1335962911000,
'last_modified':1335962907000},
{'name':'memo','creation_date':1335894073000,
'last_modified':1335955713000}],207);
o.jio.stop();
});
test ('Remove document', function () { // o.jio.stop();
// Test if DavStorage can remove documents. // });
var o = {}, clock = this.sandbox.useFakeTimers(), t = this, // test ('Get document list', function () {
mytest = function (message,value,errnodel) { // // Test if LocalStorage can get a list of documents.
var server = t.sandbox.useFakeServer(); // // We create 2 documents inside localStorage to check them.
server.respondWith (
"DELETE","https://ca-davstorage:8080/dav/davremove/jiotests/file", // var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
[errnodel,{},'']); // doc1 = {}, doc2 = {},
o.f = function (result) { // mytest = function (value){
deepEqual (result.status,value,message);}; // o.f = function (result) {
t.spy(o,'f'); // deepEqual (objectifyDocumentArray(result.return_value),
o.jio.removeDocument({'name':'file','onResponse':o.f,'max_tries':1}); // objectifyDocumentArray(value),'getting list');
clock.tick(500); // };
server.respond(); // t.spy(o,'f');
if (!o.f.calledOnce) { // o.jio.getDocumentList({'onResponse': o.f,'max_tries':1});
ok(false, 'no response / too much results'); // clock.tick(510);
} // if (!o.f.calledOnce) {
}; // ok(false, 'no response / too much results');
o.jio = JIO.newJio({'type':'dav','user_name':'davremove', // }
'password':'checkpwd', // };
'url':'https://ca-davstorage:8080'}, // o.jio = JIO.newJio({'type':'local','user_name':'MrListName'},
{'ID':'jiotests'}); // {"ID":'jiotests'});
// doc1 = {'name':'file','content':'content',
// 'last_modified':1,'creation_date':0};
// doc2 = {'name':'memo','content':'test',
// 'last_modified':5,'creation_date':2};
// addFile ('MrListName','jiotests',doc1);
// addFile ('MrListName','jiotests',doc2);
// delete doc1.content;
// delete doc2.content;
// mytest ([doc1,doc2]);
mytest('remove document','done',204); // o.jio.stop();
mytest('remove an already removed document','done',404); // });
o.jio.stop();
});
module ('Jio ReplicateStorage'); // test ('Document remove', function () {
// // Test if LocalStorage can remove documents.
// // We launch a remove from localstorage and we check if the file is
// // realy removed.
// var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
// mytest = function (){
// o.f = function (result) {
// deepEqual(result.status,'done','removing document');};
// t.spy(o,'f');
// o.jio.removeDocument(
// {'name':'file','onResponse': o.f,'max_tries':1});
// clock.tick(510);
// if (!o.f.calledOnce) {
// ok(false, 'no response / too much results');
// } else {
// // check if the file is still there
// o.tmp = LocalOrCookieStorage.getItem (
// 'jio/local/MrRemoveName/jiotests/file');
// ok (!o.tmp, 'check no content');
// }
// };
// o.jio = JIO.newJio({'type':'local','user_name':'MrRemoveName'},
// {"ID":'jiotests'});
// // test removing a file
// LocalOrCookieStorage.setItem ('jio/local/MrRemoveName/jiotests/file',{});
// mytest ();
test ('Check name availability', function () { // o.jio.stop();
// Tests the replicate storage // });
// method : checkNameAvailability
// It will test all the possibilities that could cause a server,
// like synchronisation problem...
var o = {}, clock = this.sandbox.useFakeTimers(), t = this, // module ('Jio DAVStorage');
mytest = function (message,value) {
o.f = function (result) { // test ('Check name availability', function () {
deepEqual (result.return_value,value,message); // // Test if DavStorage can check the availabality of a name.
};
t.spy(o,'f'); // var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
o.jio.checkNameAvailability({'user_name':'Dummy','onResponse':o.f, // mytest = function (method,value,errno) {
'max_tries':o.max_tries}); // var server = t.sandbox.useFakeServer();
clock.tick(300000); // server.respondWith ("PROPFIND",
if (!o.f.calledOnce) { // "https://ca-davstorage:8080/dav/davcheck/",
ok(false,'no respose / too much results'); // [errno, {'Content-Type': 'text/xml' },
} // '']);
}; // o.f = function (result) {
o.max_tries = 1; // deepEqual(result[method],value,'checking name availability');};
// DummyStorageAllOK,OK // t.spy(o,'f');
o.jio = JIO.newJio({'type':'replicate','storage_array':[ // o.jio.checkNameAvailability({'user_name':'davcheck','onResponse':o.f,
{'type':'dummyallok','user_name':'1'}, // 'max_tries':1});
{'type':'dummyallok','user_name':'2'}]}, // clock.tick(500);
{'ID':'jiotests'}); // server.respond();
mytest('DummyStoragesAllOK,OK : name available',true); // if (!o.f.calledOnce) {
o.jio.stop(); // ok(false, 'no response / too much results');
// DummyStorageAllOK,Fail // }
o.jio = JIO.newJio({'type':'replicate','storage_array':[ // };
{'type':'dummyallok','user_name':'1'},
{'type':'dummyallfail','user_name':'2'}]}, // o.jio = JIO.newJio({'type':'dav','user_name':'davcheck',
{'ID':'jiotests'}); // 'password':'checkpwd',
mytest('DummyStoragesAllOK,Fail : name not available',undefined); // 'url':'https://ca-davstorage:8080'},
o.jio.stop(); // {'ID':'jiotests'});
// DummyStorageAllFail,OK // // 404 error, the name does not exist, name is available.
o.jio = JIO.newJio({'type':'replicate','storage_array':[ // mytest ('return_value',true,404);
{'type':'dummyallfail','user_name':'1'}, // // 200 error, responding ok, the name already exists, name is not available.
{'type':'dummyallok','user_name':'2'}]}, // mytest ('return_value',false,200);
{'ID':'jiotests'}); // // 405 error, random error
mytest('DummyStoragesAllFail,OK : name not available',undefined); // mytest ('status','fail',405);
o.jio.stop();
// DummyStorageAllFail,Fail
o.jio = JIO.newJio({'type':'replicate','storage_array':[
{'type':'dummyallfail','user_name':'1'},
{'type':'dummyallfail','user_name':'2'}]},
{'ID':'jiotests'});
mytest('DummyStoragesAllFail,Fail : fail to check name',undefined);
o.jio.stop();
// DummyStorageAllOK,3Tries
o.max_tries = 3 ;
o.jio = JIO.newJio({'type':'replicate','storage_array':[
{'type':'dummyallok','user_name':'1'},
{'type':'dummyall3tries','user_name':'2'}]},
{'ID':'jiotests'});
mytest('DummyStoragesAllOK,3Tries : name available',true);
o.jio.stop();
// DummyStorageAll{3tries,{3tries,3tries},3tries}
o.max_tries = 3 ;
o.jio = JIO.newJio({'type':'replicate','storage_array':[
{'type':'dummyall3tries','user_name':'1'},
{'type':'replicate','storage_array':[
{'type':'dummyall3tries','user_name':'2'},
{'type':'dummyall3tries','user_name':'3'}]},
{'type':'dummyall3tries','user_name':'4'}]},
{'ID':'jiotests'});
mytest('DummyStorageAll{3tries,{3tries,3tries},3tries} : name available',
true);
o.jio.stop();
});
test ('Document load', function () { // o.jio.stop();
// Test if ReplicateStorage can load several documents. // });
var o = {}; var clock = this.sandbox.useFakeTimers(); var t = this; // test ('Document load', function () {
var mytest = function (message,doc) { // // Test if DavStorage can load documents.
o.f = function (result) {
deepEqual (result.return_value,doc,message);}; // var davload = getXML('responsexml/davload'),
t.spy(o,'f'); // o = {}, clock = this.sandbox.useFakeTimers(), t = this,
o.jio.loadDocument({'name':'file','onResponse':o.f}); // mytest = function (message,doc,errprop,errget) {
clock.tick(100000); // var server = t.sandbox.useFakeServer();
if (!o.f.calledOnce) { // server.respondWith (
ok(false, 'no response / too much results'); // "PROPFIND","https://ca-davstorage:8080/dav/davload/jiotests/file",
} // [errprop,{'Content-Type':'text/xml; charset="utf-8"'},
}; // davload]);
o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[ // server.respondWith (
{'type':'dummyallok','user_name':'1'}, // "GET","https://ca-davstorage:8080/dav/davload/jiotests/file",
{'type':'dummyallok','user_name':'2'}]}, // [errget,{},'content']);
{'ID':'jiotests'}); // o.f = function (result) {
mytest('DummyStorageAllOK,OK: load same file',{ // deepEqual (result.return_value,doc,message);};
'name':'file','content':'content', // t.spy(o,'f');
'last_modified':15000, // o.jio.loadDocument({'name':'file','onResponse':o.f,'max_tries':1});
'creation_date':10000}); // clock.tick(500);
o.jio.stop(); // server.respond();
o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[ // if (!o.f.calledOnce) {
{'type':'dummyallok','user_name':'1'}, // ok(false, 'no response / too much results');
{'type':'dummyall3tries','user_name':'2'}]}, // }
{'ID':'jiotests'}); // };
mytest('DummyStorageAllOK,3tries: load 2 different files',{ // o.jio = JIO.newJio({'type':'dav','user_name':'davload',
'name':'file','content':'content', // 'password':'checkpwd',
'last_modified':15000, // 'url':'https://ca-davstorage:8080'},
'creation_date':10000}); // {'ID':'jiotests'});
// // note: http errno:
// // 200 OK
// // 201 Created
// // 204 No Content
// // 207 Multi Status
// // 403 Forbidden
// // 404 Not Found
// // load an inexistant document.
// mytest ('load inexistant document',undefined,404,404);
// // load a document.
// mytest ('load document',{'name':'file','content':'content',
// 'last_modified':1335953199000,
// 'creation_date':1335953202000},207,200);
// o.jio.stop();
// });
o.jio.stop(); // test ('Document save', function () {
}); // // Test if DavStorage can save documents.
// var davsave = getXML('responsexml/davsave'),
// o = {}, clock = this.sandbox.useFakeTimers(), t = this,
// mytest = function (message,value,errnoput,errnoprop) {
// var server = t.sandbox.useFakeServer();
// server.respondWith (
// // lastmodified = 7000, creationdate = 5000
// "PROPFIND","https://ca-davstorage:8080/dav/davsave/jiotests/file",
// [errnoprop,{'Content-Type':'text/xml; charset="utf-8"'},
// davsave]);
// server.respondWith (
// "PUT",
// "https://ca-davstorage:8080/dav/davsave/jiotests/file",
// [errnoput, {'Content-Type':'x-www-form-urlencoded'},
// 'content']);
// server.respondWith (
// "GET","https://ca-davstorage:8080/dav/davsave/jiotests/file",
// [errnoprop===207?200:errnoprop,{},'content']);
// // server.respondWith ("MKCOL","https://ca-davstorage:8080/dav",
// // [200,{},'']);
// // server.respondWith ("MKCOL","https://ca-davstorage:8080/dav/davsave",
// // [200,{},'']);
// // server.respondWith ("MKCOL",
// // "https://ca-davstorage:8080/dav/davsave/jiotests",
// // [200,{},'']);
// o.f = function (result) {
// deepEqual (result.status,value,message);};
// t.spy(o,'f');
// o.jio.saveDocument({'name':'file','content':'content',
// 'onResponse':o.f,'max_tries':1});
// clock.tick(500);
// server.respond();
// if (!o.f.calledOnce) {
// ok(false, 'no response / too much results');
// }
// };
// o.jio = JIO.newJio({'type':'dav','user_name':'davsave',
// 'password':'checkpwd',
// 'url':'https://ca-davstorage:8080'},
// {'ID':'jiotests'});
// // note: http errno:
// // 200 OK
// // 201 Created
// // 204 No Content
// // 207 Multi Status
// // 403 Forbidden
// // 404 Not Found
// // // the path does not exist, we want to create it, and save the file.
// // mytest('create path if not exists, and create document',
// // true,201,404);
// // the document does not exist, we want to create it
// mytest('create document','done',201,404);
// clock.tick(8000);
// // the document already exists, we want to overwrite it
// mytest('overwrite document','done',204,207);
// o.jio.stop();
// });
test ('Document save', function () { // test ('Get Document List', function () {
// Test if ReplicateStorage can save several documents. // // Test if DavStorage can get a list a document.
// var davlist = getXML('responsexml/davlist'),
// o = {}, clock = this.sandbox.useFakeTimers(), t = this,
// mytest = function (message,value,errnoprop) {
// var server = t.sandbox.useFakeServer();
// server.respondWith (
// "PROPFIND",'https://ca-davstorage:8080/dav/davlist/jiotests/',
// [errnoprop,{'Content-Type':'text/xml; charset="utf-8"'},
// davlist]);
// o.f = function (result) {
// if (result.status === 'fail') {
// deepEqual (result.return_value, value, message);
// } else {
// deepEqual (objectifyDocumentArray(result.return_value),
// objectifyDocumentArray(value),message);
// }
// };
// t.spy(o,'f');
// o.jio.getDocumentList({'onResponse':o.f,'max_tries':1});
// clock.tick(500);
// server.respond();
// if (!o.f.calledOnce) {
// ok(false, 'no response / too much results');
// }
// };
// o.jio = JIO.newJio({'type':'dav','user_name':'davlist',
// 'password':'checkpwd',
// 'url':'https://ca-davstorage:8080'},
// {'ID':'jiotests'});
// mytest('fail to get list',undefined,404);
// mytest('getting list',[{'name':'file','creation_date':1335962911000,
// 'last_modified':1335962907000},
// {'name':'memo','creation_date':1335894073000,
// 'last_modified':1335955713000}],207);
// o.jio.stop();
// });
var o = {}, clock = this.sandbox.useFakeTimers(), t = this, // test ('Remove document', function () {
mytest = function (message,value) { // // Test if DavStorage can remove documents.
o.f = function (result) {
deepEqual (result.status,value,message);}; // var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
t.spy(o,'f'); // mytest = function (message,value,errnodel) {
o.jio.saveDocument({'name':'file','content':'content', // var server = t.sandbox.useFakeServer();
'onResponse':o.f,'max_tries':3}); // server.respondWith (
clock.tick(500); // "DELETE","https://ca-davstorage:8080/dav/davremove/jiotests/file",
if (!o.f.calledOnce) { // [errnodel,{},'']);
ok(false, 'no response / too much results'); // o.f = function (result) {
} // deepEqual (result.status,value,message);};
}; // t.spy(o,'f');
o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[ // o.jio.removeDocument({'name':'file','onResponse':o.f,'max_tries':1});
{'type':'dummyallok','user_name':'1'}, // clock.tick(500);
{'type':'dummyallok','user_name':'2'}]}, // server.respond();
{'ID':'jiotests'}); // if (!o.f.calledOnce) {
mytest('DummyStorageAllOK,OK: save a file.','done'); // ok(false, 'no response / too much results');
o.jio.stop(); // }
}); // };
// o.jio = JIO.newJio({'type':'dav','user_name':'davremove',
// 'password':'checkpwd',
// 'url':'https://ca-davstorage:8080'},
// {'ID':'jiotests'});
// mytest('remove document','done',204);
// mytest('remove an already removed document','done',404);
// o.jio.stop();
// });
test ('Get Document List', function () { // module ('Jio ReplicateStorage');
// Test if ReplicateStorage can get several list.
// test ('Check name availability', function () {
// // Tests the replicate storage
// // method : checkNameAvailability
// // It will test all the possibilities that could cause a server,
// // like synchronisation problem...
// var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
// mytest = function (message,value) {
// o.f = function (result) {
// deepEqual (result.return_value,value,message);
// };
// t.spy(o,'f');
// o.jio.checkNameAvailability({'user_name':'Dummy','onResponse':o.f,
// 'max_tries':o.max_tries});
// clock.tick(300000);
// if (!o.f.calledOnce) {
// ok(false,'no respose / too much results');
// }
// };
// o.max_tries = 1;
// // DummyStorageAllOK,OK
// o.jio = JIO.newJio({'type':'replicate','storage_array':[
// {'type':'dummyallok','user_name':'1'},
// {'type':'dummyallok','user_name':'2'}]},
// {'ID':'jiotests'});
// mytest('DummyStoragesAllOK,OK : name available',true);
// o.jio.stop();
// // DummyStorageAllOK,Fail
// o.jio = JIO.newJio({'type':'replicate','storage_array':[
// {'type':'dummyallok','user_name':'1'},
// {'type':'dummyallfail','user_name':'2'}]},
// {'ID':'jiotests'});
// mytest('DummyStoragesAllOK,Fail : name not available',undefined);
// o.jio.stop();
// // DummyStorageAllFail,OK
// o.jio = JIO.newJio({'type':'replicate','storage_array':[
// {'type':'dummyallfail','user_name':'1'},
// {'type':'dummyallok','user_name':'2'}]},
// {'ID':'jiotests'});
// mytest('DummyStoragesAllFail,OK : name not available',undefined);
// o.jio.stop();
// // DummyStorageAllFail,Fail
// o.jio = JIO.newJio({'type':'replicate','storage_array':[
// {'type':'dummyallfail','user_name':'1'},
// {'type':'dummyallfail','user_name':'2'}]},
// {'ID':'jiotests'});
// mytest('DummyStoragesAllFail,Fail : fail to check name',undefined);
// o.jio.stop();
// // DummyStorageAllOK,3Tries
// o.max_tries = 3 ;
// o.jio = JIO.newJio({'type':'replicate','storage_array':[
// {'type':'dummyallok','user_name':'1'},
// {'type':'dummyall3tries','user_name':'2'}]},
// {'ID':'jiotests'});
// mytest('DummyStoragesAllOK,3Tries : name available',true);
// o.jio.stop();
// // DummyStorageAll{3tries,{3tries,3tries},3tries}
// o.max_tries = 3 ;
// o.jio = JIO.newJio({'type':'replicate','storage_array':[
// {'type':'dummyall3tries','user_name':'1'},
// {'type':'replicate','storage_array':[
// {'type':'dummyall3tries','user_name':'2'},
// {'type':'dummyall3tries','user_name':'3'}]},
// {'type':'dummyall3tries','user_name':'4'}]},
// {'ID':'jiotests'});
// mytest('DummyStorageAll{3tries,{3tries,3tries},3tries} : name available',
// true);
// o.jio.stop();
// });
var o = {}, clock = this.sandbox.useFakeTimers(), t = this, // test ('Document load', function () {
mytest = function (message,value) { // // Test if ReplicateStorage can load several documents.
o.f = function (result) {
deepEqual (objectifyDocumentArray(result.return_value), // var o = {}; var clock = this.sandbox.useFakeTimers(); var t = this;
objectifyDocumentArray(value),'getting list'); // var mytest = function (message,doc) {
}; // o.f = function (result) {
t.spy(o,'f'); // deepEqual (result.return_value,doc,message);};
o.jio.getDocumentList({'onResponse':o.f,'max_tries':3}); // t.spy(o,'f');
clock.tick(100000); // o.jio.loadDocument({'name':'file','onResponse':o.f});
if (!o.f.calledOnce) { // clock.tick(100000);
ok(false, 'no response / too much results'); // if (!o.f.calledOnce) {
} // ok(false, 'no response / too much results');
}; // }
o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[ // };
{'type':'dummyallok','user_name':'1'}, // o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[
{'type':'dummyall3tries','user_name':'2'}]}, // {'type':'dummyallok','user_name':'1'},
{'ID':'jiotests'}); // {'type':'dummyallok','user_name':'2'}]},
o.doc1 = {'name':'file', // {'ID':'jiotests'});
'last_modified':15000,'creation_date':10000}; // mytest('DummyStorageAllOK,OK: load same file',{
o.doc2 = {'name':'memo', // 'name':'file','content':'content',
'last_modified':25000,'creation_date':20000}; // 'last_modified':15000,
mytest('DummyStorageAllOK,3tries: get document list .',[o.doc1,o.doc2]); // 'creation_date':10000});
o.jio.stop(); // o.jio.stop();
}); // o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[
// {'type':'dummyallok','user_name':'1'},
// {'type':'dummyall3tries','user_name':'2'}]},
// {'ID':'jiotests'});
// mytest('DummyStorageAllOK,3tries: load 2 different files',{
// 'name':'file','content':'content',
// 'last_modified':15000,
// 'creation_date':10000});
test ('Remove document', function () { // o.jio.stop();
// Test if ReplicateStorage can remove several documents. // });
var o = {}, clock = this.sandbox.useFakeTimers(), t = this, // test ('Document save', function () {
mytest = function (message,value) { // // Test if ReplicateStorage can save several documents.
o.f = function (result) {
deepEqual (result.status,value,message);}; // var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
t.spy(o,'f'); // mytest = function (message,value) {
o.jio.removeDocument({'name':'file','onResponse':o.f,'max_tries':3}); // o.f = function (result) {
clock.tick(100000); // deepEqual (result.status,value,message);};
if (!o.f.calledOnce) { // t.spy(o,'f');
ok(false, 'no response / too much results'); // o.jio.saveDocument({'name':'file','content':'content',
} // 'onResponse':o.f,'max_tries':3});
}; // clock.tick(500);
o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[ // if (!o.f.calledOnce) {
{'type':'dummyallok','user_name':'1'}, // ok(false, 'no response / too much results');
{'type':'dummyall3tries','user_name':'2'}]}, // }
{'ID':'jiotests'}); // };
mytest('DummyStorageAllOK,3tries: remove document.','done'); // o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[
o.jio.stop(); // {'type':'dummyallok','user_name':'1'},
}); // {'type':'dummyallok','user_name':'2'}]},
// {'ID':'jiotests'});
// mytest('DummyStorageAllOK,OK: save a file.','done');
// o.jio.stop();
// });
module ('Jio IndexedStorage'); // test ('Get Document List', function () {
// // Test if ReplicateStorage can get several list.
// var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
// mytest = function (message,value) {
// o.f = function (result) {
// deepEqual (objectifyDocumentArray(result.return_value),
// objectifyDocumentArray(value),'getting list');
// };
// t.spy(o,'f');
// o.jio.getDocumentList({'onResponse':o.f,'max_tries':3});
// clock.tick(100000);
// if (!o.f.calledOnce) {
// ok(false, 'no response / too much results');
// }
// };
// o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[
// {'type':'dummyallok','user_name':'1'},
// {'type':'dummyall3tries','user_name':'2'}]},
// {'ID':'jiotests'});
// o.doc1 = {'name':'file',
// 'last_modified':15000,'creation_date':10000};
// o.doc2 = {'name':'memo',
// 'last_modified':25000,'creation_date':20000};
// mytest('DummyStorageAllOK,3tries: get document list .',[o.doc1,o.doc2]);
// o.jio.stop();
// });
test ('Check name availability', function () { // test ('Remove document', function () {
var o = {}, clock = this.sandbox.useFakeTimers(), t = this, // // Test if ReplicateStorage can remove several documents.
mytest = function (message,value) {
o.f = function (result) { // var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
deepEqual (result.return_value,value,message);}; // mytest = function (message,value) {
t.spy(o,'f'); // o.f = function (result) {
o.jio.checkNameAvailability({user_name:'MrIndexedCheck', // deepEqual (result.status,value,message);};
onResponse:o.f,max_tries:3}); // t.spy(o,'f');
clock.tick(100000); // o.jio.removeDocument({'name':'file','onResponse':o.f,'max_tries':3});
if (!o.f.calledOnce) { // clock.tick(100000);
ok(false, 'no response / too much results'); // if (!o.f.calledOnce) {
} // ok(false, 'no response / too much results');
}; // }
o.jio=JIO.newJio({type:'indexed', // };
storage:{type:'dummyall3tries', // o.jio=JIO.newJio({'type':'replicate','user_name':'Dummy','storage_array':[
user_name:'indexedcheck'}}, // {'type':'dummyallok','user_name':'1'},
{ID:'jiotests'}); // {'type':'dummyall3tries','user_name':'2'}]},
mytest('dummy ok : name must be available', true); // {'ID':'jiotests'});
o.jio.stop(); // mytest('DummyStorageAllOK,3tries: remove document.','done');
}); // o.jio.stop();
// });
test ('Document load', function () { // module ('Jio IndexedStorage');
var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.newJio({type:'indexed', // test ('Check name availability', function () {
storage:{type:'dummyall3tries', // var o = {}, clock = this.sandbox.useFakeTimers(), t = this,
user_name:'indexedload'}}, // mytest = function (message,value) {
{ID:'jiotests'}); // o.f = function (result) {
// loading must take long time with dummyall3tries // deepEqual (result.return_value,value,message);};
o.f = function () {}; // t.spy(o,'f');
this.spy(o,'f'); // o.jio.checkNameAvailability({user_name:'MrIndexedCheck',
o.jio.loadDocument({name:'memo',max_tries:3,onResponse:o.f, // onResponse:o.f,max_tries:3});
options:{metadata_only:true}}); // clock.tick(100000);
clock.tick(500); // if (!o.f.calledOnce) {
ok(!o.f.calledOnce,'Callback must not be called'); // ok(false, 'no response / too much results');
// wait long time too retreive list // }
clock.tick(100000); // };
// now we can test if the document metadata are loaded faster. // o.jio=JIO.newJio({type:'indexed',
o.doc = {name:'memo',last_modified:25000,creation_date:20000}; // storage:{type:'dummyall3tries',
o.f2 = function (result) { // user_name:'indexedcheck'}},
deepEqual (result.return_value,o.doc,'Document metadata retrieved'); // {ID:'jiotests'});
}; // mytest('dummy ok : name must be available', true);
this.spy(o,'f2'); // o.jio.stop();
o.jio.loadDocument({name:'memo',max_tries:3,onResponse:o.f2, // });
options:{metadata_only:true}});
clock.tick(500);
if (!o.f2.calledOnce) {
ok (false, 'no response / too much results');
}
// test a simple document loading
o.doc2 = {name:'file',last_modified:17000,
creation_date:11000,content:'content2'};
o.f3 = function (result) {
deepEqual (result.return_value,o.doc2,'Simple document loading');
};
this.spy(o,'f3');
o.jio.loadDocument({name:'file',max_tries:3,onResponse:o.f3});
clock.tick(100000);
if (!o.f3.calledOnce) {
ok (false, 'no response / too much results');
}
o.jio.stop();
});
test ('Document save', function () { // test ('Document load', function () {
var o = {}, clock = this.sandbox.useFakeTimers(); // var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.newJio({type:'indexed', // o.jio=JIO.newJio({type:'indexed',
storage:{type:'dummyall3tries', // storage:{type:'dummyall3tries',
user_name:'indexedsave'}}, // user_name:'indexedload'}},
{ID:'jiotests'}); // {ID:'jiotests'});
o.f = function (result) { // // loading must take long time with dummyall3tries
deepEqual (result.status,'done','document save'); // o.f = function () {};
}; // this.spy(o,'f');
this.spy(o,'f'); // o.jio.loadDocument({name:'memo',max_tries:3,onResponse:o.f,
o.jio.saveDocument({name:'file',max_tries:3,onResponse:o.f}); // options:{metadata_only:true}});
clock.tick(100000); // clock.tick(500);
if (!o.f.calledOnce){ // ok(!o.f.calledOnce,'Callback must not be called');
ok (false, 'no response / too much results'); // // wait long time too retreive list
} // clock.tick(100000);
o.jio.stop(); // // now we can test if the document metadata are loaded faster.
}); // o.doc = {name:'memo',last_modified:25000,creation_date:20000};
// o.f2 = function (result) {
// deepEqual (result.return_value,o.doc,'Document metadata retrieved');
// };
// this.spy(o,'f2');
// o.jio.loadDocument({name:'memo',max_tries:3,onResponse:o.f2,
// options:{metadata_only:true}});
// clock.tick(500);
// if (!o.f2.calledOnce) {
// ok (false, 'no response / too much results');
// }
// // test a simple document loading
// o.doc2 = {name:'file',last_modified:17000,
// creation_date:11000,content:'content2'};
// o.f3 = function (result) {
// deepEqual (result.return_value,o.doc2,'Simple document loading');
// };
// this.spy(o,'f3');
// o.jio.loadDocument({name:'file',max_tries:3,onResponse:o.f3});
// clock.tick(100000);
// if (!o.f3.calledOnce) {
// ok (false, 'no response / too much results');
// }
// o.jio.stop();
// });
test ('Get document list', function () { // test ('Document save', function () {
var o = {}, clock = this.sandbox.useFakeTimers(); // var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.newJio({type:'indexed', // o.jio=JIO.newJio({type:'indexed',
storage:{type:'dummyall3tries', // storage:{type:'dummyall3tries',
user_name:'indexedgetlist'}}, // user_name:'indexedsave'}},
{ID:'jiotests'}); // {ID:'jiotests'});
o.doc1 = {name:'file',last_modified:15000,creation_date:10000}; // o.f = function (result) {
o.doc2 = {name:'memo',last_modified:25000,creation_date:20000}; // deepEqual (result.status,'done','document save');
// getting list must take long time with dummyall3tries // };
o.f = function () {}; // this.spy(o,'f');
this.spy(o,'f'); // o.jio.saveDocument({name:'file',max_tries:3,onResponse:o.f});
o.jio.getDocumentList({max_tries:3,onResponse:o.f}); // clock.tick(100000);
clock.tick(500); // if (!o.f.calledOnce){
ok(!o.f.calledOnce,'Callback must not be called'); // ok (false, 'no response / too much results');
// wail long time too retreive list // }
clock.tick(100000); // o.jio.stop();
// now we can test if the document list is loaded faster // });
o.f2 = function (result) {
deepEqual (result.return_value,[o.doc1,o.doc2],'get document list');
};
this.spy(o,'f2');
o.jio.getDocumentList({max_tries:3,onResponse:o.f2});
clock.tick(500);
if (!o.f2.calledOnce) {
ok (false, 'no response / too much results');
}
});
test ('Remove document', function () { // test ('Get document list', function () {
var o = {}, clock = this.sandbox.useFakeTimers(); // var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.newJio({type:'indexed', // o.jio=JIO.newJio({type:'indexed',
storage:{type:'dummyall3tries', // storage:{type:'dummyall3tries',
user_name:'indexedsave'}}, // user_name:'indexedgetlist'}},
{ID:'jiotests'}); // {ID:'jiotests'});
o.f = function (result) { // o.doc1 = {name:'file',last_modified:15000,creation_date:10000};
deepEqual (result.status,'done','document remove'); // o.doc2 = {name:'memo',last_modified:25000,creation_date:20000};
}; // // getting list must take long time with dummyall3tries
this.spy(o,'f'); // o.f = function () {};
o.jio.removeDocument({name:'file',max_tries:3,onResponse:o.f}); // this.spy(o,'f');
clock.tick(100000); // o.jio.getDocumentList({max_tries:3,onResponse:o.f});
if (!o.f.calledOnce){ // clock.tick(500);
ok (false, 'no response / too much results'); // ok(!o.f.calledOnce,'Callback must not be called');
} // // wail long time too retreive list
o.jio.stop(); // clock.tick(100000);
}); // // now we can test if the document list is loaded faster
// o.f2 = function (result) {
// deepEqual (result.return_value,[o.doc1,o.doc2],'get document list');
// };
// this.spy(o,'f2');
// o.jio.getDocumentList({max_tries:3,onResponse:o.f2});
// clock.tick(500);
// if (!o.f2.calledOnce) {
// ok (false, 'no response / too much results');
// }
// });
module ('Jio CryptedStorage'); // test ('Remove document', function () {
// var o = {}, clock = this.sandbox.useFakeTimers();
// o.jio=JIO.newJio({type:'indexed',
// storage:{type:'dummyall3tries',
// user_name:'indexedsave'}},
// {ID:'jiotests'});
// o.f = function (result) {
// deepEqual (result.status,'done','document remove');
// };
// this.spy(o,'f');
// o.jio.removeDocument({name:'file',max_tries:3,onResponse:o.f});
// clock.tick(100000);
// if (!o.f.calledOnce){
// ok (false, 'no response / too much results');
// }
// o.jio.stop();
// });
test ('Check name availability' , function () { // module ('Jio CryptedStorage');
var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.newJio({type:'crypted', // test ('Check name availability' , function () {
storage:{type:'local', // var o = {}, clock = this.sandbox.useFakeTimers();
user_name:'cryptcheck'}}, // o.jio=JIO.newJio({type:'crypted',
{ID:'jiotests'}); // storage:{type:'local',
o.f = function (result) { // user_name:'cryptcheck'}},
deepEqual (result.return_value,true,'name must be available'); // {ID:'jiotests'});
}; // o.f = function (result) {
this.spy(o,'f'); // deepEqual (result.return_value,true,'name must be available');
o.jio.checkNameAvailability({user_name:'cryptcheck', // };
max_tries:1,onResponse:o.f}); // this.spy(o,'f');
clock.tick(1000); // o.jio.checkNameAvailability({user_name:'cryptcheck',
if (!o.f.calledOnce) { // max_tries:1,onResponse:o.f});
ok (false, 'no response / too much results'); // clock.tick(1000);
} // if (!o.f.calledOnce) {
o.jio.stop(); // ok (false, 'no response / too much results');
}); // }
// o.jio.stop();
// });
test ('Document save' , function () { // test ('Document save' , function () {
var o = {}, clock = this.sandbox.useFakeTimers(); // var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.newJio({type:'crypted', // o.jio=JIO.newJio({type:'crypted',
user_name:'cryptsave', // user_name:'cryptsave',
password:'mypwd', // password:'mypwd',
storage:{type:'local', // storage:{type:'local',
user_name:'cryptsavelocal'}}, // user_name:'cryptsavelocal'}},
{ID:'jiotests'}); // {ID:'jiotests'});
o.f = function (result) { // o.f = function (result) {
deepEqual (result.status,'done','save ok'); // deepEqual (result.status,'done','save ok');
}; // };
this.spy(o,'f'); // this.spy(o,'f');
o.jio.saveDocument({name:'testsave',content:'contentoftest', // o.jio.saveDocument({name:'testsave',content:'contentoftest',
max_tries:1,onResponse:o.f}); // max_tries:1,onResponse:o.f});
clock.tick(1000); // clock.tick(1000);
if (!o.f.calledOnce) { // if (!o.f.calledOnce) {
ok (false, 'no response / too much results'); // ok (false, 'no response / too much results');
} // }
// encrypt 'testsave' with 'cryptsave:mypwd' password // // encrypt 'testsave' with 'cryptsave:mypwd' password
o.tmp = LocalOrCookieStorage.getItem( // o.tmp = LocalOrCookieStorage.getItem(
'jio/local/cryptsavelocal/jiotests/rZx5PJxttlf9QpZER/5x354bfX54QFa1'); // 'jio/local/cryptsavelocal/jiotests/rZx5PJxttlf9QpZER/5x354bfX54QFa1');
if (o.tmp) { // if (o.tmp) {
delete o.tmp.last_modified; // delete o.tmp.last_modified;
delete o.tmp.creation_date; // delete o.tmp.creation_date;
} // }
deepEqual (o.tmp, // deepEqual (o.tmp,
{name:'rZx5PJxttlf9QpZER/5x354bfX54QFa1', // {name:'rZx5PJxttlf9QpZER/5x354bfX54QFa1',
content:'upZkPIpitF3QMT/DU5jM3gP0SEbwo1n81rMOfLE'}, // content:'upZkPIpitF3QMT/DU5jM3gP0SEbwo1n81rMOfLE'},
'Check if the document is realy crypted'); // 'Check if the document is realy crypted');
o.jio.stop(); // o.jio.stop();
}); // });
test ('Document Load' , function () { // test ('Document Load' , function () {
var o = {}, clock = this.sandbox.useFakeTimers(); // var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.newJio({type:'crypted', // o.jio=JIO.newJio({type:'crypted',
user_name:'cryptload', // user_name:'cryptload',
password:'mypwd', // password:'mypwd',
storage:{type:'local', // storage:{type:'local',
user_name:'cryptloadlocal'}}, // user_name:'cryptloadlocal'}},
{ID:'jiotests'}); // {ID:'jiotests'});
o.f = function (result) { // o.f = function (result) {
if (result.status === 'done') { // if (result.status === 'done') {
deepEqual (result.return_value, // deepEqual (result.return_value,
{name:'testload', // {name:'testload',
content:'contentoftest', // content:'contentoftest',
last_modified:500, // last_modified:500,
creation_date:500}, // creation_date:500},
'load ok'); // 'load ok');
} else { // } else {
ok (false ,'cannot load'); // ok (false ,'cannot load');
} // }
}; // };
this.spy(o,'f'); // this.spy(o,'f');
// encrypt 'testload' with 'cryptload:mypwd' password // // encrypt 'testload' with 'cryptload:mypwd' password
// and 'contentoftest' with 'cryptload:mypwd' // // and 'contentoftest' with 'cryptload:mypwd'
LocalOrCookieStorage.setItem( // LocalOrCookieStorage.setItem(
'jio/local/cryptloadlocal/jiotests/hiG4H80pwkXCCrlLl1X0BD0BfWLZwDUX', // 'jio/local/cryptloadlocal/jiotests/hiG4H80pwkXCCrlLl1X0BD0BfWLZwDUX',
{name:'mRyQFcUvUKq6tLGUjBo34P3oc2LPxEju', // {name:'mRyQFcUvUKq6tLGUjBo34P3oc2LPxEju',
content:'kSulH8Qo105dSKHcY2hEBXWXC9b+3PCEFSm1k7k', // content:'kSulH8Qo105dSKHcY2hEBXWXC9b+3PCEFSm1k7k',
last_modified:500,creation_date:500}); // last_modified:500,creation_date:500});
o.jio.loadDocument({name:'testload', // o.jio.loadDocument({name:'testload',
max_tries:1,onResponse:o.f}); // max_tries:1,onResponse:o.f});
clock.tick(1000); // clock.tick(1000);
if (!o.f.calledOnce) { // if (!o.f.calledOnce) {
ok (false, 'no response / too much results'); // ok (false, 'no response / too much results');
} // }
o.jio.stop(); // o.jio.stop();
LocalOrCookieStorage.deleteItem( // LocalOrCookieStorage.deleteItem(
'jio/local/cryptloadlocal/jiotests/hiG4H80pwkXCCrlLl1X0BD0BfWLZwDUX'); // 'jio/local/cryptloadlocal/jiotests/hiG4H80pwkXCCrlLl1X0BD0BfWLZwDUX');
}); // });
test ('Get Document List', function () { // test ('Get Document List', function () {
var o = {}, clock = this.sandbox.useFakeTimers(); // var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.newJio({type:'crypted', // o.jio=JIO.newJio({type:'crypted',
user_name:'cryptgetlist', // user_name:'cryptgetlist',
password:'mypwd', // password:'mypwd',
storage:{type:'local', // storage:{type:'local',
user_name:'cryptgetlistlocal'}}, // user_name:'cryptgetlistlocal'}},
{ID:'jiotests'}); // {ID:'jiotests'});
o.f = function (result) { // o.f = function (result) {
if (result.status === 'done') { // if (result.status === 'done') {
deepEqual (objectifyDocumentArray(result.return_value), // deepEqual (objectifyDocumentArray(result.return_value),
objectifyDocumentArray(o.doc_list),'Getting list'); // objectifyDocumentArray(o.doc_list),'Getting list');
} else { // } else {
console.warn (result); // console.warn (result);
ok (false, 'Cannot get list'); // ok (false, 'Cannot get list');
} // }
}; // };
this.spy(o,'f'); // this.spy(o,'f');
o.doc_list = [ // o.doc_list = [
{name:'testgetlist1',last_modified:500,creation_date:200}, // {name:'testgetlist1',last_modified:500,creation_date:200},
{name:'testgetlist2',last_modified:300,creation_date:300} // {name:'testgetlist2',last_modified:300,creation_date:300}
]; // ];
o.doc_encrypt_list = [ // o.doc_encrypt_list = [
{name:'541eX0WTMDw7rqIP7Ofxd1nXlPOtejxGnwOzMw', // {name:'541eX0WTMDw7rqIP7Ofxd1nXlPOtejxGnwOzMw',
content:'/4dBPUdmLolLfUaDxPPrhjRPdA', // content:'/4dBPUdmLolLfUaDxPPrhjRPdA',
last_modified:500,creation_date:200}, // last_modified:500,creation_date:200},
{name:'541eX0WTMDw7rqIMyJ5tx4YHWSyxJ5UjYvmtqw', // {name:'541eX0WTMDw7rqIMyJ5tx4YHWSyxJ5UjYvmtqw',
content:'/4FBALhweuyjxxD53eFQDSm4VA', // content:'/4FBALhweuyjxxD53eFQDSm4VA',
last_modified:300,creation_date:300} // last_modified:300,creation_date:300}
]; // ];
// encrypt with 'cryptgetlist:mypwd' as password // // encrypt with 'cryptgetlist:mypwd' as password
LocalOrCookieStorage.setItem( // LocalOrCookieStorage.setItem(
'jio/local_file_name_array/cryptgetlistlocal/jiotests', // 'jio/local_file_name_array/cryptgetlistlocal/jiotests',
[o.doc_encrypt_list[0].name,o.doc_encrypt_list[1].name]); // [o.doc_encrypt_list[0].name,o.doc_encrypt_list[1].name]);
LocalOrCookieStorage.setItem( // LocalOrCookieStorage.setItem(
'jio/local/cryptgetlistlocal/jiotests/'+o.doc_encrypt_list[0].name, // 'jio/local/cryptgetlistlocal/jiotests/'+o.doc_encrypt_list[0].name,
o.doc_encrypt_list[0]); // o.doc_encrypt_list[0]);
LocalOrCookieStorage.setItem( // LocalOrCookieStorage.setItem(
'jio/local/cryptgetlistlocal/jiotests/'+o.doc_encrypt_list[1].name, // 'jio/local/cryptgetlistlocal/jiotests/'+o.doc_encrypt_list[1].name,
o.doc_encrypt_list[1]); // o.doc_encrypt_list[1]);
o.jio.getDocumentList({max_tries:1,onResponse:o.f}); // o.jio.getDocumentList({max_tries:1,onResponse:o.f});
clock.tick (2000); // 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');
} // }
clock.tick(1000); // clock.tick(1000);
o.jio.stop(); // o.jio.stop();
}); // });
test ('Remove document', function () { // test ('Remove document', function () {
var o = {}, clock = this.sandbox.useFakeTimers(); // var o = {}, clock = this.sandbox.useFakeTimers();
o.jio=JIO.newJio({type:'crypted', // o.jio=JIO.newJio({type:'crypted',
user_name:'cryptremove', // user_name:'cryptremove',
password:'mypwd', // password:'mypwd',
storage:{type:'local', // storage:{type:'local',
user_name:'cryptremovelocal'}}, // user_name:'cryptremovelocal'}},
{ID:'jiotests'}); // {ID:'jiotests'});
o.f = function (result) { // o.f = function (result) {
deepEqual (result.status,'done','Document remove'); // deepEqual (result.status,'done','Document remove');
}; // };
this.spy(o,'f'); // this.spy(o,'f');
// encrypt with 'cryptremove:mypwd' as password // // encrypt with 'cryptremove:mypwd' as password
LocalOrCookieStorage.setItem( // LocalOrCookieStorage.setItem(
'jio/local_file_name_array/cryptremovelocal/jiotests', // 'jio/local_file_name_array/cryptremovelocal/jiotests',
["JqCLTjyxQqO9jwfxD/lyfGIX+qA"]); // ["JqCLTjyxQqO9jwfxD/lyfGIX+qA"]);
LocalOrCookieStorage.setItem( // LocalOrCookieStorage.setItem(
'jio/local/cryptremovelocal/jiotests/JqCLTjyxQqO9jwfxD/lyfGIX+qA', // 'jio/local/cryptremovelocal/jiotests/JqCLTjyxQqO9jwfxD/lyfGIX+qA',
{"name":"JqCLTjyxQqO9jwfxD/lyfGIX+qA", // {"name":"JqCLTjyxQqO9jwfxD/lyfGIX+qA",
"content":"LKaLZopWgML6IxERqoJ2mUyyO", // "content":"LKaLZopWgML6IxERqoJ2mUyyO",
"creation_date":500, // "creation_date":500,
"last_modified":500}); // "last_modified":500});
o.jio.removeDocument({name:'file',max_tries:1,onResponse:o.f}); // o.jio.removeDocument({name:'file',max_tries:1,onResponse:o.f});
clock.tick(1000); // clock.tick(1000);
if (!o.f.calledOnce){ // if (!o.f.calledOnce){
ok (false, 'no response / too much results'); // ok (false, 'no response / too much results');
} // }
o.jio.stop(); // o.jio.stop();
}); // });
}; // end thisfun }; // end thisfun
......
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