|
| 1 | +#!/usr/bin/env bash |
| 2 | +bash -n "$0" | exit 1 |
| 3 | +set -x |
| 4 | +# Remote cursor moves testcase for comdb2 |
| 5 | +################################################################################ |
| 6 | + |
| 7 | + |
| 8 | +# we rely on the following global variables to be set |
| 9 | +echo "main db vars" |
| 10 | +vars="TESTCASE DBNAME DBDIR TESTSROOTDIR TESTDIR CDB2_OPTIONS CDB2_CONFIG SECONDARY_DBNAME SECONDARY_DBDIR SECONDARY_CDB2_CONFIG SECONDARY_CDB2_OPTIONS TERTIARY_DBNAME TERTIARY_DBDIR TERTIARY_CDB2_CONFIG TERTIARY_CDB2_OPTIONS QUATERNARY_DBNAME QUATERNARY_DBDIR QUATERNARY_CDB2_CONFIG QUATERNARY_CDB2_OPTIONS" |
| 11 | +for required in $vars; do |
| 12 | + q=${!required} |
| 13 | + echo "$required=$q" |
| 14 | + if [[ -z "$q" ]]; then |
| 15 | + echo "$required not set" >&2 |
| 16 | + exit 1 |
| 17 | + fi |
| 18 | +done |
| 19 | + |
| 20 | +shards="" |
| 21 | +SHARDS_LIST="$DBNAME $SECONDARY_DBNAME $TERTIARY_DBNAME $QUATERNARY_DBNAME" |
| 22 | +numshards=4 |
| 23 | + |
| 24 | +S0_SQLT="cdb2sql --tabs ${CDB2_OPTIONS} ${DBNAME} default" |
| 25 | +S0_SQL="cdb2sql ${CDB2_OPTIONS} ${DBNAME} default" |
| 26 | +S1_SQLT="cdb2sql --tabs ${SECONDARY_CDB2_OPTIONS} ${SECONDARY_DBNAME} default" |
| 27 | +S1_SQL="cdb2sql ${SECONDARY_CDB2_OPTIONS} ${SECONDARY_DBNAME} default" |
| 28 | +S2_SQLT="cdb2sql --tabs ${TERTIARY_CDB2_OPTIONS} ${TERTIARY_DBNAME} default" |
| 29 | +S2_SQL="cdb2sql ${TERTIARY_CDB2_OPTIONS} ${TERTIARY_DBNAME} default" |
| 30 | +S3_SQLT="cdb2sql --tabs ${QUATERNARY_CDB2_OPTIONS} ${QUATERNARY_DBNAME} default" |
| 31 | +S3_SQL="cdb2sql ${QUATERNARY_CDB2_OPTIONS} ${QUATERNARY_DBNAME} default" |
| 32 | + |
| 33 | +OUT=log.txt |
| 34 | + |
| 35 | +export stopfile=./stopfile.txt |
| 36 | + |
| 37 | +rm ${OUT} |
| 38 | + |
| 39 | +function fail_exit() |
| 40 | +{ |
| 41 | + echo "Failed $@" | tee ${DBNAME}.fail_exit # runtestcase script looks for this file |
| 42 | + touch $stopfile |
| 43 | +} |
| 44 | + |
| 45 | +function setup_testcase { |
| 46 | + $S0_SQL "DROP TABLE IF EXISTS t" |
| 47 | +} |
| 48 | + |
| 49 | +function verify_table { |
| 50 | + tbl=$1 |
| 51 | + $S0_SQLT "SELECT * from ${tbl}" |
| 52 | + if (( $? != 0 )); then |
| 53 | + fail_exit "verify_table failed. Could not select from ${tbl} on ${DBNAME}" |
| 54 | + fi |
| 55 | + $S1_SQLT "SELECT * from ${tbl}" |
| 56 | + if (( $? != 0 )); then |
| 57 | + fail_exit "verify_table failed. Could not select from ${tbl} on ${SECONDARY_DBNAME}" |
| 58 | + fi |
| 59 | + $S2_SQLT "SELECT * from ${tbl}" |
| 60 | + if (( $? != 0 )); then |
| 61 | + fail_exit "verify_table failed. Could not select from ${tbl} on ${TERNARY_DBNAME}" |
| 62 | + fi |
| 63 | + $S3_SQLT "SELECT * from ${tbl}" |
| 64 | + if (( $? != 0 )); then |
| 65 | + fail_exit "verify_table failed. Could not select from ${tbl} on ${QUATERNARY_DBNAME}" |
| 66 | + fi |
| 67 | +} |
| 68 | +function verify_llmeta { |
| 69 | + expected=$1 |
| 70 | + result=$($S0_SQLT "EXEC PROCEDURE sys.cmd.send('llmeta list')" | grep "gen_shard") |
| 71 | + entry=`echo $result | cut -d ' ' -f 3 | cut -d '=' -f 2` |
| 72 | + if [ "$entry" != "$expected" ]; then |
| 73 | + fail_exit "verify_llmeta failed on $DBNAME. Expected $expected but got $entry" |
| 74 | + fi |
| 75 | + result=$($S1_SQLT "EXEC PROCEDURE sys.cmd.send('llmeta list')" | grep "gen_shard") |
| 76 | + entry=`echo $result | cut -d ' ' -f 3 | cut -d '=' -f 2` |
| 77 | + if [ "$entry" != "$expected" ]; then |
| 78 | + fail_exit "verify_llmeta failed on ${SECONDARY_DBNAME}. Expected $expected but got $entry" |
| 79 | + fi |
| 80 | + result=$($S2_SQLT "EXEC PROCEDURE sys.cmd.send('llmeta list')" | grep "gen_shard") |
| 81 | + entry=`echo $result | cut -d ' ' -f 3 | cut -d '=' -f 2` |
| 82 | + if [ "$entry" != "$expected" ]; then |
| 83 | + fail_exit "verify_llmeta failed on ${TERNARY_DBNAME}. Expected $expected but got $entry" |
| 84 | + fi |
| 85 | + result=$($S3_SQLT "EXEC PROCEDURE sys.cmd.send('llmeta list')" | grep "gen_shard") |
| 86 | + entry=`echo $result | cut -d ' ' -f 3 | cut -d '=' -f 2` |
| 87 | + if [ "$entry" != "$expected" ]; then |
| 88 | + fail_exit "verify_llmeta failed on ${QUATERNARY_DBNAME}. Expected $expected but got $entry" |
| 89 | + fi |
| 90 | +} |
| 91 | + |
| 92 | +function test_creation_nonkey { |
| 93 | + $S0_SQL "create table t(a int , b int) partitioned by columns(a) on (${shards})" |
| 94 | + if (( $? == 0 )); then |
| 95 | + fail_exit "test_creation succeeded. Should have failed creating a sharded table with a non-key sharding key" |
| 96 | + fi |
| 97 | +} |
| 98 | + |
| 99 | +function test_deletion { |
| 100 | + $S0_SQL "create table t(a int unique, b int) partitioned by columns(a) on (${shards})" |
| 101 | + if (( $? != 0 )); then |
| 102 | + fail_exit "test_creation failed. Could not create table" |
| 103 | + fi |
| 104 | + verify_table "t" |
| 105 | + $S0_SQL "drop table t" |
| 106 | + verify_llmeta '' |
| 107 | +} |
| 108 | + |
| 109 | +function test_creation { |
| 110 | + $S0_SQL "create table t(a int unique, b int) partitioned by columns(a) on (${shards})" |
| 111 | + if (( $? != 0 )); then |
| 112 | + fail_exit "test_creation failed. Could not create table" |
| 113 | + fi |
| 114 | + verify_table "t" |
| 115 | + expected="\"{\"t\":\"{\\\"TABLENAME\\\":\\\"t\\\",\\\"NUMDBS\\\":4,\\\"DBNAMES\\\":[\\\"${DBNAME}\\\",\\\"${SECONDARY_DBNAME}\\\",\\\"${TERTIARY_DBNAME}\\\",\\\"${QUATERNARY_DBNAME}\\\"],\\\"NUMCOLS\\\":1,\\\"COLUMNS\\\":[\\\"a\\\"],\\\"SHARDNAMES\\\":[\\\"\$1_t\\\",\\\"\$2_t\\\",\\\"\$3_t\\\",\\\"\$4_t\\\"]}\"}\"" |
| 116 | + verify_llmeta $expected |
| 117 | +} |
| 118 | + |
| 119 | +function run_test { |
| 120 | + testcase="testing creation" |
| 121 | + setup_testcase |
| 122 | + test_creation |
| 123 | + |
| 124 | + testcase="testing deletion" |
| 125 | + setup_testcase |
| 126 | + test_deletion |
| 127 | + |
| 128 | + testcase="testing creation with non-key sharding key" |
| 129 | + setup_testcase |
| 130 | + test_creation_nonkey |
| 131 | +} |
| 132 | + |
| 133 | +rm $stopfile >/dev/null 2>&1 |
| 134 | + |
| 135 | + |
| 136 | +for shard in $SHARDS_LIST; do |
| 137 | + shards+=" ${shard}," |
| 138 | +done |
| 139 | + |
| 140 | +# remove the last ',' |
| 141 | +shards=`echo $shards | sed 's/.$//'` |
| 142 | +echo $shards |
| 143 | + |
| 144 | +run_test |
| 145 | + |
| 146 | +if [[ -f $stopfile ]]; then |
| 147 | + echo "Testcase failed" |
| 148 | + exit -1 |
| 149 | +fi |
| 150 | + |
| 151 | +echo "Success" |
0 commit comments