Skip to content

Commit dd20d08

Browse files
authored
travis first pass (#23)
travis tests including kafka integration tests
1 parent 7834283 commit dd20d08

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

.travis.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# this file is only used for GitHub
2+
# it is not related to your Kafka Streams learning
3+
sudo: required
4+
5+
services:
6+
- docker
7+
8+
addons:
9+
hosts:
10+
- kafka1
11+
- kafka2
12+
- kafka3
13+
- zoo1
14+
- zoo2
15+
- zoo3
16+
- kafka-schema-registry
17+
- kafka-schema-registry-ui
18+
- kafka-rest-proxy
19+
- kafka-topics-ui
20+
- kafka-connect-ui
21+
- zoonavigator-web
22+
- zoonavigator-api
23+
24+
# install the kafka binaries
25+
apt:
26+
sources:
27+
- sourceline: 'deb [arch=amd64] https://packages.confluent.io/deb/4.1 stable main'
28+
key_url: 'https://packages.confluent.io/deb/4.1/archive.key'
29+
packages:
30+
- confluent-platform-oss-2.11
31+
# - kafkacat
32+
33+
script:
34+
# test the java components
35+
- ./test.sh zk-single-kafka-single.yml 2
36+
- ./test.sh zk-multiple-kafka-single.yml 4
37+
- ./test.sh zk-single-kafka-multiple.yml 4
38+
- ./test.sh zk-multiple-kafka-multiple.yml 6
39+
- ./test.sh full-stack.yml 10

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[![Build Status](https://travis-ci.org/simplesteph/kafka-stack-docker-compose.svg?branch=master)](https://travis-ci.org/simplesteph/kafka-stack-docker-compose)
2+
3+
14
# kafka-stack-docker-compose
25

36
This replicates as well as possible real deployment configurations, where you have your zookeeper servers and kafka servers actually all distinct from each other. This solves all the networking hurdles that comes with docker-compose, and is compatible cross platform. It only requires an update to your host files.

test.sh

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
set -e
3+
4+
export file=$1
5+
#!/bin/bash
6+
f () {
7+
errcode=$? # save the exit code as the first thing done in the trap function
8+
echo "error $errorcode"
9+
echo "the command executing at the time of the error was"
10+
echo "$BASH_COMMAND"
11+
echo "on line ${BASH_LINENO[0]}"
12+
# do some error handling, cleanup, logging, notification
13+
# $BASH_COMMAND contains the command that was being executed at the time of the trap
14+
# ${BASH_LINENO[0]} contains the line number in the script of that command
15+
# exit the script or return to try again, etc.
16+
# creating stack...
17+
docker-compose -f $file down
18+
exit $errcode # or use some other value or do return instead
19+
}
20+
trap f ERR
21+
22+
all_great(){
23+
# for testing
24+
echo "Verifying Process"
25+
running=`docker-compose -f $1 ps | grep Up | wc -l`
26+
if [ "$running" != "$2" ]; then
27+
# for logging
28+
docker-compose -f $1 ps
29+
# debug
30+
docker-compose -f $1 logs
31+
exit 1
32+
fi
33+
}
34+
35+
kafka_tests(){
36+
echo "Testing Kafka"
37+
topic="testtopic"
38+
if grep -q kafka3 $1; then replication_factor="3"; else replication_factor="1"; fi
39+
for i in 1 2 3 4 5; do echo "trying to create test topic" && kafka-topics --create --topic $topic --replication-factor $replication_factor --partitions 12 --zookeeper localhost:2181 && break || sleep 5; done
40+
for x in {1..100}; do echo $x; done | kafka-console-producer --broker-list localhost:9092 --topic $topic
41+
rows=`kafka-console-consumer --bootstrap-server localhost:9092 --topic $topic --from-beginning --timeout-ms 2000 | wc -l`
42+
# rows=`kafkacat -C -b localhost:9092 -t $topic -o beginning -e | wc -l `
43+
if [ "$rows" != "100" ]; then
44+
kafka-console-consumer --bootstrap-server localhost:9092 --topic test-topic --from-beginning --timeout-ms 2000 | wc -l
45+
exit 1
46+
else
47+
echo "Kafka Test Success"
48+
fi
49+
}
50+
51+
# creating stack...
52+
docker-compose -f $file up -d
53+
sleep 10
54+
# logging
55+
docker-compose -f $file ps
56+
# tests
57+
all_great $1 $2
58+
kafka_tests $1
59+
all_great $1 $2
60+
# teardown
61+
docker-compose -f $file down
62+
echo "Success!"

0 commit comments

Comments
 (0)