Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
officejs
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
nexedi
officejs
Commits
2722fe85
Commit
2722fe85
authored
Aug 14, 2012
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update ReplicateStorage and Jio tests
parent
bbf74f1f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
78 deletions
+71
-78
OfficeJS/src/jio.storage/replicatestorage.js
OfficeJS/src/jio.storage/replicatestorage.js
+38
-40
OfficeJS/test/jiotests.js
OfficeJS/test/jiotests.js
+33
-38
No files found.
OfficeJS/src/jio.storage/replicatestorage.js
View file @
2722fe85
...
@@ -20,84 +20,82 @@ var newReplicateStorage = function ( spec, my ) {
...
@@ -20,84 +20,82 @@ var newReplicateStorage = function ( spec, my ) {
return
''
;
return
''
;
};
};
priv
.
isTheLast
=
function
()
{
priv
.
isTheLast
=
function
(
error_array
)
{
return
(
priv
.
return_value
_array
.
length
===
priv
.
nb_storage
);
return
(
error
_array
.
length
===
priv
.
nb_storage
);
};
};
priv
.
doJob
=
function
(
command
,
errormessage
)
{
priv
.
doJob
=
function
(
command
,
errormessage
,
nodocid
)
{
var
done
=
false
,
error_array
=
[],
i
,
var
done
=
false
,
error_array
=
[],
i
,
onErrorDo
=
function
(
result
)
{
error
=
function
(
err
)
{
priv
.
return_value_array
.
push
(
result
);
if
(
!
done
)
{
if
(
!
done
)
{
error_array
.
push
(
result
);
error_array
.
push
(
err
);
if
(
priv
.
isTheLast
())
{
if
(
priv
.
isTheLast
(
error_array
))
{
that
.
error
(
that
.
error
(
{
{
status
:
207
,
status
:
207
,
statusText
:
'
Multi-Status
'
,
statusText
:
'
Multi-Status
'
,
message
:
errormessage
,
error
:
'
multi_status
'
,
array
:
error_array
});
message
:
'
All
'
+
errormessage
+
(
!
nodocid
?
'
"
'
+
command
.
getDocId
()
+
'
"
'
:
'
'
)
+
'
requests have failed.
'
,
reason
:
'
requests fail
'
,
array
:
error_array
});
}
}
}
}
},
},
onSuccessDo
=
function
(
result
)
{
success
=
function
(
val
)
{
priv
.
return_value_array
.
push
(
result
);
if
(
!
done
)
{
if
(
!
done
)
{
done
=
true
;
done
=
true
;
that
.
success
(
result
);
that
.
success
(
val
);
}
}
};
};
for
(
i
=
0
;
i
<
priv
.
nb_storage
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
priv
.
nb_storage
;
i
+=
1
)
{
var
newcommand
=
command
.
clone
();
var
cloned_option
=
command
.
cloneOption
();
var
newstorage
=
that
.
newStorage
(
priv
.
storagelist
[
i
]);
that
.
addJob
(
command
.
getLabel
(),
priv
.
storagelist
[
i
],
newcommand
.
onErrorDo
(
onErrorDo
);
command
.
cloneDoc
(),
cloned_option
,
success
,
error
);
newcommand
.
onSuccessDo
(
onSuccessDo
);
that
.
addJob
(
newstorage
,
newcommand
);
}
}
};
};
that
.
post
=
function
(
command
)
{
priv
.
doJob
(
command
,
'
post
'
);
that
.
end
();
};
/**
/**
* Save a document in several storages.
* Save a document in several storages.
* @method
saveDocumen
t
* @method
pu
t
*/
*/
that
.
saveDocument
=
function
(
command
)
{
that
.
put
=
function
(
command
)
{
priv
.
doJob
(
priv
.
doJob
(
command
,
'
put
'
);
command
,
'
All save "
'
+
command
.
getPath
()
+
'
" requests have failed.
'
);
that
.
end
();
that
.
end
();
};
};
/**
/**
* Load a document from several storages, and send the first retreived
* Load a document from several storages, and send the first retreived
* document.
* document.
* @method
loadDocumen
t
* @method
ge
t
*/
*/
that
.
loadDocument
=
function
(
command
)
{
that
.
get
=
function
(
command
)
{
priv
.
doJob
(
priv
.
doJob
(
command
,
'
get
'
);
command
,
'
All load "
'
+
command
.
getPath
()
+
'
" requests have failed.
'
);
that
.
end
();
that
.
end
();
};
};
/**
/**
* Get a document list from several storages, and returns the first
* Get a document list from several storages, and returns the first
* retreived document list.
* retreived document list.
* @method
getDocumentList
* @method
allDocs
*/
*/
that
.
getDocumentList
=
function
(
command
)
{
that
.
allDocs
=
function
(
command
)
{
priv
.
doJob
(
priv
.
doJob
(
command
,
'
allDocs
'
,
true
);
command
,
'
All get document list requests have failed.
'
);
that
.
end
();
that
.
end
();
};
};
/**
/**
* Remove a document from several storages.
* Remove a document from several storages.
* @method remove
Document
* @method remove
*/
*/
that
.
removeDocument
=
function
(
command
)
{
that
.
remove
=
function
(
command
)
{
priv
.
doJob
(
priv
.
doJob
(
command
,
'
remove
'
);
command
,
'
All remove "
'
+
command
.
getPath
()
+
'
" requests have failed.
'
);
that
.
end
();
that
.
end
();
};
};
...
...
OfficeJS/test/jiotests.js
View file @
2722fe85
...
@@ -873,17 +873,17 @@ test ('Document load', function () {
...
@@ -873,17 +873,17 @@ test ('Document load', function () {
var
o
=
{};
o
.
clock
=
this
.
sandbox
.
useFakeTimers
();
o
.
t
=
this
;
var
o
=
{};
o
.
clock
=
this
.
sandbox
.
useFakeTimers
();
o
.
t
=
this
;
o
.
clock
.
tick
(
base_tick
);
o
.
clock
.
tick
(
base_tick
);
o
.
mytest
=
function
(
message
,
doc
,
doc2
)
{
o
.
mytest
=
function
(
message
,
doc
,
doc2
)
{
o
.
f
=
function
(
result
)
{
o
.
f
=
function
(
err
,
val
)
{
var
gooddoc
=
doc
;
var
gooddoc
=
doc
;
if
(
result
&&
!
result
.
status
)
{
if
(
val
)
{
if
(
doc2
&&
result
.
content
===
doc2
.
content
)
{
if
(
doc2
&&
val
.
content
===
doc2
.
content
)
{
gooddoc
=
doc2
;
gooddoc
=
doc2
;
}
}
}
}
deepEqual
(
result
,
gooddoc
,
message
);
deepEqual
(
err
||
val
,
gooddoc
,
message
);
};
};
o
.
t
.
spy
(
o
,
'
f
'
);
o
.
t
.
spy
(
o
,
'
f
'
);
o
.
jio
.
loadDocument
(
'
file
'
,{
success
:
o
.
f
,
error
:
o
.
f
,
max_retry
:
3
}
);
o
.
jio
.
get
(
'
file
'
,{
max_retry
:
3
},
o
.
f
);
o
.
clock
.
tick
(
10000
);
o
.
clock
.
tick
(
10000
);
if
(
!
o
.
f
.
calledOnce
)
{
if
(
!
o
.
f
.
calledOnce
)
{
if
(
o
.
f
.
called
)
{
if
(
o
.
f
.
called
)
{
...
@@ -897,9 +897,10 @@ test ('Document load', function () {
...
@@ -897,9 +897,10 @@ test ('Document load', function () {
{
type
:
'
dummyallok
'
,
username
:
'
1
'
},
{
type
:
'
dummyallok
'
,
username
:
'
1
'
},
{
type
:
'
dummyallok
'
,
username
:
'
2
'
}]});
{
type
:
'
dummyallok
'
,
username
:
'
2
'
}]});
o
.
mytest
(
'
DummyStorageAllOK,OK: load same file
'
,{
o
.
mytest
(
'
DummyStorageAllOK,OK: load same file
'
,{
name
:
'
file
'
,
content
:
'
content
'
,
_id
:
'
file
'
,
content
:
'
content
'
,
last_modified
:
15000
,
_last_modified
:
15000
,
creation_date
:
10000
});
_creation_date
:
10000
});
o
.
jio
.
stop
();
o
.
jio
.
stop
();
o
.
jio
=
JIO
.
newJio
({
type
:
'
replicate
'
,
storagelist
:[
o
.
jio
=
JIO
.
newJio
({
type
:
'
replicate
'
,
storagelist
:[
...
@@ -907,13 +908,12 @@ test ('Document load', function () {
...
@@ -907,13 +908,12 @@ test ('Document load', function () {
{
type
:
'
dummyallok
'
}]});
{
type
:
'
dummyallok
'
}]});
o
.
mytest
(
'
DummyStorageAllOK,3tries: load 2 different files
'
,
o
.
mytest
(
'
DummyStorageAllOK,3tries: load 2 different files
'
,
{
{
name
:
'
file
'
,
content
:
'
content
'
,
_id
:
'
file
'
,
content
:
'
content
'
,
last_modified
:
15000
,
creation_date
:
10000
_last_modified
:
15000
,
_
creation_date
:
10000
},{
},{
name
:
'
file
'
,
content
:
'
content2
'
,
_id
:
'
file
'
,
content
:
'
content file
'
,
last_modified
:
17000
,
creation_date
:
11000
_last_modified
:
17000
,
_
creation_date
:
11000
});
});
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
});
...
@@ -923,17 +923,14 @@ test ('Document save', function () {
...
@@ -923,17 +923,14 @@ test ('Document save', function () {
var
o
=
{};
o
.
clock
=
this
.
sandbox
.
useFakeTimers
();
o
.
t
=
this
;
var
o
=
{};
o
.
clock
=
this
.
sandbox
.
useFakeTimers
();
o
.
t
=
this
;
o
.
clock
.
tick
(
base_tick
);
o
.
clock
.
tick
(
base_tick
);
o
.
mytest
=
function
(
message
,
value
)
{
o
.
mytest
=
function
(
message
,
value
)
{
o
.
f
=
function
(
result
)
{
o
.
f
=
function
(
err
,
val
)
{
if
(
!
result
)
{
if
(
err
)
{
result
=
'
done
'
;
err
=
err
.
status
;
}
else
{
result
=
'
fail
'
;
}
}
deepEqual
(
result
,
value
,
message
);
deepEqual
(
err
||
val
,
value
,
message
);
};
};
o
.
t
.
spy
(
o
,
'
f
'
);
o
.
t
.
spy
(
o
,
'
f
'
);
o
.
jio
.
saveDocument
(
'
file
'
,
'
content
'
,{
o
.
jio
.
put
({
_id
:
'
file
'
,
content
:
'
content
'
},{
max_retry
:
3
},
o
.
f
);
success
:
o
.
f
,
error
:
o
.
f
,
max_retry
:
3
});
o
.
clock
.
tick
(
500
);
o
.
clock
.
tick
(
500
);
if
(
!
o
.
f
.
calledOnce
)
{
if
(
!
o
.
f
.
calledOnce
)
{
if
(
o
.
f
.
called
)
{
if
(
o
.
f
.
called
)
{
...
@@ -946,13 +943,13 @@ test ('Document save', function () {
...
@@ -946,13 +943,13 @@ test ('Document save', function () {
o
.
jio
=
JIO
.
newJio
({
type
:
'
replicate
'
,
storagelist
:[
o
.
jio
=
JIO
.
newJio
({
type
:
'
replicate
'
,
storagelist
:[
{
type
:
'
dummyallok
'
,
username
:
'
1
'
},
{
type
:
'
dummyallok
'
,
username
:
'
1
'
},
{
type
:
'
dummyallok
'
,
username
:
'
2
'
}]});
{
type
:
'
dummyallok
'
,
username
:
'
2
'
}]});
o
.
mytest
(
'
DummyStorageAllOK,OK: save a file.
'
,
'
done
'
);
o
.
mytest
(
'
DummyStorageAllOK,OK: save a file.
'
,
{
ok
:
true
,
id
:
'
file
'
}
);
o
.
jio
.
stop
();
o
.
jio
.
stop
();
o
.
jio
=
JIO
.
newJio
({
type
:
'
replicate
'
,
storagelist
:[
o
.
jio
=
JIO
.
newJio
({
type
:
'
replicate
'
,
storagelist
:[
{
type
:
'
dummyall3tries
'
,
username
:
'
1
'
},
{
type
:
'
dummyall3tries
'
,
username
:
'
1
'
},
{
type
:
'
dummyallok
'
,
username
:
'
2
'
}]});
{
type
:
'
dummyallok
'
,
username
:
'
2
'
}]});
o
.
mytest
(
'
DummyStorageAll3Tries,OK: save a file.
'
,
'
done
'
);
o
.
mytest
(
'
DummyStorageAll3Tries,OK: save a file.
'
,
{
ok
:
true
,
id
:
'
file
'
}
);
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
});
...
@@ -962,12 +959,12 @@ test ('Get Document List', function () {
...
@@ -962,12 +959,12 @@ test ('Get Document List', function () {
var
o
=
{};
o
.
clock
=
this
.
sandbox
.
useFakeTimers
();
o
.
t
=
this
;
var
o
=
{};
o
.
clock
=
this
.
sandbox
.
useFakeTimers
();
o
.
t
=
this
;
o
.
clock
.
tick
(
base_tick
);
o
.
clock
.
tick
(
base_tick
);
o
.
mytest
=
function
(
message
,
value
)
{
o
.
mytest
=
function
(
message
,
value
)
{
o
.
f
=
function
(
result
)
{
o
.
f
=
function
(
err
,
val
)
{
deepEqual
(
objectifyDocumentArray
(
result
),
deepEqual
(
err
||
objectifyDocumentArray
(
val
.
rows
),
objectifyDocumentArray
(
value
),
message
);
objectifyDocumentArray
(
value
),
message
);
};
};
o
.
t
.
spy
(
o
,
'
f
'
);
o
.
t
.
spy
(
o
,
'
f
'
);
o
.
jio
.
getDocumentList
(
'
.
'
,{
success
:
o
.
f
,
error
:
o
.
f
,
max_retry
:
3
}
);
o
.
jio
.
allDocs
({
max_retry
:
3
},
o
.
f
);
o
.
clock
.
tick
(
10000
);
o
.
clock
.
tick
(
10000
);
if
(
!
o
.
f
.
calledOnce
)
{
if
(
!
o
.
f
.
calledOnce
)
{
if
(
o
.
f
.
called
)
{
if
(
o
.
f
.
called
)
{
...
@@ -980,10 +977,10 @@ test ('Get Document List', function () {
...
@@ -980,10 +977,10 @@ test ('Get Document List', function () {
o
.
jio
=
JIO
.
newJio
({
type
:
'
replicate
'
,
storagelist
:[
o
.
jio
=
JIO
.
newJio
({
type
:
'
replicate
'
,
storagelist
:[
{
type
:
'
dummyall3tries
'
,
username
:
'
1
'
},
{
type
:
'
dummyall3tries
'
,
username
:
'
1
'
},
{
type
:
'
dummyallok
'
,
username
:
'
2
'
}]});
{
type
:
'
dummyallok
'
,
username
:
'
2
'
}]});
o
.
doc1
=
{
name
:
'
file
'
,
o
.
doc1
=
{
id
:
'
file
'
,
key
:
'
file
'
,
value
:{
last_modified
:
15000
,
creation_date
:
10000
};
_last_modified
:
15000
,
_creation_date
:
10000
}
};
o
.
doc2
=
{
name
:
'
memo
'
,
o
.
doc2
=
{
id
:
'
memo
'
,
key
:
'
memo
'
,
value
:{
last_modified
:
25000
,
creation_date
:
20000
};
_last_modified
:
25000
,
_creation_date
:
20000
}
};
o
.
mytest
(
'
DummyStorageAllOK,3tries: get document list.
'
,
o
.
mytest
(
'
DummyStorageAllOK,3tries: get document list.
'
,
[
o
.
doc1
,
o
.
doc2
]);
[
o
.
doc1
,
o
.
doc2
]);
o
.
jio
.
stop
();
o
.
jio
.
stop
();
...
@@ -1002,16 +999,14 @@ test ('Remove document', function () {
...
@@ -1002,16 +999,14 @@ test ('Remove document', function () {
var
o
=
{};
o
.
clock
=
this
.
sandbox
.
useFakeTimers
();
o
.
t
=
this
;
var
o
=
{};
o
.
clock
=
this
.
sandbox
.
useFakeTimers
();
o
.
t
=
this
;
o
.
clock
.
tick
(
base_tick
);
o
.
clock
.
tick
(
base_tick
);
o
.
mytest
=
function
(
message
,
value
)
{
o
.
mytest
=
function
(
message
,
value
)
{
o
.
f
=
function
(
result
)
{
o
.
f
=
function
(
err
,
val
)
{
if
(
!
result
)
{
if
(
err
)
{
result
=
'
done
'
;
err
=
err
.
status
;
}
else
{
result
=
'
fail
'
;
}
}
deepEqual
(
result
,
value
,
message
);
deepEqual
(
err
||
val
,
value
,
message
);
};
};
o
.
t
.
spy
(
o
,
'
f
'
);
o
.
t
.
spy
(
o
,
'
f
'
);
o
.
jio
.
remove
Document
(
'
file
'
,{
success
:
o
.
f
,
error
:
o
.
f
,
max_retry
:
3
}
);
o
.
jio
.
remove
({
_id
:
'
file
'
},{
max_retry
:
3
},
o
.
f
);
o
.
clock
.
tick
(
10000
);
o
.
clock
.
tick
(
10000
);
if
(
!
o
.
f
.
calledOnce
)
{
if
(
!
o
.
f
.
calledOnce
)
{
if
(
o
.
f
.
called
)
{
if
(
o
.
f
.
called
)
{
...
@@ -1024,7 +1019,7 @@ test ('Remove document', function () {
...
@@ -1024,7 +1019,7 @@ test ('Remove document', function () {
o
.
jio
=
JIO
.
newJio
({
type
:
'
replicate
'
,
storagelist
:[
o
.
jio
=
JIO
.
newJio
({
type
:
'
replicate
'
,
storagelist
:[
{
type
:
'
dummyallok
'
,
username
:
'
1
'
},
{
type
:
'
dummyallok
'
,
username
:
'
1
'
},
{
type
:
'
dummyall3tries
'
,
username
:
'
2
'
}]});
{
type
:
'
dummyall3tries
'
,
username
:
'
2
'
}]});
o
.
mytest
(
'
DummyStorageAllOK,3tries: remove document.
'
,
'
done
'
);
o
.
mytest
(
'
DummyStorageAllOK,3tries: remove document.
'
,
{
ok
:
true
,
id
:
'
file
'
}
);
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
});
...
...
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