PageRenderTime 21ms CodeModel.GetById 9ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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