Skip to content

Commit 8d3f485

Browse files
committed
Merge branch 'bootstrap-test-console-too' into bootstrap-test
2 parents dbf7789 + d0c1440 commit 8d3f485

File tree

3 files changed

+174
-119
lines changed

3 files changed

+174
-119
lines changed

test/basic-produce-consume.yml

Lines changed: 0 additions & 113 deletions
This file was deleted.

test/basic-with-kafkacat.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ data:
2020
2121
UNIQUE="${HOSTNAME}@$(date -u -Ins)"
2222
23-
echo "Test $UNIQUE" >> /shared/produce.tmp
23+
echo "${UNIQUE: -41:5}:Test $UNIQUE" >> /shared/produce.tmp
2424
sleep $PC_WAIT
2525
LAST=$(tail -n 1 /shared/consumed.tmp)
2626
@@ -112,7 +112,7 @@ spec:
112112
spec:
113113
containers:
114114
- name: producer
115-
image: solsson/kafkacat@sha256:ebebf47061300b14a4b4c2e1e4303ab29f65e4b95d34af1b14bb8f7ec6da7cef
115+
image: solsson/kafkacat@sha256:b32eedf936f3cde44cd164ddc77dfcf7565a8af4e357ff6de1abe4389ca530c9
116116
env:
117117
- name: BOOTSTRAP
118118
value: kafka-0.broker.kafka.svc.cluster.local:9092
@@ -123,23 +123,23 @@ spec:
123123
echo "--- start $HOSTNAME $(date --iso-8601='ns' -u) ---" >> /shared/produce.tmp
124124
;
125125
tail -f /shared/produce.tmp |
126-
kafkacat -P -b $BOOTSTRAP -t test-basic-with-kafkacat -v -T -d broker
126+
kafkacat -P -b $BOOTSTRAP -t test-basic-with-kafkacat -v -T -d broker -K ':'
127127
;
128128
volumeMounts:
129129
- name: config
130130
mountPath: /test
131131
- name: shared
132132
mountPath: /shared
133133
- name: consumer
134-
image: solsson/kafkacat@sha256:ebebf47061300b14a4b4c2e1e4303ab29f65e4b95d34af1b14bb8f7ec6da7cef
134+
image: solsson/kafkacat@sha256:b32eedf936f3cde44cd164ddc77dfcf7565a8af4e357ff6de1abe4389ca530c9
135135
env:
136136
- name: BOOTSTRAP
137137
value: kafka-0.broker.kafka.svc.cluster.local:9092
138138
command:
139139
- /bin/bash
140140
- -cex
141141
- >
142-
kafkacat -C -b $BOOTSTRAP -t test-basic-with-kafkacat -o -1 -f '%T;%p;%o;%s\n' -u -d broker |
142+
kafkacat -C -b $BOOTSTRAP -t test-basic-with-kafkacat -o -1 -f '%T;%k:%p;%o;%s\n' -u -d broker |
143143
tee /shared/consumed.tmp
144144
;
145145
volumeMounts:
@@ -148,7 +148,7 @@ spec:
148148
- name: shared
149149
mountPath: /shared
150150
- name: testcase
151-
image: solsson/kafkacat@sha256:ebebf47061300b14a4b4c2e1e4303ab29f65e4b95d34af1b14bb8f7ec6da7cef
151+
image: solsson/kafkacat@sha256:b32eedf936f3cde44cd164ddc77dfcf7565a8af4e357ff6de1abe4389ca530c9
152152
env:
153153
- name: BOOTSTRAP
154154
value: kafka-0.broker.kafka.svc.cluster.local:9092

