2014-03-23 03:26:07 +00:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
# Скрипт для тестирования запросов к ClickHouse.
|
|
|
|
|
# Из файлов *.sql в заданной директории, в алфавитном порядке, отправляются все запросы.
|
2014-03-23 15:16:58 +00:00
|
|
|
|
# Результаты сравниваются с эталонами.
|
2014-03-23 03:26:07 +00:00
|
|
|
|
|
|
|
|
|
QUERIES_DIR="./queries"
|
2014-03-28 15:58:59 +00:00
|
|
|
|
CLIENT_PROGRAM="clickhouse-client -n"
|
2014-03-23 03:26:07 +00:00
|
|
|
|
|
2014-07-10 18:58:04 +00:00
|
|
|
|
if [ -t 1 ]; then # stdout - терминал.
|
|
|
|
|
COLOR_RESET="\033[0m"
|
|
|
|
|
COLOR_WHITE="\033[1;37m"
|
|
|
|
|
COLOR_FAIL="\033[1;31m"
|
|
|
|
|
COLOR_UNKNOWN="\033[1;30m"
|
|
|
|
|
COLOR_OK="\033[1;32m"
|
2014-07-31 13:53:54 +00:00
|
|
|
|
COLOR_SKIPPED="\033[1;34m"
|
2014-07-10 18:58:04 +00:00
|
|
|
|
else
|
|
|
|
|
COLOR_RESET=""
|
|
|
|
|
COLOR_WHITE=""
|
|
|
|
|
COLOR_FAIL=""
|
|
|
|
|
COLOR_UNKNOWN=""
|
|
|
|
|
COLOR_OK=""
|
2014-07-31 13:53:54 +00:00
|
|
|
|
COLOR_SKIPPED=""
|
2014-07-10 18:58:04 +00:00
|
|
|
|
fi
|
2014-03-23 03:26:07 +00:00
|
|
|
|
|
|
|
|
|
MSG_FAIL="${COLOR_WHITE}[ ${COLOR_FAIL}FAIL${COLOR_WHITE} ]${COLOR_RESET}"
|
|
|
|
|
MSG_UNKNOWN="${COLOR_WHITE}[ ${COLOR_UNKNOWN}UNKNOWN${COLOR_WHITE} ]${COLOR_RESET}"
|
|
|
|
|
MSG_OK="${COLOR_WHITE}[ ${COLOR_OK}OK${COLOR_WHITE} ]${COLOR_RESET}"
|
2014-07-31 13:53:54 +00:00
|
|
|
|
MSG_SKIPPED="${COLOR_WHITE}[ ${COLOR_SKIPPED}SKIPPED${COLOR_WHITE} ]${COLOR_RESET}"
|
2014-03-23 03:26:07 +00:00
|
|
|
|
|
2014-03-23 03:46:25 +00:00
|
|
|
|
ERRORS=0
|
2014-03-23 03:40:09 +00:00
|
|
|
|
|
2014-03-25 23:15:14 +00:00
|
|
|
|
|
2014-07-31 13:53:54 +00:00
|
|
|
|
if [ "$1" == "--zookeeper" ]; then
|
|
|
|
|
ZOOKEEPER=1
|
2014-07-31 13:58:49 +00:00
|
|
|
|
shift
|
|
|
|
|
elif [ "$1" == "--no-zookeeper" ]; then
|
|
|
|
|
ZOOKEEPER=0
|
|
|
|
|
shift
|
2014-07-31 13:53:54 +00:00
|
|
|
|
elif grep -q '<zookeeper' /etc/clickhouse-server/config-preprocessed.xml; then
|
|
|
|
|
ZOOKEEPER=1
|
|
|
|
|
else
|
|
|
|
|
ZOOKEEPER=0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
2016-02-08 21:09:09 +00:00
|
|
|
|
# Тесты, зависящие от данных Метрики - не публикуются наружу. Создаём симлинки на внутренний репозиторий. Весьма неудобно.
|
2016-03-04 21:28:05 +00:00
|
|
|
|
QUERIES_PRIVATE_DIR="../../private/tests/${QUERIES_DIR}"
|
2016-02-08 21:09:09 +00:00
|
|
|
|
if [ -d "$QUERIES_PRIVATE_DIR" ]; then
|
|
|
|
|
for dir in $(ls $QUERIES_PRIVATE_DIR)
|
|
|
|
|
do
|
|
|
|
|
[ -d "$QUERIES_DIR/$dir" ] || ln -s "../$QUERIES_PRIVATE_DIR/$dir" "$QUERIES_DIR/$dir"
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
2014-03-24 02:50:39 +00:00
|
|
|
|
for dir in $(ls $QUERIES_DIR)
|
2014-03-23 03:26:07 +00:00
|
|
|
|
do
|
2014-03-24 02:50:39 +00:00
|
|
|
|
tests_name=$(echo $dir | sed -E 's/^[0-9_]+//')
|
|
|
|
|
|
|
|
|
|
echo
|
|
|
|
|
echo "Running $tests_name tests."
|
|
|
|
|
echo
|
|
|
|
|
|
|
|
|
|
if [[ "$tests_name" =~ "stateful" && 0 -eq $(echo "EXISTS TABLE test.hits" | $CLIENT_PROGRAM) ]]; then
|
|
|
|
|
echo "Won't run stateful tests because test data wasn't loaded. See README.txt."
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
|
2016-08-10 04:48:14 +00:00
|
|
|
|
for query_file in $QUERIES_DIR/$dir/*$1*.{sql,sh}
|
2014-03-24 02:50:39 +00:00
|
|
|
|
do
|
2016-08-10 04:48:14 +00:00
|
|
|
|
# No corresponding files
|
|
|
|
|
if [[ ! -e "$query_file" ]]; then
|
2014-04-24 23:13:06 +00:00
|
|
|
|
continue
|
|
|
|
|
fi
|
2014-03-23 03:26:07 +00:00
|
|
|
|
|
2016-08-10 04:48:14 +00:00
|
|
|
|
extension=$(echo $query_file | sed -r 's/^.+\.(sql|sh)$/\1/')
|
|
|
|
|
test_name=$(basename $query_file .$extension)
|
|
|
|
|
|
2015-09-29 23:58:26 +00:00
|
|
|
|
printf "%-70s" "$test_name: "
|
2014-07-31 13:53:54 +00:00
|
|
|
|
|
|
|
|
|
if [ $ZOOKEEPER -eq 0 ] && (echo "$test_name" | grep -q 'zookeeper'); then
|
|
|
|
|
echo -e "$MSG_SKIPPED - no zookeeper"
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
|
2014-03-24 02:50:39 +00:00
|
|
|
|
result_file=$QUERIES_DIR/$dir/$test_name.result
|
|
|
|
|
error_file=$QUERIES_DIR/$dir/$test_name.error
|
|
|
|
|
reference_file=$QUERIES_DIR/$dir/$test_name.reference
|
|
|
|
|
diff_file=$QUERIES_DIR/$dir/$test_name.diff
|
2014-03-23 03:26:07 +00:00
|
|
|
|
|
2014-04-24 23:13:06 +00:00
|
|
|
|
if [[ "$extension" == "sql" ]]; then
|
|
|
|
|
$CLIENT_PROGRAM < $query_file > $result_file 2> $error_file
|
|
|
|
|
ret_code=$?
|
|
|
|
|
else
|
|
|
|
|
$query_file > $result_file 2> $error_file
|
|
|
|
|
ret_code=$?
|
|
|
|
|
fi
|
2014-03-23 03:26:07 +00:00
|
|
|
|
|
2014-03-24 02:50:39 +00:00
|
|
|
|
if [ $ret_code -ne 0 ]; then
|
|
|
|
|
ERRORS=$(($ERRORS + 1))
|
|
|
|
|
echo -e "$MSG_FAIL - return code $ret_code"
|
|
|
|
|
if [ -s "$error_file" ]; then
|
|
|
|
|
cat $error_file
|
|
|
|
|
fi
|
|
|
|
|
# разорвано соединение с сервером
|
|
|
|
|
if grep -q -E "Connection refused|Attempt to read after eof" $error_file; then
|
|
|
|
|
exit 1;
|
|
|
|
|
fi
|
|
|
|
|
elif [ -s "$error_file" ]; then
|
|
|
|
|
ERRORS=$(($ERRORS + 1))
|
|
|
|
|
echo -e "$MSG_FAIL - having stderror:"
|
2014-03-23 03:26:07 +00:00
|
|
|
|
cat $error_file
|
2014-03-24 02:50:39 +00:00
|
|
|
|
elif grep -q "Exception" $result_file; then
|
2014-03-23 03:46:25 +00:00
|
|
|
|
ERRORS=$(($ERRORS + 1))
|
2014-03-24 02:50:39 +00:00
|
|
|
|
echo -e "$MSG_FAIL - having exception:"
|
|
|
|
|
cat $result_file
|
|
|
|
|
elif [ ! -e "$reference_file" ]; then
|
2016-08-10 04:48:14 +00:00
|
|
|
|
echo -e "$MSG_UNKNOWN - no reference file"
|
2014-03-23 03:26:07 +00:00
|
|
|
|
else
|
2014-03-24 02:50:39 +00:00
|
|
|
|
diff $reference_file $result_file > $diff_file
|
|
|
|
|
if [ -s "$diff_file" ]; then
|
|
|
|
|
ERRORS=$(($ERRORS + 1))
|
|
|
|
|
echo -e "$MSG_FAIL - result differs with reference:"
|
|
|
|
|
cat $diff_file
|
|
|
|
|
else
|
|
|
|
|
echo -e "$MSG_OK"
|
|
|
|
|
rm $error_file $result_file $diff_file
|
|
|
|
|
fi
|
2014-03-23 03:26:07 +00:00
|
|
|
|
fi
|
2014-03-24 02:50:39 +00:00
|
|
|
|
done
|
2014-03-23 03:26:07 +00:00
|
|
|
|
done
|
2014-03-23 03:40:09 +00:00
|
|
|
|
|
2014-03-23 03:46:25 +00:00
|
|
|
|
|
|
|
|
|
echo
|
|
|
|
|
|
|
|
|
|
if [ $ERRORS -gt 0 ]; then
|
|
|
|
|
echo -e "${COLOR_FAIL}Having $ERRORS errors!${COLOR_RESET}"
|
|
|
|
|
exit 1
|
|
|
|
|
else
|
2014-03-24 02:50:39 +00:00
|
|
|
|
echo -e "${COLOR_OK}All tests passed.${COLOR_RESET}"
|
2014-03-23 03:46:25 +00:00
|
|
|
|
exit 0
|
|
|
|
|
fi
|