Skip to content

Commit 9dad451

Browse files
committed
Merge remote-tracking branch 'origin/bootstrap-test' into kubernetes-1.8-test
2 parents 1216d25 + 9db60f0 commit 9dad451

File tree

1 file changed

+99
-23
lines changed

1 file changed

+99
-23
lines changed

test/basic-with-kafkacat.yml

Lines changed: 99 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,69 @@
11
---
22
kind: ConfigMap
33
metadata:
4-
name: basic-with-kafkacat
4+
name: test-basic-with-kafkacat
55
namespace: test-kafka
66
apiVersion: v1
77
data:
88

99
setup.sh: |-
1010
touch /tmp/testlog
11-
tail -f /tmp/testlog
1211
13-
continue.sh: |-
14-
exit 0
12+
tail -f /tmp/testlog
1513
16-
run.sh: |-
14+
test.sh: |-
1715
exec >> /tmp/testlog
1816
exec 2>&1
1917
20-
unique=$(date -Ins)
18+
PC_WAIT=.2
19+
MAX_AGE=5
20+
21+
UNIQUE="${HOSTNAME}@$(date -u -Ins)"
22+
23+
echo "Test $UNIQUE" >> /shared/produce.tmp
24+
sleep $PC_WAIT
25+
LAST=$(tail -n 1 /shared/consumed.tmp)
26+
27+
LAST_TS=$(echo $LAST | awk -F';' '{print $1}')
28+
LAST_MSG=$(echo $LAST | awk -F';' '{print $4}')
29+
NOW=$(date -u +%s%3N)
30+
DIFF_S=$((($NOW - $LAST_TS)/1000))
31+
DIFF_MS=$((($NOW - $LAST_TS)%1000))
32+
#echo "$NOW ($(date +%FT%H:%M:%S.%3N)):"
33+
#echo "$LAST_TS"
34+
35+
if [ $DIFF_S -gt $MAX_AGE ]; then
36+
echo "Last message is $DIFF_S.$DIFF_MS old:"
37+
echo "$LAST_MSG"
38+
exit 10
39+
fi
40+
41+
if [[ "$LAST_MSG" != *"$UNIQUE" ]]; then
42+
echo "Last message (at $LAST_TS) isn't from this test run ($UNIQUE):"
43+
echo "$LAST_MSG"
44+
exit 11
45+
fi
2146
22-
echo "Test $unique" | kafkacat -P -b $BOOTSTRAP -t test-basic-with-kafkacat -v
23-
kafkacat -C -b $BOOTSTRAP -t test-basic-with-kafkacat -o -1 -e | grep $unique
47+
# get info about this message
48+
kafkacat -Q -b $BOOTSTRAP -t test-basic-with-kafkacat:0:$LAST_TS \
49+
-X socket.timeout.ms=600 -X session.timeout.ms=300 -X request.timeout.ms=50 -X metadata.request.timeout.ms=600
50+
[ $? -eq 0 ] || echo "At $(date +%FT%H:%M:%S.%3N) bootstrap broker(s) might be down"
51+
# but don't fail the test; producer and consumer should keep going if there are other brokers
52+
53+
# We haven't asserted that the consumer works, so we'll just have to assume that it will exit if it fails
2454
2555
exit 0
2656
57+
quit-on-nonzero-exit.sh: |-
58+
exec >> /tmp/testlog
59+
exec 2>&1
60+
61+
exit 0
2762
---
2863
apiVersion: batch/v1
2964
kind: Job
3065
metadata:
31-
name: basic-with-kafkacat
66+
name: test-basic-with-kafkacat
3267
namespace: test-kafka
3368
spec:
3469
template:
@@ -53,51 +88,92 @@ spec:
5388
apiVersion: apps/v1beta1
5489
kind: Deployment
5590
metadata:
56-
name: basic-with-kafkacat
91+
name: test-basic-with-kafkacat
5792
namespace: test-kafka
5893
spec:
5994
replicas: 1
95+
strategy:
96+
type: Recreate
6097
template:
6198
metadata:
6299
labels:
63-
test-target: kafka
100+
test-target: kube-test
64101
test-type: readiness
102+
# for example:
103+
# readonly - can be used in production
104+
# isolated - read/write but in a manner that does not affect other services
105+
# load - unsuitable for production because it uses significant resources
106+
# chaos - unsuitable for production because it injects failure modes
107+
#test-use:
65108
spec:
66109
containers:
110+
- name: producer
111+
image: solsson/kafkacat@sha256:ebebf47061300b14a4b4c2e1e4303ab29f65e4b95d34af1b14bb8f7ec6da7cef
112+
env:
113+
- name: BOOTSTRAP
114+
value: kafka-0.broker.kafka.svc.cluster.local:9092
115+
command:
116+
- /bin/bash
117+
- -cex
118+
- >
119+
echo "--- start $HOSTNAME $(date --iso-8601='ns' -u) ---" >> /shared/produce.tmp
120+
;
121+
tail -f /shared/produce.tmp |
122+
kafkacat -P -b $BOOTSTRAP -t test-basic-with-kafkacat -v -T -d broker
123+
;
124+
volumeMounts:
125+
- name: config
126+
mountPath: /test
127+
- name: shared
128+
mountPath: /shared
129+
- name: consumer
130+
image: solsson/kafkacat@sha256:ebebf47061300b14a4b4c2e1e4303ab29f65e4b95d34af1b14bb8f7ec6da7cef
131+
env:
132+
- name: BOOTSTRAP
133+
value: kafka-0.broker.kafka.svc.cluster.local:9092
134+
command:
135+
- /bin/bash
136+
- -cex
137+
- >
138+
kafkacat -C -b $BOOTSTRAP -t test-basic-with-kafkacat -o -1 -f '%T;%p;%o;%s\n' -u -d broker |
139+
tee /shared/consumed.tmp
140+
;
141+
volumeMounts:
142+
- name: config
143+
mountPath: /test
144+
- name: shared
145+
mountPath: /shared
67146
- name: testcase
68-
# common test images
69-
#image: solsson/curl@sha256:8b0927b81d10043e70f3e05e33e36fb9b3b0cbfcbccdb9f04fd53f67a270b874
70147
image: solsson/kafkacat@sha256:ebebf47061300b14a4b4c2e1e4303ab29f65e4b95d34af1b14bb8f7ec6da7cef
71-
#image: solsson/kubectl-kafkacat@sha256:3715a7ede3f168f677ee6faf311ff6887aff31f660cfeecad5d87b4f18516321
72148
env:
73149
- name: BOOTSTRAP
74-
#value: kafka-0.broker.kafka.svc.cluster.local:9092,kafka-1.broker.kafka.svc.cluster.local:9092,kafka-2.broker.kafka.svc.cluster.local:9092
75150
value: kafka-0.broker.kafka.svc.cluster.local:9092
76-
- name: ZOOKEEPER
77-
value: zookeeper.kafka.svc.cluster.local:2181
78-
# Test set up
79151
command:
80152
- /bin/bash
81153
- -e
82154
- /test/setup.sh
83-
# Test run, again and again
84155
readinessProbe:
85156
exec:
86157
command:
87158
- /bin/bash
88159
- -e
89-
- /test/run.sh
90-
# Test quit on nonzero exit
160+
- /test/test.sh
161+
initialDelaySeconds: 10
162+
periodSeconds: 10
91163
livenessProbe:
92164
exec:
93165
command:
94166
- /bin/bash
95167
- -e
96-
- /test/continue.sh
168+
- /test/quit-on-nonzero-exit.sh
97169
volumeMounts:
98170
- name: config
99171
mountPath: /test
172+
- name: shared
173+
mountPath: /shared
100174
volumes:
101175
- name: config
102176
configMap:
103-
name: basic-with-kafkacat
177+
name: test-basic-with-kafkacat
178+
- name: shared
179+
emptyDir: {}

0 commit comments

Comments
 (0)