github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/tests/availability/processor.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  
    10  MAX_RETRIES=20
    11  
    12  function test_processor_ha() {
    13      test_stop_processor
    14  }
    15  
    16  # test_stop_processor stops the working processor
    17  # and then resume it.
    18  # We expect the data after resuming is replicated.
    19  function test_stop_processor() {
    20      echo "run test case test_stop_processor"
    21      # start a capture server
    22      run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY
    23      # ensure the server become the owner
    24      ensure $MAX_RETRIES "$CDC_BINARY cli capture list 2>&1 | grep '\"is-owner\": true'"
    25      owner_pid=$(ps -C $CDC_BINARY -o pid= | awk '{print $1}')
    26      owner_id=$($CDC_BINARY cli capture list 2>&1 | awk -F '"' '/id/{print $4}')
    27      echo "owner pid:" $owner_pid
    28      echo "owner id" $owner_id
    29  
    30      # get the change feed id
    31      changefeed=$($CDC_BINARY cli changefeed list 2>&1 | awk -F '"' '/id/{print $4}')
    32      echo "changefeed id:" $changefeed
    33  
    34      # stop the change feed job
    35      # use ensure to wait for the change feed loading into memory from etcd
    36      ensure $MAX_RETRIES "curl -s -d \"cf-id=$changefeed&admin-job=1\" http://127.0.0.1:8300/capture/owner/admin | grep true"
    37  
    38      run_sql "INSERT INTO test.availability1(id, val) VALUES (4, 4);"
    39  
    40      # resume the change feed job
    41      curl -d "cf-id=$changefeed&admin-job=2" http://127.0.0.1:8300/capture/owner/admin
    42      ensure $MAX_RETRIES nonempty 'select id, val from test.availability1 where id=4 and val=4'
    43  
    44      echo "test_stop_processor pass"
    45      cleanup_process $CDC_BINARY
    46  }