From a1b02f0b1675acd74f22face0d08873794ba4d59 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=B6ren=20Henning?= <soeren.henning@email.uni-kiel.de>
Date: Thu, 27 Jan 2022 16:24:48 +0100
Subject: [PATCH] Add test runner and tests for UC1

---
 theodolite-benchmarks/docker-test/README.md   | 10 +++++++
 .../docker-test/smoketest-runner.sh           | 28 +++++++++++++++++++
 .../docker-test/uc1-beam-flink/test.sh        | 10 +++++++
 .../docker-test/uc1-beam-samza/test.sh        | 12 ++++++++
 .../docker-test/uc1-flink/test.sh             | 10 +++++++
 .../docker-test/uc1-kstreams/test.sh          | 10 +++++++
 6 files changed, 80 insertions(+)
 create mode 100755 theodolite-benchmarks/docker-test/smoketest-runner.sh
 create mode 100755 theodolite-benchmarks/docker-test/uc1-beam-flink/test.sh
 create mode 100755 theodolite-benchmarks/docker-test/uc1-beam-samza/test.sh
 create mode 100755 theodolite-benchmarks/docker-test/uc1-flink/test.sh
 create mode 100755 theodolite-benchmarks/docker-test/uc1-kstreams/test.sh

diff --git a/theodolite-benchmarks/docker-test/README.md b/theodolite-benchmarks/docker-test/README.md
index fd1e9bf47..3525b2eec 100644
--- a/theodolite-benchmarks/docker-test/README.md
+++ b/theodolite-benchmarks/docker-test/README.md
@@ -36,3 +36,13 @@ the host, for example, from the IDE or Gradle. In such cases, the following adju
 
 You can now connect to Kafka from your host system with bootstrap server `localhost:19092` and contact the Schema
 Registry via `localhost:8081`. **Pay attention to the Kafka port, which is *19092* instead of the default one *9092*.**
+
+## Running Smoke Tests
+
+The `smoketest-runner.sh` script can be used to run a simple test for a specific Docker Compose file. You can call it with
+
+```sh
+./smoketest-runner.sh <docker-compose-dir>
+```
+
+where `<docker-compose-dir>` is the directory of a Docker-Compose file, for example, `uc2-beam-samza`. The script exists with a zero exit code in case of success and a non-zero exit code otherwise.
diff --git a/theodolite-benchmarks/docker-test/smoketest-runner.sh b/theodolite-benchmarks/docker-test/smoketest-runner.sh
new file mode 100755
index 000000000..08093d319
--- /dev/null
+++ b/theodolite-benchmarks/docker-test/smoketest-runner.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+COMPOSE_FILE_PATH=$1
+echo "Run test for '$COMPOSE_FILE_PATH'."
+
+cd $COMPOSE_FILE_PATH
+docker-compose pull
+docker-compose up -d kafka zookeeper schema-registry
+sleep 10s
+docker-compose up -d
+sleep 5s
+docker-compose ps
+sleep 55s
+if test -f "./test.sh"; then
+    ./test.sh
+    RETURN=$?
+else
+    RETURN=$?
+    echo "test.sh does not exists for '$COMPOSE_FILE_PATH'." 
+fi
+if [ $RETURN -eq 0 ]; then
+    echo "Test for '$COMPOSE_FILE_PATH' has passed."
+else
+    echo "Test for '$COMPOSE_FILE_PATH' has failed."
+fi
+
+docker-compose down
+exit $RETURN
diff --git a/theodolite-benchmarks/docker-test/uc1-beam-flink/test.sh b/theodolite-benchmarks/docker-test/uc1-beam-flink/test.sh
new file mode 100755
index 000000000..39952ba39
--- /dev/null
+++ b/theodolite-benchmarks/docker-test/uc1-beam-flink/test.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+docker-compose logs --tail 100 benchmark-taskmanager |
+    sed -n "s/^.*Record:\s\(\S*\)$/\1/p" |
+    tee /dev/tty |
+    jq .identifier |
+    sort |
+    uniq |
+    wc -l |
+    grep "\b10\b"
diff --git a/theodolite-benchmarks/docker-test/uc1-beam-samza/test.sh b/theodolite-benchmarks/docker-test/uc1-beam-samza/test.sh
new file mode 100755
index 000000000..1fdbe9ff9
--- /dev/null
+++ b/theodolite-benchmarks/docker-test/uc1-beam-samza/test.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+docker-compose logs --tail 100 benchmark |
+    sed -n "s/^.*Key:\s\(\S*\), Value:\s\(\S*\).*$/\2/p" |
+    tee /dev/tty |
+    jq .identifier |
+    sort |
+    uniq |
+    wc -l |
+    grep "\b10\b"
+
+
diff --git a/theodolite-benchmarks/docker-test/uc1-flink/test.sh b/theodolite-benchmarks/docker-test/uc1-flink/test.sh
new file mode 100755
index 000000000..b50d0e6d6
--- /dev/null
+++ b/theodolite-benchmarks/docker-test/uc1-flink/test.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+docker-compose logs --tail 100 benchmark-taskmanager |
+    sed -n "s/^.*Key:\s\(\S*\), Value:\s\(\S*\).*$/\1 \2/p" |
+    tee /dev/tty |
+    awk '{print $1}'|
+    sort |
+    uniq |
+    wc -l |
+    grep "\b10\b"
diff --git a/theodolite-benchmarks/docker-test/uc1-kstreams/test.sh b/theodolite-benchmarks/docker-test/uc1-kstreams/test.sh
new file mode 100755
index 000000000..c26a28988
--- /dev/null
+++ b/theodolite-benchmarks/docker-test/uc1-kstreams/test.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+docker-compose logs --tail 100 benchmark |
+    sed -n "s/^.*Record:\s\(\S*\)$/\1/p" |
+    tee /dev/tty |
+    jq .identifier |
+    sort |
+    uniq |
+    wc -l |
+    grep "\b10\b"
-- 
GitLab