-
-
Save snopoke/cc62366f9856e3f301f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Simple script for simulating document conflicts in Cloudant / CouchDB | |
DEST="conflict_test" | |
DOC="doc_with_conflicts" | |
USERNAME="my-username" | |
read -s -p "Enter Password: " PASSWORD | |
HOST="$USERNAME.cloudant.com" | |
ROOT="https://$HOST" | |
ROOT_PW="https://$USERNAME:$PASSWORD@$HOST" | |
function create() { | |
echo "create" | |
exit | |
echo "create destination database" | |
curl -u $USERNAME:$PASSWORD -X PUT "$ROOT/$DEST" | |
# loop 1-->10 | |
for i in `seq 1 10`; do | |
DB="conflict_test$i" | |
TS=`date +%s` | |
json="{ \"_id\": \"$DOC\", \"ts\": $TS}" | |
echo "Creating database $DB with single doc $json" | |
# create a database e.g. DB1 | |
curl -u $USERNAME:$PASSWORD -X PUT "$ROOT/$DB" | |
# put a document in it e.g. { "_id": "mydoc", "ts": 42 } | |
curl -u $USERNAME:$PASSWORD -X POST -d "$json" "$ROOT/$DB" -H "Content-Type: application/json" | |
# replicate this database to mydb | |
repl="{ \"source\": \"$ROOT_PW/$DB\", \"target\": \"$ROOT_PW/$DEST\" }" | |
echo "Replicating to $DEST" | |
curl -u $USERNAME:$PASSWORD -X POST -d "$repl" "$ROOT/_replicate" -H "Content-Type: application/json" | |
sleep 1 | |
done | |
# let replication complete | |
sleep 10 | |
# read back our conflicted document /mydb/mydoc | |
curl -u $USERNAME:$PASSWORD "$ROOT/$DEST/$DOC?conflicts=true" | |
} | |
function cleanup() { | |
echo "Deleting destination database" | |
curl -u $USERNAME:$PASSWORD -X DELETE "$ROOT/$DEST" | |
for i in `seq 1 10`; do | |
DB="conflict_test$i" | |
echo "Deleting $DB" | |
curl -u $USERNAME:$PASSWORD -X DELETE "$ROOT/$DB" | |
done | |
} | |
if [ "$#" -ne 1 ]; then | |
echo "Usage: simulate_conflicts.sh [create|cleanup]" | |
exit | |
fi | |
$1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment