Skip to content

Commit 2cc7021

Browse files
committed
Converts (console-) produce-consume test to online ...
style like kafkacat, but without the timestamp diff feature because I couldn't get message timestamp out of the console consumer. Also I had to increase PC_WAIT.
1 parent df056b9 commit 2cc7021

File tree

2 files changed

+168
-117
lines changed

2 files changed

+168
-117
lines changed

test/basic-produce-consume.yml

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

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)