#!/usr/bin/env bash # Regenerates every file in gatling-spring-boot/output/. # Needs JDK 25 and Maven on the PATH and python3 (standard library only). # k6 is optional: set K6=/path/to/k6 or have it on the PATH; without it the k6 steps are skipped. # Takes about 6 minutes: no single load run is longer than ~70 seconds. set -euo pipefail cd "$(dirname "$0")/.." PORT="${PORT:-18300}" export APP_URL="http://localhost:${PORT}" K6="${K6:-$(command -v k6 || true)}" OUT=output JAR=target/gatling-spring-boot-lab-1.0.0.jar # keep transcripts free of JVM launcher noise that varies per machine filter() { grep -vE '^(Picked up JAVA_TOOL_OPTIONS|WARNING: )' || true; } rm -f "$OUT"/*.txt "$OUT"/*.json "$OUT"/*.svg mkdir -p "$OUT" # 1. unit test: the capacity limit the whole post relies on (writes output/01-saturation-test.txt) mvn -B -q clean test 2>&1 | filter # 2. build and start the app under test mvn -B -q package -DskipTests 2>&1 | filter mkdir -p target/k6 PORT="$PORT" java -jar "$JAR" > target/app.log 2>&1 & APP_PID=$! trap 'kill $APP_PID 2>/dev/null || true' EXIT for _ in $(seq 1 60); do curl -fs "$APP_URL/api/stats" > /dev/null 2>&1 && break sleep 1 done curl -fs "$APP_URL/api/quote/ORCL" > "$OUT/02-single-request.txt"; echo >> "$OUT/02-single-request.txt" # 3. Gatling runs, one simulation per mvn invocation gatling() { # mvn -B test-compile gatling:test -Dgatling.simulationClass="lab.gatling.$2" 2>&1 | filter > "$OUT/$1" } gatling 03-basic-console.txt BasicSimulation gatling 04-knee-steps-console.txt KneeStepsSimulation python3 scripts/analyze.py gatling "$(ls -dt target/gatling/kneestepssimulation-* | head -1)" gatling 06-knee-ramp-console.txt KneeRampSimulation gatling 07-closed-model-console.txt ClosedModelSimulation # 4. the run that must fail the build; keep going, record Maven's exit code set +e gatling 05-failing-assertion-console.txt FailingAssertionSimulation echo "maven exit code: ${PIPESTATUS[0]}" > "$OUT/05b-failing-assertion-exit.txt" set -e # 5. k6, same app, same profile if [ -n "$K6" ]; then "$K6" version > "$OUT/20-k6-version.txt" "$K6" run --quiet --out json=target/k6/knee.json k6/knee.js > "$OUT/22-k6-knee-console.txt" 2>&1 python3 scripts/analyze.py k6 target/k6/knee.json set +e "$K6" run --quiet k6/threshold-fail.js > "$OUT/23-k6-threshold-fail-console.txt" 2>&1 echo "k6 exit code: $?" > "$OUT/23b-k6-threshold-fail-exit.txt" set -e else echo "k6 not found: skipping k6 steps" >&2 fi python3 scripts/analyze.py chart echo "done: $(ls "$OUT" | wc -l) files in $OUT/"