Add idempotency module: Idempotency-Key for POST APIs on Spring Boot 4.1.2 with Redis and Postgres stores
One servlet filter, two interchangeable stores, 18 tests (9 scenarios x 2 stores) against a real redis-server 7.0.15 and PostgreSQL 16.15, and 20 captured transcripts under output/: replay, 422 on a changed body, concurrent duplicates, expiry, the crash window and a handler slower than the lock. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b5yg8grY17JsVAJviV
This commit is contained in:
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regenerates every file under output/.
|
||||
#
|
||||
# ./scripts/run-all.sh
|
||||
#
|
||||
# Needs JDK 25, Maven 3.9, redis-server and redis-cli (7.x) on the PATH, and a PostgreSQL 14+ that
|
||||
# the application can reach (IDEM_DB_URL / IDEM_DB_USER / IDEM_DB_PASSWORD, default
|
||||
# jdbc:postgresql://localhost:5432/idem as idem/idem). The tests start a throwaway redis-server on a
|
||||
# free port; they do truncate the payments and idempotency_keys tables in that database.
|
||||
# Transcripts 01-08 come out of the test suite, so each line in them is an assertion that fails the
|
||||
# build when it stops being true. Transcript 00 is psql, run by scripts/timezone-trap.sh.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
mkdir -p output
|
||||
|
||||
echo "== time zone trap (transcript 00)"
|
||||
./scripts/timezone-trap.sh >/dev/null || true
|
||||
|
||||
echo "== test suite (transcripts 01-08, two stores)"
|
||||
mvn -B test | tee /tmp/idempotency-mvn.log | grep -E '^\[(INFO|WARNING|ERROR)\] Tests run:' | sed 's/^\[[A-Z]*\] //' > output/09-test-summary.txt
|
||||
|
||||
echo
|
||||
echo "output:"
|
||||
ls -1 output
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
# Shows why the tests pin -Duser.timezone=UTC. pgjdbc sends the JVM's default zone to Postgres as
|
||||
# the TimeZone startup parameter. A JVM whose zone is the legacy id Asia/Calcutta then fails with
|
||||
# FATAL: invalid value for parameter "TimeZone": "Asia/Calcutta"
|
||||
# on a Postgres whose tzdata lacks the legacy alias. Needs psql and a database reachable with
|
||||
# IDEM_DB_* (defaults match application.yml). Writes output/00-timezone-trap.txt.
|
||||
set -uo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
mkdir -p output
|
||||
export PGPASSWORD="${IDEM_DB_PASSWORD:-idem}"
|
||||
P=(psql -h "${IDEM_DB_HOST:-localhost}" -U "${IDEM_DB_USER:-idem}" "${IDEM_DB_NAME:-idem}")
|
||||
{
|
||||
echo "\$ psql -c \"SHOW server_version\""
|
||||
"${P[@]}" -t -A -c "SHOW server_version" 2>&1
|
||||
echo
|
||||
echo "\$ psql -c \"SET timezone='Asia/Calcutta'\""
|
||||
"${P[@]}" -c "SET timezone='Asia/Calcutta'" 2>&1
|
||||
echo
|
||||
echo "\$ psql -c \"SET timezone='Asia/Kolkata'\""
|
||||
"${P[@]}" -c "SET timezone='Asia/Kolkata'" 2>&1
|
||||
echo
|
||||
echo "\$ ls /usr/share/zoneinfo/Asia | grep -E 'Calcutta|Kolkata'"
|
||||
ls /usr/share/zoneinfo/Asia | grep -E 'Calcutta|Kolkata'
|
||||
echo
|
||||
echo "\$ dpkg -l tzdata | tail -1"
|
||||
dpkg -l tzdata | tail -1 | awk '{print $2, $3}'
|
||||
} > output/00-timezone-trap.txt
|
||||
cat output/00-timezone-trap.txt
|
||||
Reference in New Issue
Block a user