Revision 623762333831 () - Diff

Link to this snippet: https://friendpaste.com/3cT1qPwc7LhCgNm63a9aSg
Embed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/sh -ex
# This script tests upgrading CouchDB from 1.0 to 1.1
# See https://issues.apache.org/jira/browse/COUCHDB-951 for details

# Expects to run from it's source dir
# Usage:
# $ ./run.sh


# Setup environment
CWD=`pwd`
cd /tmp # nothing lasts forever
TESTDIR=couchdb-upgrade-1.0-to-1.1
rm -rf $TESTDIR # we may have been here before, start over
mkdir -p $TESTDIR
cd $TESTDIR

OPENSSL=`which openssl`
if [ -z "$OPENSSL" ]; then
echo "Can’t find md5 or openssl, exiting."
exit 1
fi

mkdir -p src
mkdir -p 1.0
mkdir -p 1.1

cd src

git clone git://git.apache.org/couchdb.git --depth=1 # be gentle

cd couchdb

# build 1.0.x
git checkout 1.0.x
./bootstrap
./configure --prefix=/tmp/$TESTDIR/1.0
make -j4 # woooosh
make install

# build 1.1.x
git checkout 1.1.x
./bootstrap
./configure --prefix=/tmp/$TESTDIR/1.1
make -j4 # woooosh
make install

cd ../..
cd 1.0

# launch 1.0
# disable delayed commits, so we can copy the database file from under the
# running couch instance after our curl returns
# TODO: could be a curl config call
echo "[couchdb]" > llocal.ini
echo "delayed_commits=false" >> llocal.ini
echo "" >> llocal.ini
./bin/couchdb -b -a llocal.ini

cd ..
cd 1.1

# launch 1.1
# disable delayed commits, so we can copy the database file from under the
# running couch instance after our curl returns
# TODO: could be a curl config call
echo "[couchdb]" > llocal.ini
echo "delayed_commits=false" >> llocal.ini

# set port number to +1 so both couches can run in parallel
echo "[httpd]" >> llocal.ini
echo "port=5985" >> llocal.ini
echo "" >> llocal.ini
./bin/couchdb -b -a llocal.ini

# wait for couches to boot, you may have to adjust this on slower systems
sleep 2
cd ..

# create test db in 1.0

COUCH10=http://127.0.0.1:5984
curl -X PUT $COUCH10/test-db
curl -X PUT $COUCH10/test-db/test-doc/attachment.txt \
-H "Content-Type: text/plain" \
-d "My Hovercraft is full of eels"

# test binary files at 2k, 4k and 8k
for bin in $CWD/attachments/*.bin; do
# store binary
binbasename=`basename $bin`
binname=`basename -s .bin $bin`
curl -X PUT $COUCH10/test-db/test-doc-$binname/$binbasename \
-H "Content-Type: application/octet-stream" \
--data-binary @$bin
done

# copy test db to 1.1
cp 1.0/var/lib/couchdb/test-db.couch 1.1/var/lib/couchdb/test-db.couch

# compact with 1.1
COUCH11=http://127.0.0.1:5985
curl -X POST $COUCH11/test-db/_compact -H "Content-Type: application/json"

# validate test db
TEST_PASSED=true

RESULT=`curl $COUCH11/test-db/test-doc/attachment.txt`
if [ "$RESULT" != "My Hovercraft is full of eels" ]; then
TEST_PASSED=false
fi

mkdir attachment-results
cd attachment-results
for bin in $CWD/attachments/*.bin; do
binbasename=`basename $bin`
binname=`basename -s .bin $bin`
curl -O $COUCH11/test-db/test-doc-$binname/$binbasename
BEFORE=`$OPENSSL sha $bin | awk '{print $2}'`
AFTER=`$OPENSSL sha $binbasename | awk '{print $2}'`
if [ "$BEFORE" != "$AFTER" ]; then
TEST_PASSED=false
fi
done

cd ..

# shutdown couches

cd /tmp/$TESTDIR

cd 1.0
./bin/couchdb -d

cd ..
cd 1.1
./bin/couchdb -d

# resultin
if [ "$TEST_PASSED" = "false" ]; then
echo "UPGRADE FAILED"
else
echo "UPGRADE PASSED"
fi

# DONE