Logistics Service Step‐by‐Step Guide: Implementing & Testing the - Wiz-DevTech/prettygirllz GitHub Wiki
Step-by-Step Guide: Implementing & Testing the Logistics Service
This guide provides a detailed, step-by-step walkthrough for setting up, running, and testing the Logistics Service Module.
🔧 Step 1: Environment Setup
1.1 Install Prerequisites
✅ Required Software:
- Java 17+ (or Node.js 16+)
- Docker (for databases & messaging)
- PostgreSQL (or MongoDB)
- Kafka (or RabbitMQ)
- Redis (caching)
📌 Install Docker (if missing):
# Linux (Debian/Ubuntu)
sudo apt update && sudo apt install docker.io docker-compose
# Mac (Homebrew)
brew install docker docker-compose
1.2 Clone the Repository
git clone https://github.com/your-repo/logistics-service.git
cd logistics-service
⚙️ Step 2: Configure the Service
2.1 Set Up Environment Variables
Create a .env
file in the root directory:
# Database
DB_URL=jdbc:postgresql://localhost:5432/logistics
DB_USER=admin
DB_PASSWORD=admin123
# Messaging
KAFKA_BROKERS=localhost:9092
# Caching
REDIS_HOST=localhost
REDIS_PORT=6379
# Fraud Detection
FRAUD_DETECTION_ENABLED=true
MAX_RETRIES=3
2.2 Start Dependencies with Docker
docker-compose up -d postgres kafka redis
✅ Verify running containers:
docker ps
(Should show postgres
, kafka
, and redis
containers.)
🚀 Step 3: Run the Logistics Service
3.1 Build & Run (Java/Spring Boot)
./mvnw clean install
./mvnw spring-boot:run
(Server starts at http://localhost:8080
)
3.2 Build & Run (Node.js)
npm install
npm start
(Server starts at http://localhost:3000
)
🧪 Step 4: Testing the Service
4.1 Unit Tests
# Java
./mvnw test
# Node.js
npm test
✅ Expected: All tests pass (✔️ 15/15 tests OK
).
4.2 Integration Tests
# Java
./mvnw verify -Pintegration-test
# Node.js
npm run test:integration
✅ Checks:
- Database connectivity ✅
- Kafka message publishing ✅
- Redis caching ✅
📡 Step 5: API Testing (Manual Verification)
5.1 Test Delivery Routing
Request:
curl -X POST http://localhost:8080/api/deliveries \
-H "Content-Type: application/json" \
-d '{
"orderId": "test123",
"destination": "home",
"address": "123 Main St"
}'
✅ Expected Response:
{
"status": "ROUTED",
"deliveryMethod": "HOME_DELIVERY"
}
5.2 Test Fraud Detection
Trigger a suspicious delivery:
curl -X POST http://localhost:8080/api/fraud/check \
-H "Content-Type: application/json" \
-d '{
"orderId": "fraud-test",
"userId": "user-789",
"location": "unexpected_country"
}'
✅ Expected Response (Blocked):
{
"status": "BLOCKED",
"reason": "Suspicious location"
}
5.3 Test Error Handling
Simulate a failing delivery:
curl -X POST http://localhost:8080/api/deliveries \
-H "Content-Type: application/json" \
-d '{
"orderId": "fail-test",
"destination": "home",
"simulateFailure": true
}'
✅ Expected Behavior:
- Retries 3 times (check logs)
- Falls back to Drop Zone Network
- Logs error in Redis/ELK
📊 Step 6: Monitoring & Logs
6.1 Check Application Logs
# Java (Spring Boot)
tail -f logs/application.log
# Node.js
npm run logs
6.2 Verify Kafka Messages
docker exec -it kafka /bin/kafka-console-consumer \
--bootstrap-server localhost:9092 \
--topic delivery-events
(Should show delivery routing events.)
6.3 Check Redis Cache
docker exec -it redis redis-cli KEYS "*"
🚨 Troubleshooting
Issue | Solution |
---|---|
DB Connection Failed |
Check .env DB credentials |
Kafka Not Responding |
Restart Kafka: docker restart kafka |
Fraud Detection False Positives |
Adjust thresholds in FraudConfig |
High Retry Failures |
Check network connectivity to HDS/DZN |
🎉 Next Steps
- Deploy to Kubernetes/AWS
- Set up Prometheus/Grafana for metrics
- Add CI/CD (GitHub Actions)
✅ Success! Your Logistics Service is now running and testable. 🚀
For issues, refer to the GitHub repo.