Skip to content

Latest commit

 

History

History
303 lines (222 loc) · 6.85 KB

File metadata and controls

303 lines (222 loc) · 6.85 KB

SwiftEats Kafka Platform - Complete Testing Guide

Quick Start (One-Line Commands)

# Start infrastructure
./scripts/setup.sh

# Start services (after infrastructure is ready)
cd docker && docker-compose -f docker-compose.services.yml up -d

# Check health
curl http://localhost:8081/health && curl http://localhost:8082/health && curl http://localhost:8083/health && curl http://localhost:8085/health

Step-by-Step Testing Guide

Step 1: Start Infrastructure

cd /Users/csurukanti/go/src/github.com/swifteats-kafka-platform
./scripts/setup.sh

Wait for all infrastructure containers to start (~2 minutes).

Verify:

docker ps | grep swifteats | wc -l  # Should show ~12 containers

Step 2: Build and Start Services

Option A: Using Docker Compose (Recommended)

cd docker
docker-compose -f docker-compose.services.yml build
docker-compose -f docker-compose.services.yml up -d

Option B: Local Build (if Docker TLS issues)

# Set environment variables
export DB_HOST=localhost
export KAFKA_BOOTSTRAP_SERVERS=localhost:9092,localhost:9094,localhost:9096
export REDIS_HOST=localhost

# Build all services
cd services/order-service && go build -o order-service cmd/order-service/main.go && ./order-service &
cd ../payment-service && go build -o payment-service cmd/payment-service/main.go && ./payment-service &
cd ../driver-service && go build -o driver-service cmd/driver-service/main.go && ./driver-service &
cd ../fraud-detection && go build -o fraud-detection cmd/fraud-detection/main.go && ./fraud-detection &

Step 3: Verify All Services

# Wait for services to start
sleep 30

# Check health endpoints
curl http://localhost:8081/health  # Order Service
curl http://localhost:8082/health  # Payment Service
curl http://localhost:8083/health  # Driver Service
curl http://localhost:8085/health  # Fraud Detection

Expected: {"status":"UP","service":"<service-name>"}


Step 4: Test Order Service

# Create an order
curl -X POST http://localhost:8081/api/orders \
  -H "Content-Type: application/json" \
  -d '{
    "customerId": "d0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
    "restaurantId": "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11",
    "items": [
      {
        "menuItemId": "550e8400-e29b-41d4-a716-446655440001",
        "name": "Classic Burger",
        "quantity": 2,
        "unitPrice": 12.99
      }
    ],
    "deliveryAddress": {
      "street": "123 Main St",
      "city": "San Francisco",
      "state": "CA",
      "zipCode": "94102",
      "latitude": 37.7749,
      "longitude": -122.4194
    },
    "tip": 5.00
  }'

# Get customer's orders
curl http://localhost:8081/api/orders/customer/d0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14

# Verify in database
docker exec -it swifteats-postgres psql -U swifteats -c \
  "SELECT id, customer_id, status, total_amount FROM orders ORDER BY created_at DESC LIMIT 3;"

Step 5: Test Driver Service

# Update driver location
DRIVER_ID="550e8400-e29b-41d4-a716-446655440003"

curl -X POST http://localhost:8083/api/drivers/${DRIVER_ID}/location \
  -H "Content-Type: application/json" \
  -d '{
    "latitude": 37.7749,
    "longitude": -122.4194,
    "speed": 25.5,
    "heading": 180.0
  }'

# Check database
docker exec -it swifteats-postgres psql -U swifteats -c \
  "SELECT id, name, current_latitude, current_longitude, last_location_update FROM drivers;"

Step 6: Test Kafka Message Flow

# View driver location updates
docker exec swifteats-kafka-1 kafka-console-consumer \
  --bootstrap-server kafka-1:29092 \
  --topic swifteats.drivers.location.updates.v1 \
  --from-beginning \
  --max-messages 5

# View order events
docker exec swifteats-kafka-1 kafka-console-consumer \
  --bootstrap-server kafka-1:29092 \
  --topic swifteats.orders.order.events.v1 \
  --from-beginning \
  --max-messages 5

# Access Kafka UI
# Open: http://localhost:8080

Step 7: Test Outbox Pattern

# View outbox events
docker exec -it swifteats-postgres psql -U swifteats -c \
  "SELECT id, aggregate_type, event_type, status, created_at FROM outbox_events ORDER BY created_at DESC LIMIT 10;"

# Check for unpublished events (should be 0)
docker exec -it swifteats-postgres psql -U swifteats -c \
  "SELECT COUNT(*) FROM outbox_events WHERE status = 'PENDING';"

Step 8: Monitoring

# View all logs
docker-compose -f docker-compose.yml -f docker-compose.services.yml logs -f

# View specific service logs
docker logs swifteats-order-service -f
docker logs swifteats-driver-service -f

# Access Grafana (if configured)
# Open: http://localhost:3000 (admin/swifteats)

# Access Kafka UI
# Open: http://localhost:8080

Cleanup

# Stop services only
cd docker
docker-compose -f docker-compose.services.yml down

# Stop everything
docker-compose -f docker-compose.yml -f docker-compose.services.yml down

# Complete cleanup (removes volumes)
docker-compose -f docker-compose.yml -f docker-compose.services.yml down -v

# Or use the teardown script
./scripts/teardown.sh

Troubleshooting

Services not starting

# Check logs
docker logs swifteats-order-service
docker logs swifteats-driver-service

# Check if ports are available
lsof -i :8081
lsof -i :8083

# Rebuild services
cd docker
docker-compose -f docker-compose.services.yml build --no-cache
docker-compose -f docker-compose.services.yml up -d

Kafka issues

# Verify Kafka is running
docker exec swifteats-kafka-1 kafka-broker-api-versions --bootstrap-server kafka-1:29092

# List topics
docker exec swifteats-kafka-1 kafka-topics --bootstrap-server kafka-1:29092 --list

Database issues

# Check PostgreSQL
docker exec swifteats-postgres pg_isready -U swifteats

# Connect to database
docker exec -it swifteats-postgres psql -U swifteats

Advanced Testing

Load Testing

./scripts/load-test.sh

Integration Tests

./scripts/integration-test.sh

Driver Simulator

./scripts/start-driver-simulator.sh

Key Endpoints

Service Port Health Description
Order Service 8081 /health Order management
Payment Service 8082 /health Payment processing
Driver Service 8083 /health Driver tracking
Fraud Detection 8085 /health Fraud analysis
Kafka UI 8080 / Kafka monitoring
PostgreSQL 5432 - Database
Redis 6379 - Cache

Architecture Patterns Demonstrated

Event-Driven Architecture - Kafka-based messaging ✅ Saga Pattern - Distributed transactions ✅ Outbox Pattern - Reliable event publishing ✅ CQRS - Command Query Responsibility Segregation ✅ Event Sourcing - Event-based state management ✅ Microservices - Independent, scalable services


For detailed testing scenarios, see the full guide above.