mqltest.sh 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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" ]]; then
  40. ./mql "$@"
  41. exit $?
  42. fi
  43. if [[ "${filescount}" == "1" ]]; then
  44. n=`ps -ef | grep "mql %@" | grep -v grep | wc -l`
  45. n=`expr $n + 1`
  46. logfile="${keyspace}.${n}test.log"
  47. ./mql "$@" 2>&1 | tee ${logfile}
  48. exit $?
  49. fi
  50. filepath=`echo "$@" | awk '{print $NF}'`
  51. # remove ./
  52. filepath=${filepath/\.\//}
  53. # remove last slash
  54. filepath=${filepath%/}
  55. mqlproc=`ps -ef | grep -v grep | grep mql | grep "${filepath}"`
  56. if [[ "$mqlproc" != "" ]]; then
  57. echo "another mql test is running"
  58. exit 111
  59. fi
  60. if [[ -e ${logfile} ]]; then
  61. mv -f ${logfile} ${lastlogfile}
  62. fi
  63. 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}'`
  64. if [[ "${n}" == "0" ]]; then
  65. n=1
  66. else
  67. n=`cat ${keyspace}.test.count 2>/dev/null`
  68. n=`expr 0${n} + 1`
  69. fi
  70. echo "${n}" > ${keyspace}.test.count
  71. ./mql "$@" "log.prefix=test $n" 2>&1 | tee ${logfile}
  72. lastline=`tail -n 1 $logfile 2>&1`
  73. if [[ "$lastline" = "FAIL" ]]; then
  74. exit 123
  75. elif [[ "$lastline" = "PASS" ]]; then
  76. echo "./mql $@" "log.prefix=test $n" 2>/dev/null >> ${keyspace}.history.log
  77. echo "${odbver}" 2>/dev/null >> ${keyspace}.history.log
  78. grep "test.code.version=" $logfile 2>/dev/null >> ${keyspace}.history.log
  79. tail -n 4 $logfile | head -n 1 2>/dev/null >> ${keyspace}.history.log
  80. exit 0
  81. elif [[ `echo "$lastline" | grep './mqltest.sh:' | grep "已杀死"` != "" ]]; then
  82. exit 99
  83. elif [[ `echo "$lastline" | grep './mqltest.sh:' | grep "killed"` != "" ]]; then
  84. exit 99
  85. fi
  86. # unkown status
  87. exit 125