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
2f914bc0
Commit
2f914bc0
authored
Dec 27, 2012
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dummystorages updated
parent
dec4d34f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
238 additions
and
131 deletions
+238
-131
src/jio.dummystorages.js
src/jio.dummystorages.js
+238
-131
No files found.
src/jio.dummystorages.js
View file @
2f914bc0
// Adds
3
dummy storages to JIO
// Adds
5
dummy storages to JIO
// type:
// type:
// - dummyallok
// - dummyallok
// - dummyallfail
// - dummyallfail
// - dummyallnotfound
// - dummyallnotfound
// - dummyall3tries
// - dummyall3tries
// - dummyalldocs
(
function
()
{
var
jioDummyStorageLoader
=
function
(
jIO
)
{
(
function
()
{
var
jioDummyStorageLoader
=
function
(
jIO
)
{
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
...
@@ -11,64 +12,24 @@
...
@@ -11,64 +12,24 @@
var
newDummyStorageAllOk
=
function
(
spec
,
my
)
{
var
newDummyStorageAllOk
=
function
(
spec
,
my
)
{
var
that
=
my
.
basicStorage
(
spec
,
my
);
var
that
=
my
.
basicStorage
(
spec
,
my
);
var
super_serialized
=
that
.
serialized
;
that
.
specToStore
=
function
()
{
that
.
serialized
=
function
()
{
return
{
"
username
"
:
spec
.
username
};
var
o
=
super_serialized
();
o
.
username
=
spec
.
username
;
return
o
;
};
};
// Fake revisions
var
fakeCount
=
0
;
var
generateRevision
=
function
(
command
,
action
,
reset
){
var
that
=
{},
priv
=
{},
fakeRevision
=
""
,
fakeCount
=
reset
===
true
?
0
:
fakeCount
,
now
=
Date
.
now
();
that
.
makeHash
=
function
(){
return
that
.
hashCode
(
''
+
command
.
getDocId
()
+
'
'
+
now
+
''
);
};
that
.
hashCode
=
function
(
string
)
{
return
hex_sha256
(
string
);
};
that
.
generateNextRev
=
function
(
previous_revision
,
string
)
{
return
(
parseInt
(
previous_revision
.
split
(
'
-
'
)[
0
],
10
)
+
1
)
+
'
-
'
+
priv
.
hashCode
(
previous_revision
+
string
);
};
if
(
fakeRevision
===
""
&&
fakeCount
===
0
){
fakeRevision
=
'
1-
'
+
that
.
makeHash
();
}
else
{
if
(
action
!==
"
post
"
){
fakeRevision
=
that
.
generateNextRev
(
fakeRev
,
that
.
makeHash
);
}
}
return
fakeRevision
;
};
that
.
post
=
function
(
command
)
{
that
.
post
=
function
(
command
)
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
that
.
success
({
that
.
success
({
ok
:
true
,
"
ok
"
:
true
,
id
:
command
.
getDocId
(),
"
id
"
:
command
.
getDocId
()
rev
:
generateRevision
(
command
,
"
post
"
,
true
)
});
});
},
100
);
},
100
);
// 100 ms, for jiotests simple job waiting
};
// end post
};
// end post
that
.
put
=
function
(
command
)
{
that
.
put
=
function
(
command
)
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
that
.
success
({
that
.
success
({
ok
:
true
,
"
ok
"
:
true
,
id
:
command
.
getDocId
(),
"
id
"
:
command
.
getDocId
()
rev
:
generateRevision
(
command
,
"
put
"
,
true
)
});
});
},
100
);
// 100 ms, for jiotests simple job waiting
},
100
);
// 100 ms, for jiotests simple job waiting
};
// end put
};
// end put
...
@@ -76,49 +37,50 @@
...
@@ -76,49 +37,50 @@
that
.
putAttachment
=
function
(
command
)
{
that
.
putAttachment
=
function
(
command
)
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
that
.
success
({
that
.
success
({
ok
:
true
,
"
ok
"
:
true
,
id
:
command
.
getDocId
(),
"
id
"
:
command
.
getDocId
()
+
"
/
"
+
command
.
getAttachmentId
()
rev
:
generateRevision
(
command
,
"
putAttachment
"
,
true
)
});
});
},
100
);
// 100 ms, for jiotests simple job waiting
},
100
);
// 100 ms, for jiotests simple job waiting
};
// end putAttachment
};
// end putAttachment
that
.
get
=
function
(
command
)
{
that
.
get
=
function
(
command
)
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
if
(
command
.
getAttachmentId
())
{
return
that
.
success
(
'
0123456789
'
);
}
that
.
success
({
that
.
success
({
_id
:
command
.
getDocId
(),
"
_id
"
:
command
.
getDocId
(),
_rev
:
generateRevision
(
command
,
"
get
"
,
true
),
"
title
"
:
'
get_title
'
content
:
'
content
'
});
});
},
100
);
},
100
);
// 100 ms, for jiotests simple job waiting
};
// end get
// 100 ms, for jiotests simple job waiting
};
// end get
that
.
allDocs
=
function
(
command
)
{
that
.
allDocs
=
function
(
command
)
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
var
o
=
{
that
.
error
({
total_rows
:
2
,
"
status
"
:
405
,
rows
:
[{
"
statusText
"
:
"
Method Not Allowed
"
,
id
:
'
file
'
,
"
error
"
:
"
method_not_allowed
"
,
key
:
'
file
'
,
"
message
"
:
"
Your are not allowed to use this command
"
,
value
:
{
"
rev
"
:
generateRevision
(
command
,
"
allDocs
"
,
true
)}
"
reason
"
:
"
LocalStorage forbids AllDocs command executions
"
},{
});
id
:
'
memo
'
,
});
key
:
'
memo
'
,
value
:
{
"
rev
"
:
generateRevision
(
command
,
"
allDocs
"
,
true
)}
}]
};
that
.
success
(
o
);
},
100
);
};
// end allDocs
};
// end allDocs
that
.
remove
=
function
(
command
)
{
that
.
remove
=
function
(
command
)
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
that
.
success
({
if
(
command
.
getAttachmentId
())
{
ok
:
true
,
that
.
success
({
id
:
command
.
getDocId
(),
"
ok
"
:
true
,
rev
:
generateRevision
(
command
,
"
remove
"
,
true
)
"
id
"
:
command
.
getDocId
()
+
"
/
"
+
command
.
getAttachmentId
()
});
});
},
100
);
}
else
{
that
.
success
({
"
ok
"
:
true
,
"
id
"
:
command
.
getDocId
()
});
}
},
100
);
// 100 ms, for jiotests simple job waiting
};
// end remove
};
// end remove
return
that
;
return
that
;
...
@@ -137,7 +99,7 @@
...
@@ -137,7 +99,7 @@
error
:
'
unknown_error
'
,
error
:
'
unknown_error
'
,
message
:
'
Execution encountred an error.
'
,
message
:
'
Execution encountred an error.
'
,
reason
:
'
Execution encountred an error
'
});
reason
:
'
Execution encountred an error
'
});
});
}
,
100
);
};
};
that
.
post
=
function
(
command
)
{
that
.
post
=
function
(
command
)
{
...
@@ -148,12 +110,24 @@
...
@@ -148,12 +110,24 @@
priv
.
error
();
priv
.
error
();
};
// end put
};
// end put
that
.
putAttachment
=
function
(
command
)
{
priv
.
error
();
};
// end put
that
.
get
=
function
(
command
)
{
that
.
get
=
function
(
command
)
{
priv
.
error
();
priv
.
error
();
};
// end get
};
// end get
that
.
allDocs
=
function
(
command
)
{
that
.
allDocs
=
function
(
command
)
{
priv
.
error
();
setTimeout
(
function
()
{
that
.
error
({
"
status
"
:
405
,
"
statusText
"
:
"
Method Not Allowed
"
,
"
error
"
:
"
method_not_allowed
"
,
"
message
"
:
"
Your are not allowed to use this command
"
,
"
reason
"
:
"
LocalStorage forbids AllDocs command executions
"
});
});
};
// end allDocs
};
// end allDocs
that
.
remove
=
function
(
command
)
{
that
.
remove
=
function
(
command
)
{
...
@@ -172,8 +146,8 @@
...
@@ -172,8 +146,8 @@
that
.
post
=
function
(
command
)
{
that
.
post
=
function
(
command
)
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
that
.
success
({
that
.
success
({
ok
:
true
,
"
ok
"
:
true
,
id
:
command
.
getDocId
()
"
id
"
:
command
.
getDocId
()
});
});
},
100
);
},
100
);
};
// end post
};
// end post
...
@@ -181,37 +155,52 @@
...
@@ -181,37 +155,52 @@
that
.
put
=
function
(
command
)
{
that
.
put
=
function
(
command
)
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
that
.
success
({
that
.
success
({
ok
:
true
,
"
ok
"
:
true
,
id
:
command
.
getDocId
()
"
id
"
:
command
.
getDocId
()
});
},
100
);
};
// end put
that
.
putAttachment
=
function
(
command
)
{
setTimeout
(
function
()
{
that
.
success
({
"
ok
"
:
true
,
"
id
"
:
command
.
getDocId
()
+
"
/
"
+
command
.
getAttachmentId
()
});
});
},
100
);
},
100
);
};
// end put
};
// end put
that
.
get
=
function
(
command
)
{
that
.
get
=
function
(
command
)
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
that
.
error
({
status
:
404
,
statusText
:
'
Not Found
'
,
that
.
error
({
error
:
'
not_found
'
,
"
status
"
:
404
,
message
:
'
Document "
'
+
command
.
getDocId
()
+
"
statusText
"
:
"
Not Found
"
,
'
" not found.
'
,
"
error
"
:
"
not_found
"
,
reason
:
'
Document "
'
+
command
.
getDocId
()
+
"
message
"
:
"
Document '
"
+
command
.
getDocId
()
+
'
" not found
'
});
"
' not found
"
,
"
reason
"
:
"
Document '
"
+
command
.
getDocId
()
+
"
' does not exist
"
});
},
100
);
},
100
);
};
// end get
};
// end get
that
.
allDocs
=
function
(
command
)
{
that
.
allDocs
=
function
(
command
)
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
that
.
error
({
status
:
404
,
statusText
:
'
Not Found
'
,
that
.
error
({
error
:
'
not_found
'
,
"
status
"
:
405
,
message
:
'
User list not found.
'
,
"
statusText
"
:
"
Method Not Allowed
"
,
reason
:
'
User list not found
'
});
"
error
"
:
"
method_not_allowed
"
,
},
100
);
"
message
"
:
"
Your are not allowed to use this command
"
,
"
reason
"
:
"
LocalStorage forbids AllDocs command executions
"
});
});
};
// end allDocs
};
// end allDocs
that
.
remove
=
function
(
command
)
{
that
.
remove
=
function
(
command
)
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
that
.
success
({
that
.
success
({
ok
:
true
,
"
ok
"
:
true
,
id
:
command
.
getDocId
()
"
id
"
:
command
.
getDocId
()
});
});
},
100
);
},
100
);
};
// end remove
};
// end remove
...
@@ -226,15 +215,12 @@
...
@@ -226,15 +215,12 @@
newDummyStorageAll3Tries
=
function
(
spec
,
my
)
{
newDummyStorageAll3Tries
=
function
(
spec
,
my
)
{
var
that
=
my
.
basicStorage
(
spec
,
my
),
priv
=
{};
var
that
=
my
.
basicStorage
(
spec
,
my
),
priv
=
{};
// this s
erialized
method is used to make simple difference between
// this s
pecToStore
method is used to make simple difference between
// two dummyall3tries storages:
// two dummyall3tries storages:
// so {type:'dummyall3tries',a:'b'} differs from
// so {type:'dummyall3tries',a:'b'} differs from
// {type:'dummyall3tries',c:'d'}.
// {type:'dummyall3tries',c:'d'}.
var
super_serialized
=
that
.
serialized
;
that
.
specToStore
=
function
()
{
that
.
serialized
=
function
()
{
return
{
"
applicationname
"
:
spec
.
applicationname
};
var
o
=
super_serialized
();
o
.
applicationname
=
spec
.
applicationname
;
return
o
;
};
};
priv
.
doJob
=
function
(
command
,
if_ok_return
)
{
priv
.
doJob
=
function
(
command
,
if_ok_return
)
{
...
@@ -243,12 +229,16 @@
...
@@ -243,12 +229,16 @@
priv
.
Try3OKElseFail
(
command
.
getTried
(),
if_ok_return
);
priv
.
Try3OKElseFail
(
command
.
getTried
(),
if_ok_return
);
},
100
);
},
100
);
};
};
priv
.
Try3OKElseFail
=
function
(
tries
,
if_ok_return
)
{
priv
.
Try3OKElseFail
=
function
(
tries
,
if_ok_return
)
{
if
(
typeof
tries
===
'
undefined
'
)
{
if
(
typeof
tries
===
'
undefined
'
)
{
return
that
.
error
({
status
:
0
,
statusText
:
'
Unknown Error
'
,
return
that
.
error
({
error
:
'
unknown_error
'
,
"
status
"
:
0
,
message
:
'
Cannot get tried.
'
,
"
statusText
"
:
"
Unknown Error
"
,
reason
:
'
Cannot get tried
'
});
"
error
"
:
"
unknown_error
"
,
"
message
"
:
"
Cannot get tried
"
,
"
reason
"
:
"
Unknown
"
});
}
}
if
(
tries
<
3
)
{
if
(
tries
<
3
)
{
return
that
.
retry
(
return
that
.
retry
(
...
@@ -258,55 +248,171 @@
...
@@ -258,55 +248,171 @@
return
that
.
success
(
if_ok_return
);
return
that
.
success
(
if_ok_return
);
}
}
if
(
tries
>
3
)
{
if
(
tries
>
3
)
{
return
that
.
error
({
status
:
1
,
statusText
:
'
Too Much Tries
'
,
return
that
.
error
({
error
:
'
too_much_tries
'
,
"
status
"
:
1
,
message
:
'
Too much tries.
'
,
"
statusText
"
:
"
Too Much Tries
"
,
reason
:
'
Too much tries
'
});
"
error
"
:
"
too_much_tries
"
,
"
message
"
:
"
Too much tries
"
,
"
reason
"
:
"
Too much tries
"
});
}
}
};
};
that
.
post
=
function
(
command
)
{
that
.
post
=
function
(
command
)
{
priv
.
doJob
(
command
,{
ok
:
true
,
id
:
command
.
getDocId
()});
priv
.
doJob
(
command
,{
"
ok
"
:
true
,
"
id
"
:
command
.
getDocId
()});
};
// end post
};
// end post
that
.
put
=
function
(
command
)
{
that
.
put
=
function
(
command
)
{
priv
.
doJob
(
command
,{
ok
:
true
,
id
:
command
.
getDocId
()});
priv
.
doJob
(
command
,{
"
ok
"
:
true
,
"
id
"
:
command
.
getDocId
()});
};
// end put
};
// end put
that
.
ge
t
=
function
(
command
)
{
that
.
putAttachmen
t
=
function
(
command
)
{
priv
.
doJob
(
command
,{
priv
.
doJob
(
command
,{
_id
:
command
.
getDocId
(),
"
ok
"
:
true
,
content
:
'
content
'
+
command
.
getDocId
(),
"
id
"
:
command
.
getDocId
()
+
"
/
"
+
command
.
getAttachmentId
()
_creation_date
:
11000
,
_last_modified
:
17000
});
});
};
// end put
that
.
get
=
function
(
command
)
{
if
(
command
.
getAttachmentId
())
{
priv
.
doJob
(
command
,
"
0123456789
"
);
}
else
{
priv
.
doJob
(
command
,{
"
_id
"
:
command
.
getDocId
(),
"
title
"
:
'
Title of
'
+
command
.
getDocId
(),
});
}
};
// end get
};
// end get
that
.
allDocs
=
function
(
command
)
{
that
.
allDocs
=
function
(
command
)
{
priv
.
doJob
(
command
,{
setTimeout
(
function
()
{
total_rows
:
2
,
that
.
error
({
rows
:[{
"
status
"
:
405
,
id
:
'
file
'
,
key
:
'
file
'
,
"
statusText
"
:
"
Method Not Allowed
"
,
value
:{
"
error
"
:
"
method_not_allowed
"
,
_creation_date
:
10000
,
"
message
"
:
"
Your are not allowed to use this command
"
,
_last_modified
:
15000
"
reason
"
:
"
LocalStorage forbids AllDocs command executions
"
});
});
};
// end allDocs
that
.
remove
=
function
(
command
)
{
if
(
command
.
getAttachmentId
())
{
priv
.
doJob
(
command
,{
"
ok
"
:
true
,
"
id
"
:
command
.
getDocId
()
+
"
/
"
+
command
.
getAttachmentId
()
});
}
else
{
priv
.
doJob
(
command
,{
"
ok
"
:
true
,
"
id
"
:
command
.
getDocId
()});
}
};
// end remove
return
that
;
},
// end Dummy Storage All 3 Tries
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// Dummy Storage 5 : all docs
newDummyStorageAllDocs
=
function
(
spec
,
my
)
{
var
that
=
my
.
basicStorage
(
spec
,
my
);
that
.
specToStore
=
function
()
{
return
{
"
username
"
:
spec
.
username
};
};
that
.
post
=
function
(
command
)
{
setTimeout
(
function
()
{
that
.
success
({
"
ok
"
:
true
,
"
id
"
:
command
.
getDocId
()
});
},
100
);
// 100 ms, for jiotests simple job waiting
};
// end post
that
.
put
=
function
(
command
)
{
setTimeout
(
function
()
{
that
.
success
({
"
ok
"
:
true
,
"
id
"
:
command
.
getDocId
()
});
},
100
);
// 100 ms, for jiotests simple job waiting
};
// end put
that
.
putAttachment
=
function
(
command
)
{
setTimeout
(
function
()
{
that
.
success
({
"
ok
"
:
true
,
"
id
"
:
command
.
getDocId
()
+
"
/
"
+
command
.
getAttachmentId
()
});
},
100
);
// 100 ms, for jiotests simple job waiting
};
// end putAttachment
that
.
get
=
function
(
command
)
{
setTimeout
(
function
()
{
if
(
command
.
getAttachmentId
())
{
return
that
.
success
(
'
0123456789
'
);
}
that
.
success
({
"
_id
"
:
command
.
getDocId
(),
"
title
"
:
"
get_title
"
});
},
100
);
// 100 ms, for jiotests simple job waiting
};
// end get
that
.
allDocs
=
function
(
command
)
{
setTimeout
(
function
()
{
var
addRow
,
o
=
{
"
total_rows
"
:
0
,
"
rows
"
:
[]
};
addRow
=
function
(
id
,
key
,
doc
)
{
var
row
=
{
"
id
"
:
"
file
"
,
"
key
"
:
"
file
"
,
"
value
"
:
{}
};
if
(
command
.
getOption
(
"
include_docs
"
))
{
row
[
"
doc
"
]
=
doc
;
}
}
},{
o
.
rows
.
push
(
row
);
id
:
'
memo
'
,
key
:
'
memo
'
,
o
.
total_rows
+=
1
;
value
:{
};
_creation_date
:
20000
,
addRow
(
"
file
"
,
"
file
"
,
{
_last_modified
:
25000
"
_id
"
:
"
file
"
,
"
Title
"
:
"
myFile
"
,
});
addRow
(
"
mylongtitledfilethatidontliketowritebyhandonablackboard
"
,
"
mylongti.alias1
"
,
{
"
_id
"
:
"
mylongtitledfilethatidontliketowritebyhandonablackboard
"
,
"
Title
"
:
"
myLongFile
"
,
}
}
}]});
);
that
.
success
(
o
);
});
};
// end allDocs
};
// end allDocs
that
.
remove
=
function
(
command
)
{
that
.
remove
=
function
(
command
)
{
priv
.
doJob
(
command
,{
ok
:
true
,
id
:
command
.
getDocId
()});
setTimeout
(
function
()
{
if
(
command
.
getAttachmentId
())
{
that
.
success
({
"
ok
"
:
true
,
"
id
"
:
command
.
getDocId
()
+
"
/
"
+
command
.
getAttachmentId
()
});
}
else
{
that
.
success
({
"
ok
"
:
true
,
"
id
"
:
command
.
getDocId
()
});
}
},
100
);
// 100 ms, for jiotests simple job waiting
};
// end remove
};
// end remove
return
that
;
return
that
;
};
};
// end Dummy Storage All
3 Trie
s
// end Dummy Storage All
Doc
s
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// add key to storageObjectType of global jio
// add key to storageObjectType of global jio
...
@@ -314,6 +420,7 @@
...
@@ -314,6 +420,7 @@
jIO
.
addStorageType
(
'
dummyallfail
'
,
newDummyStorageAllFail
);
jIO
.
addStorageType
(
'
dummyallfail
'
,
newDummyStorageAllFail
);
jIO
.
addStorageType
(
'
dummyallnotfound
'
,
newDummyStorageAllNotFound
);
jIO
.
addStorageType
(
'
dummyallnotfound
'
,
newDummyStorageAllNotFound
);
jIO
.
addStorageType
(
'
dummyall3tries
'
,
newDummyStorageAll3Tries
);
jIO
.
addStorageType
(
'
dummyall3tries
'
,
newDummyStorageAll3Tries
);
jIO
.
addStorageType
(
'
dummyalldocs
'
,
newDummyStorageAllDocs
);
};
};
...
...
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