github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/tests/changefeed_finish/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  MAX_RETRIES=10
    11  
    12  function check_changefeed_is_finished() {
    13      pd=$1
    14      changefeed=$2
    15      state=$(cdc cli changefeed query -s -c=$changefeed|jq ".state"|tr -d '"')
    16      if [[ ! "$state" -eq "finished" ]]; then
    17          echo "state $state is not finished"
    18          exit 1
    19      fi
    20  
    21      info=$(cdc cli changefeed query -c=$changefeed|sed "/has been deleted/d"|jq ".info")
    22      if [[ ! "$info" -eq "null" ]]; then
    23          echo "unexpected changefeed info $info, should be null"
    24          exit 1
    25      fi
    26  
    27      status_length=$(cdc cli changefeed query -c=$changefeed|sed "/has been deleted/d"|jq '."task-status"|length')
    28      if [[ ! "$status_length" -eq "0" ]]; then
    29          echo "unexpected task status length $status_length, should be 0"
    30          exit 1
    31      fi
    32  }
    33  
    34  export -f check_changefeed_is_finished
    35  
    36  function run() {
    37      rm -rf $WORK_DIR && mkdir -p $WORK_DIR
    38      start_tidb_cluster --workdir $WORK_DIR
    39      cd $WORK_DIR
    40  
    41      pd_addr="http://$UP_PD_HOST_1:$UP_PD_PORT_1"
    42      TOPIC_NAME="ticdc-changefeed-pause-resume-$RANDOM"
    43      case $SINK_TYPE in
    44          kafka) SINK_URI="kafka://127.0.0.1:9092/$TOPIC_NAME?partition-num=4&kafka-version=${KAFKA_VERSION}";;
    45          *) SINK_URI="mysql://normal:123456@127.0.0.1:3306/?max-txn-row=1";;
    46      esac
    47      if [ "$SINK_TYPE" == "kafka" ]; then
    48        run_kafka_consumer $WORK_DIR "kafka://127.0.0.1:9092/$TOPIC_NAME?partition-num=4&version=${KAFKA_VERSION}"
    49      fi
    50      run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --addr "127.0.0.1:8300" --pd $pd_addr
    51      now=$(cdc cli tso query --pd=http://$UP_PD_HOST_1:$UP_PD_PORT_1)
    52      # 90s after now
    53      target_ts=$(( $now + 90 * 10 ** 3 * 2 ** 18 ))
    54      changefeed_id=$(cdc cli changefeed create --sink-uri="$SINK_URI" --target-ts=$target_ts 2>&1|tail -n2|head -n1|awk '{print $2}')
    55  
    56      run_sql "CREATE DATABASE changefeed_finish;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    57      run_sql "CREATE table changefeed_finish.t (id int primary key auto_increment, t datetime DEFAULT CURRENT_TIMESTAMP)"
    58      for i in $(seq 1 10); do
    59          run_sql "insert into changefeed_finish.t values (),(),(),()" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    60      done
    61      check_sync_diff $WORK_DIR $CUR/conf/diff_config.toml
    62  
    63      sleep 90
    64  
    65      ensure $MAX_RETRIES check_changefeed_is_finished $pd_addr $changefeed_id
    66  
    67      cleanup_process $CDC_BINARY
    68  }
    69  
    70  trap stop_tidb_cluster EXIT
    71  run $*
    72  check_logs $WORK_DIR
    73  echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"