forked from mongodb-labs/mongoreplay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsanity_check.sh
executable file
·71 lines (57 loc) · 1.53 KB
/
sanity_check.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
#!/bin/bash
PORT=27017
STARTMONGO=false
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PCAPFILE="$SCRIPT_DIR/mongoreplay/mongoreplay_test.out"
while test $# -gt 0; do
case "$1" in
-f|--file)
shift
PCAPFILE="$1"
shift
;;
-p|--port)
shift
PORT="$1"
shift
;;
-m|--start-mongo)
shift
STARTMONGO=true
;;
*)
echo "Unknown arg: $1"
exit 1
esac
done
command -v mongoreplay >/dev/null
if [ $? != 0 ]; then
echo "mongoreplay must be in PATH"
exit 1
fi
set -e
set -o verbose
OUTFILE="$(echo $PCAPFILE | cut -f 1 -d '.').playback"
mongoreplay record -f $PCAPFILE -p $OUTFILE
if [ "$STARTMONGO" = true ]; then
rm -rf "$SCRIPT_DIR/data"
mkdir "$SCRIPT_DIR/data"
echo "starting MONGOD"
mongod --port=$PORT --dbpath="$SCRIPT_DIR/data" &
MONGOPID=$!
fi
mongo --port=$PORT mongoplay_test --eval "db.setProfilingLevel(2);"
mongo --port=$PORT mongoplay_test --eval "db.createCollection('sanity_check', {});"
export MONGOREPLAY_HOST="mongodb://localhost:$PORT"
mongoreplay play -p $OUTFILE
mongo --port=$PORT mongoplay_test --eval "var profile_results = db.system.profile.find({'ns':'mongoplay_test.sanity_check'});
assert.gt(profile_results.size(), 0);"
mongo --port=$PORT mongoplay_test --eval "var query_results = db.sanity_check.find({'test_success':1});
assert.gt(query_results.size(), 0);"
# test that files are correctly gziped ( TOOLS-1503 )
mongoreplay record -f $PCAPFILE -p ${OUTFILE} --gzip
gunzip -t ${OUTFILE}
echo "Success!"
if [ "$STARTMONGO" = true ]; then
kill $MONGOPID
fi