mqltest.sh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. export LANG=zh_CN.utf8
  2. export LC_ALL=zh_CN.utf8 2>/dev/null
  3. #改变工作目录到当前脚本所在路径
  4. if [[ "$0" =~ / ]]; then cd "${0%/*}"; fi
  5. export CWD=`pwd`
  6. if [[ -e ~/odbserver/mql ]]; then
  7. mqlver=`ls -l mql`
  8. newmqlver=`cd ~/odbserver/; ls -l mql; cd ${CWD}`
  9. if [[ "$mqlver" != "$newmqlver" ]]; then
  10. cp -pf ~/odbserver/mql mql
  11. fi
  12. fi
  13. if [[ ! -e mql.conf ]]; then
  14. if [[ "${ODBPATH}" = "" ]]; then
  15. export ODBPATH=127.0.0.1:11001
  16. fi
  17. if [[ "${KEYSPACE}" = "" ]]; then
  18. export KEYSPACE=oktest
  19. fi
  20. fi
  21. odbver=`./mql odbver? log.level=error "$@"`
  22. odbpath=`./mql odbpath? log.level=error "$@"`
  23. keyspace=`./mql keyspace? log.level=error "$@"`
  24. if [[ `echo "${keyspace}" | wc -w` == "1" ]]; then
  25. logfile="${keyspace}.test.log"
  26. lastlogfile="${keyspace}.last.log"
  27. else
  28. logfile="test.log"
  29. lastlogfile="last.log"
  30. fi
  31. if [[ "${odbpath}" != "" ]]; then
  32. echo ODBPATH="${odbpath}"
  33. fi
  34. if [[ "${keyspace}" != "" ]]; then
  35. echo keyspace="${keyspace}"
  36. fi
  37. sleep 2
  38. filescount=`./mql files? log.level=error "$@" | wc -l`
  39. if [[ "${filescount}" == "0" || "${filescount}" == "1" ]]; then
  40. ./mql "$@"
  41. exit $?
  42. fi
  43. filepath=`echo "$@" | awk '{print $NF}'`
  44. # remove ./
  45. filepath=${filepath/\.\//}
  46. # remove last slash
  47. filepath=${filepath%/}
  48. mqlproc=`ps -ef | grep -v grep | grep mql | grep "${filepath}"`
  49. if [[ "$mqlproc" != "" ]]; then
  50. echo "another mql test is running"
  51. exit 111
  52. fi
  53. if [[ -e ${logfile} ]]; then
  54. mv -f ${logfile} ${lastlogfile}
  55. fi
  56. n=`./mql keyspace=matrix - "cql:select count(*) from system_schema.columns where keyspace_name='${keyspace}' and table_name='object_test'" 2>/dev/null | grep "count" | grep -v "grep" | grep -v "select" | awk '{print $2}'`
  57. if [[ "${n}" == "0" ]]; then
  58. n=1
  59. else
  60. n=`cat ${keyspace}.test.count 2>/dev/null`
  61. n=`expr 0${n} + 1`
  62. fi
  63. echo "${n}" > ${keyspace}.test.count
  64. ./mql "$@" "log.prefix=test $n" 2>&1 | tee ${logfile}
  65. lastline=`tail -n 1 $logfile 2>&1`
  66. if [[ "$lastline" = "FAIL" ]]; then
  67. exit 123
  68. elif [[ "$lastline" = "PASS" ]]; then
  69. echo "./mql $@" "log.prefix=test $n" 2>/dev/null >> ${keyspace}.history.log
  70. echo "${odbver}" 2>/dev/null >> ${keyspace}.history.log
  71. grep "test.code.version=" $logfile 2>/dev/null >> ${keyspace}.history.log
  72. tail -n 4 $logfile | head -n 1 2>/dev/null >> ${keyspace}.history.log
  73. exit 0
  74. elif [[ `echo "$lastline" | grep './mqltest.sh:' | grep "已杀死"` != "" ]]; then
  75. exit 99
  76. elif [[ `echo "$lastline" | grep './mqltest.sh:' | grep "killed"` != "" ]]; then
  77. exit 99
  78. fi
  79. # unkown status
  80. exit 125