cd hexfeed-backend
./mvnw spring-boot:runWait until you see: Started FeedSystemDependenciesApplication
cd hexfeed-backend
./test-websocket-automated.sh --autoThis will:
- ✅ Login and get JWT token
- ✅ Open WebSocket test client in browser
- ✅ Guide you through testing
- ✅ Create test posts to verify notifications
-
Open the test client:
open websocket-test-client.html
-
Get JWT token:
curl -X POST http://localhost:8080/api/v1/auth/login \ -H "Content-Type: application/json" \ -d '{"username":"testuser","email":"test@example.com"}' \ | jq -r '.data.token'
-
In the browser:
- Paste the JWT token
- Click "Connect"
- Click "Subscribe to Location"
- You should see confirmation with hex IDs!
-
Create a test post:
TOKEN="your_token_here" curl -X POST http://localhost:8080/api/v1/posts \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $TOKEN" \ -d '{ "content": "Test WebSocket notification!", "latitude": 37.7749, "longitude": -122.4194 }'
-
Watch the browser - you should see the notification appear instantly! 🎉
| Method | Difficulty | Best For | Interactive |
|---|---|---|---|
| HTML Client (Recommended) | ⭐ Easy | Visual testing, demos | ✅ Yes |
| Automated Script | ⭐ Easy | CI/CD, quick verification | |
| Python Client | ⭐⭐ Medium | Automation, scripting | ✅ Yes |
| Browser Console | ⭐⭐ Medium | Quick debugging | ✅ Yes |
| Postman | ⭐⭐⭐ Advanced | API testing workflows | ✅ Yes |
# 1. Login
TOKEN=$(curl -s -X POST http://localhost:8080/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"testuser","email":"test@example.com"}' \
| jq -r '.data.token')
# 2. Open HTML client
open websocket-test-client.html
# 3. Paste token, click Connect
# 4. Click "Subscribe to Location"
# 5. Success! ✅Expected: Connection status shows "Connected", subscription confirmed with 7 hex IDs
# After completing Basic Connection Test:
# Create a post
curl -X POST http://localhost:8080/api/v1/posts \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"content": "🔴 LIVE notification test!",
"latitude": 37.7749,
"longitude": -122.4194
}'
# Watch the browser - notification appears instantly!Expected: Browser shows new post notification within 1-2 seconds
# After connecting and subscribing:
# Just wait and watch the browser
# Every 30 seconds you should see:
# 💓 Heartbeat receivedExpected: Regular heartbeat messages every 30 seconds
# Create 10 posts rapidly
for i in {1..10}; do
curl -s -X POST http://localhost:8080/api/v1/posts \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "{
\"content\": \"Stress test post #$i\",
\"latitude\": 37.7749,
\"longitude\": -122.4194
}" &
done
wait
# Check browser - should receive all 10 notifications!Expected: All 10 notifications received, no drops, no errors
# 1. Subscribe to San Francisco (in browser)
# Lat: 37.7749, Lon: -122.4194
# 2. Create post in SF (should receive)
curl -s -X POST http://localhost:8080/api/v1/posts \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"content": "Post in SF - you SHOULD see this",
"latitude": 37.7749,
"longitude": -122.4194
}'
# 3. Create post in LA (should NOT receive)
curl -s -X POST http://localhost:8080/api/v1/posts \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"content": "Post in LA - you should NOT see this",
"latitude": 34.0522,
"longitude": -118.2437
}'Expected: Only SF post notification received, LA post filtered out
Fix:
# 1. Check if backend is running
curl http://localhost:8080/actuator/health
# 2. If not running, start it
./mvnw spring-boot:run
# 3. Wait for "Started" message, then try againFix:
# Get fresh token
TOKEN=$(curl -s -X POST http://localhost:8080/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"testuser","email":"test@example.com"}' \
| jq -r '.data.token')
echo "Use this token: $TOKEN"Make sure to include "Bearer " prefix in the HTML client!
Fix:
# 1. Check Kafka is running
docker ps | grep kafka
# 2. If not running, start services
docker-compose up -d
# 3. Check backend logs
tail -f logs/hexfeed-backend.log | grep -i "websocket\|kafka"
# 4. Verify subscription
# In browser, click "Get Connection Status"
# Should show: subscribed_hex_count: 7This is expected if heartbeat stops. The client should:
- Send pong response every 30 seconds (automatic in HTML client)
- Reconnect automatically if disconnected
Check browser console for heartbeat messages.
Expected performance metrics:
| Metric | Target | Actual |
|---|---|---|
| Connection Time | < 200ms | ~ |
| Subscription Response | < 300ms | ~ |
| Notification Latency | < 1s | ~ |
| Concurrent Users | 1000+ | ~ |
| Memory per Connection | < 1MB | ~ |
Test your setup:
# Monitor connections
curl http://localhost:8080/actuator/metrics/websocket.connections 2>/dev/null || echo "Actuator not enabled"
# Check logs for performance
tail -f logs/hexfeed-backend.log | grep -i "websocket\|performance"If you prefer command-line testing:
# Install dependencies
pip install websocket-client requests
# Run interactive client
python3 websocket_test_client.py
# Or automated
python3 websocket_test_client.py --autoCommands in Python client:
hexfeed> login # Login and get token
hexfeed> connect # Connect to WebSocket
hexfeed> subscribe 37.7749 -122.4194 # Subscribe to location
hexfeed> post 37.7749 -122.4194 Hello! # Create test post
hexfeed> stats # Show statistics
hexfeed> quit # Exit
Import the Postman collection:
# Location
hexfeed-backend/HexFeed_WebSocket_Testing.postman_collection.json
# Import in Postman
# File > Import > Select the JSON fileTesting flow:
- Run "Setup > Login and Get JWT Token"
- Note: Postman WebSocket support is limited
- Use for REST API testing, HTML client for WebSocket
Mark as complete when verified:
- ✅ Backend starts without errors
- ✅ HTML client opens and loads
- ✅ Login returns JWT token
- ✅ WebSocket connects successfully (green status)
- ✅ Subscription returns 7 hex IDs
- ✅ Notifications received for new posts
- ✅ Heartbeat works (every 30s)
- ✅ Multiple posts all trigger notifications
- ✅ Location filtering works (no notifications from far posts)
- ✅ Reconnection works after disconnect
- ✅ No memory leaks (check with long test)
- ✅ Stress test passes (10 rapid posts)
All checked? 🎉 WebSocket is working perfectly!
After successful WebSocket testing:
- Integration Testing: Test full flow: REST → Kafka → WebSocket
- Load Testing: Test with 100+ concurrent users
- Frontend Integration: Connect React/Vue/Angular app
- Production Setup:
- Enable TLS (wss:// instead of ws://)
- Configure external message broker (RabbitMQ)
- Setup monitoring (Grafana dashboards)
- Mobile Testing: Test with mobile WebSocket clients
- Full Guide: WEBSOCKET_TESTING_GUIDE.md
- API Docs: API_Testing_Guide.md
- Architecture: ../docs/ClassArchitectureDiagram.md
- Check logs:
tail -f logs/hexfeed-backend.log - Review troubleshooting section above
- Check GitHub issues: (if applicable)
- Review Spring WebSocket docs
Happy Testing! 🎉
Remember: Real-time is magical when it works! ✨