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

Improve Job management.

parent c96a5bc7
...@@ -132,31 +132,62 @@ test ('All tests', function () { ...@@ -132,31 +132,62 @@ test ('All tests', function () {
module ( 'Jio Job Managing' ); module ( 'Jio Job Managing' );
test ('Add 2 same jobs', function () { test ('Simple Job Elimination', function () {
// Check possibilities when adding 2 same jobs.
var o = {}, clock = this.sandbox.useFakeTimers(), id = 0; var o = {}, clock = this.sandbox.useFakeTimers(), id = 0;
o.f1 = this.spy(); o.f2 = this.spy()
o.jio = JIO.createNew({'type':'dummyallok','userName':'dummy'},
{'ID':'jiotests'});
id = o.jio.id;
o.jio.saveDocument({'fileName':'file','fileContent':'content',
'callback':o.f1});
ok(LocalOrCookieStorage.getItem('jio/jobObject/'+id)['1'],
'job creation');
clock.tick(10);
o.jio.removeDocument({'fileName':'file','fileContent':'content',
'callback':o.f2});
deepEqual(LocalOrCookieStorage.getItem('jio/jobObject/'+id)['1'],
undefined,'job elimination');
});
test ('Simple Job Replacement', function () {
// Test if the second job write over the first one // Test if the second job write over the first one
var o = {}, clock = this.sandbox.useFakeTimers(), id = 0;
o.f1 = this.spy(); o.f2 = this.spy()
o.jio = JIO.createNew({'type':'dummyallok','userName':'dummy'}, o.jio = JIO.createNew({'type':'dummyallok','userName':'dummy'},
{'ID':'jiotests'}); {'ID':'jiotests'});
id = o.jio.id; id = o.jio.id;
o.jio.saveDocument({'fileName':'file','fileContent':'content'}); o.jio.saveDocument({'fileName':'file','fileContent':'content',
'callback':o.f1});
clock.tick(10); clock.tick(10);
o.jio.saveDocument({'fileName':'file','fileContent':'content'}); o.jio.saveDocument({'fileName':'file','fileContent':'content',
'callback':o.f2});
deepEqual(LocalOrCookieStorage.getItem( deepEqual(LocalOrCookieStorage.getItem(
'jio/jobObject/'+id)['1'].date,10, 'jio/jobObject/'+id)['1'].date,10,
'The first job date have to be equal to the second job date.'); 'The first job date have to be equal to the second job date.');
clock.tick(500);
ok(!o.f1.calledOnce,'no callback for the first save request');
ok(o.f2.calledOnce,'second callback is called once');
o.jio.stop(); o.jio.stop();
clock.tick(-10);
});
test ('Simple Job Waiting', function () {
// Test if the second job doesn't erase the first ongoing one // Test if the second job doesn't erase the first ongoing one
var o = {}, clock = this.sandbox.useFakeTimers(), id = 0;
o.f3 = this.spy(); o.f4 = this.spy();
o.jio = JIO.createNew({'type':'dummyallok','userName':'dummy'}, o.jio = JIO.createNew({'type':'dummyallok','userName':'dummy'},
{'ID':'jiotests'}); {'ID':'jiotests'});
id = o.jio.id; id = o.jio.id;
o.jio.saveDocument({'fileName':'file','fileContent':'content'}); o.jio.saveDocument({'fileName':'file','fileContent':'content',
'callback':o.f3});
clock.tick(200); clock.tick(200);
o.jio.saveDocument({'fileName':'file','fileContent':'content'}); o.jio.saveDocument({'fileName':'file','fileContent':'content',
'callback':o.f4});
ok(LocalOrCookieStorage.getItem( ok(LocalOrCookieStorage.getItem(
'jio/jobObject/'+id)['2'] && 'jio/jobObject/'+id)['2'] &&
LocalOrCookieStorage.getItem( LocalOrCookieStorage.getItem(
...@@ -166,16 +197,15 @@ test ('Add 2 same jobs', function () { ...@@ -166,16 +197,15 @@ test ('Add 2 same jobs', function () {
'jio/jobObject/'+id)['2'].status === 'wait' && 'jio/jobObject/'+id)['2'].status === 'wait' &&
LocalOrCookieStorage.getItem( LocalOrCookieStorage.getItem(
'jio/jobObject/'+id)['2'].waitingFor && 'jio/jobObject/'+id)['2'].waitingFor &&
LocalOrCookieStorage.getItem( JSON.stringify (LocalOrCookieStorage.getItem(
'jio/jobObject/'+id)['2'].waitingFor.jobID === '1', 'jio/jobObject/'+id)['2'].waitingFor.jobIdArray) === '["1"]',
'The second job must be waiting for the first to end'); 'The second job must be waiting for the first to end');
clock.tick(500);
ok(o.f3.calledOnce,'first request passed');
ok(o.f4.calledOnce,'restore waiting job');
o.jio.stop(); o.jio.stop();
}); });
test ('Restore a previous waiting job', function () {
ok(false,'not implemented yet');
});
module ( 'Jio LocalStorage' ); module ( 'Jio LocalStorage' );
test ('Check name availability', function () { test ('Check name availability', function () {
...@@ -591,25 +621,29 @@ test ('Check name availability', function () { ...@@ -591,25 +621,29 @@ test ('Check name availability', function () {
}; };
// DummyStorageAllOK,OK // DummyStorageAllOK,OK
o.jio = JIO.createNew({'type':'replicate','storageArray':[ o.jio = JIO.createNew({'type':'replicate','storageArray':[
{'type':'dummyallok'},{'type':'dummyallok'}]}, {'type':'dummyallok','userName':'1'},
{'type':'dummyallok','userName':'2'}]},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('DummyStoragesAllOK,OK : name available',true); mytest('DummyStoragesAllOK,OK : name available',true);
o.jio.stop(); o.jio.stop();
// DummyStorageAllOK,Fail // DummyStorageAllOK,Fail
o.jio = JIO.createNew({'type':'replicate','storageArray':[ o.jio = JIO.createNew({'type':'replicate','storageArray':[
{'type':'dummyallok'},{'type':'dummyallfail'}]}, {'type':'dummyallok','userName':'1'},
{'type':'dummyallfail','userName':'2'}]},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('DummyStoragesAllOK,Fail : name not available',false); mytest('DummyStoragesAllOK,Fail : name not available',false);
o.jio.stop(); o.jio.stop();
// DummyStorageAllFail,OK // DummyStorageAllFail,OK
o.jio = JIO.createNew({'type':'replicate','storageArray':[ o.jio = JIO.createNew({'type':'replicate','storageArray':[
{'type':'dummyallfail'},{'type':'dummyallok'}]}, {'type':'dummyallfail','userName':'1'},
{'type':'dummyallok','userName':'2'}]},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('DummyStoragesAllFail,OK : name not available',false); mytest('DummyStoragesAllFail,OK : name not available',false);
o.jio.stop(); o.jio.stop();
// DummyStorageAllFail,Fail // DummyStorageAllFail,Fail
o.jio = JIO.createNew({'type':'replicate','storageArray':[ o.jio = JIO.createNew({'type':'replicate','storageArray':[
{'type':'dummyallfail'},{'type':'dummyallfail'}]}, {'type':'dummyallfail','userName':'1'},
{'type':'dummyallfail','userName':'2'}]},
{'ID':'jiotests'}); {'ID':'jiotests'});
mytest('DummyStoragesAllFail,Fail : name not available',false); mytest('DummyStoragesAllFail,Fail : name not available',false);
o.jio.stop(); o.jio.stop();
......
This diff is collapsed.
...@@ -713,6 +713,7 @@ ...@@ -713,6 +713,7 @@
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// ReplicateStorage // ReplicateStorage
ReplicateStorage = function ( options ) { ReplicateStorage = function ( options ) {
// TODO Add a tests that check if there is no duplicate storages.
this.queue = options.queue; this.queue = options.queue;
this.id = null; this.id = null;
this.length = options.storage.storageArray.length; this.length = options.storage.storageArray.length;
...@@ -750,7 +751,7 @@ ...@@ -750,7 +751,7 @@
job.callback(res); job.callback(res);
} }
}; };
this.queue.createJob ( newjob ); this.queue.createJob ( newjob ) ;
} }
}, },
saveDocument: function ( job, jobendcallback ) { saveDocument: function ( job, jobendcallback ) {
...@@ -766,9 +767,8 @@ ...@@ -766,9 +767,8 @@
// returns {'status':string,'message':string,'isSaved':boolean, // returns {'status':string,'message':string,'isSaved':boolean,
// 'resultArray':Array} in the jobendcallback arguments. // 'resultArray':Array} in the jobendcallback arguments.
// TODO // TODO
}, },
loadDocument: function ( job, jobendcallback ) { loadDocument: function ( job, jobendcallback ) {
// TODO // TODO
......
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