-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathrun.sh
executable file
·87 lines (71 loc) · 1.87 KB
/
run.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
#!/bin/bash
[ "$DEBUG" ] && set -x
set -eo pipefail -o errtrace
dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
image="$1"
# Use the image being tested as our client image since it should already have curl
clientImage="$image"
# Create an instance of the container-under-test
cid="$(
docker run -d \
-e MAX_HEAP_SIZE='128m' \
-e HEAP_NEWSIZE='32m' \
-e JVM_OPTS='
-Dcom.sun.management.jmxremote.port=7199
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
' \
"$image"
)"
trap "docker rm -vf $cid > /dev/null" EXIT
trap "( set -x; docker logs --tail=20 $cid )" ERR
_status() {
docker run --rm --link "$cid":cassandra "$clientImage" nodetool -h cassandra status
}
# Make sure our container is up
. "$dir/../../retry.sh" '_status'
cqlsh() {
docker run -i --rm \
--link "$cid":cassandra \
"$clientImage" \
cqlsh -u cassandra -p cassandra "$@" cassandra
}
# Make sure our container is listening
. "$dir/../../retry.sh" 'cqlsh < /dev/null'
# https://wiki.apache.org/cassandra/GettingStarted#Step_4:_Using_cqlsh
cqlsh -e "
CREATE KEYSPACE mykeyspace
WITH REPLICATION = {
'class': 'SimpleStrategy',
'replication_factor': 1
}
"
cqlsh -k mykeyspace -e "
CREATE TABLE users (
user_id int PRIMARY KEY,
fname text,
lname text
)
"
cqlsh -k mykeyspace -e "
INSERT INTO users (user_id, fname, lname)
VALUES (1745, 'john', 'smith')
"
cqlsh -k mykeyspace -e "
INSERT INTO users (user_id, fname, lname)
VALUES (1744, 'john', 'doe')
"
cqlsh -k mykeyspace -e "
INSERT INTO users (user_id, fname, lname)
VALUES (1746, 'john', 'smith')
"
# TODO find some way to get cqlsh to provide machine-readable output D:
[[ "$(cqlsh -k mykeyspace -e "
SELECT * FROM users
")" == *'3 rows'* ]]
cqlsh -k mykeyspace -e "
CREATE INDEX ON users (lname)
"
[[ "$(cqlsh -k mykeyspace -e "
SELECT * FROM users WHERE lname = 'smith'
")" == *'2 rows'* ]]