Skip to content

Instantly share code, notes, and snippets.

@muhqu
Created September 7, 2011 13:38
Show Gist options
  • Save muhqu/1200578 to your computer and use it in GitHub Desktop.
Save muhqu/1200578 to your computer and use it in GitHub Desktop.
#!/bin/bash
URL="http://127.0.0.1:5984"
DBNAME_A="deletion_conflicts_test_a"
DBNAME_B="deletion_conflicts_test_b"
echo "setup"
curl -H 'Content-Type:application/json' -X DELETE "$URL/$DBNAME_A"
curl -H 'Content-Type:application/json' -X DELETE "$URL/$DBNAME_B"
curl -H 'Content-Type:application/json' -X PUT "$URL/$DBNAME_A"
curl -H 'Content-Type:application/json' -X PUT "$URL/$DBNAME_B"
curl -g -H 'Content-Type:application/json' -X PUT "$URL/$DBNAME_A/_design/conflicts" -d '{ '\
' "views":{ '\
' "conflicts":{ '\
' "reduce":"_count", '\
' "map":"function (doc) { '\
' if (doc._conflicts) { '\
' emit([doc._id, 0], {_rev: doc._rev}); '\
' doc._conflicts.forEach(function(rev, i){ '\
' emit([doc._id, i+1], {_rev: rev}); '\
' }) '\
' } '\
' }" '\
' } '\
' } '\
'}'
curl -X GET "$URL/$DBNAME_A/_design/conflicts/_view/conflicts"
echo
echo "new doc"
OUT=$(curl -s -H 'Content-Type:application/json' -X PUT "$URL/$DBNAME_A/foo" -d '{"name":"Foo"}')
echo "$OUT"
DOC_FIRST_REV=$(echo "$OUT" | sed -e 's/.*rev":"//' -e 's/"}//')
echo "rev is $DOC_FIRST_REV"
echo
echo "all docs on A"
curl -X GET "$URL/$DBNAME_A/_all_docs"
echo
echo "replicate A -> B"
curl -H 'Content-Type:application/json' -X POST "$URL/_replicate" -d '{"source":"'$DBNAME_A'","target":"'$DBNAME_B'"}'
echo
echo "all docs on B"
curl -X GET "$URL/$DBNAME_B/_all_docs"
echo
echo "modify doc on B"
OUT=$(curl -s -H 'Content-Type:application/json' -X PUT "$URL/$DBNAME_B/foo" -d '{"_rev":"'$DOC_FIRST_REV'","name":"Foobarus"}')
echo "$OUT"
DOC_REV_ON_B=$(echo "$OUT" | sed -e 's/.*rev":"//' -e 's/"}//')
echo "rev is $DOC_REV_ON_B"
echo
echo "delete doc on A"
OUT=$(curl -s -H 'Content-Type:application/json' -X DELETE "$URL/$DBNAME_A/foo?rev=$DOC_FIRST_REV")
echo "$OUT"
DOC_REV_ON_A=$(echo "$OUT" | sed -e 's/.*rev":"//' -e 's/"}//')
echo "rev is $DOC_REV_ON_A"
echo
echo "replicate A -> B"
curl -H 'Content-Type:application/json' -X POST "$URL/_replicate" -d '{"source":"'$DBNAME_A'","target":"'$DBNAME_B'"}'
echo
echo "show conflicts on B"
curl -X GET "$URL/$DBNAME_B/_design/conflicts/_view/conflicts"
echo
echo "all docs on A"
curl -X GET "$URL/$DBNAME_A/_all_docs"
echo
echo "all docs on B"
curl -X GET "$URL/$DBNAME_B/_all_docs"
echo
cowsay "Issue: B should show conflicts for the 'foo' document as it was \
'modified' on A and B between two replications."
setup
{"ok":true}
{"ok":true}
{"ok":true}
{"ok":true}
{"ok":true,"id":"_design/conflicts","rev":"1-e55a76ebdc20810393f77c075d01b0b7"}
{"rows":[]}
new doc
{"ok":true,"id":"foo","rev":"1-ef8eae5156806f9a44075563e6038634"}
rev is 1-ef8eae5156806f9a44075563e6038634
all docs on A
{"total_rows":2,"offset":0,"rows":[
{"id":"_design/conflicts","key":"_design/conflicts","value":{"rev":"1-e55a76ebdc20810393f77c075d01b0b7"}},
{"id":"foo","key":"foo","value":{"rev":"1-ef8eae5156806f9a44075563e6038634"}}
]}
replicate A -> B
{"ok":true,"session_id":"6649e5b09417311d044a0669f223f91c","source_last_seq":2,"history":[{"session_id":"6649e5b09417311d044a0669f223f91c","start_time":"Wed, 07 Sep 2011 13:38:06 GMT","end_time":"Wed, 07 Sep 2011 13:38:06 GMT","start_last_seq":0,"end_last_seq":2,"recorded_seq":2,"missing_checked":0,"missing_found":2,"docs_read":2,"docs_written":2,"doc_write_failures":0}]}
all docs on B
{"total_rows":2,"offset":0,"rows":[
{"id":"_design/conflicts","key":"_design/conflicts","value":{"rev":"1-e55a76ebdc20810393f77c075d01b0b7"}},
{"id":"foo","key":"foo","value":{"rev":"1-ef8eae5156806f9a44075563e6038634"}}
]}
modify doc on B
{"ok":true,"id":"foo","rev":"2-57a82e085f6a9bd1f365c9aef614af13"}
rev is 2-57a82e085f6a9bd1f365c9aef614af13
delete doc on A
{"ok":true,"id":"foo","rev":"2-a2267cdf91e0ada30e98fe267ab96adf"}
rev is 2-a2267cdf91e0ada30e98fe267ab96adf
replicate A -> B
{"ok":true,"session_id":"84b39b25ef75829f3d87f6936e6946ae","source_last_seq":3,"history":[{"session_id":"84b39b25ef75829f3d87f6936e6946ae","start_time":"Wed, 07 Sep 2011 13:38:06 GMT","end_time":"Wed, 07 Sep 2011 13:38:07 GMT","start_last_seq":2,"end_last_seq":3,"recorded_seq":3,"missing_checked":0,"missing_found":1,"docs_read":1,"docs_written":1,"doc_write_failures":0},{"session_id":"6649e5b09417311d044a0669f223f91c","start_time":"Wed, 07 Sep 2011 13:38:06 GMT","end_time":"Wed, 07 Sep 2011 13:38:06 GMT","start_last_seq":0,"end_last_seq":2,"recorded_seq":2,"missing_checked":0,"missing_found":2,"docs_read":2,"docs_written":2,"doc_write_failures":0}]}
show conflicts on B
{"rows":[]}
all docs on A
{"total_rows":1,"offset":0,"rows":[
{"id":"_design/conflicts","key":"_design/conflicts","value":{"rev":"1-e55a76ebdc20810393f77c075d01b0b7"}}
]}
all docs on B
{"total_rows":2,"offset":0,"rows":[
{"id":"_design/conflicts","key":"_design/conflicts","value":{"rev":"1-e55a76ebdc20810393f77c075d01b0b7"}},
{"id":"foo","key":"foo","value":{"rev":"2-57a82e085f6a9bd1f365c9aef614af13"}}
]}
________________________________________
/ Issue: B should show conflicts for the \
| 'foo' document as it was \ 'modified' |
\ on A and B between two replications. /
----------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment