-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrader_user_loop.sh
executable file
·136 lines (119 loc) · 4.06 KB
/
trader_user_loop.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
################
## PARAMETERS ##
################
INGRESS=$1
THREAD=$2
NUM_ITERATIONS=$3
NUM_USERS=$4
NUMBER_OF_SHARES=$5
MULT_FACTOR=${6-1}
COOKIE_FILE=$7
DIRECTORY=$8
###################
## Share symbols ##
###################
IBM="IBM"
GOOGLE="GOOG"
APPLE="AAPL"
SYMBOLS="${IBM} ${GOOGLE} ${APPLE}"
#######################
## HTTP return codes ##
#######################
CREATE_CODE=302
RETRIEVE_CODE=200
UPDATE_CODE=302
SUMMARY_CODE=200
##############
## COMMANDS ##
##############
create()
{
echo "[`date '+%H:%M:%S'`] [${THREAD}] - Creating user ${USER}..."
RESPONSE=`curl -b ${COOKIE_FILE} -o /dev/null -w '%{http_code}' -s "https://${INGRESS}/trader/addPortfolio" \
-H "Origin: https://${INGRESS}" \
-H "Referer: https://${INGRESS}/trader/addPortfolio" \
--data owner=${USER}\&submit=Submit \
--compressed --insecure`
if [ ${RESPONSE} -ne ${CREATE_CODE} ]; then
echo "[`date '+%H:%M:%S'`] [${THREAD}] - An error occured creating the user ${USER}"
# Do not exit as the test would finish
# exit 1
fi
echo "[`date '+%H:%M:%S'`] [${THREAD}] - Done"
}
update()
{
RESPONSE=`curl -b ${COOKIE_FILE} -o /dev/null -w '%{http_code}' -s "https://${INGRESS}/trader/addStock?owner=${USER}" \
-H "Origin: https://${INGRESS}" \
-H "Referer: https://${INGRESS}/trader/addStock?owner=${USER}" \
--data symbol=${SYMBOL}\&shares=${NUMBER_OF_SHARES}\&submit=Submit \
--compressed --insecure`
echo "RESPONSE: ${RESPONSE} || Iteration ${iteration} - user ${USER} - symbol ${SYMBOL}" >> output/return_code.txt
if [ ${RESPONSE} -ne ${UPDATE_CODE} ]; then
echo "[`date '+%H:%M:%S'`] [${THREAD}] - An error occured adding ${NUMBER_OF_SHARES} ${SYMBOL} shares to ${USER} stock"
# Do not exit as the test would finish
# exit 1
fi
}
retrieve()
{
RESPONSE=`curl -b ${COOKIE_FILE} -o ${DIRECTORY}/retrieve_${1}.html -w '%{http_code}' -s "https://${INGRESS}/trader/viewPortfolio?owner=${USER}" \
-H "Origin: https://${INGRESS}" \
-H "Referer: https://${INGRESS}/trader/summary" \
--compressed --insecure`
if [ ${RESPONSE} -ne ${RETRIEVE_CODE} ]; then
echo "[`date '+%H:%M:%S'`] [${THREAD}] - An error occured retrieving the info for user ${USER}"
# Do not exit as the test would finish
# exit 1
fi
}
summary()
{
echo "[`date '+%H:%M:%S'`] [${THREAD}] - Getting the ${1} summary report..."
RESPONSE=`curl -b ${COOKIE_FILE} -o ${DIRECTORY}/summary_${1}.html -w '%{http_code}' -s "https://${INGRESS}/trader/summary" \
-H "Origin: https://${INGRESS}" \
-H "Referer: https://${INGRESS}/trader/summary" \
--compressed --insecure`
if [ ${RESPONSE} -ne ${SUMMARY_CODE} ]; then
echo "[`date '+%H:%M:%S'`] [${THREAD}] - An error occured getting the ${1} summary page"
# Do not exit as the test would finish
# exit 1
fi
echo "[`date '+%H:%M:%S'`] [${THREAD}] - Done"
}
######################################
## ##
## TEST ##
## ##
######################################
echo "[`date '+%H:%M:%S'`] [${THREAD}] - Begin of script"
# Iterations
for iteration in $(seq $NUM_ITERATIONS)
do
echo "[`date '+%H:%M:%S'`] [${THREAD}] - Begin Iteration $iteration"
# For each user
for user in $(seq $NUM_USERS)
do
# Set user
USER="User_${THREAD}_${user}"
# Create user if first iteration
if [ ${iteration} -eq 1 ]; then
create
fi
# Add shares of each symbol
for symbol in ${SYMBOLS}
do
SYMBOL=${symbol}
update
done
done
NUMBER_OF_SHARES=$((NUMBER_OF_SHARES*MULT_FACTOR))
# Results after an iteration
summary "thread_${THREAD}_iteration_${iteration}"
#export_db "iteration_${iteration}"
echo "[`date '+%H:%M:%S'`] [${THREAD}] - End Iteration $iteration"
done
# Mark this thread as done
touch output/thread_${THREAD}_done.txt
exit 0