Skip to content

Commit

Permalink
WIP http.kafka.sync
Browse files Browse the repository at this point in the history
  • Loading branch information
attilakreiner committed Apr 29, 2024
1 parent 2250105 commit 9f67235
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 9 deletions.
51 changes: 42 additions & 9 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Test Examples

on: pull_request
#workflow_dispatch
on:
pull_request:
workflow_dispatch:

jobs:
test-tcp-echo:
Expand All @@ -11,17 +12,18 @@ jobs:
uses: actions/checkout@v3
- name: Create k8s Kind Cluster
uses: helm/kind-action@v1
- name: Setup
working-directory: tcp.echo
run: ./setup.sh
- name: Execute Test
working-directory: tcp.echo
run: |
set -o pipefail
./setup.sh
./test.sh | tee -a $GITHUB_STEP_SUMMARY
./test.sh | tee $GITHUB_STEP_SUMMARY
- name: Teardown
if: always()
working-directory: tcp.echo
run: |
./teardown.sh
run: ./teardown.sh

test-tls-echo:
runs-on: ubuntu-latest
Expand All @@ -30,14 +32,45 @@ jobs:
uses: actions/checkout@v3
- name: Create k8s Kind Cluster
uses: helm/kind-action@v1
- name: Setup
working-directory: tls.echo
run: ./setup.sh
- name: Execute Test
working-directory: tls.echo
run: |
set -o pipefail
./setup.sh
./test.sh | tee -a $GITHUB_STEP_SUMMARY
./test.sh | tee $GITHUB_STEP_SUMMARY
- name: Teardown
if: always()
working-directory: tls.echo
run: ./teardown.sh

test-http-kafka-sync:
runs-on: ubuntu-latest
steps:
- name: Install kcat
working-directory: /tmp
run: |
./teardown.sh
set -x
sudo apt-get update
sudo apt-get install librdkafka-dev libyajl-dev
curl -L -o kcat https://github.com/attilakreiner/kcat/releases/download/1.7.1/kcat-linux-$(arch)
chmod +x kcat
sudo mv kcat /usr/local/bin
kcat 2>&1 | grep "Version 1.7.1"
- name: Checkout
uses: actions/checkout@v3
- name: Create k8s Kind Cluster
uses: helm/kind-action@v1
- name: Setup
working-directory: http.kafka.sync
run: ./setup.sh
- name: Execute Test
working-directory: http.kafka.sync
run: |
set -o pipefail
./test.sh | tee $GITHUB_STEP_SUMMARY
- name: Teardown
if: always()
working-directory: http.kafka.sync
run: ./teardown.sh
75 changes: 75 additions & 0 deletions http.kafka.sync/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

# GIVEN
ZILLA_PORT="7114"
KAFKA_PORT="9092"
ITEM_ID="5cf7a1d5-3772-49ef-86e7-ba6f2c7d7d07"
GREETING="Hello, World!"
GREETING_DATE="Hello, World! $(date)"
EXPECTED="{\"greeting\":\"$GREETING_DATE\"}"

echo \# Testing http.kafka.sync
echo ZILLA_PORT=$ZILLA_PORT
echo KAFKA_PORT=$KAFKA_PORT
echo ITEM_ID=$ITEM_ID
echo GREETING=$GREETING
echo GREETING_DATE=$GREETING_DATE
echo EXPECTED=$EXPECTED
echo

# WHEN
# send request to zilla
timeout 300 curl -vs \
-X "PUT" http://localhost:$ZILLA_PORT/items/$ITEM_ID \
-H "Idempotency-Key: 1" \
-H "Content-Type: application/json" \
-d "{\"greeting\":\"$GREETING\"}" | tee .testoutput &

# fetch correlation id from kafka with kcat; retry until ready
for i in $(seq 1 20); do
CORRELATION_ID=$(timeout 10 kcat -C -b localhost:$KAFKA_PORT -t items-requests -J -u | jq -r '.headers | index("zilla:correlation-id") as $index | .[$index + 1]')
if [[ ! -z "$CORRELATION_ID" ]]; then
break
fi
done
echo CORRELATION_ID=$CORRELATION_ID
if [ -z "$CORRELATION_ID" ]; then
echo
exit 1
fi

# push response to kafka with kcat
echo "{\"greeting\":\"$GREETING_DATE\"}" | \
kcat -P \
-b localhost:$KAFKA_PORT \
-t items-responses \
-k "$ITEM_ID" \
-H ":status=200" \
-H "zilla:correlation-id=$CORRELATION_ID"

# fetch the output of zilla request; retry until ready
for i in $(seq 1 20); do
# debug
ls -la
ps
timeout 1 kcat -C -b localhost:9092 -t items-requests -J -u | jq .
timeout 1 kcat -C -b localhost:9092 -t items-responses -J -u | jq .
###
OUTPUT=$(cat .testoutput)
if [[ ! -z "$OUTPUT" ]]; then
break
fi
sleep 10
done
echo
echo OUTPUT=$OUTPUT


# THEN
rm .testoutput
if [ "$OUTPUT" == "$EXPECTED" ]; then
echo
else
echo
exit 1
fi

0 comments on commit 9f67235

Please sign in to comment.