blob: 2c23d2d2d90d0d07808f141115cd2add57e2e002 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
#!/bin/bash
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}=== SeaweedFS PostgreSQL Test Setup ===${NC}"
# Function to wait for service
wait_for_service() {
local service=$1
local max_wait=$2
local count=0
echo -e "${YELLOW}Waiting for $service to be ready...${NC}"
while [ $count -lt $max_wait ]; do
if docker-compose ps $service | grep -q "healthy\|Up"; then
echo -e "${GREEN}✓ $service is ready${NC}"
return 0
fi
sleep 2
count=$((count + 1))
echo -n "."
done
echo -e "${RED}✗ Timeout waiting for $service${NC}"
return 1
}
# Function to show logs
show_logs() {
local service=$1
echo -e "${BLUE}=== $service logs ===${NC}"
docker-compose logs --tail=20 $service
echo
}
# Parse command line arguments
case "$1" in
"start")
echo -e "${YELLOW}Starting SeaweedFS cluster and PostgreSQL server...${NC}"
docker-compose up -d seaweedfs postgres-server
wait_for_service "seaweedfs" 30
wait_for_service "postgres-server" 15
echo -e "${GREEN}✓ SeaweedFS and PostgreSQL server are running${NC}"
echo
echo "You can now:"
echo " • Run data producer: $0 produce"
echo " • Run test client: $0 test"
echo " • Connect with psql: $0 psql"
echo " • View logs: $0 logs [service]"
echo " • Stop services: $0 stop"
;;
"produce")
echo -e "${YELLOW}Creating MQ test data...${NC}"
docker-compose up --build mq-producer
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ Test data created successfully${NC}"
echo
echo "You can now run: $0 test"
else
echo -e "${RED}✗ Data production failed${NC}"
show_logs "mq-producer"
fi
;;
"test")
echo -e "${YELLOW}Running PostgreSQL client tests...${NC}"
docker-compose up --build postgres-client
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ Client tests completed${NC}"
else
echo -e "${RED}✗ Client tests failed${NC}"
show_logs "postgres-client"
fi
;;
"psql")
echo -e "${YELLOW}Connecting to PostgreSQL with psql...${NC}"
docker-compose run --rm psql-cli psql -h postgres-server -p 5432 -U seaweedfs -d default
;;
"logs")
service=${2:-"seaweedfs"}
show_logs "$service"
;;
"status")
echo -e "${BLUE}=== Service Status ===${NC}"
docker-compose ps
;;
"stop")
echo -e "${YELLOW}Stopping all services...${NC}"
docker-compose down
echo -e "${GREEN}✓ All services stopped${NC}"
;;
"clean")
echo -e "${YELLOW}Cleaning up everything (including data)...${NC}"
docker-compose down -v
docker system prune -f
echo -e "${GREEN}✓ Cleanup completed${NC}"
;;
"all")
echo -e "${YELLOW}Running complete test suite...${NC}"
# Start services (wait_for_service ensures they're ready)
$0 start
# Create data (docker-compose up is synchronous)
$0 produce
# Run tests
$0 test
echo -e "${GREEN}✓ Complete test suite finished${NC}"
;;
*)
echo "Usage: $0 {start|produce|test|psql|logs|status|stop|clean|all}"
echo
echo "Commands:"
echo " start - Start SeaweedFS and PostgreSQL server"
echo " produce - Create MQ test data (run after start)"
echo " test - Run PostgreSQL client tests (run after produce)"
echo " psql - Connect with psql CLI"
echo " logs - Show service logs (optionally specify service name)"
echo " status - Show service status"
echo " stop - Stop all services"
echo " clean - Stop and remove all data"
echo " all - Run complete test suite (start -> produce -> test)"
echo
echo "Example workflow:"
echo " $0 all # Complete automated test"
echo " $0 start # Manual step-by-step"
echo " $0 produce"
echo " $0 test"
echo " $0 psql # Interactive testing"
exit 1
;;
esac
|