Skip to content

Latest commit

 

History

History
149 lines (106 loc) · 2.53 KB

File metadata and controls

149 lines (106 loc) · 2.53 KB

Testing Guide

Quick Test (Single Node)

1. Run Unit Tests

# All tests
go test ./... -v

# Specific packages
go test ./storage/... -v
go test ./middleware/... -v
go test ./broker/... -v

2. Start Broker

# Terminal 1: Start broker
go run ./cmd/broker -id node-1

# You should see:
# 🚀 Starting Broker Node: node-1
# 📊 Metrics server started on :9090
# ✅ Server ready!

3. Run Demo

# Terminal 2: Run demo client
go run ./examples/demo

# Expected output:
# ✅ Produced message 0 at offset 0
# 📖 Offset 0: Hello, World!
# ...

4. Check Health

curl http://localhost:9090/health
# OK

curl http://localhost:9090/ready
# LEADER (or FOLLOWER)

curl http://localhost:9090/metrics
# Prometheus metrics

Integration Tests

# Run all integration tests (single and multi-node)
go test -v ./tests/integration/... -timeout 180s

# Specific multi-node tests
go test -v ./tests/integration/... -run TestMultiNode

3-Node Cluster Test

Start Cluster

# Terminal 1: Bootstrap node
go run . -id node-1 -grpc-port 8080 -raft-port 9080

# Terminal 2: Join cluster
go run . -id node-2 -grpc-port 8081 -raft-port 9081 -join localhost:8080

# Terminal 3: Join cluster
go run . -id node-3 -grpc-port 8082 -raft-port 9082 -join localhost:8080

Test Cluster

# Produce to leader
go run ./examples/demo

# Kill leader (Ctrl+C in Terminal 1)
# New leader elected automatically

# Produce still works on new leader
go run ./examples/demo

Performance Test

# Throughput test (100k messages)
go test -v -run TestHighThroughput -timeout 2m

# Benchmark storage
go test -bench=. ./storage/...

# Benchmark compression
go test -bench=. ./middleware/...

Manual Testing

Using grpcurl

# Install grpcurl
go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest

# Produce
grpcurl -plaintext -d '{"topic":"test","record":"SGVsbG8="}' \
  localhost:8080 v1.Log/Produce

# Consume
grpcurl -plaintext -d '{"topic":"test","offset":0}' \
  localhost:8080 v1.Log/Consume

# List topics
grpcurl -plaintext -d '{}' \
  localhost:8080 v1.Log/ListTopics

Using Go Client

See examples/demo/main.go for complete example.


Troubleshooting

Broker won't start

  • Check if ports are available: 8080, 9080, 9090
  • Delete data directory: rm -rf data/

Tests failing

  • Ensure no broker is running
  • Clean data: rm -rf data/

Cluster issues

  • Ensure unique node IDs
  • Ensure unique ports
  • Check firewall settings