github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/lightning_auto_random_default/run.sh (about)

     1  #!/bin/sh
     2  #
     3  # Copyright 2020 PingCAP, Inc.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  set -eu
    17  
    18  # FIXME: auto-random is only stable on master currently.
    19  check_cluster_version 4 0 0 AUTO_RANDOM || exit 0
    20  
    21  for backend in tidb importer local; do
    22      if [ "$backend" = 'local' ]; then
    23          check_cluster_version 4 0 0 'local backend' || continue
    24      fi
    25  
    26      run_sql 'DROP DATABASE IF EXISTS auto_random;'
    27      run_lightning --backend $backend
    28  
    29      run_sql "SELECT count(*) from auto_random.t"
    30      check_contains "count(*): 6"
    31  
    32      run_sql "SELECT id & b'000001111111111111111111111111111111111111111111111111111111111' as inc FROM auto_random.t"
    33      check_contains 'inc: 1'
    34      check_contains 'inc: 2'
    35      check_contains 'inc: 3'
    36      if [ "$backend" = 'tidb' ]; then
    37        check_contains 'inc: 4'
    38        check_contains 'inc: 5'
    39        check_contains 'inc: 6'
    40        NEXT_AUTO_RAND_VAL=7
    41      else
    42        check_contains 'inc: 25'
    43        check_contains 'inc: 26'
    44        check_contains 'inc: 27'
    45        NEXT_AUTO_RAND_VAL=28
    46      fi
    47  
    48      # tidb backend randomly generate the auto-random bit for each statement, so with 2 statements,
    49      # the distinct auto_random prefix values can be 1 or 2, so we skip this check with tidb backend
    50      if [ "$backend" != 'tidb' ]; then
    51        run_sql "select count(distinct id >> 58) as count from auto_random.t"
    52        check_contains "count: 2"
    53      fi
    54  
    55      # auto random base is 4
    56      run_sql "SELECT max(id & b'000001111111111111111111111111111111111111111111111111111111111') >= $NEXT_AUTO_RAND_VAL as ge FROM auto_random.t"
    57      check_contains 'ge: 0'
    58      run_sql "INSERT INTO auto_random.t VALUES ();"
    59      run_sql "SELECT max(id & b'000001111111111111111111111111111111111111111111111111111111111') >= $NEXT_AUTO_RAND_VAL as ge FROM auto_random.t"
    60      check_contains 'ge: 1'
    61  done