github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/tests/ddl_puller_lag/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.ddl_puller_lag1(id int primary key, val int);"
    22      run_sql "CREATE table test.ddl_puller_lag2(id int primary key, val int);"
    23  
    24      run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --failpoint 'github.com/pingcap/ticdc/cdc/processorDDLResolved=1*sleep(180000)' # old processor
    25      # run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --failpoint 'github.com/pingcap/ticdc/cdc/processor/processorDDLResolved=1*sleep(180000)' # new processor
    26  
    27      TOPIC_NAME="ticdc-ddl-puller-lag-test-$RANDOM"
    28      case $SINK_TYPE in
    29          kafka) SINK_URI="kafka+ssl://127.0.0.1:9092/$TOPIC_NAME?partition-num=4&kafka-client-id=ddl_puller_lag&kafka-version=${KAFKA_VERSION}";;
    30          *) SINK_URI="mysql+ssl://normal:123456@127.0.0.1:3306/";;
    31      esac
    32      run_cdc_cli changefeed create --start-ts=$start_ts --sink-uri="$SINK_URI"
    33      if [ "$SINK_TYPE" == "kafka" ]; then
    34        run_kafka_consumer $WORK_DIR "kafka://127.0.0.1:9092/$TOPIC_NAME?partition-num=4&version=${KAFKA_VERSION}"
    35      fi
    36  }
    37  
    38  function sql_check() {
    39      # run check in sequence and short circuit principle, if error hanppens,
    40      # the following statement will be not executed
    41  
    42      # check table ddl_puller_lag1.
    43      run_sql "SELECT id, val FROM test.ddl_puller_lag1;" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} && \
    44      check_contains "id: 1" && \
    45      check_contains "val: 1" && \
    46      check_contains "id: 2" && \
    47      check_contains "val: 22" && \
    48      check_not_contains "id: 3" && \
    49  
    50      # check table ddl_puller_lag2.
    51      run_sql "SELECT id, val FROM test.ddl_puller_lag2;" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} && \
    52      check_contains "id: 1" && \
    53      check_contains "val: 1" && \
    54      check_contains "id: 2" && \
    55      check_contains "val: 22" && \
    56      check_not_contains "id: 3"
    57  }
    58  
    59  function sql_test() {
    60      # test insert/update/delete for two table in the same way.
    61      run_sql "INSERT INTO test.ddl_puller_lag1(id, val) VALUES (1, 1);"
    62      run_sql "INSERT INTO test.ddl_puller_lag1(id, val) VALUES (2, 2);"
    63      run_sql "INSERT INTO test.ddl_puller_lag1(id, val) VALUES (3, 3);"
    64  
    65      # update id = 2 and delete id = 3
    66      run_sql "UPDATE test.ddl_puller_lag1 set val = 22 where id = 2;"
    67      run_sql "DELETE from test.ddl_puller_lag1 where id = 3;"
    68  
    69  
    70      # same dml for table ddl_puller_lag2
    71      run_sql "INSERT INTO test.ddl_puller_lag2(id, val) VALUES (1, 1);"
    72      run_sql "INSERT INTO test.ddl_puller_lag2(id, val) VALUES (2, 2);"
    73      run_sql "INSERT INTO test.ddl_puller_lag2(id, val) VALUES (3, 3);"
    74  
    75      run_sql "UPDATE test.ddl_puller_lag2 set val = 22 where id = 2;"
    76      run_sql "DELETE from test.ddl_puller_lag2 where id = 3;"
    77  
    78      i=0
    79      check_time=50
    80      set +e
    81      while [ $i -lt $check_time ]
    82      do
    83          sql_check
    84          ret=$?
    85          if [ "$ret" == 0 ]; then
    86              echo "check data successfully"
    87              break
    88          fi
    89          ((i++))
    90          echo "check data failed $i-th time, retry later"
    91          sleep 2
    92      done
    93      set -e
    94  
    95      if [ $i -ge $check_time ]; then
    96          echo "check data failed at last"
    97          exit 1
    98      fi
    99  
   100      cleanup_process $CDC_BINARY
   101  }
   102  
   103  trap stop_tidb_cluster EXIT
   104  prepare $*
   105  sleep 180
   106  sql_test $*
   107  check_logs $WORK_DIR
   108  echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"