Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xiaowu Zhang
jio
Commits
6b4c1794
Commit
6b4c1794
authored
Apr 11, 2014
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cancellers added to jIO
parent
7cd7e8bc
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
92 additions
and
9 deletions
+92
-9
src/jio/core/globals.js
src/jio/core/globals.js
+9
-0
src/jio/features/jobMaker.js
src/jio/features/jobMaker.js
+7
-0
src/jio/features/restApi.js
src/jio/features/restApi.js
+1
-0
test/jio/fakestorage.js
test/jio/fakestorage.js
+3
-0
test/jio/tests.js
test/jio/tests.js
+49
-8
test/jio/util.js
test/jio/util.js
+23
-1
No files found.
src/jio/core/globals.js
View file @
6b4c1794
...
@@ -26,12 +26,15 @@ constants.http_status_text = {
...
@@ -26,12 +26,15 @@ constants.http_status_text = {
"
0
"
:
"
Unknown
"
,
"
0
"
:
"
Unknown
"
,
"
550
"
:
"
Internal JIO Error
"
,
"
550
"
:
"
Internal JIO Error
"
,
"
551
"
:
"
Internal Storage Error
"
,
"
551
"
:
"
Internal Storage Error
"
,
"
555
"
:
"
Cancelled
"
,
"
Unknown
"
:
"
Unknown
"
,
"
Unknown
"
:
"
Unknown
"
,
"
Internal JIO Error
"
:
"
Internal JIO Error
"
,
"
Internal JIO Error
"
:
"
Internal JIO Error
"
,
"
Internal Storage Error
"
:
"
Internal Storage Error
"
,
"
Internal Storage Error
"
:
"
Internal Storage Error
"
,
"
Cancelled
"
:
"
Cancelled
"
,
"
unknown
"
:
"
Unknown
"
,
"
unknown
"
:
"
Unknown
"
,
"
internal_jio_error
"
:
"
Internal JIO Error
"
,
"
internal_jio_error
"
:
"
Internal JIO Error
"
,
"
internal_storage_error
"
:
"
Internal Storage Error
"
,
"
internal_storage_error
"
:
"
Internal Storage Error
"
,
"
cancelled
"
:
"
Cancelled
"
,
"
200
"
:
"
Ok
"
,
"
200
"
:
"
Ok
"
,
"
201
"
:
"
Created
"
,
"
201
"
:
"
Created
"
,
...
@@ -138,12 +141,15 @@ constants.http_status = {
...
@@ -138,12 +141,15 @@ constants.http_status = {
"
0
"
:
0
,
"
0
"
:
0
,
"
550
"
:
550
,
"
550
"
:
550
,
"
551
"
:
551
,
"
551
"
:
551
,
"
555
"
:
555
,
"
Unknown
"
:
0
,
"
Unknown
"
:
0
,
"
Internal JIO Error
"
:
550
,
"
Internal JIO Error
"
:
550
,
"
Internal Storage Error
"
:
551
,
"
Internal Storage Error
"
:
551
,
"
Cancelled
"
:
555
,
"
unknown
"
:
0
,
"
unknown
"
:
0
,
"
internal_jio_error
"
:
550
,
"
internal_jio_error
"
:
550
,
"
internal_storage_error
"
:
551
,
"
internal_storage_error
"
:
551
,
"
cancelled
"
:
555
,
"
200
"
:
200
,
"
200
"
:
200
,
"
201
"
:
201
,
"
201
"
:
201
,
...
@@ -250,12 +256,15 @@ constants.http_action = {
...
@@ -250,12 +256,15 @@ constants.http_action = {
"
0
"
:
"
error
"
,
"
0
"
:
"
error
"
,
"
550
"
:
"
error
"
,
"
550
"
:
"
error
"
,
"
551
"
:
"
error
"
,
"
551
"
:
"
error
"
,
"
555
"
:
"
error
"
,
"
Unknown
"
:
"
error
"
,
"
Unknown
"
:
"
error
"
,
"
Internal JIO Error
"
:
"
error
"
,
"
Internal JIO Error
"
:
"
error
"
,
"
Internal Storage Error
"
:
"
error
"
,
"
Internal Storage Error
"
:
"
error
"
,
"
Cancelled
"
:
"
error
"
,
"
unknown
"
:
"
error
"
,
"
unknown
"
:
"
error
"
,
"
internal_jio_error
"
:
"
error
"
,
"
internal_jio_error
"
:
"
error
"
,
"
internal_storage_error
"
:
"
error
"
,
"
internal_storage_error
"
:
"
error
"
,
"
cancelled
"
:
"
error
"
,
"
200
"
:
"
success
"
,
"
200
"
:
"
success
"
,
"
201
"
:
"
success
"
,
"
201
"
:
"
success
"
,
...
...
src/jio/features/jobMaker.js
View file @
6b4c1794
...
@@ -58,6 +58,13 @@ function enableJobMaker(jio, shared, options) {
...
@@ -58,6 +58,13 @@ function enableJobMaker(jio, shared, options) {
job
.
command
.
storage
=
function
()
{
job
.
command
.
storage
=
function
()
{
return
shared
.
createRestApi
.
apply
(
null
,
arguments
);
return
shared
.
createRestApi
.
apply
(
null
,
arguments
);
};
};
job
.
command
.
setCanceller
=
function
(
canceller
)
{
job
.
cancellers
[
"
command:canceller
"
]
=
canceller
;
};
job
.
cancellers
=
job
.
cancellers
||
{};
job
.
cancellers
[
"
job:canceller
"
]
=
function
()
{
shared
.
emit
(
"
job:reject
"
,
job
,
[
"
cancelled
"
]);
};
}
}
function
createJobFromRest
(
param
)
{
function
createJobFromRest
(
param
)
{
...
...
src/jio/features/restApi.js
View file @
6b4c1794
...
@@ -61,6 +61,7 @@ function enableRestAPI(jio, shared) { // (jio, shared, options)
...
@@ -61,6 +61,7 @@ function enableRestAPI(jio, shared) { // (jio, shared, options)
param
.
solver
.
reject
=
reject
;
param
.
solver
.
reject
=
reject
;
param
.
solver
.
notify
=
notify
;
param
.
solver
.
notify
=
notify
;
},
function
()
{
},
function
()
{
if
(
!
param
.
cancellers
)
{
return
;
}
var
k
;
var
k
;
for
(
k
in
param
.
cancellers
)
{
for
(
k
in
param
.
cancellers
)
{
if
(
param
.
cancellers
.
hasOwnProperty
(
k
))
{
if
(
param
.
cancellers
.
hasOwnProperty
(
k
))
{
...
...
test/jio/fakestorage.js
View file @
6b4c1794
...
@@ -66,6 +66,9 @@
...
@@ -66,6 +66,9 @@
},
},
free
:
function
()
{
free
:
function
()
{
delete
fakestorage
[
that
.
_id
+
'
/
'
+
method
];
delete
fakestorage
[
that
.
_id
+
'
/
'
+
method
];
},
setCanceller
:
function
()
{
return
command
.
setCanceller
.
apply
(
command
,
arguments
);
}
}
};
};
};
};
...
...
test/jio/tests.js
View file @
6b4c1794
/*jslint indent: 2, maxlen: 80, nomen: true */
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global define, window, exports, require, jIO, fake_storage, ok, module, test,
/*global define, window, exports, require, jIO, fake_storage, ok, module, test,
stop, start, deepEqual, FileReader, Blob, setTimeout, clearTimeout,
stop, start, deepEqual, FileReader, Blob, setTimeout, clearTimeout,
localStorage */
localStorage
, test_util
*/
(
function
(
dependencies
,
module
)
{
(
function
(
dependencies
,
factory
)
{
"
use strict
"
;
"
use strict
"
;
if
(
typeof
define
===
'
function
'
&&
define
.
amd
)
{
if
(
typeof
define
===
"
function
"
&&
define
.
amd
)
{
return
define
(
dependencies
,
module
);
return
define
(
dependencies
,
factory
);
}
}
if
(
typeof
exports
===
'
object
'
)
{
if
(
typeof
module
===
"
object
"
&&
module
!==
null
&&
return
module
(
require
(
'
fakestorage
'
),
require
(
'
jio
'
));
typeof
module
.
exports
===
"
object
"
&&
module
.
exports
!==
null
&&
typeof
require
===
"
function
"
)
{
return
factory
(
dependencies
.
map
(
require
));
}
}
module
(
fake_storage
,
jIO
);
factory
(
fake_storage
,
jIO
,
test_util
);
}([
'
fakestorage
'
,
'
jio
'
,
'
sinon_qunit
'
],
function
(
fake_storage
,
jIO
)
{
}([
'
fakestorage
'
,
'
jio
'
,
'
test_util
'
,
'
sinon_qunit
'
],
function
(
fake_storage
,
jIO
,
util
)
{
"
use strict
"
;
"
use strict
"
;
var
test_name
,
JIO
=
jIO
.
JIO
,
commands
=
fake_storage
.
commands
;
var
test_name
,
JIO
=
jIO
.
JIO
,
commands
=
fake_storage
.
commands
;
...
@@ -353,6 +360,40 @@
...
@@ -353,6 +360,40 @@
},
50
);
},
50
);
});
});
test
(
'
should be cancelled
'
,
1
,
function
()
{
var
time_array
=
[],
put_promise
,
start
=
util
.
starter
(
1000
),
jio
=
new
JIO
({
"
type
"
:
"
fake
"
,
"
id
"
:
"
Cancel Err
"
},
{
"
workspace
"
:
{}
});
stop
();
put_promise
=
jio
.
put
({
"
_id
"
:
"
a
"
});
put_promise
.
then
(
start
,
function
(
answer
)
{
time_array
.
push
(
answer
);
deepEqual
(
time_array
,
[
"
cancelled
"
,
{
"
error
"
:
"
cancelled
"
,
"
id
"
:
"
a
"
,
"
message
"
:
"
Command failed
"
,
"
method
"
:
"
put
"
,
"
reason
"
:
"
unknown
"
,
"
result
"
:
"
error
"
,
"
status
"
:
555
,
"
statusText
"
:
"
Cancelled
"
}]);
start
();
});
setTimeout
(
function
()
{
commands
[
'
Cancel Err/put
'
].
setCanceller
(
function
()
{
time_array
.
push
(
"
cancelled
"
);
});
put_promise
.
cancel
();
},
50
);
});
module
(
'
JIO parameters
'
);
module
(
'
JIO parameters
'
);
test
(
'
should throw error when giving no parameter to `post`
'
,
1
,
function
()
{
test
(
'
should throw error when giving no parameter to `post`
'
,
1
,
function
()
{
...
...
test/jio/util.js
View file @
6b4c1794
/*jslint indent: 2, maxlen: 80 */
/*jslint indent: 2, maxlen: 80 */
/*global define, exports, window, require, localStorage, start, ok, deepEqual,
/*global define, exports, window, require, localStorage, start, ok, deepEqual,
sinon */
sinon
, setTimeout, clearTimeout
*/
(
function
(
dependencies
,
module
)
{
(
function
(
dependencies
,
module
)
{
"
use strict
"
;
"
use strict
"
;
...
@@ -20,6 +20,28 @@
...
@@ -20,6 +20,28 @@
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// Tools
// Tools
/**
* Creates a QUnit.start wrapper that allows to trigger start several times.
*
* @param {Number} num Timeout in ms
* @return {Function} The wrapper
*/
function
starter
(
num
)
{
var
started
=
false
,
ident
;
function
startFn
()
{
if
(
!
started
)
{
started
=
true
;
clearTimeout
(
ident
);
start
();
}
}
if
(
num
)
{
ident
=
setTimeout
(
startFn
,
num
);
}
return
startFn
;
}
exports
.
starter
=
starter
;
/**
/**
* Test if the string is an Uuid
* Test if the string is an Uuid
*
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment