github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/tests/integration_tests/cdc_server_tips/run.sh (about) 1 #!/bin/bash 2 3 set -eu 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 stdout_file=$WORK_DIR/stdout.log 11 cdc_launched= 12 13 function prepare_tidb_cluster() { 14 rm -rf $WORK_DIR && mkdir -p $WORK_DIR 15 start_tidb_cluster --workdir $WORK_DIR 16 17 cd $WORK_DIR 18 19 # record tso before we create tables to skip the system table DDLs 20 start_ts=$(run_cdc_cli_tso_query ${UP_PD_HOST_1} ${UP_PD_PORT_1}) 21 22 run_sql "CREATE table test.simple1(id int primary key, val int);" 23 } 24 25 function try_to_run_cdc() { 26 if [[ $1 == "valid" ]]; then 27 echo "try a VALID cdc server command" 28 run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY 29 else 30 echo "try an INVALID cdc server command" 31 run_cdc_server --supposed-to-fail "true" --workdir $WORK_DIR --binary $CDC_BINARY --pd "None" 32 fi 33 34 #Wait the failed cdc to quit 35 sleep 20 36 echo $1" ~~~ running cdc " "$(ps -a | grep 'cdc')" 37 38 if [[ $(ps -a | grep "cdc.test") == "" ]]; then 39 cdc_launched="false" 40 echo 'Failed to start cdc, the usage tips should be printed' 41 return 0 42 fi 43 44 cdc_launched="true" 45 echo 'Succeed to run cdc, now create a changefeed, no usage tips should be printed' 46 echo "pid"$(ps -a | grep "cdc.test") 47 48 TOPIC_NAME="ticdc-server-tips-test-$RANDOM" 49 case $SINK_TYPE in 50 kafka) SINK_URI="kafka+ssl://127.0.0.1:9092/$TOPIC_NAME?protocol=open-protocol&partition-num=4&kafka-client-id=cdc_server_tips&kafka-version=${KAFKA_VERSION}&max-message-bytes=10485760" ;; 51 storage) SINK_URI="file://$WORK_DIR/storage_test/$TOPIC_NAME?protocol=canal-json&enable-tidb-extension=true" ;; 52 pulsar) 53 run_pulsar_cluster $WORK_DIR normal 54 SINK_URI="pulsar://127.0.0.1:6650/$TOPIC_NAME?protocol=canal-json&enable-tidb-extension=true" 55 ;; 56 *) SINK_URI="mysql+ssl://normal:123456@127.0.0.1:3306/" ;; 57 esac 58 run_cdc_cli changefeed create --start-ts=$start_ts --sink-uri="$SINK_URI" 59 case $SINK_TYPE in 60 kafka) run_kafka_consumer $WORK_DIR "kafka://127.0.0.1:9092/$TOPIC_NAME?protocol=open-protocol&partition-num=4&version=${KAFKA_VERSION}&max-message-bytes=10485760" ;; 61 storage) run_storage_consumer $WORK_DIR $SINK_URI "" "" ;; 62 pulsar) run_pulsar_consumer --upstream-uri $SINK_URI ;; 63 esac 64 echo 'Succeed to create a changefeed, no usage tips should be printed' 65 } 66 67 stop_cdc() { 68 echo "Later, cdc will receive a signal(SIGINT) and exit" 69 cdc_pid=$(ps -a | grep -m 1 "cdc.test" | awk '{print $1}') 70 echo "cdc pid is "$cdc_pid 71 sleep 60 72 kill_cdc_pid $cdc_pid 73 sleep 30 74 } 75 76 trap stop_tidb_cluster EXIT 77 prepare_tidb_cluster 78 79 # If cdc gets started normally, no usage tips should be printed when exit 80 try_to_run_cdc "valid" 81 if [[ "$cdc_launched" == "true" ]]; then 82 # If the cdc was launched, send a signal to stop it and check stdout 83 stop_cdc 84 check_usage_tips "$stdout_file" "true" 85 fi 86 echo " 1st test case $TEST_NAME success! " 87 88 # invalid command and should print usage tips 89 try_to_run_cdc "invalid" 90 if [[ "$cdc_launched" == "false" ]]; then 91 check_usage_tips "$stdout_file" "false" 92 else 93 echo "CDC should not get started with invalid argument" 94 exit 1 95 fi 96 echo " 2nd test case $TEST_NAME success! " 97 98 echo "[$(date)] <<<<<< run all test cases $TEST_NAME success! >>>>>> "