test/produce-consume.yml

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
---
2+
kind: ConfigMap
3+
metadata:
4+
name: produce-consume
5+
namespace: test-kafka
6+
apiVersion: v1
7+
data:
8+
9+
setup.sh: |-
10+
touch /tmp/testlog
11+
12+
tail -f /tmp/testlog
13+
14+
test.sh: |-
15+
exec >> /tmp/testlog
16+
exec 2>&1
17+
18+
# As low as in kafkacat based test didn't work, but this value can likely be squeezed
19+
PC_WAIT=2.0
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+
[ -z "$LAST" ] && echo "Nothing consumed yet" && exit 1
27+
28+
# Haven't found how to get message timestamp in console-consumer, see kafkacat based test instead
29+
LAST_MSG=$LAST
30+
31+
if [[ "$LAST_MSG" != *"$UNIQUE" ]]; then
32+
echo "Last message (at $(date +%FT%T)) isn't from this test run ($UNIQUE):"
33+
echo "$LAST_MSG"
34+
exit 11
35+
fi
36+
37+
echo "OK ($LAST_MSG at $(date +%FT%T))"
38+
# We haven't asserted that the consumer works, so we'll just have to assume that it will exit if it fails
39+
40+
exit 0
41+
42+
quit-on-nonzero-exit.sh: |-
43+
exec >> /tmp/testlog
44+
exec 2>&1
45+
46+
exit 0
47+
---
48+
apiVersion: batch/v1
49+
kind: Job
50+
metadata:
51+
name: produce-consume
52+
namespace: test-kafka
53+
spec:
54+
template:
55+
spec:
56+
containers:
57+
- name: topic-create
58+
image: solsson/kafka:1.0.0@sha256:17fdf1637426f45c93c65826670542e36b9f3394ede1cb61885c6a4befa8f72d
59+
command:
60+
- ./bin/kafka-topics.sh
61+
- --zookeeper
62+
- zookeeper.kafka.svc.cluster.local:2181
63+
- --create
64+
- --if-not-exists
65+
- --topic
66+
- test-produce-consume
67+
- --partitions
68+
- "1"
69+
- --replication-factor
70+
- "2"
71+
restartPolicy: Never
72+
---
73+
apiVersion: apps/v1beta2
74+
kind: Deployment
75+
metadata:
76+
name: produce-consume
77+
namespace: test-kafka
78+
spec:
79+
replicas: 1
80+
strategy:
81+
type: Recreate
82+
selector:
83+
matchLabels:
84+
test-target: kafka
85+
test-type: readiness
86+
template:
87+
metadata:
88+
labels:
89+
test-target: kafka
90+
test-type: readiness
91+
# for example:
92+
# readonly - can be used in production
93+
# isolated - read/write but in a manner that does not affect other services
94+
# load - unsuitable for production because it uses significant resources
95+
# chaos - unsuitable for production because it injects failure modes
96+
#test-use:
97+
spec:
98+
containers:
99+
- name: producer
100+
image: solsson/kafka:1.0.0@sha256:17fdf1637426f45c93c65826670542e36b9f3394ede1cb61885c6a4befa8f72d
101+
env:
102+
- name: BOOTSTRAP
103+
value: kafka-0.broker.kafka.svc.cluster.local:9092
104+
command:
105+
- /bin/bash
106+
- -cex
107+
- >
108+
echo "--- start $HOSTNAME $(date --iso-8601='ns' -u) ---" >> /shared/produce.tmp
109+
;
110+
tail -f /shared/produce.tmp |
111+
./bin/kafka-console-producer.sh --broker-list $BOOTSTRAP --topic test-produce-consume
112+
;
113+
volumeMounts:
114+
- name: config
115+
mountPath: /test
116+
- name: shared
117+
mountPath: /shared
118+
- name: consumer
119+
image: solsson/kafka:1.0.0@sha256:17fdf1637426f45c93c65826670542e36b9f3394ede1cb61885c6a4befa8f72d
120+
env:
121+
- name: BOOTSTRAP
122+
value: kafka-0.broker.kafka.svc.cluster.local:9092
123+
command:
124+
- /bin/bash
125+
- -cex
126+
- >
127+
./bin/kafka-console-consumer.sh --bootstrap-server $BOOTSTRAP --topic test-produce-consume |
128+
tee /shared/consumed.tmp
129+
;
130+
volumeMounts:
131+
- name: config
132+
mountPath: /test
133+
- name: shared
134+
mountPath: /shared
135+
- name: testcase
136+
image: solsson/kafkacat@sha256:ebebf47061300b14a4b4c2e1e4303ab29f65e4b95d34af1b14bb8f7ec6da7cef
137+
env:
138+
- name: BOOTSTRAP
139+
value: kafka-0.broker.kafka.svc.cluster.local:9092
140+
command:
141+
- /bin/bash
142+
- -e
143+
- /test/setup.sh
144+
readinessProbe:
145+
exec:
146+
command:
147+
- /bin/bash
148+
- -e
149+
- /test/test.sh
150+
initialDelaySeconds: 10
151+
periodSeconds: 10
152+
livenessProbe:
153+
exec:
154+
command:
155+
- /bin/bash
156+
- -e
157+
- /test/quit-on-nonzero-exit.sh
158+
volumeMounts:
159+
- name: config
160+
mountPath: /test
161+
- name: shared
162+
mountPath: /shared
163+
volumes:
164+
- name: config
165+
configMap:
166+
name: produce-consume
167+
- name: shared
168+
emptyDir: {}

0 commit comments

Comments
 (0)