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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Vincent Bechu
jio
Commits
ab653402
Commit
ab653402
authored
Jan 06, 2017
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ReplicateStorage: fix unexpected error occuring in case of document not matching the query
parent
55c1be2e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
286 additions
and
8 deletions
+286
-8
src/jio.storage/replicatestorage.js
src/jio.storage/replicatestorage.js
+20
-8
test/jio.storage/replicatestorage.tests.js
test/jio.storage/replicatestorage.tests.js
+266
-0
No files found.
src/jio.storage/replicatestorage.js
View file @
ab653402
...
@@ -227,7 +227,8 @@
...
@@ -227,7 +227,8 @@
}
}
function
checkSignatureDifference
(
queue
,
source
,
destination
,
id
,
function
checkSignatureDifference
(
queue
,
source
,
destination
,
id
,
conflict_force
,
conflict_ignore
,
conflict_force
,
conflict_revert
,
conflict_ignore
,
is_creation
,
is_modification
,
is_creation
,
is_modification
,
getMethod
,
options
)
{
getMethod
,
options
)
{
queue
queue
...
@@ -273,7 +274,12 @@
...
@@ -273,7 +274,12 @@
if
(
conflict_ignore
===
true
)
{
if
(
conflict_ignore
===
true
)
{
return
;
return
;
}
}
if
(
conflict_force
!==
true
)
{
if
(
conflict_revert
===
true
)
{
return
propagateModification
(
destination
,
source
,
remote_doc
,
remote_hash
,
id
);
}
if
(
conflict_force
===
false
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Conflict on '
"
+
id
+
"
':
"
+
throw
new
jIO
.
util
.
jIOError
(
"
Conflict on '
"
+
id
+
"
':
"
+
stringify
(
doc
)
+
"
!==
"
+
stringify
(
doc
)
+
"
!==
"
+
stringify
(
remote_doc
),
stringify
(
remote_doc
),
...
@@ -307,7 +313,8 @@
...
@@ -307,7 +313,8 @@
function
checkBulkSignatureDifference
(
queue
,
source
,
destination
,
id_list
,
function
checkBulkSignatureDifference
(
queue
,
source
,
destination
,
id_list
,
document_status_list
,
options
,
document_status_list
,
options
,
conflict_force
,
conflict_ignore
)
{
conflict_force
,
conflict_revert
,
conflict_ignore
)
{
queue
queue
.
push
(
function
()
{
.
push
(
function
()
{
return
source
.
bulk
(
id_list
);
return
source
.
bulk
(
id_list
);
...
@@ -328,7 +335,8 @@
...
@@ -328,7 +335,8 @@
for
(
i
=
0
;
i
<
result_list
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
result_list
.
length
;
i
+=
1
)
{
checkSignatureDifference
(
sub_queue
,
source
,
destination
,
checkSignatureDifference
(
sub_queue
,
source
,
destination
,
id_list
[
i
].
parameter_list
[
0
],
id_list
[
i
].
parameter_list
[
0
],
conflict_force
,
conflict_ignore
,
conflict_force
,
conflict_revert
,
conflict_ignore
,
document_status_list
[
i
].
is_creation
,
document_status_list
[
i
].
is_creation
,
document_status_list
[
i
].
is_modification
,
document_status_list
[
i
].
is_modification
,
getResult
(
i
),
options
);
getResult
(
i
),
options
);
...
@@ -391,6 +399,7 @@
...
@@ -391,6 +399,7 @@
}
else
{
}
else
{
checkSignatureDifference
(
queue
,
source
,
destination
,
key
,
checkSignatureDifference
(
queue
,
source
,
destination
,
key
,
options
.
conflict_force
,
options
.
conflict_force
,
options
.
conflict_revert
,
options
.
conflict_ignore
,
options
.
conflict_ignore
,
is_creation
,
is_modification
,
is_creation
,
is_modification
,
source
.
get
.
bind
(
source
),
source
.
get
.
bind
(
source
),
...
@@ -413,6 +422,7 @@
...
@@ -413,6 +422,7 @@
document_list
,
document_status_list
,
document_list
,
document_status_list
,
options
,
options
,
options
.
conflict_force
,
options
.
conflict_force
,
options
.
conflict_revert
,
options
.
conflict_ignore
);
options
.
conflict_ignore
);
}
}
});
});
...
@@ -464,10 +474,10 @@
...
@@ -464,10 +474,10 @@
use_post
:
context
.
_use_remote_post
,
use_post
:
context
.
_use_remote_post
,
conflict_force
:
(
context
.
_conflict_handling
===
conflict_force
:
(
context
.
_conflict_handling
===
CONFLICT_KEEP_LOCAL
),
CONFLICT_KEEP_LOCAL
),
conflict_
ignore
:
(
(
context
.
_conflict_handling
===
conflict_
revert
:
(
context
.
_conflict_handling
===
CONFLICT_CONTINUE
)
||
CONFLICT_KEEP_REMOTE
),
(
context
.
_conflict_handling
===
conflict_ignore
:
(
context
.
_conflict_handling
===
CONFLICT_KEEP_REMOTE
)
),
CONFLICT_CONTINUE
),
check_modification
:
context
.
_check_local_modification
,
check_modification
:
context
.
_check_local_modification
,
check_creation
:
context
.
_check_local_creation
,
check_creation
:
context
.
_check_local_creation
,
check_deletion
:
context
.
_check_local_deletion
check_deletion
:
context
.
_check_local_deletion
...
@@ -494,6 +504,8 @@
...
@@ -494,6 +504,8 @@
use_bulk_get
:
use_bulk_get
,
use_bulk_get
:
use_bulk_get
,
conflict_force
:
(
context
.
_conflict_handling
===
conflict_force
:
(
context
.
_conflict_handling
===
CONFLICT_KEEP_REMOTE
),
CONFLICT_KEEP_REMOTE
),
conflict_revert
:
(
context
.
_conflict_handling
===
CONFLICT_KEEP_LOCAL
),
conflict_ignore
:
(
context
.
_conflict_handling
===
conflict_ignore
:
(
context
.
_conflict_handling
===
CONFLICT_CONTINUE
),
CONFLICT_CONTINUE
),
check_modification
:
context
.
_check_remote_modification
,
check_modification
:
context
.
_check_remote_modification
,
...
...
test/jio.storage/replicatestorage.tests.js
View file @
ab653402
...
@@ -1014,6 +1014,139 @@
...
@@ -1014,6 +1014,139 @@
});
});
});
});
test
(
"
local and remote document creations: keep local,
"
+
"
local not matching query
"
,
function
()
{
stop
();
expect
(
3
);
var
context
=
this
;
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
local_sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
memory
"
}
},
remote_sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
memory
"
}
},
query
:
{
query
:
'
type: "foobar"
'
},
conflict_handling
:
1
});
RSVP
.
all
([
context
.
jio
.
put
(
"
conflict
"
,
{
"
title
"
:
"
foo
"
}),
context
.
jio
.
__storage
.
_remote_sub_storage
.
put
(
"
conflict
"
,
{
"
title
"
:
"
bar
"
,
"
type
"
:
"
foobar
"
})
])
.
then
(
function
()
{
return
context
.
jio
.
repair
();
})
.
then
(
function
()
{
return
context
.
jio
.
__storage
.
_signature_sub_storage
.
get
(
"
conflict
"
);
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
hash
:
"
5ea9013447539ad65de308cbd75b5826a2ae30e5
"
});
})
.
then
(
function
()
{
return
context
.
jio
.
get
(
"
conflict
"
);
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
title
:
"
foo
"
});
})
.
then
(
function
()
{
return
context
.
jio
.
__storage
.
_remote_sub_storage
.
get
(
"
conflict
"
);
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
title
:
"
foo
"
});
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
local and remote document creations: keep local,
"
+
"
remote not matching query
"
,
function
()
{
stop
();
expect
(
3
);
var
context
=
this
;
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
local_sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
memory
"
}
},
remote_sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
memory
"
}
},
query
:
{
query
:
'
type: "foobar"
'
},
conflict_handling
:
1
});
RSVP
.
all
([
context
.
jio
.
put
(
"
conflict
"
,
{
"
title
"
:
"
foo
"
,
"
type
"
:
"
foobar
"
}),
context
.
jio
.
__storage
.
_remote_sub_storage
.
put
(
"
conflict
"
,
{
"
title
"
:
"
bar
"
})
])
.
then
(
function
()
{
return
context
.
jio
.
repair
();
})
.
then
(
function
()
{
return
context
.
jio
.
__storage
.
_signature_sub_storage
.
get
(
"
conflict
"
);
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
hash
:
"
a0a1b37cee3709101b752c56e59b9d66cce09961
"
});
})
.
then
(
function
()
{
return
context
.
jio
.
get
(
"
conflict
"
);
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
title
:
"
foo
"
,
type
:
"
foobar
"
});
})
.
then
(
function
()
{
return
context
.
jio
.
__storage
.
_remote_sub_storage
.
get
(
"
conflict
"
);
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
title
:
"
foo
"
,
type
:
"
foobar
"
});
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
local and remote document creations: keep remote
"
,
function
()
{
test
(
"
local and remote document creations: keep remote
"
,
function
()
{
stop
();
stop
();
expect
(
3
);
expect
(
3
);
...
@@ -1142,6 +1275,139 @@
...
@@ -1142,6 +1275,139 @@
});
});
});
});
test
(
"
local and remote document creations: keep remote,
"
+
"
local not matching query
"
,
function
()
{
stop
();
expect
(
3
);
var
context
=
this
;
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
local_sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
memory
"
}
},
remote_sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
memory
"
}
},
query
:
{
query
:
'
type: "foobar"
'
},
conflict_handling
:
2
});
RSVP
.
all
([
context
.
jio
.
put
(
"
conflict
"
,
{
"
title
"
:
"
foo
"
}),
context
.
jio
.
__storage
.
_remote_sub_storage
.
put
(
"
conflict
"
,
{
"
title
"
:
"
bar
"
,
"
type
"
:
"
foobar
"
})
])
.
then
(
function
()
{
return
context
.
jio
.
repair
();
})
.
then
(
function
()
{
return
context
.
jio
.
__storage
.
_signature_sub_storage
.
get
(
"
conflict
"
);
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
hash
:
"
45efa2292d54cc4ce1f726ea197bc0b9721fc1dc
"
});
})
.
then
(
function
()
{
return
context
.
jio
.
get
(
"
conflict
"
);
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
title
:
"
bar
"
,
type
:
"
foobar
"
});
})
.
then
(
function
()
{
return
context
.
jio
.
__storage
.
_remote_sub_storage
.
get
(
"
conflict
"
);
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
title
:
"
bar
"
,
type
:
"
foobar
"
});
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
local and remote document creations: keep remote,
"
+
"
remote not matching query
"
,
function
()
{
stop
();
expect
(
3
);
var
context
=
this
;
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
local_sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
memory
"
}
},
remote_sub_storage
:
{
type
:
"
query
"
,
sub_storage
:
{
type
:
"
memory
"
}
},
query
:
{
query
:
'
type: "foobar"
'
},
conflict_handling
:
2
});
RSVP
.
all
([
context
.
jio
.
put
(
"
conflict
"
,
{
"
title
"
:
"
foo
"
,
"
type
"
:
"
foobar
"
}),
context
.
jio
.
__storage
.
_remote_sub_storage
.
put
(
"
conflict
"
,
{
"
title
"
:
"
bar
"
})
])
.
then
(
function
()
{
return
context
.
jio
.
repair
();
})
.
then
(
function
()
{
return
context
.
jio
.
__storage
.
_signature_sub_storage
.
get
(
"
conflict
"
);
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
hash
:
"
6799f3ea80e325b89f19589282a343c376c1f1af
"
});
})
.
then
(
function
()
{
return
context
.
jio
.
get
(
"
conflict
"
);
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
title
:
"
bar
"
});
})
.
then
(
function
()
{
return
context
.
jio
.
__storage
.
_remote_sub_storage
.
get
(
"
conflict
"
);
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
title
:
"
bar
"
});
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
local and remote document creations: continue
"
,
function
()
{
test
(
"
local and remote document creations: continue
"
,
function
()
{
stop
();
stop
();
expect
(
4
);
expect
(
4
);
...
...
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