github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/lightning_tidb_duplicate_data/run.sh (about) 1 #!/bin/sh 2 # 3 # Copyright 2019 PingCAP, Inc. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 set -eu 17 18 # reset substitution if last time failed half way 19 # on BSD/macOS sed -i must have a following string as backup filename extension 20 sed -i.bak 's/new/old/g' "tests/lightning_tidb_duplicate_data/data/dup.dup.sql" && rm tests/lightning_tidb_duplicate_data/data/dup.dup.sql.bak 21 22 for type in replace ignore error; do 23 run_sql 'DROP DATABASE IF EXISTS dup;' 24 25 export GO_FAILPOINTS="github.com/pingcap/br/pkg/lightning/backend/tidb/FailIfImportedSomeRows=return" 26 set +e 27 run_lightning --config "tests/$TEST_NAME/$type.toml" 2> /dev/null 28 ERRORCODE=$? 29 set -e 30 [ "$ERRORCODE" -ne 0 ] 31 32 # backup original sql to dup.dup.sql.bak 33 sed -i.bak 's/old/new/g' "tests/lightning_tidb_duplicate_data/data/dup.dup.sql" 34 35 unset GO_FAILPOINTS 36 37 if [ $type = 'error' ]; then 38 set +e 39 run_lightning --config "tests/$TEST_NAME/$type.toml" --log-file "$TEST_DIR/lightning-error-on-dup.log" 40 ERRORCODE=$? 41 set -e 42 [ "$ERRORCODE" -ne 0 ] 43 tail -20 "$TEST_DIR/lightning-error-on-dup.log" > "$TEST_DIR/lightning-error-on-dup.tail" 44 grep -Fq 'Duplicate entry' "$TEST_DIR/lightning-error-on-dup.tail" 45 elif [ $type = 'replace' ]; then 46 run_lightning --config "tests/$TEST_NAME/$type.toml" 47 run_sql 'SELECT count(*) FROM dup.dup' 48 check_contains 'count(*): 2' 49 run_sql 'SELECT d FROM dup.dup WHERE pk = 1' 50 check_contains 'd: new' 51 run_sql 'SELECT d FROM dup.dup WHERE pk = 2' 52 check_contains 'd: new' 53 elif [ $type = 'ignore' ]; then 54 run_lightning --config "tests/$TEST_NAME/$type.toml" 55 run_sql 'SELECT count(*) FROM dup.dup' 56 check_contains 'count(*): 2' 57 run_sql 'SELECT d FROM dup.dup WHERE pk = 1' 58 check_contains 'd: old' 59 run_sql 'SELECT d FROM dup.dup WHERE pk = 2' 60 check_contains 'd: new' 61 fi 62 63 mv tests/lightning_tidb_duplicate_data/data/dup.dup.sql.bak tests/lightning_tidb_duplicate_data/data/dup.dup.sql 64 done