test/bin-test/test-dav-sync-split1.sh

changeset 681
3320429502cf
child 682
a7072ebb1ce0
equal deleted inserted replaced
680:e66f2645be65 681:3320429502cf
1 #!/bin/sh
2 #
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 #
5 # Copyright 2019 Olaf Wintermann. All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are met:
9 #
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 #
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
28 #
29
30 if [ -z "$DAV_BIN" ];
31 then
32 echo "DAV_BIN variable not set"
33 exit 1
34 fi
35 if [ -z "$DAV_SYNC_BIN" ];
36 then
37 echo "DAV_BIN variable not set"
38 exit 1
39 fi
40
41 XATTR=../../build/xattrtool
42
43 # checks if tmp-sync/out.txt contains a specific text
44 # arg1: pattern
45 # arg2: errormsg
46 check_tmpout()
47 {
48 TEST=`cat tmp-sync/out.txt | grep "$1"`
49 if [ $? -ne 0 ];
50 then
51 echo "$2"
52 exit 2
53 fi
54 }
55
56 # checks if tmp-sync/out.txt does not contain a specific text
57 # arg1: pattern
58 # arg2: errormsg
59 ncheck_tmpout()
60 {
61 TEST=`cat tmp-sync/out.txt | grep "$1"`
62 if [ $? -eq 0 ];
63 then
64 echo "$2"
65 exit 2
66 fi
67 }
68
69 # do dav-sync push and check return value
70 # arg1: dir
71 # arg2: errormsg
72 dav_sync_push()
73 {
74 $DAV_SYNC_BIN push $1 > tmp-sync/out.txt
75 if [ $? -ne 0 ];
76 then
77 echo "$2"
78 exit 2
79 fi
80 }
81 # do dav-sync pull and check return value
82 # arg1: dir
83 # arg2: errormsg
84 dav_sync_pull()
85 {
86 $DAV_SYNC_BIN pull $1 > tmp-sync/out.txt
87 if [ $? -ne 0 ];
88 then
89 echo "$2"
90 exit 2
91 fi
92 }
93
94 rm -f .dav/dav-sync-tests-test6a-db.xml
95 rm -f .dav/dav-sync-tests-test6b-db.xml
96
97 $DAV_BIN rm dav-test-repo/sync/test6 2> /dev/null
98
99 $DAV_BIN mkcol dav-test-repo/sync/test6 2> /dev/null
100
101 # tmp sync dir
102 rm -Rf tmp-sync
103 mkdir tmp-sync
104 mkdir tmp-sync/test6a
105 mkdir tmp-sync/test6b
106
107 # ----------------------------------------------------------------------------
108 # test 1: add some small files and sync
109 # expected result: everything synced, no split
110
111 mkdir tmp-sync/test6a/dir1
112 mkdir tmp-sync/test6a/dir1/sub1
113
114 cp synctest/file1 tmp-sync/test6a
115 cp synctest/file2 tmp-sync/test6a/dir1
116 cp synctest/file3 tmp-sync/test6a/dir1/sub1
117
118 dav_sync_push test6a "test 1: push failed"
119 check_tmpout "3 files pushed" "test 1: wrong push counter"
120 check_tmpout "0 conflicts" "test 1: wrong conflict counter (push)"
121 check_tmpout "0 errors" "test 1: wrong error counter (push)"
122
123 dav_sync_pull test6b "test 1: pull failed"
124 check_tmpout "3 files pulled" "test 1: wrong pull counter"
125 check_tmpout "0 conflicts" "test 1: wrong conflict counter (pull)"
126 check_tmpout "0 errors" "test 1: wrong error counter (pull)"
127
128 $DAV_BIN info dav-test-repo/sync/test6/file1 | grep "type: resource" > /dev/null 2>&1
129 if [ $? -ne 0 ]; then
130 echo "test 1: file1 not a resource"
131 exit 2
132 fi
133 $DAV_BIN info dav-test-repo/sync/test6/dir1/file2 | grep "type: resource" > /dev/null 2>&1
134 if [ $? -ne 0 ]; then
135 echo "test 1: file2 not a resource"
136 exit 2
137 fi
138 $DAV_BIN info dav-test-repo/sync/test6/dir1/sub1/file3 | grep "type: resource" > /dev/null 2>&1
139 if [ $? -ne 0 ]; then
140 echo "test 1: file3 not a resource"
141 exit 2
142 fi
143
144 # ----------------------------------------------------------------------------
145 # test 2: add a large file
146 # expected result: split
147
148 head -c 1048576 /dev/zero | sed 's/\x0/a/g' > tmp-sync/xa
149 cat tmp-sync/xa | sed 's/a/b/g' > tmp-sync/xb
150 cat tmp-sync/xa | sed 's/a/c/g' > tmp-sync/xc
151 cat tmp-sync/xa | sed 's/a/1/g' > tmp-sync/x1
152 cat tmp-sync/xa | sed 's/a/2/g' > tmp-sync/x2
153 cat tmp-sync/xa | sed 's/a/3/g' > tmp-sync/x3
154
155 cat tmp-sync/xa tmp-sync/xb tmp-sync/xc tmp-sync/x1 tmp-sync/x2 tmp-sync/x3 > tmp-sync/test6a/big1
156
157 dav_sync_push test6a "test 2: push failed"
158 check_tmpout "1 file pushed" "test 2: wrong push counter"
159 check_tmpout "0 conflicts" "test 2: wrong conflict counter (push)"
160 check_tmpout "0 errors" "test 2: wrong error counter (push)"
161
162 dav_sync_pull test6b "test 2: pull failed"
163 check_tmpout "1 file pulled" "test 2: wrong pull counter"
164 check_tmpout "0 conflicts" "test 2: wrong conflict counter (pull)"
165 check_tmpout "0 errors" "test 2: wrong error counter (pull)"
166
167 $DAV_BIN info dav-test-repo/sync/test6/big1 | grep "type: collection" > /dev/null 2>&1
168 if [ $? -ne 0 ]; then
169 echo "test 2: big1 not a collection"
170 exit 2
171 fi
172
173 HASH1=`cat tmp-sync/test6a/big1 | sha256sum`
174 HASH2=`cat tmp-sync/test6b/big1 | sha256sum`
175 if [ "$HASH1" != "$HASH2" ]; then
176 echo "test 2: big1 not equal"
177 exit 2
178 fi
179
180 $DAV_BIN list -l dav-test-repo/sync/test6/big1 > tmp-sync/list.txt 2> /dev/null
181 if [ $? -ne 0 ]; then
182 echo "test 2: dav list failed"
183 exit 2
184 fi
185
186 TEST=`cat tmp-sync/list.txt | wc -l`
187 if [ $TEST -ne 6 ]; then
188 echo "test 2: wrong block count"
189 exit 2
190 fi
191
192 LASTMODIFIED_PART0=`$DAV_BIN get-property dav-test-repo/sync/test6/big1/0 D:getlastmodified`
193 LASTMODIFIED_PART1=`$DAV_BIN get-property dav-test-repo/sync/test6/big1/1 D:getlastmodified`
194 LASTMODIFIED_PART2=`$DAV_BIN get-property dav-test-repo/sync/test6/big1/2 D:getlastmodified`
195 LASTMODIFIED_PART3=`$DAV_BIN get-property dav-test-repo/sync/test6/big1/3 D:getlastmodified`
196 LASTMODIFIED_PART4=`$DAV_BIN get-property dav-test-repo/sync/test6/big1/4 D:getlastmodified`
197 LASTMODIFIED_PART5=`$DAV_BIN get-property dav-test-repo/sync/test6/big1/5 D:getlastmodified`
198
199
200 # ----------------------------------------------------------------------------
201 # test 3: modify first block
202 # expected result: first block synced
203
204 sleep 2
205
206 dd if=tmp-sync/xc of=tmp-sync/test6a/big1 conv=notrunc > /dev/null 2>&1
207
208 dav_sync_push test6a "test 3: push failed"
209 check_tmpout "1 file pushed" "test 3: wrong push counter"
210 check_tmpout "0 conflicts" "test 3: wrong conflict counter (push)"
211 check_tmpout "0 errors" "test 3: wrong error counter (push)"
212
213 dav_sync_pull test6b "test 3: pull failed"
214 check_tmpout "1 file pulled" "test 3: wrong pull counter"
215 check_tmpout "0 conflicts" "test 3: wrong conflict counter (pull)"
216 check_tmpout "0 errors" "test 3: wrong error counter (pull)"
217
218 HASH1=`cat tmp-sync/test6a/big1 | sha256sum`
219 HASH2=`cat tmp-sync/test6b/big1 | sha256sum`
220 if [ "$HASH1" != "$HASH2" ]; then
221 echo "test 3: big1 not equal"
222 exit 2
223 fi
224
225 LASTMODIFIED_PART0_2=`$DAV_BIN get-property dav-test-repo/sync/test6/big1/0 D:getlastmodified`
226 LASTMODIFIED_PART1_2=`$DAV_BIN get-property dav-test-repo/sync/test6/big1/1 D:getlastmodified`
227 LASTMODIFIED_PART2_2=`$DAV_BIN get-property dav-test-repo/sync/test6/big1/2 D:getlastmodified`
228
229 if [ "$LASTMODIFIED_PART0" = "$LASTMODIFIED_PART0_2" ]; then
230 echo "test 3: part 0 not updated"
231 exit 2
232 fi
233 if [ "$LASTMODIFIED_PART1" != "$LASTMODIFIED_PART1_2" ]; then
234 echo "test 3: part 1 updated"
235 exit 2
236 fi
237 if [ "$LASTMODIFIED_PART2" != "$LASTMODIFIED_PART2_2" ]; then
238 echo "test 3: part 2 updated"
239 exit 2
240 fi
241

mercurial