forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request pingcap#12 from NingLin-P/add-integration-tests-dev
add integration tests
- Loading branch information
Showing
14 changed files
with
449 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
This folder contains all tests which relies on external processes such as TiDB. | ||
|
||
Unit tests (the `*_test.go` files inside the source directory) should *never* rely on external | ||
programs. | ||
|
||
## Preparations | ||
|
||
1. The following 6 executables must be copied or linked into these locations: | ||
* `bin/tidb-server` | ||
* `bin/tikv-server` | ||
* `bin/pd-server` | ||
* `bin/pd-ctl` | ||
* `bin/tikv-importer` | ||
* `bin/go-ycsb` | ||
|
||
The versions must be ≥2.1.0 as usual. | ||
|
||
2. The following programs must be installed: | ||
|
||
* `mysql` (the CLI client) | ||
* `curl` | ||
|
||
3. The user executing the tests must have permission to create the folder | ||
`/tmp/backup_restore_test`. All test artifacts will be written into this folder. | ||
|
||
## Running | ||
|
||
Make sure the path is `br/` | ||
|
||
Run `make integration_test` to execute the integration tests. This command will | ||
|
||
1. Build `br` | ||
2. Check that all 6 required executables and `br` executable exist | ||
3. Execute `tests/run.sh` | ||
|
||
If the first tow steps are done before, you could also run `tests/run.sh` directly. | ||
This script will | ||
|
||
1. Start PD, TiKV, TiDB and TiKV-Importer in background with local storage | ||
2. Find out all `tests/*/run.sh` and run it | ||
|
||
## Writing new tests | ||
|
||
New integration tests can be written as shell scripts in `tests/TEST_NAME/run.sh`. | ||
The script should exit with a nonzero error code on failure. | ||
|
||
Several convenient commands are provided: | ||
|
||
* `run_sql <SQL>` — Executes an SQL query on the TiDB database |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
# | ||
# Copyright 2019 PingCAP, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -eu | ||
|
||
echo "[$(date)] Executing SQL: $1" > "$TEST_DIR/sql_res.$TEST_NAME.txt" | ||
mysql -uroot -h127.0.0.1 -P4000 --default-character-set utf8 -E -e "$1" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/bin/sh | ||
# | ||
# Copyright 2019 PingCAP, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -eu | ||
DB="$TEST_NAME" | ||
TABLE="usertable" | ||
DB_COUNT=3 | ||
|
||
for i in $(seq $DB_COUNT); do | ||
run_sql "CREATE DATABASE $DB${i};" | ||
go-ycsb load mysql -P tests/$TEST_NAME/workload -p mysql.host=$TIDB_IP -p mysql.port=$TIDB_PORT -p mysql.user=root -p mysql.db=$DB${i} | ||
done | ||
|
||
for i in $(seq $DB_COUNT); do | ||
row_count_ori[${i}]=$(run_sql "SELECT COUNT(*) FROM $DB${i}.$TABLE;" | awk '/COUNT/{print $2}') | ||
done | ||
|
||
# backup full | ||
br --pd $PD_ADDR backup full -s "local://$TEST_DIR/$DB/backupdata" --ratelimit 100 --concurrency 4 | ||
|
||
for i in $(seq $DB_COUNT); do | ||
run_sql "DROP DATABASE $DB${i};" | ||
done | ||
|
||
# restore full | ||
br restore full --connect "root@tcp($TIDB_ADDR)/" --importer $IMPORTER_ADDR --meta backupmeta --status $TIDB_IP:10080 --pd $PD_ADDR | ||
|
||
for i in $(seq $DB_COUNT); do | ||
row_count_new[${i}]=$(run_sql "SELECT COUNT(*) FROM $DB${i}.$TABLE;" | awk '/COUNT/{print $2}') | ||
done | ||
|
||
fail=false | ||
for i in $(seq $DB_COUNT); do | ||
if [ "${row_count_ori[i]}" != "${row_count_new[i]}" ];then | ||
fail=true | ||
echo "TEST: [$TEST_NAME] fail on database $DB${i}" | ||
fi | ||
echo "[original] row count: ${row_count_ori[i]}, [after br] row count: ${row_count_new[i]}" | ||
done | ||
|
||
if $fail; then | ||
echo "TEST: [$TEST_NAME] failed!" | ||
exit 1 | ||
else | ||
echo "TEST: [$TEST_NAME] successed!" | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
recordcount=2000 | ||
operationcount=0 | ||
workload=core | ||
|
||
readallfields=true | ||
|
||
readproportion=0 | ||
updateproportion=0 | ||
scanproportion=0 | ||
insertproportion=0 | ||
|
||
requestdistribution=uniform |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/sh | ||
# | ||
# Copyright 2019 PingCAP, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -eu | ||
DB="$TEST_NAME" | ||
TABLE="usertable" | ||
|
||
run_sql "CREATE DATABASE $DB;" | ||
|
||
go-ycsb load mysql -P tests/$TEST_NAME/workload -p mysql.host=$TIDB_IP -p mysql.port=$TIDB_PORT -p mysql.user=root -p mysql.db=$DB | ||
|
||
row_count_ori=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}') | ||
|
||
# add shuffle leader scheduler | ||
pd-ctl -u "http://$PD_ADDR" -d sched add shuffle-leader-scheduler | ||
|
||
# backup with shuffle leader | ||
br --pd $PD_ADDR backup table -s "local://$TEST_DIR/$DB/backupdata" --db $DB -t $TABLE --ratelimit 100 --concurrency 4 | ||
|
||
run_sql "DELETE FROM $DB.$TABLE;" | ||
|
||
# restore with shuffle leader | ||
br restore table --db $DB --table $TABLE --connect "root@tcp($TIDB_ADDR)/" --importer $IMPORTER_ADDR --meta backupmeta --status $TIDB_IP:10080 --pd $PD_ADDR | ||
|
||
# remove shuffle leader scheduler | ||
pd-ctl -u "http://$PD_ADDR" -d sched remove shuffle-leader-scheduler | ||
|
||
row_count_new=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}') | ||
|
||
echo "[original] row count: $row_count_ori, [after br] row count: $row_count_new" | ||
|
||
if [ "$row_count_ori" -eq "$row_count_new" ];then | ||
echo "TEST: [$TEST_NAME] successed!" | ||
else | ||
echo "TEST: [$TEST_NAME] failed!" | ||
exit 1 | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
recordcount=2000 | ||
operationcount=0 | ||
workload=core | ||
|
||
readallfields=true | ||
|
||
readproportion=0 | ||
updateproportion=0 | ||
scanproportion=0 | ||
insertproportion=0 | ||
|
||
requestdistribution=uniform |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/sh | ||
# | ||
# Copyright 2019 PingCAP, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -eu | ||
DB="$TEST_NAME" | ||
TABLE="usertable" | ||
|
||
run_sql "CREATE DATABASE $DB;" | ||
|
||
go-ycsb load mysql -P tests/$TEST_NAME/workload -p mysql.host=$TIDB_IP -p mysql.port=$TIDB_PORT -p mysql.user=root -p mysql.db=$DB | ||
|
||
row_count_ori=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}') | ||
|
||
# add shuffle region scheduler | ||
pd-ctl -u "http://$PD_ADDR" -d sched add shuffle-region-scheduler | ||
|
||
# backup with shuffle region | ||
br --pd $PD_ADDR backup table -s "local://$TEST_DIR/$DB/backupdata" --db $DB -t $TABLE --ratelimit 100 --concurrency 4 | ||
|
||
run_sql "DELETE FROM $DB.$TABLE;" | ||
|
||
# restore with shuffle region | ||
br restore table --db $DB --table $TABLE --connect "root@tcp($TIDB_ADDR)/" --importer $IMPORTER_ADDR --meta backupmeta --status $TIDB_IP:10080 --pd $PD_ADDR | ||
|
||
# remove shuffle region scheduler | ||
pd-ctl -u "http://$PD_ADDR" -d sched remove shuffle-region-scheduler | ||
|
||
row_count_new=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}') | ||
|
||
echo "[original] row count: $row_count_ori, [after br] row count: $row_count_new" | ||
|
||
if [ "$row_count_ori" -eq "$row_count_new" ];then | ||
echo "TEST: [$TEST_NAME] successed!" | ||
else | ||
echo "TEST: [$TEST_NAME] failed!" | ||
exit 1 | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
recordcount=2000 | ||
operationcount=0 | ||
workload=core | ||
|
||
readallfields=true | ||
|
||
readproportion=0 | ||
updateproportion=0 | ||
scanproportion=0 | ||
insertproportion=0 | ||
|
||
requestdistribution=uniform |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/sh | ||
# | ||
# Copyright 2019 PingCAP, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -eu | ||
DB="$TEST_NAME" | ||
TABLE="usertable" | ||
|
||
run_sql "CREATE DATABASE $DB;" | ||
|
||
go-ycsb load mysql -P tests/$TEST_NAME/workload -p mysql.host=$TIDB_IP -p mysql.port=$TIDB_PORT -p mysql.user=root -p mysql.db=$DB | ||
|
||
row_count_ori=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}') | ||
|
||
# backup table | ||
br --pd $PD_ADDR backup table -s "local://$TEST_DIR/$DB/backupdata" --db $DB -t $TABLE --ratelimit 100 --concurrency 4 | ||
|
||
run_sql "DELETE FROM $DB.$TABLE;" | ||
|
||
# restore table | ||
br restore table --db $DB --table $TABLE --connect "root@tcp($TIDB_ADDR)/" --importer $IMPORTER_ADDR --meta backupmeta --status $TIDB_IP:10080 --pd $PD_ADDR | ||
|
||
row_count_new=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}') | ||
|
||
echo "[original] row count: $row_count_ori, [after br] row count: $row_count_new" | ||
|
||
if [ "$row_count_ori" -eq "$row_count_new" ];then | ||
echo "TEST: [$TEST_NAME] successed!" | ||
else | ||
echo "TEST: [$TEST_NAME] failed!" | ||
exit 1 | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
recordcount=2000 | ||
operationcount=0 | ||
workload=core | ||
|
||
readallfields=true | ||
|
||
readproportion=0 | ||
updateproportion=0 | ||
scanproportion=0 | ||
insertproportion=0 | ||
|
||
requestdistribution=uniform |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# config of tidb | ||
|
||
# Schema lease duration | ||
# There are lot of ddl in the tests, setting this | ||
# to 0s to accelerate the tests | ||
lease = "0s" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# config of tikv | ||
|
||
[coprocessor] | ||
region-max-keys = 20 | ||
region-split-keys = 12 |
Oops, something went wrong.