/test-scripts/masterTestScript.sh

http://go-web-server.googlecode.com/ · Shell · 96 lines · 62 code · 8 blank · 26 comment · 8 complexity · 7c0b14b1892cb2eb2a9dab9fd546a39e MD5 · raw file

  1. #!/bin/bash
  2. # ************* Assumptions *************
  3. # 1. This script is running in the same
  4. # directory as the client program and
  5. # any other executables required by
  6. # this script.
  7. # 2. The "servers" variable list must be
  8. # seeded with the correct IP addresses.
  9. # 3. The port number is also provided.
  10. # 4. You can adjust the number of
  11. # iterations, the default is 100.
  12. # ***************************************
  13. # user adjustable variables
  14. servers=( 172.16.11.149 172.16.11.151 172.16.11.148 172.16.11.150 )
  15. port=( 12345 12345 12345 12345 )
  16. numIterations=100
  17. # program variables
  18. correctResult=0
  19. incorrectResult=0
  20. incorrectCount=0
  21. highIncorrectCount=0
  22. noResponse=0
  23. # hash table implementation
  24. hput () {
  25. eval hash"$1"='$2'
  26. }
  27. hget () {
  28. eval storedValue='${hash'"$1"'#hash}'
  29. if [[ "$storedValue" = "$2" || "$storedValue" = "" ]]
  30. then
  31. correctResult=$(($correctResult + 1))
  32. incorrectCount=0
  33. else
  34. incorrectResult=$(($incorrectResult + 1))
  35. incorrectCount=`expr $incorrectCount + 1`
  36. if [ "$highIncorrectCount" -lt "$incorrectCount" ]
  37. then
  38. highIncorrectCount=$incorrectCount
  39. fi
  40. fi
  41. }
  42. # Show consistency capabilities
  43. echo "Testing Consistency"
  44. # execute many requests from the client
  45. for (( c=0; c<$numIterations; c++ ))
  46. do
  47. # uncomment the line below for printing of current iteration
  48. # echo $c
  49. # generate random number for server selection
  50. n=$(($RANDOM % 4))
  51. # generate the random key
  52. k=$(($RANDOM % 4 + 1)) #8 + 1))
  53. export key=`./generateString $k`
  54. # generate the random value
  55. v=$(($RANDOM % 20 + 1)) #48 + 1))
  56. export value=`./generateString $v`
  57. # pick get or set operation (get = 0, set = 1)
  58. getOrSet=$(($RANDOM % 2))
  59. if [ "$getOrSet" -eq 0 ]
  60. then
  61. # invoke the client program for get
  62. export rt=`./client -h ${servers[$n]}:${port[$n]} -k $key | grep "\["`
  63. export retrievedValue=`python getValue.py $rt`
  64. if [ "$retrievedValue" = "[[" ]
  65. then
  66. noResponse=`expr $noResponse + 1`
  67. else
  68. hget $key $retrievedValue
  69. fi
  70. else # $getOrSet = 1
  71. # invoke the client program for set
  72. export rt=`./client -h ${servers[$n]}:${port[$n]} -k $key -v $value | grep "\["`
  73. export retrievedValue=`python getValue.py $rt`
  74. if [ "$retrievedValue" = "[[" ]
  75. then
  76. noResponse=`expr $noResponse + 1`
  77. else
  78. hget $key $retrievedValue
  79. hput $key $value
  80. fi
  81. fi
  82. done
  83. # print the results
  84. echo "For" $numIterations "get or set operations:"
  85. echo $correctResult "returned the correct value, and"
  86. echo $incorrectResult "returned the incorrect value"
  87. echo "The maximum incorrect results in a row was" $highIncorrectCount
  88. echo "No response from" $noResponse