1 Star 0 Fork 1

yangbiaoallen / kafka-stack-docker-compose

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
test.sh 2.07 KB
一键复制 编辑 原始数据 按行查看 历史
Stephane Maarek 提交于 2018-08-06 14:11 . remove usage of /etc/hosts (#29)
#!/bin/bash
set -e
export file=$1
#!/bin/bash
f () {
errcode=$? # save the exit code as the first thing done in the trap function
echo "error $errorcode"
echo "the command executing at the time of the error was"
echo "$BASH_COMMAND"
echo "on line ${BASH_LINENO[0]}"
# do some error handling, cleanup, logging, notification
# $BASH_COMMAND contains the command that was being executed at the time of the trap
# ${BASH_LINENO[0]} contains the line number in the script of that command
# exit the script or return to try again, etc.
# creating stack...
docker-compose -f $file down
exit $errcode # or use some other value or do return instead
}
trap f ERR
all_great(){
# for testing
echo "Verifying Process"
running=`docker-compose -f $1 ps | grep Up | wc -l`
if [ "$running" != "$2" ]; then
# for logging
docker-compose -f $1 ps
# debug
docker-compose -f $1 logs
exit 1
fi
}
kafka_tests(){
echo "Testing Kafka"
topic="testtopic"
if grep -q kafka3 $1; then replication_factor="3"; else replication_factor="1"; fi
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 $DOCKER_HOST_IP:2181 && break || sleep 5; done
for x in {1..100}; do echo $x; done | kafka-console-producer --broker-list $DOCKER_HOST_IP:9092 --topic $topic
rows=`kafka-console-consumer --bootstrap-server $DOCKER_HOST_IP:9092 --topic $topic --from-beginning --timeout-ms 2000 | wc -l`
# rows=`kafkacat -C -b $DOCKER_HOST_IP:9092 -t $topic -o beginning -e | wc -l `
if [ "$rows" != "100" ]; then
kafka-console-consumer --bootstrap-server $DOCKER_HOST_IP:9092 --topic test-topic --from-beginning --timeout-ms 2000 | wc -l
exit 1
else
echo "Kafka Test Success"
fi
}
# creating stack...
docker-compose -f $file up -d
sleep 10
# logging
docker-compose -f $file ps
# tests
all_great $1 $2
kafka_tests $1
all_great $1 $2
# teardown
docker-compose -f $file down
echo "Success!"
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yangbiaoallen/kafka-stack-docker-compose.git
git@gitee.com:yangbiaoallen/kafka-stack-docker-compose.git
yangbiaoallen
kafka-stack-docker-compose
kafka-stack-docker-compose
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891