-
Notifications
You must be signed in to change notification settings - Fork 8
/
test.sh
executable file
·165 lines (144 loc) · 3.02 KB
/
test.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/sh
set -o errexit
kill() {
if [ "$(uname)" = "Darwin" ]; then
SERVICE='raft-key-value'
if pgrep -xq -- "${SERVICE}"; then
pkill -f "${SERVICE}"
fi
else
set +e # killall will error if finds no process to kill
killall raft-key-value
set -e
fi
}
rpc() {
local uri=$1
local body="$2"
echo '---'" rpc(:$uri, $body)"
{
if [ ".$body" = "." ]; then
curl --silent "127.0.0.1:$uri"
else
curl --silent "127.0.0.1:$uri" -H "Content-Type: application/json" -d "$body"
fi
} | {
if type jq > /dev/null 2>&1; then
jq
else
cat
fi
}
echo
echo
}
build_cluster() {
echo "Adding node 2 and node 3 as learners, to receive log from leader node 1"
echo
rpc 2100$1/init '{}'
echo "Node $1 added as leaner"
if test $1 -ne 1
then
rpc 2100$1/add-learner '[1, "127.0.0.1:21001"]'
echo "Node 1 added as leaner"
fi
if test $1 -ne 2
then
rpc 2100$1/add-learner '[2, "127.0.0.1:21002"]'
echo "Node 2 added as leaner"
fi
if test $1 -ne 3
then
rpc 2100$1/add-learner '[3, "127.0.0.1:21003"]'
echo "Node 3 added as leaner"
fi
}
place_order() {
##############################################################{
echo "Place order on leader"
for i in {1..1500}
do
echo
JSON='{"Place": { "order": {"live": "Limit", "side": "Buy", "price": 400'
JSON+="$i.0,"
JSON+='"volume": 4.4, "id": '
JSON+="$i,"
JSON+=' "sequance": '
JSON+="$i"
JSON+='} }}'
echo $JSON
rpc 2100$1/write "$JSON"
done
echo "Data written"
}
get_metrics() {
echo "Get metrics from the leader"
echo
rpc 2100$1/metrics
}
kill_node() {
case $1 in
"1")
pkill -f 'raft-key-value --id 1'
;;
"2")
pkill -f 'raft-key-value --id 2'
;;
"3")
pkill -f 'raft-key-value --id 3'
;;
esac
}
start_node() {
nohup ./target/debug/raft-key-value --id $1 --http-addr 127.0.0.1:2100$1 > n$1.log &
}
change_membership () {
echo "Changing membership from [1] to 3 nodes cluster: [$1]"
echo
rpc 21001/change-membership '[1]'
echo "Membership changed"
}
clean() {
echo "Cleaning"
surname=`date -Iseconds`
mv /tmp/snapshot /tmp/snapshot.$surname
mkdir -p /tmp/snapshot
mv /tmp/journal /tmp/journal.$surname
mkdir -p /tmp/journal
}
export RUST_LOG=debug
export RUST_LIB_BACKTRACE=1
export RUST_BACKTRACE=1
echo "Run command $1"
case $1 in
"place-order")
place_order $2
;;
"metrics")
get_metrics $2
;;
"kill-node")
kill_node $2
;;
"kill")
kill
;;
"start-node")
start_node $2
;;
"get-seq")
rpc 2100$2/read '"orderbook_sequance"'
;;
"build-cluster")
build_cluster $2
;;
"change-membership")
change_membership $2
;;
"clean")
clean
;;
*)
"Nothing is done!"
;;
esac