github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/tests/multi_changefeed/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  MAX_RETRIES=10
    12  
    13  function check_old_value_enabled() {
    14      row_logs=$(grep "EmitRowChangedEvents" "$1/cdc.log" || true)
    15      echo $row_logs
    16  
    17      # check update rows
    18      # check if exist a row include `column` and `pre-column`
    19      update_with_old_value_count=$(grep "EmitRowChangedEvents" "$1/cdc.log" | grep 'pre\-columns\\\":\[' | grep '\"columns\\\":\[' | wc -l || true)
    20      if [[ "$update_with_old_value_count" -eq 0 ]]; then
    21         echo "can't found update row with old value"
    22         exit 1
    23      fi
    24  
    25      # check if exist a update row without `pre-column`
    26      update_without_old_value_count=$(grep "EmitRowChangedEvents" "$1/cdc.log" | grep -v 'pre\-columns\\\":\[' | grep 'value\\\":2' | wc -l || true)
    27      if [[ "$update_without_old_value_count" -eq 0 ]]; then
    28         echo "can't found update row without old value"
    29         exit 1
    30      fi
    31  
    32      # check delete rows
    33      # check if exist a delete row with a complete `pre-column`
    34      delete_with_old_value_count=$(grep "EmitRowChangedEvents" "$1/cdc.log" | grep 'pre\-columns\\\":\[' | grep 'columns\\\":null' | grep 'value\\\":2' | wc -l || true)
    35      if [[ "$delete_with_old_value_count" -eq 0 ]]; then
    36         echo "can't found delete row with old value"
    37         exit 1
    38      fi
    39  
    40      # check if exist a delete row without a complete `pre-column`
    41      delete_without_old_value_count=$(grep "EmitRowChangedEvents" "$1/cdc.log" | grep 'pre\-columns\\\":\[' | grep 'columns\\\":null' | grep 'value\\\":1},null' | wc -l || true)
    42      if [[ "$delete_without_old_value_count" -eq 0 ]]; then
    43         echo "can't found delete row without old value"
    44         exit 1
    45      fi
    46  }
    47  
    48  
    49  export -f check_old_value_enabled
    50  
    51  function run() {
    52      # kafka is not supported yet.
    53      if [ "$SINK_TYPE" == "kafka" ]; then
    54        return
    55      fi
    56  
    57      rm -rf $WORK_DIR && mkdir -p $WORK_DIR
    58      start_tidb_cluster --workdir $WORK_DIR
    59      cd $WORK_DIR
    60  
    61      pd_addr="http://$UP_PD_HOST_1:$UP_PD_PORT_1"
    62      SINK_URI="blackhole://"
    63  
    64      run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --addr "127.0.0.1:8300" --pd $pd_addr
    65      cdc cli changefeed create --pd=$pd_addr --sink-uri="$SINK_URI" -c "old-value-cf" --config="$CUR/conf/changefeed1.toml"
    66      cdc cli changefeed create --pd=$pd_addr --sink-uri="$SINK_URI" -c "no-old-value-cf" --config="$CUR/conf/changefeed2.toml"
    67      run_sql "CREATE DATABASE multi_changefeed;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    68      run_sql "CREATE table multi_changefeed.t1 (id int primary key, val int);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    69      run_sql "INSERT INTO multi_changefeed.t1 VALUES (1,1);" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    70      run_sql "UPDATE multi_changefeed.t1 SET val = 2;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    71      run_sql "DELETE FROM multi_changefeed.t1;" ${UP_TIDB_HOST} ${UP_TIDB_PORT}
    72  
    73      ensure $MAX_RETRIES check_old_value_enabled $WORK_DIR
    74      cleanup_process $CDC_BINARY
    75  }
    76  
    77  trap stop_tidb_cluster EXIT
    78  run $*
    79  echo "[$(date)] <<<<<< run test case $TEST_NAME success! >>>>>>"