From 0c033f45b835dc4c8f324f1628d78ea2728922a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Busse?= Date: Wed, 3 Mar 2021 22:16:55 +0100 Subject: [PATCH] tests: Improve tests --- Makefile | 3 ++- tests/install_bash_unit.sh | 0 tests/test_hbase_exporter_up.sh | 22 ++++++++++++++++++++++ tests/test_hbase_up.sh | 13 ++++++++++--- 4 files changed, 34 insertions(+), 4 deletions(-) mode change 100644 => 100755 tests/install_bash_unit.sh create mode 100644 tests/test_hbase_exporter_up.sh diff --git a/Makefile b/Makefile index e297b19..83a0bf0 100644 --- a/Makefile +++ b/Makefile @@ -17,9 +17,10 @@ all: protoc -I=/usr/local/include/ --proto_path=. --python_out=$(bindings_path) server/zookeeper/*.proto test: - ./hbase-setup.sh + ./tests/install_bash_unit.sh ./bash_unit ./bash_unit tests/test_hbase_up.sh + ./bash_unit tests/test_hbase_exporter_up.sh clean: rm -rf $(hbase_tmp_path) diff --git a/tests/install_bash_unit.sh b/tests/install_bash_unit.sh old mode 100644 new mode 100755 diff --git a/tests/test_hbase_exporter_up.sh b/tests/test_hbase_exporter_up.sh new file mode 100644 index 0000000..27a4c5f --- /dev/null +++ b/tests/test_hbase_exporter_up.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +setup() { + cd ../ + ./hbase-exporter --zookeeper-server ${ZK_SERVER:-"127.0.0.1:2181"} 2>&1 > /dev/null & + PID=$! + sleep 5 +} + +test_hbase_exporter_up() { + nc -znu -w1 ${1:-"127.0.0.1"} ${2:-"9010"} + curl -s http://127.0.0.1:9010 +} + +test_hbase_exporter_zk_connection() { + r=$(curl -s http://127.0.0.1:9010 | grep '^zookeeper_num_live' | cut -d " " -f2) + assert_not_equals "0.0" "$r" "Zookeeper not live" +} + +teardown() { + kill "$PID" +} diff --git a/tests/test_hbase_up.sh b/tests/test_hbase_up.sh index 583ef5e..2361ce9 100644 --- a/tests/test_hbase_up.sh +++ b/tests/test_hbase_up.sh @@ -7,8 +7,17 @@ ZK_PORT=2181 HBASE_TIME_STARTUP=8 HBASE_VERSION="2.4.1" + +setup_suite() { + export JAVA_HOME=${JAVA_HOME:-"/usr/local"} + PWD=$(pwd) + cd ../ + ./hbase-setup.sh + cd $PWD +} + test_run_hbase() { - cd "../hbase-${HBASE_VERSION}" + cd "hbase-${HBASE_VERSION}" ./bin/hbase-daemon.sh --config conf start $1 sleep ${HBASE_TIME_STARTUP} } @@ -22,5 +31,3 @@ test_hbase_zk_running() { "ruok" END } - -export JAVA_HOME=${JAVA_HOME:-"/usr/local"}