github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/tests/simple/run.sh (about) 1 #!/bin/bash 2 3 set -e 4 5 CUR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) 6 source $CUR/../_utils/test_prepare 7 WORK_DIR=$OUT_DIR/$TEST_NAME 8 CDC_BINARY=cdc.test 9 SINK_TYPE=$1 10 11 function prepare() { 12 rm -rf $WORK_DIR && mkdir -p $WORK_DIR 13 14 start_tidb_cluster --workdir $WORK_DIR 15 16 cd $WORK_DIR 17 18 # record tso before we create tables to skip the system table DDLs 19 start_ts=$(run_cdc_cli tso query --pd=http://$UP_PD_HOST_1:$UP_PD_PORT_1) 20 21 run_sql "CREATE table test.simple1(id int primary key, val int);" 22 run_sql "CREATE table test.simple2(id int primary key, val int);" 23 24 run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY 25 26 TOPIC_NAME="ticdc-simple-test-$RANDOM" 27 case $SINK_TYPE in 28 kafka) SINK_URI="kafka+ssl://127.0.0.1:9092/$TOPIC_NAME?partition-num=4&kafka-client-id=cdc_test_simple&kafka-version=${KAFKA_VERSION}";; 29 *) SINK_URI="mysql+ssl://normal:123456@127.0.0.1:3306/";; 30 esac 31 run_cdc_cli changefeed create --start-ts=$start_ts --sink-uri="$SINK_URI" 32 if [ "$SINK_TYPE" == "kafka" ]; then 33 run_kafka_consumer $WORK_DIR "kafka://127.0.0.1:9092/$TOPIC_NAME?partition-num=4&version=${KAFKA_VERSION}" 34 fi 35 } 36 37 function sql_check() { 38 # run check in sequence and short circuit principle, if error hanppens, 39 # the following statement will be not executed 40 41 # check table simple1. 42 run_sql "SELECT id, val FROM test.simple1;" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} && \ 43 check_contains "id: 1" && \ 44 check_contains "val: 1" && \ 45 check_contains "id: 2" && \ 46 check_contains "val: 22" && \ 47 check_not_contains "id: 3" && \ 48 49 # check table simple2. 50 run_sql "SELECT id, val FROM test.simple2;" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} && \ 51 check_contains "id: 1" && \ 52 check_contains "val: 1" && \ 53 check_contains "id: 2" && \ 54 check_contains "val: 22" && \ 55 check_not_contains "id: 3" 56 } 57 58 function sql_test() { 59 # test insert/update/delete for two table in the same way. 60 run_sql "INSERT INTO test.simple1(id, val) VALUES (1, 1);" 61 run_sql "INSERT INTO test.simple1(id, val) VALUES (2, 2);" 62 run_sql "INSERT INTO test.simple1(id, val) VALUES (3, 3);" 63 64 # update id = 2 and delete id = 3 65 run_sql "UPDATE test.simple1 set val = 22 where id = 2;" 66 run_sql "DELETE from test.simple1 where id = 3;" 67 68 69 # same dml for table simple2 70 run_sql "INSERT INTO test.simple2(id, val) VALUES (1, 1);" 71 run_sql "INSERT INTO test.simple2(id, val) VALUES (2, 2);" 72 run_sql "INSERT INTO test.simple2(id, val) VALUES (3, 3);" 73 74 run_sql "UPDATE test.simple2 set val = 22 where id = 2;" 75 run_sql "DELETE from test.simple2 where id = 3;" 76 77 i=0 78 check_time=50 79 set +e 80 while [ $i -lt $check_time ] 81 do 82 sql_check 83 ret=$? 84 if [ "$ret" == 0 ]; then 85 echo "check data successfully" 86 break 87 fi 88 ((i++)) 89 echo "check data failed $i-th time, retry later" 90 sleep 2 91 done 92 set -e 93 94 if [ $i -ge $check_time ]; then 95 echo "check data failed at last" 96 exit 1 97 fi 98 99 cleanup_process $CDC_BINARY 100 } 101 102 trap stop_tidb_cluster EXIT 103 prepare $* 104 sql_test $* 105 check_logs $WORK_DIR 106 echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"