Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Mukul
jio
Commits
3c3d9a39
Commit
3c3d9a39
authored
Apr 30, 2015
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ReplicateStorage: allow to sync only some documents.
Definition is done by a jIO.allDocs query
parent
7e85fd8e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
129 additions
and
5 deletions
+129
-5
src/jio.storage/replicatestorage.js
src/jio.storage/replicatestorage.js
+5
-2
test/jio.storage/replicatestorage.tests.js
test/jio.storage/replicatestorage.tests.js
+124
-3
No files found.
src/jio.storage/replicatestorage.js
View file @
3c3d9a39
...
...
@@ -36,12 +36,15 @@
}
function
ReplicateStorage
(
spec
)
{
this
.
_query_options
=
spec
.
query
||
{};
this
.
_local_sub_storage
=
jIO
.
createJIO
(
spec
.
local_sub_storage
);
this
.
_remote_sub_storage
=
jIO
.
createJIO
(
spec
.
remote_sub_storage
);
this
.
_signature_hash
=
"
_replicate_
"
+
generateHash
(
JSON
.
stringify
(
spec
.
local_sub_storage
)
+
JSON
.
stringify
(
spec
.
remote_sub_storage
)
JSON
.
stringify
(
spec
.
remote_sub_storage
)
+
JSON
.
stringify
(
this
.
_query_options
)
);
this
.
_signature_sub_storage
=
jIO
.
createJIO
({
type
:
"
document
"
,
...
...
@@ -236,7 +239,7 @@
return
queue
.
push
(
function
()
{
return
RSVP
.
all
([
source
.
allDocs
(),
source
.
allDocs
(
context
.
_query_options
),
context
.
_signature_sub_storage
.
allDocs
()
]);
})
...
...
test/jio.storage/replicatestorage.tests.js
View file @
3c3d9a39
...
...
@@ -44,8 +44,10 @@
ok
(
jio
.
__storage
.
_remote_sub_storage
instanceof
jio
.
constructor
);
equal
(
jio
.
__storage
.
_remote_sub_storage
.
__type
,
"
replicatestorage500
"
);
deepEqual
(
jio
.
__storage
.
_query_options
,
{});
equal
(
jio
.
__storage
.
_signature_hash
,
"
_replicate_7
b54b9b5183574854e5870beb19b15152a36ef4e
"
);
"
_replicate_7
209dfbcaff00f6637f939fdd71fa896793ed385
"
);
ok
(
jio
.
__storage
.
_signature_sub_storage
instanceof
jio
.
constructor
);
equal
(
jio
.
__storage
.
_signature_sub_storage
.
__type
,
"
document
"
);
...
...
@@ -60,6 +62,27 @@
});
test
(
"
accept query
"
,
function
()
{
var
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
local_sub_storage
:
{
type
:
"
replicatestorage200
"
},
remote_sub_storage
:
{
type
:
"
replicatestorage500
"
},
query
:
{
query
:
'
portal_type: "Foo"
'
,
limit
:
[
0
,
1234567890
]}
});
deepEqual
(
jio
.
__storage
.
_query_options
,
{
query
:
'
portal_type: "Foo"
'
,
limit
:
[
0
,
1234567890
]}
);
equal
(
jio
.
__storage
.
_signature_hash
,
"
_replicate_623653d45a4e770a2c9f6b71e3144d18ee1b5bec
"
);
});
/////////////////////////////////////////////////////////////////
// replicateStorage.get
/////////////////////////////////////////////////////////////////
...
...
@@ -994,7 +1017,7 @@
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
"
Cannot find document:
"
+
"
_replicate_
2be6c0851d60bcd9afe829e7133a136d266c779c
"
);
"
_replicate_
e0cd4a29dc7c74a9de1d7a9cdbfcbaa776863d67
"
);
equal
(
error
.
status_code
,
404
);
})
.
then
(
function
()
{
...
...
@@ -1008,7 +1031,7 @@
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
"
Cannot find document:
"
+
"
_replicate_
2be6c0851d60bcd9afe829e7133a136d266c779c
"
);
"
_replicate_
e0cd4a29dc7c74a9de1d7a9cdbfcbaa776863d67
"
);
equal
(
error
.
status_code
,
404
);
})
.
fail
(
function
(
error
)
{
...
...
@@ -1088,4 +1111,102 @@
});
});
test
(
"
sync all documents by default
"
,
function
()
{
stop
();
expect
(
5
);
var
context
=
this
;
function
Storage200DefaultQuery
()
{
return
this
;
}
Storage200DefaultQuery
.
prototype
.
get
=
function
()
{
ok
(
true
,
"
get 200 check repair called
"
);
return
{};
};
Storage200DefaultQuery
.
prototype
.
hasCapacity
=
function
()
{
return
true
;
};
Storage200DefaultQuery
.
prototype
.
buildQuery
=
function
(
query
)
{
deepEqual
(
query
,
{});
return
[];
};
Storage200DefaultQuery
.
prototype
.
allAttachments
=
function
()
{
ok
(
true
,
"
allAttachments 200 check repair called
"
);
return
{};
};
jIO
.
addStorage
(
'
replicatestorage200defaultquery
'
,
Storage200DefaultQuery
);
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
local_sub_storage
:
{
type
:
"
replicatestorage200defaultquery
"
},
remote_sub_storage
:
{
type
:
"
replicatestorage200defaultquery
"
}
});
return
context
.
jio
.
repair
()
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
sync can be restricted to some documents
"
,
function
()
{
stop
();
expect
(
5
);
var
context
=
this
,
query
=
{
query
:
'
portal_type: "Foo"
'
,
limit
:
[
0
,
1234567890
]};
function
Storage200CustomQuery
()
{
return
this
;
}
Storage200CustomQuery
.
prototype
.
get
=
function
()
{
ok
(
true
,
"
get 200 check repair called
"
);
return
{};
};
Storage200CustomQuery
.
prototype
.
hasCapacity
=
function
()
{
return
true
;
};
Storage200CustomQuery
.
prototype
.
buildQuery
=
function
(
options
)
{
deepEqual
(
options
,
query
);
return
[];
};
Storage200CustomQuery
.
prototype
.
allAttachments
=
function
()
{
ok
(
true
,
"
allAttachments 200 check repair called
"
);
return
{};
};
jIO
.
addStorage
(
'
replicatestorage200customquery
'
,
Storage200CustomQuery
);
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
local_sub_storage
:
{
type
:
"
replicatestorage200customquery
"
},
remote_sub_storage
:
{
type
:
"
replicatestorage200customquery
"
},
query
:
{
query
:
'
portal_type: "Foo"
'
,
limit
:
[
0
,
1234567890
]}
});
return
context
.
jio
.
repair
()
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
}(
jIO
,
QUnit
));
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