export LANG=zh_CN.utf8 export LC_ALL=zh_CN.utf8 #改变工作目录到当前脚本所在路径 if [[ "$0" =~ / ]]; then cd "${0%/*}"; fi #通过env文件配置环境变量 if [[ -f "./env" ]]; then . ./env fi if [[ "$ETCDPATH" = "" ]]; then export ETCDPATH=47.92.151.165:2379 fi if [[ "$ETCDUSER" = "" ]]; then #// ETCDUSER=root export ETCDUSER= fi if [[ "$ETCDPASS" = "" ]]; then #// ETCDPASS=VXOrp3iEqNBlSTp8LR3nSg== export ETCDPASS= fi if [[ "$CASSANDRAPATH" = "" ]]; then export CASSANDRAPATH=47.92.151.165 fi if [[ "$CASSANDRALOOKUP" = "" ]]; then #// 默认为false,跨域连接时需要置true export CASSANDRALOOKUP=true fi if [[ "$NATSPATH" = "" ]]; then export NATSPATH=nats://user:N5JbKeT1C3uOUh317OVXjg==@47.92.151.165:4222 fi testunit=TestAll if [[ "$1" != "" ]]; then testunit="$1" fi export CASSANDRAKEYSPACE= if [[ "$2" != "" ]]; then export CASSANDRAKEYSPACE="$2" fi export shadow=1 if [[ "$3" != "" ]]; then export shadow="$3" fi export Name="test" if [[ "$4" != "" ]]; then export Name="$4" fi if [[ "$DC" != "" ]]; then export DC="${Name}dc${shadow}" fi export LOG_LEVEL=WARN if [[ "$5" != "" ]]; then export LOG_LEVEL="$5" fi if [[ ${CASSANDRAKEYSPACE} == "" ]]; then echo "usage: "$0" <测试点,空表示所有> <集群节点数,默认 1> <节点名,默认test> <日志级别,默认 WARN>" exit 1 fi if [[ "${TESTLOOPCOUNT}" == "" ]]; then export TESTLOOPCOUNT=1 fi testrun() { starttime=`date +%s` loopcount=0 while [[ $loopcount -lt ${TESTLOOPCOUNT} && $ret -eq 0 ]]; do loopcount=`expr $loopcount + 1` echo "测试次数: "${loopcount}" TESTLOOPCOUNT=${TESTLOOPCOUNT}" echo "测试时间: "`date "+%Y-%m-%d %H:%M:%S"` echo "测试点: "${testunit} echo "Keyspace: "${CASSANDRAKEYSPACE} echo "节点名: "${Name} echo "DC: "${DC} echo "集群节点数: "${shadow} echo "日志级别: "${LOG_LEVEL} echo "ETCDPATH: "$ETCDPATH echo "ETCDUSER: "$ETCDUSER echo "ETCDPASS: "$ETCDPASS echo "CASSANDRAPATH: "$CASSANDRAPATH echo "CASSANDRALOOKUP: "$CASSANDRALOOKUP echo "NATSPATH: "$NATSPATH ./odbtest -test.timeout 36000s -test.v -test.count=1 -test.run ^${testunit}$ test.shadow=${shadow} log.consolelevel=${LOG_LEVEL} keyspace=${CASSANDRAKEYSPACE} 2>&1 ret=$? done endtime=`date +%s` echo "used time:"$((endtime-starttime))"s" tailpid=`ps -ef | grep "tail -f test_${CASSANDRAKEYSPACE}.log" | grep -v grep | awk '{print $2}'` if [[ "$tailpid" != "" ]]; then kill -9 $tailpid fi } stoptest() { testpid=`ps -ef | grep './odbtest' | grep "${testunit}" | grep "keyspace=${CASSANDRAKEYSPACE}" | awk '{print $2}'` if [[ "$testpid" != "" ]]; then kill -9 $testpid fi tailpid=`ps -ef | grep "tail -f test_${CASSANDRAKEYSPACE}.log" | grep -v grep | awk '{print $2}'` if [[ "$tailpid" != "" ]]; then kill -9 $tailpid fi } stoptest sleep 1 trap "stoptest" INT echo "" > test_${CASSANDRAKEYSPACE}.log tail -f test_${CASSANDRAKEYSPACE}.log & testrun > test_${CASSANDRAKEYSPACE}.log